Skip to content

Commit 72a8bff

Browse files
committed
fix: ignoring multiline merge commit message (#20)
1 parent e818b15 commit 72a8bff

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

lib/src/is_ignored.dart

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
bool isIgnored(String message,
22
{bool? defaultIgnores, Iterable<String>? ignores}) {
3-
final base = defaultIgnores == false ? [] : wildcards;
4-
return [...base, ...?ignores?.map(ignore)].any((mathcer) => mathcer(message));
3+
return [if (defaultIgnores != false) ..._wildcards, ...?ignores]
4+
.any((pattern) => RegExp(pattern).hasMatch(message));
55
}
66

7-
final wildcards = [
8-
ignore(
9-
r'((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)'),
10-
ignore(r'(Merge tag (.*?))(?:\r?\n)*$'),
11-
ignore(r'(R|r)evert (.*)'),
12-
ignore(r'(fixup|squash)!'),
13-
ignore(r'(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))'),
14-
ignore(r'Merge remote-tracking branch(\s*)(.*)'),
15-
ignore(r'Automatic merge(.*)'),
16-
ignore(r'Auto-merged (.*?) into (.*)'),
7+
final _wildcards = [
8+
r'((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*)',
9+
r'(Merge tag (.*?))(?:\r?\n)*$',
10+
r'(R|r)evert (.*)',
11+
r'(fixup|squash)!',
12+
r'(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))',
13+
r'Merge remote-tracking branch(\s*)(.*)',
14+
r'Automatic merge(.*)',
15+
r'Auto-merged (.*?) into (.*)',
1716
];
18-
19-
Matcher ignore(String pattern) =>
20-
(String message) => RegExp(pattern).hasMatch(message);
21-
22-
typedef Matcher = bool Function(String);

test/ignore_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:commitlint_cli/src/lint.dart';
2+
import 'package:commitlint_cli/src/types/rule.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
test('Should ignore configurated multi-line merge message', () async {
7+
final message = '''Merge branch 'develop' into feature/xyz
8+
9+
# Conflicts:
10+
# xyz.yaml
11+
''';
12+
final result = await lint(
13+
message,
14+
{
15+
'type-empty': Rule(
16+
severity: RuleSeverity.error,
17+
condition: RuleCondition.never,
18+
),
19+
},
20+
defaultIgnores: true);
21+
expect(result.valid, true);
22+
expect(result.input, equals(message));
23+
});
24+
}

0 commit comments

Comments
 (0)