| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::GitHooks::Plugin::RequireTicketID; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
476436
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
81
|
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
107
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
14
|
use base 'App::GitHooks::Plugin'; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
631
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Internal dependencies. |
|
9
|
3
|
|
|
3
|
|
771
|
use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); |
|
|
3
|
|
|
|
|
4047
|
|
|
|
3
|
|
|
|
|
894
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
App::GitHooks::Plugin::RequireTicketID - Require a ticket ID in the commit message. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
If you are using a ticketing system, it is very useful to make sure that all |
|
20
|
|
|
|
|
|
|
your commit messages include a ticket ID to provide more context into why the |
|
21
|
|
|
|
|
|
|
code is being changed. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 VERSION |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Version 1.1.0 |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '1.1.0'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 CONFIGURATION OPTIONS |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This plugin supports the following options in the main section of your |
|
36
|
|
|
|
|
|
|
C<.githooksrc> file. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
project_prefixes = OPS, DEV |
|
39
|
|
|
|
|
|
|
extract_ticket_id_from_commit = /^($project_prefixes-\d+|--): / |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 project_prefixes |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
A comma-separated list of project prefixes, in case you want to use this in |
|
45
|
|
|
|
|
|
|
C or C. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
project_prefixes = OPS, DEV |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 extract_ticket_id_from_commit |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
A regular expression with _one_ capturing group that will be applied to the |
|
53
|
|
|
|
|
|
|
first line of a commit message to extract the ticket ID referenced, if there is |
|
54
|
|
|
|
|
|
|
one. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
extract_ticket_id_from_commit = /^($project_prefixes-\d+|--): / |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 run_commit_msg() |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Code to execute as part of the commit-msg hook. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $success = App::GitHooks::Plugin::RequireTicketID->run_commit_msg(); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub run_commit_msg |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
2
|
|
|
2
|
1
|
7976
|
my ( $class, %args ) = @_; |
|
72
|
2
|
|
|
|
|
4
|
my $commit_message = delete( $args{'commit_message'} ); |
|
73
|
2
|
|
|
|
|
2
|
my $app = delete( $args{'app'} ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# We must have a ticket ID. |
|
76
|
2
|
|
|
|
|
9
|
my $ticket_id = $commit_message->get_ticket_id(); |
|
77
|
2
|
100
|
|
|
|
253
|
if ( !defined( $ticket_id ) ) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
1
|
|
|
|
|
4
|
my $failure_character = $app->get_failure_character(); |
|
80
|
1
|
|
|
|
|
10
|
my $indent = ' '; |
|
81
|
1
|
|
|
|
|
5
|
print $app->color( 'red', $failure_character . " Your commit message needs to start with a ticket ID.\n" ); |
|
82
|
1
|
|
|
|
|
18
|
return $PLUGIN_RETURN_FAILED; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
3
|
return $PLUGIN_RETURN_PASSED; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 BUGS |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
|
92
|
|
|
|
|
|
|
L. |
|
93
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
|
94
|
|
|
|
|
|
|
your bug as I make changes. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SUPPORT |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
perldoc App::GitHooks::Plugin::RequireTicketID |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
You can also look for information at: |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * GitHub's request tracker |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * MetaCPAN |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L, |
|
130
|
|
|
|
|
|
|
C<< >>. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright 2013-2017 Guillaume Aubert. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This code is free software; you can redistribute it and/or modify it under the |
|
138
|
|
|
|
|
|
|
same terms as Perl 5 itself. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY |
|
141
|
|
|
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
142
|
|
|
|
|
|
|
PARTICULAR PURPOSE. See the LICENSE file for more details. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |