r51280 - in /branches/upstream/libsvn-hooks-perl/current: Changes META.yml README lib/SVN/Hooks.pm lib/SVN/Hooks/CheckJira.pm

angelabad-guest at users.alioth.debian.org angelabad-guest at users.alioth.debian.org
Wed Jan 20 12:21:40 UTC 2010


Author: angelabad-guest
Date: Wed Jan 20 12:21:28 2010
New Revision: 51280

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=51280
Log:
[svn-upgrade] Integrating new upstream version, libsvn-hooks-perl (0.25)

Modified:
    branches/upstream/libsvn-hooks-perl/current/Changes
    branches/upstream/libsvn-hooks-perl/current/META.yml
    branches/upstream/libsvn-hooks-perl/current/README
    branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm
    branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/CheckJira.pm

Modified: branches/upstream/libsvn-hooks-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/Changes?rev=51280&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/Changes (original)
+++ branches/upstream/libsvn-hooks-perl/current/Changes Wed Jan 20 12:21:28 2010
@@ -1,4 +1,10 @@
 Revision history for SVN-Hooks. -*- text -*-
+
+0.24    2010-01-19
+
+	Add a 'post_action' pseudo-check to CheckJira so that the
+	plugin can perform an action during the post-commit hook
+	phase.
 
 0.24	2010-01-06
 

Modified: branches/upstream/libsvn-hooks-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/META.yml?rev=51280&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/META.yml (original)
+++ branches/upstream/libsvn-hooks-perl/current/META.yml Wed Jan 20 12:21:28 2010
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                SVN-Hooks
-version:             0.24
+version:             0.25
 abstract:            A framework for implementing Subversion hooks.
 license:             ~
 author:              

Modified: branches/upstream/libsvn-hooks-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/README?rev=51280&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/README (original)
+++ branches/upstream/libsvn-hooks-perl/current/README Wed Jan 20 12:21:28 2010
@@ -1,6 +1,6 @@
 Name:    SVN-Hooks
 What:    Framework for Subversion hooks
-Version: 0.24
+Version: 0.25
 Author:  Gustavo Chaves <gnustavo at cpan.org>
 
 SVN-Hooks is a framework for creating Subversion hooks

Modified: branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm?rev=51280&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm (original)
+++ branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm Wed Jan 20 12:21:28 2010
@@ -15,11 +15,11 @@
 
 =head1 VERSION
 
-Version 0.24
+Version 0.25
 
 =cut
 
-our $VERSION = '0.24';
+our $VERSION = '0.25';
 
 =head1 SYNOPSIS
 

Modified: branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/CheckJira.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/CheckJira.pm?rev=51280&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/CheckJira.pm (original)
+++ branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/CheckJira.pm Wed Jan 20 12:21:28 2010
@@ -25,7 +25,7 @@
 by an hyfen from a sequence of digits. E.g., CDS-123, RT-1, and
 SVN-97.
 
-It's active in the C<pre-commit> hook.
+It's active in the C<pre-commit> and/or the C<post-commit> hook.
 
 It's configured by the following directives.
 
@@ -144,6 +144,17 @@
 objects for every referenced issue. The subroutine must simply return
 with no value to indicate success and must die to indicate failure.
 
+=item post_action => CODE-REF
+
+This is not a check, but an opportunity to perform some action after a
+successful commit. The code reference passed will be called once
+during the post-commit hook phase. Its first argument is the
+JIRA::Client object used to talk to the JIRA server. The second
+argument is the SVN::Look object that can be used to inspect all the
+information about the commit proper.  The following arguments are the
+JIRA keys mentioned in the commit log message. The value returned by
+the routine, if any, is ignored.
+
 =back
 
 You can set defaults for these options using a CHECK_JIRA directive
@@ -174,6 +185,33 @@
 
     CHECK_JIRA(default => {projects => 'CDS'});
     CHECK_JIRA(qr/./);
+
+The C<'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 refered 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 refered 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->addComment($key, $format);
+            }
+        }
+    }
+
+    CHECK_JIRA(qr/./ => {
+        post_action => add_comment("Subversion Commit r{rev} by {author} on {date}\n{log_msg}")
+    });
 
 =cut
 
@@ -207,6 +245,7 @@
     by_assignee => \&_validate_bool,
     check_one   => \&_validate_code,
     check_all   => \&_validate_code,
