line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::GitHooks::Plugin::RequireCommitMessage; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
725612
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
116
|
|
4
|
4
|
|
|
4
|
|
13
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
93
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
14
|
use base 'App::GitHooks::Plugin'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
633
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Internal dependencies. |
9
|
4
|
|
|
4
|
|
733
|
use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); |
|
4
|
|
|
|
|
3037
|
|
|
4
|
|
|
|
|
471
|
|
10
|
4
|
|
|
4
|
|
664
|
use App::GitHooks::Utils; |
|
4
|
|
|
|
|
2249
|
|
|
4
|
|
|
|
|
581
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
App::GitHooks::Plugin::RequireCommitMessage - Require a commit message. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
If you are using C, commit messages |
21
|
|
|
|
|
|
|
will need to include a ticket ID but the rest of the commit message can be |
22
|
|
|
|
|
|
|
empty. To prevent this, this plugin looks at the commit message, excluding the |
23
|
|
|
|
|
|
|
ticket ID, and requires that it is not empty before allowing the commit to go |
24
|
|
|
|
|
|
|
through. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 VERSION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Version 1.1.0 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our $VERSION = '1.1.0'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 run_commit_msg() |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Code to execute as part of the commit-msg hook. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $success = App::GitHooks::Plugin::RequireCommitMessage->run_commit_msg(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub run_commit_msg |
47
|
|
|
|
|
|
|
{ |
48
|
3
|
|
|
3
|
1
|
11769
|
my ( $class, %args ) = @_; |
49
|
3
|
|
|
|
|
7
|
my $commit_message = delete( $args{'commit_message'} ); |
50
|
3
|
|
|
|
|
5
|
my $app = delete( $args{'app'} ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Note: this allows catching the case where the ticket ID prefix was |
53
|
|
|
|
|
|
|
# auto-generated, but no message was entered by the user. |
54
|
3
|
|
|
|
|
14
|
my $summary = $commit_message->get_summary(); |
55
|
3
|
|
|
|
|
84
|
my $ticket_regex = App::GitHooks::Utils::get_ticket_id_from_commit_regex( $app ); |
56
|
3
|
50
|
|
|
|
232
|
$summary =~ s/$ticket_regex//i |
57
|
|
|
|
|
|
|
if defined( $ticket_regex ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# We must have a message. |
60
|
3
|
100
|
33
|
|
|
21
|
if ( !defined( $summary ) || ( $summary !~ /\w/ ) ) |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
|
|
10
|
my $failure_character = $app->get_failure_character(); |
63
|
1
|
|
|
|
|
22
|
print $app->color( 'red', $failure_character . " You did not enter a commit message.\n" ); |
64
|
1
|
|
|
|
|
21
|
return $PLUGIN_RETURN_FAILED; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
5
|
return $PLUGIN_RETURN_PASSED; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 BUGS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
74
|
|
|
|
|
|
|
L. |
75
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
76
|
|
|
|
|
|
|
your bug as I make changes. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SUPPORT |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
perldoc App::GitHooks::Plugin::RequireCommitMessage |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
You can also look for information at: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * GitHub's request tracker |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * CPAN Ratings |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * MetaCPAN |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L, |
112
|
|
|
|
|
|
|
C<< >>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright 2013-2015 Guillaume Aubert. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under |
120
|
|
|
|
|
|
|
the terms of the GNU General Public License version 3 as published by the Free |
121
|
|
|
|
|
|
|
Software Foundation. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
124
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
125
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with |
128
|
|
|
|
|
|
|
this program. If not, see http://www.gnu.org/licenses/ |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |