App::GitHooks::Plugin::MatchBranchTicketID - Detect discrepancies between the ticket ID specified by the branch name and the one in the commit message.
App::GitHooks::Plugin::PrependTicketID
allows pulling ticket IDs from the branch name.
This way,
if you're committing a lot,
having a proper branch name can save you a lot of time.
That said, you sometimes need to commit using a different ticket ID than what the branch specifies. In order to prevent typos, this plugin will detect if the ticket ID specified in the commit message doesn't match the ticket ID infered from the branch name, and ask you to confirm that you want to proceed forward.
Version 1.0.2
This plugin supports the following options in the main section of your .githooksrc
file.
project_prefixes = OPS, DEV, TEST extract_ticket_id_from_branch = /^($project_prefixes\d+)/ normalize_branch_ticket_id = s/^(.*?)(\d+)$/\U$1-$2/ extract_ticket_id_from_commit = /^($project_prefixes-\d+|--): /
The list of valid ticket prefixes.
project_prefixes = OPS, DEV, TEST
A regular expression with one capturing group that will extract the ticket ID from a branch name.
extract_ticket_id_from_branch = /^($project_prefixes\d+)/
In the example above, if a branch is named dev1293_my_new_feature
, the regular expression will identify dev1293
as the ticket ID corresponding to that branch.
Note that:
dev1293_my_new_feature
and ga/dev1293_my_new_feature
will be identified as tied to dev1293
with the regex above.project_prefixes
configuration option, to avoid duplication of information.A replacement expression to normalize the ticket ID extracted with extract_ticket_id_from_branch
.
normalize_branch_ticket_id = s/^(.*?)(\d+)$/\U$1-$2/
In the example above, dev1293_my_new_feature
gave dev1293
, which is then normalized as DEV-1293
.
A regular expression with one capturing group that will extract the ticket ID from a commit message.
extract_ticket_id_from_commit = /^($project_prefixes-\d+|--): /
Note that:
project_prefixes
configuration option, to avoid duplication of information.--
to indicate that no ticket ID is available. This allows an occasional commit without a ticket ID, while making it easy to identify / review later. But you can configure this regular expression to use NONE
or any other keyword instead.Code to execute as part of the commit-msg hook.
my $success = App::GitHooks::Plugin::MatchBranchTicketID->run_commit_msg();
Please report any bugs or feature requests through the web interface at https://github.com/guillaumeaubert/App-GitHooks-Plugin-MatchBranchTicketID/issues/new. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::GitHooks::Plugin::MatchBranchTicketID
You can also look for information at:
https://github.com/guillaumeaubert/App-GitHooks-Plugin-MatchBranchTicketID/issues
http://annocpan.org/dist/app-githooks-plugin-matchbranchticketid
http://cpanratings.perl.org/d/app-githooks-plugin-matchbranchticketid
https://metacpan.org/release/App-GitHooks-Plugin-MatchBranchTicketID
Guillaume Aubert, <aubertg at cpan.org>
.
Copyright 2013-2016 Guillaume Aubert.
This code is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file for more details.