Skip to content

Commit bf81b1a

Browse files
committed
CheckJira: Implement the skip-logs directive
Issue: #58
1 parent eb9b7f0 commit bf81b1a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/Git/Hooks/CheckJira.pm

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Log::Any '$log';
99
use Git::Hooks;
1010
use Git::Repository::Log;
1111
use Path::Tiny;
12-
use List::MoreUtils qw/last_index uniq/;
12+
use List::MoreUtils qw/any last_index uniq/;
1313

1414
my $PKG = __PACKAGE__;
1515
my $CFG = __PACKAGE__ =~ s/.*::/githooks./r;
@@ -32,6 +32,8 @@ sub _setup_config {
3232
$default->{require} //= ['true'];
3333
$default->{unresolved} //= ['true'];
3434

35+
push $default->{'skip-logs'}->@*, qr/^(?:Merge|Reapply|Revert) /;
36+
3537
return;
3638
}
3739

@@ -124,6 +126,14 @@ sub _jql_query {
124126
return $cache->{jql}{$jql};
125127
}
126128

129+
sub _skip_logs {
130+
my ($git, $commit) = @_;
131+
132+
state $regexes = [map {qr/$_/} $git->get_config($CFG => 'skip-logs')];
133+
my $message = $commit->message;
134+
return any {$message =~ $_} @$regexes;
135+
}
136+
127137
sub _disconnect_jira {
128138
my ($git) = @_;
129139
delete $git->cache($PKG)->{jira};
@@ -378,6 +388,8 @@ sub check_commit_msg {
378388

379389
if ($commit->parent() > 1 && $git->get_config_boolean($CFG => 'skip-merges')) {
380390
return 1;
391+
} elsif (_skip_logs($git, $commit)) {
392+
return 1;
381393
} else {
382394
return _check_jira_keys($git, $commit, $ref, uniq(grok_msg_jiras($git, $commit->message)));
383395
}
@@ -952,6 +964,15 @@ In this case, the visibility isn't restricted at all.
952964
953965
=back
954966
967+
=head2 skip-logs REGEXP
968+
969+
Use this multi-valued directive to make CheckJira don't check
970+
commits which log messages match any of the REGEXes specified with it.
971+
972+
By default, CheckJira already skips commits with messages matching the REGEXP
973+
C<qr/^(?:Merge|Reapply|Revert) />, which most probably were created by git-merge
974+
and git-revert commands.
975+
955976
=head2 skip-merges BOOL
956977
957978
By default, all commits are checked. You can exempt merge commits from being

0 commit comments

Comments
 (0)