SVN::Hooks::CheckJira(3pm) | User Contributed Perl Documentation | SVN::Hooks::CheckJira(3pm) |
SVN::Hooks::CheckJira - Integrate Subversion with the JIRA ticketing system.
version 1.36
This SVN::Hooks plugin requires that any Subversion commits affecting some parts of the repository structure must make reference to valid JIRA issues in the commit log message. JIRA issues are referenced by their keys which consists of a sequence of uppercase letters separated by an hyfen from a sequence of digits. E.g., CDS-123, RT-1, and SVN-97.
It's active in the "pre-commit" and/or the "post-commit" hook.
It's configured by the following directives.
This directive specifies how to connect and to authenticate to the JIRA server. BASEURL is the base URL of the JIRA server, usually, something like "http://jira.example.com/jira". LOGIN and PASSWORD are the credentials of a JIRA user who has browsing rights to the JIRA projects that will be referenced in the commit logs.
The fourth argument is an optional qr/Regexp/ object. It will be used to match against the commit logs in order to extract the list of JIRA issue keys. By default, the JIRA keys are looked for in the whole commit log, which is equivalent to qr/(.*)/. Sometimes this can be suboptimal because the user can introduce in the message some text that inadvertently looks like a JIRA issue key without being so. With this argument, the log message is matched against the REGEXP and only the first matched group (i.e., the part of the message captured by the first parenthesis ($1)) is used to look for JIRA issue keys.
The fifth argument is another optional qr/Regexp/ object. It is used to match JIRA project keys, which match qr/[A-Z]{2,}/ by default. However, since you can specify different patterns for JIRA project keys (<http://confluence.atlassian.com/display/JIRA/Configuring+Project+Keys>), you need to be able to specify this here too.
The JIRA issue keys are extracted from the commit log (or the part of it specified by the REGEXP) with the following pattern: "qr/\b([A-Z]+-\d+)\b/g";
This directive tells how each part of the repository structure must be integrated with JIRA.
During a commit, all files being changed are tested against the REGEXP of each CHECK_JIRA directive, in the order that they were called. If at least one changed file matches a regexp, the issues cited in the commit log are checked against their current status on JIRA according to the options specified after the REGEXP.
The available options are the following:
If you have code relying on the JIRA::Client module you're advised to rewrite it using the JIRA::REST module. As a stopgap measure you can disregard the JIRA::REST object and create your own JIRA::Client object. For this you only need the three arguments you've passed to the CHECK_JIRA_CONFIG directive.
The subroutine must simply return with no value to indicate success and must die to indicate failure.
Plese, read the JIRA::REST and SVN::Look modules documentation to understand how to use these objects.
You can set defaults for these options using a CHECK_JIRA directive with the string 'default' as a first argument, instead of a qr/Regexp/.
# Set some defaults CHECK_JIRA(default => { projects => 'CDS,TST', by_assignee => 1, }); # Check if some commits are scheduled, i.e., if they reference # JIRA issues that have at least one fix version. sub is_scheduled { my ($jira, $issue, $svnlook) = @_; return scalar @{$issue->{fixVersions}}; } CHECK_JIRA(qr/^(trunk|branches/fix)/ => { check_one => \&is_scheduled, });
Note that you need to call CHECK_JIRA at least once with a qr/Regexp/ in order to trigger the checks. A call for ('default' doesn't count. If you want to change defaults and force checks for every commit, do this:
CHECK_JIRA(default => {projects => 'CDS'}); CHECK_JIRA(qr/./);
The 'post_action' pseudo-check can be used to interact with the JIRA server after a successful commit. For instance, you may want to add a comment to each referred issue like this:
# This routine returns a closure that can be passed to # post_action. The closure receives a string to be added as a # comment to each issue referred to by the commit message. The # commit info can be interpolated inside the comment using the # SVN::Look method names inside angle brackets. sub add_comment { my ($format) = @_; return sub { my ($jira, $svnlook, @keys) = @_; # Substitute keywords in the input comment with calls # into the $svnlook reference $format =~ s/\{(\w+)\}/"\$svnlook->$1()"/eeg; for my $key (@keys) { $jira->POST("/issue/$key/comment", undef, { body => $format }); } } } CHECK_JIRA(qr/./ => { post_action => add_comment("Subversion Commit r{rev} by {author} on {date}\n{log_msg}") });
You can use a generic CHECK_JIRA excluding specific directories from it using the "exclude" option like this:
CHECK_JIRA(qr:^(trunk|branches/[^/]): => { exclude => qr:/documentation/:, # other options... });
This directive globally disables all CHECK_JIRA directives. It's useful, for instance, when your JIRA server must be taken down for maintenance and you don't want to reject Subversion commits in this period.
Gustavo L. de M. Chaves <gnustavo@cpan.org>
This software is copyright (c) 2022 by CPqD <www.cpqd.com.br>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2022-09-11 | perl v5.34.0 |