On Fri, Jan 15, 2010 at 1:17 PM, Chris.Rule via RT <
bug-SVN-Hooks@rt.cpan.org> wrote:
Show quoted text> Queue: SVN-Hooks
> Ticket <URL:
http://rt.cpan.org/Ticket/Display.html?id=53706 >
>
> I think merging the two is a very good idea; if nothing else to only have a
> single JIRA::Client object that has to be defined.
>
> I had implemented this as a post-commit script because at that point I know
> the commit has happened. I think this functionality would need to stay the
> same. Wouldn't want to add a comment to some issues then have later issues
> cause the commit to be aborted for some reason. Given this, attempting to
> use the existing check_one or check_all subs may be problematic since these
> would also be called in the pre-commit script. I wouldn't want to have to
> say "if (pre-commit) do something" in the scripts. To easy to do something
> that I wouldn't want, forget to add the check, and could break existing
> scripts.
>
Of course! I forgot about the pre/post commit hooks. But this also solves
the problem with modifying the check_all function signature, because I don't
need to. All I have to do is to add another option to CHECK_JIRA. Perhaps an
options called "post_commit" which would accept a ref to a subroutine with
the following signature: ($jira, $svnlook, @issues). This soubroutine would
be called during the post_commit phase and not during the pre_commit phase.
Show quoted text> >> In order to allow for the substitutions inside the comment string one
> could do tricks with closures.
> Wow! Something I've never run into with Perl. This seems pretty obscure but
> it might work. Not sure how though.
>
A closure is simply a routine defined inside another but which uses a local
variable of the outer routine. In this case I was thinking about something
along these lines:
sub add_comment {
my ($format) = @_;
sub closure {
my ($jira, $svnlook, @issues) = @_;
... extract the commit info from $svnlook
my $comment = $format;
... make all substitutions inside $comment
foreach my $issue (@issues) {
$jira->addComment($issue, $comment);
}
}
return \&closure;
}
CHECK_JIRA(... post_commit => add_comment("Subversion Commit rev {rev} by
{author} on {date}\n{logmessage}"));
With add_comment defined in your svn-hooks.conf you can have several
CHECK_JIRA calls, each one specifying a different comment format.
How this seems to you?
I'll try to release a new version of SVN::Hooks along these lines during the
weekend.
Gustavo.