+    post_action => \&_validate_code,
 );
 
 sub CHECK_JIRA {
@@ -232,6 +271,7 @@
 	}
     }
     $conf->{'pre-commit'} = \&pre_commit;
+    $conf->{'post-commit'} = \&post_commit if exists $opts->{post_action};
 
     return 1;
 }
@@ -248,32 +288,14 @@
     };
 };
 
-sub _check_jira {
-    my ($self, $svnlook, $opts) = @_;
-
-    my $conf = $self->{conf}
-	or croak "$HOOK: plugin not configured. Please, use the CHECK_JIRA_CONFIG directive.\n";
-
-    # Grok the JIRA issue keys from the commit log
-    my ($match) = ($svnlook->log_msg() =~ $conf->{match});
-    my @keys    = defined $match ? $match =~ /\b[A-Z]+-\d+\b/g : ();
-
-    if ($opts->{require}) {
-	croak "$HOOK: you must cite at least one JIRA issue key in the commit message.\n"
-	    unless @keys;
-    }
-
-    return unless @keys;
-
-    # Connect to JIRA if not yet connected.
-    unless (exists $conf->{jira}) {
-	$conf->{jira} = eval {JIRA::Client->new(@{$conf->{conf}})};
-	croak "CHECK_JIRA_CONFIG: cannot connect to the JIRA server: $@\n" if $@;
-    }
+sub _pre_checks {
+    my ($self, $svnlook, $keys, $opts) = @_;
+
+    my $conf = $self->{conf};
 
     # Grok and check each JIRA issue
     my @issues;
-    foreach my $key (@keys) {
+    foreach my $key (@$keys) {
 	my $issue = eval {$conf->{jira}->getIssue($key)};
 	if ($opts->{valid}) {
 	    croak "$HOOK: issue $key is not valid: $@\n" if $@;
@@ -301,23 +323,67 @@
     return;
 }
 
+sub _post_action {
+    my ($self, $svnlook, $keys, $opts) = @_;
+
+    if (my $action = $opts->{post_action}) {
+	$action->($self->{conf}->{jira}, $svnlook, @$keys);
+    }
+
+    return;
+}
+
+sub _check_if_needed {
+    my ($self, $svnlook, $docheck) = @_;
+
+    my $conf = $self->{conf}
+	or croak "$HOOK: plugin not configured. Please, use the CHECK_JIRA_CONFIG directive.\n";
+
+    my @files = $svnlook->changed();
+
+    foreach my $check (@{$self->{checks}}) {
+	my ($regex, $opts) = @$check;
+
+	for my $file (@files) {
+	    if ($file =~ $regex) {
+
+		# Grok the JIRA issue keys from the commit log
+		my ($match) = ($svnlook->log_msg() =~ $conf->{match});
+		my @keys    = defined $match ? $match =~ /\b[A-Z]+-\d+\b/g : ();
+
+		my %opts = (%{$self->{defaults}}, %$opts);
+
+		if ($opts{require}) {
+		    croak "$HOOK: you must cite at least one JIRA issue key in the commit message.\n"
+			unless @keys;
+		}
+
+		return unless @keys;
+
+		# Connect to JIRA if not yet connected.
+		unless (exists $conf->{jira}) {
+		    $conf->{jira} = eval {JIRA::Client->new(@{$conf->{conf}})};
+		    croak "CHECK_JIRA_CONFIG: cannot connect to the JIRA server: $@\n" if $@;
+		}
+
+		$docheck->($self, $svnlook, \@keys, \%opts);
+		last;
+	    }
+	}
+    }
+
+    return;
+}
+
 sub pre_commit {
     my ($self, $svnlook) = @_;
-
-    my @files = $svnlook->changed();
-
-    foreach my $check (@{$self->{checks}}) {
-	my ($regex, $opts) = @$check;
-
-	for my $file (@files) {
-	    if ($file =~ $regex) {
-		my %opts = (%{$self->{defaults}}, %$opts);
-		_check_jira($self, $svnlook, \%opts);
-		last;
-	    }
-	}
-    }
-
+    _check_if_needed($self, $svnlook, \&_pre_checks);
+    return;
+}
+
+sub post_commit {
+    my ($self, $svnlook) = @_;
+    _check_if_needed($self, $svnlook, \&_post_action);
     return;
 }
 




More information about the Pkg-perl-cvs-commits mailing list