Skip to content

Commit

Permalink
fix: commit scopes that contain "-" should be treated as valid scopes (
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar authored Mar 30, 2023
1 parent d1fd8d1 commit 615c208
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/conventional_commit/lib/conventional_commit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
final _mergeCommitPrefixRegex = RegExp('^Merged? (.*?:)?');

final _conventionalCommitHeaderRegex = RegExp(
r'(?<type>[a-zA-Z0-9_]+)(\((?<scope>[a-zA-Z0-9_,\s\*]+)\))?(?<breaking>!)?: ?(?<description>.+)',
r'(?<type>[a-zA-Z0-9_]+)(\((?<scope>[a-zA-Z0-9\-_,\s\*]+)\))?(?<breaking>!)?: ?(?<description>.+)',
);

final _breakingChangeRegex =
Expand Down
27 changes: 27 additions & 0 deletions packages/conventional_commit/test/conventional_commit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ feat(*): a new something (#1234)
This also fixes an issue something else.
''';

const commitMessageHyphenScope = '''
feat(remote-config)!: add support for onConfigUpdated (#10647)
This PR is a breaking change for Remote Config since we're removing the ChangeNotifier mixin that came with FirebaseRemoteConfig. You should handle the state of the RemoteConfig using your own state provider.
''';

void main() {
group('$ConventionalCommit', () {
test('invalid commit messages', () {
Expand Down Expand Up @@ -121,6 +127,27 @@ void main() {
expect(commit.scopes, equals(['*']));
});

test('correctly handles messages with a scope that contains "-"', () {
final commit = ConventionalCommit.tryParse(commitMessageHyphenScope);
expect(commit, isNotNull);
expect(
commit!.description,
equals('add support for onConfigUpdated (#10647)'),
);
expect(
commit.body,
equals(
"This PR is a breaking change for Remote Config since we're removing "
'the ChangeNotifier mixin that came with FirebaseRemoteConfig. You '
'should handle the state of the RemoteConfig using your own state '
'provider.',
),
);
expect(commit.type, equals('feat'));
expect(commit.isBreakingChange, equals(true));
expect(commit.scopes, equals(['remote-config']));
});

test('header', () {
expect(
ConventionalCommit.tryParse('docs: foo bar')!.header,
Expand Down

0 comments on commit 615c208

Please sign in to comment.