| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::GitHooks::Plugin::RequireCommitMessage; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 717075 | use strict; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 93 |  | 
| 4 | 4 |  |  | 4 |  | 15 | use warnings; | 
|  | 4 |  |  |  |  | 4 |  | 
|  | 4 |  |  |  |  | 87 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 13 | use base 'App::GitHooks::Plugin'; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 695 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | # Internal dependencies. | 
| 9 | 4 |  |  | 4 |  | 747 | use App::GitHooks::Constants qw( :PLUGIN_RETURN_CODES ); | 
|  | 4 |  |  |  |  | 3891 |  | 
|  | 4 |  |  |  |  | 461 |  | 
| 10 | 4 |  |  | 4 |  | 480 | use App::GitHooks::Utils; | 
|  | 4 |  |  |  |  | 3091 |  | 
|  | 4 |  |  |  |  | 644 |  | 
| 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.2.0 | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =cut | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | our $VERSION = '1.2.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 | 11147 | my ( $class, %args ) = @_; | 
| 49 | 3 |  |  |  |  | 5 | my $commit_message = delete( $args{'commit_message'} ); | 
| 50 | 3 |  |  |  |  | 6 | 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 |  |  |  |  | 13 | my $summary = $commit_message->get_summary(); | 
| 55 | 3 |  |  |  |  | 81 | my $ticket_regex = App::GitHooks::Utils::get_ticket_id_from_commit_regex( $app ); | 
| 56 | 3 | 50 |  |  |  | 273 | $summary =~ s/$ticket_regex//i | 
| 57 |  |  |  |  |  |  | if defined( $ticket_regex ); | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | # We must have a message. | 
| 60 | 3 | 100 | 33 |  |  | 22 | if ( !defined( $summary ) || ( $summary !~ /\w/ ) ) | 
| 61 |  |  |  |  |  |  | { | 
| 62 | 1 |  |  |  |  | 6 | my $failure_character = $app->get_failure_character(); | 
| 63 | 1 |  |  |  |  | 16 | print $app->color( 'red', $failure_character . " You did not enter a commit message.\n" ); | 
| 64 | 1 |  |  |  |  | 19 | return $PLUGIN_RETURN_FAILED; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 2 |  |  |  |  | 6 | 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-2017 Guillaume Aubert. | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | This code is free software; you can redistribute it and/or modify it under the | 
| 120 |  |  |  |  |  |  | same terms as Perl 5 itself. | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | This program is distributed in the hope that it will be useful, but WITHOUT ANY | 
| 123 |  |  |  |  |  |  | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | 
| 124 |  |  |  |  |  |  | PARTICULAR PURPOSE. See the LICENSE file for more details. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =cut | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | 1; |