Skip to content

Commit af9f787

Browse files
committed
CheckJira: Implement the skip-logs directive
Issue: #58
1 parent 10cc15e commit af9f787

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lib/Git/Hooks/CheckJira.pm

+26-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;
@@ -124,6 +124,16 @@ sub _jql_query {
124124
return $cache->{jql}{$jql};
125125
}
126126

127+
sub _skip_logs {
128+
my ($git, $commit) = @_;
129+
130+
my $cache = $git->cache($PKG);
131+
$cache->{skip_logs_regexes} = [map {qr/$_/} $git->get_config($CFG => 'skip-logs')]
132+
unless exists $cache->{skip_logs_regexes};
133+
my $message = $commit->message;
134+
return any {$message =~ $_} $cache->{skip_logs_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
}
@@ -572,6 +584,11 @@ may configure it in a Git configuration file like this:
572584
# fixVersion named after the same major.minor version number.
573585
fixversion = ^refs/heads/(\\d+\\.\\d+)\\. ^$+
574586
587+
# Skip commits created by git-merge
588+
skip-logs = ^Merge\\s
589+
# Skip commits created by git-revert
590+
skip-logs = ^(?:Reapply|Revert)\\s
591+
575592
=head1 DESCRIPTION
576593
577594
This L<Git::Hooks> plugin hooks itself to the hooks below to guarantee that
@@ -952,6 +969,14 @@ In this case, the visibility isn't restricted at all.
952969
953970
=back
954971
972+
=head2 skip-logs REGEXP
973+
974+
Use this multi-valued directive to make CheckJira don't check
975+
commits which log messages match any of the REGEXes specified with it.
976+
977+
As the examples in the L<SYNOPSIS> section shows, you may want to make CheckJira
978+
skip commits automatically created by C<git-merge> or C<git-revert> commands.
979+
955980
=head2 skip-merges BOOL
956981
957982
By default, all commits are checked. You can exempt merge commits from being

0 commit comments

Comments
 (0)