| 1 | package App::GitHooks::Plugin::RequireTicketID; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use base 'App::GitHooks::Plugin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # Internal dependencies. | ||||||||||
| 9 | 3 | ▶ | use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 3 | 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<extract_ticket_id_from_commit> or C<extract_ticket_id_from_branch>. | ||||||||||
| 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 | 2 | ▶ | { | ||||||||
|
Subroutine
run_commit_msg: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 71 | 2 | my ( $class, %args ) = @_; | |||||||||
| 72 | 2 | my $commit_message = delete( $args{'commit_message'} ); | |||||||||
| 73 | 2 | my $app = delete( $args{'app'} ); | |||||||||
| 74 | |||||||||||
| 75 | # We must have a ticket ID. | ||||||||||
| 76 | 2 | my $ticket_id = $commit_message->get_ticket_id(); | |||||||||
| 77 | 2 | ▶ | if ( !defined( $ticket_id ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | { | ||||||||||
| 79 | 1 | my $failure_character = $app->get_failure_character(); | |||||||||
| 80 | 1 | my $indent = ' '; | |||||||||
| 81 | 1 | print $app->color( 'red', $failure_character . " Your commit message needs to start with a ticket ID.\n" ); | |||||||||
| 82 | 1 | return $PLUGIN_RETURN_FAILED; | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 1 | 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<https://github.com/guillaumeaubert/App-GitHooks-Plugin-RequireTicketID/issues/new>. | ||||||||||
| 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<https://github.com/guillaumeaubert/App-GitHooks-Plugin-RequireTicketID/issues> | ||||||||||
| 111 | |||||||||||
| 112 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 113 | |||||||||||
| 114 | L<http://annocpan.org/dist/app-githooks-plugin-requireticketid> | ||||||||||
| 115 | |||||||||||
| 116 | =item * CPAN Ratings | ||||||||||
| 117 | |||||||||||
| 118 | L<http://cpanratings.perl.org/d/app-githooks-plugin-requireticketid> | ||||||||||
| 119 | |||||||||||
| 120 | =item * MetaCPAN | ||||||||||
| 121 | |||||||||||
| 122 | L<https://metacpan.org/release/App-GitHooks-Plugin-RequireTicketID> | ||||||||||
| 123 | |||||||||||
| 124 | =back | ||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | =head1 AUTHOR | ||||||||||
| 128 | |||||||||||
| 129 | L<Guillaume Aubert|https://metacpan.org/author/AUBERTG>, | ||||||||||
| 130 | C<< <aubertg at cpan.org> >>. | ||||||||||
| 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 | 3 | 1; | |||||||||