r65715 - in /branches/upstream/libsvn-hooks-perl/current: Changes MANIFEST META.yml README lib/SVN/Hooks.pm lib/SVN/Hooks/CheckJira.pm lib/SVN/Hooks/Generic.pm t/02-generic.t

carnil at users.alioth.debian.org carnil at users.alioth.debian.org
Sat Dec 11 06:57:51 UTC 2010


Author: carnil
Date: Sat Dec 11 06:55:57 2010
New Revision: 65715

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

Added:
    branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/Generic.pm
    branches/upstream/libsvn-hooks-perl/current/t/02-generic.t   (with props)
Modified:
    branches/upstream/libsvn-hooks-perl/current/Changes
    branches/upstream/libsvn-hooks-perl/current/MANIFEST
    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=65715&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/Changes (original)
+++ branches/upstream/libsvn-hooks-perl/current/Changes Sat Dec 11 06:55:57 2010
@@ -1,4 +1,11 @@
 Revision history for SVN-Hooks. -*- text -*-
+
+0.31	2010-12-09
+
+	Implements the SVN::Hooks::Generic plugin to allow for the
+	easy creation of custom hooks.
+
+	Corrects CheckJira's "projects" verification.
 
 0.30	2010-10-07
 

Modified: branches/upstream/libsvn-hooks-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/MANIFEST?rev=65715&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/MANIFEST (original)
+++ branches/upstream/libsvn-hooks-perl/current/MANIFEST Sat Dec 11 06:55:57 2010
@@ -11,6 +11,7 @@
 lib/SVN/Hooks/CheckStructure.pm
 lib/SVN/Hooks/DenyChanges.pm
 lib/SVN/Hooks/DenyFilenames.pm
+lib/SVN/Hooks/Generic.pm
 lib/SVN/Hooks/JiraAcceptance.pm
 lib/SVN/Hooks/Mailer.pm
 lib/SVN/Hooks/Notify.pm
@@ -31,6 +32,7 @@
 t/02-checkstructure.t
 t/02-denychanges.t
 t/02-denyfilenames.t
+t/02-generic.t
 t/02-jiraacceptance.t
 t/02-mailer.t
 t/02-notify.t

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=65715&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/META.yml (original)
+++ branches/upstream/libsvn-hooks-perl/current/META.yml Sat Dec 11 06:55:57 2010
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               SVN-Hooks
-version:            0.30
+version:            0.31
 abstract:           A framework for implementing Subversion hooks.
 author:
     - Gustavo Chaves <gnustavo at cpan.org>

Modified: branches/upstream/libsvn-hooks-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/README?rev=65715&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/README (original)
+++ branches/upstream/libsvn-hooks-perl/current/README Sat Dec 11 06:55:57 2010
@@ -1,6 +1,6 @@
 Name:    SVN-Hooks
 What:    Framework for Subversion hooks
-Version: 0.30
+Version: 0.31
 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=65715&op=diff
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm (original)
+++ branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks.pm Sat Dec 11 06:55:57 2010
@@ -15,11 +15,11 @@
 
 =head1 VERSION
 
-Version 0.30
+Version 0.31
 
 =cut
 
-our $VERSION = '0.30';
+our $VERSION = '0.31';
 
 =head1 SYNOPSIS
 
@@ -178,6 +178,10 @@
 
 Deny the addition of files which file names doesn't comply with a
 Regexp. Usually used to disallow some characteres in the filenames.
+
+=item SVN::Hooks::Generic
+
+This meta plugin allows for the easy creation of custom made hooks.
 
 =item SVN::Hooks::Notify
 
@@ -336,7 +340,15 @@
 
     foreach my $conf (values %{$repo->{confs}}) {
 	if (my $hook = $conf->{$hook_name}) {
-	    $hook->($conf, @args);
+	    if (ref $hook eq 'CODE') {
+		$hook->($conf, @args);
+	    } elsif (ref $hook eq 'ARRAY') {
+		foreach my $h (@$hook) {
+		    $h->($conf, @args);
+		}
+	    } else {
+		die "SVN::Hooks: internal error!\n";
+	    }
 	}
     }
 

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=65715&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 Sat Dec 11 06:55:57 2010
@@ -360,6 +360,15 @@
 
 		return unless @keys;
 
+		# Check if there is a restriction on the project keys allowed
+		if (exists $opts->{projects}) {
+		    foreach my $key (@keys) {
+			my ($pkey, $pnum) = split /-/, $key;
+			croak "$HOOK: issue $key is not allowed. You must cite only JIRA issues for the following projects: ", join(', ', sort keys %{$opts->{projects}}), ".\n"
+			    unless exists $opts->{projects}{$pkey};
+		    }
+		}
+
 		# Connect to JIRA if not yet connected.
 		unless (exists $conf->{jira}) {
 		    $conf->{jira} = eval {JIRA::Client->new(@{$conf->{conf}})};

Added: branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/Generic.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/Generic.pm?rev=65715&op=file
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/Generic.pm (added)
+++ branches/upstream/libsvn-hooks-perl/current/lib/SVN/Hooks/Generic.pm Sat Dec 11 06:55:57 2010
@@ -1,0 +1,172 @@
+package SVN::Hooks::Generic;
+
+use strict;
+use warnings;
+use Carp;
+use SVN::Hooks;
+
+use Exporter qw/import/;
+my $HOOK = 'GENERIC';
+our @EXPORT = ($HOOK);
+
+our $VERSION = $SVN::Hooks::VERSION;
+
+=head1 NAME
+
+SVN::Hooks::Generic - Implement generic checks for all Subversion hooks.
+
+=head1 SYNOPSIS
+
+This SVN::Hooks plugin allows you to easily write generic checks for
+all Subversion standard hooks.
+
+It's configured by the following directive.
+
+=head2 GENERIC(HOOK => FUNCTION, HOOK => [FUNCTIONS], ...)
+
+This directive associates FUNCTION with a specific HOOK. You can make
+more than one association with a single directive call, or you can use
+multiple calls to make multiple associations. Moreover, you can
+associate a hook with a single function or with a list of functions
+(passing them as elements of an array). All functions associated with
+a hook will be called in an unspecified order with the same arguments.
+
+Each hook must be associated with functions with a specific signature,
+i.e., the arguments that are passed to the function depends on the
+hook to which it is associated.
+
+The hooks are specified by their standard names.
+
+The function signatures are the following:
+
+=over
+
+=item post-commit(SVN::Look)
+
+=item post-lock(repository-path, username)
+
+=item post-revprop-change(SVN::Look, username, property-name, action)
+
+=item post-unlock(repository-path, username)
+
+=item pre-commit(SVN::Look)
+
+=item pre-lock(repository-path, username, comment, steal-lock-flag)
+
+=item pre-revprop-change(SVN::Look, username, property-name, action)
+
+=item pre-unlock(repository-path, username, lock-token, break-unlock-flag)
+
+=item start-commit(repository-path, username, capabilities)
+
+=back
+
+The functions may perform whatever checks they want. If the checks
+succeed the function must simply return. Otherwise, they must die with
+a suitable error message, which will be sent back to the user
+performing the Subversion action which triggered the hook.
+
+The sketch below shows how this directive could be used.
+
+	sub my_start_commit {
+	    my ($repo, $username, $capabilities) = @_;
+	    // ...
+	}
+
+	sub my_pre_commit {
+	    my ($svnlook) = @_;
+	    // ...
+	}
+
+	GENERIC(
+	    'start-commit' => \&my_start_commit,
+	    'pre-commit'   => \&my_pre_commit,
+	);
+
+=cut
+
+sub GENERIC {
+    my (@args) = @_;
+
+    (@args % 2) == 0
+	or croak "$HOOK: odd number of arguments.\n";
+
+    my %args = @args;
+
+    my $conf = $SVN::Hooks::Confs->{$HOOK};
+
+    while (my ($hook, $functions) = each %args) {
+	$hook =~ /(?:(?:pre|post)-(?:commit|lock|revprop-change|unlock)|start-commit)/
+	    or die "$HOOK: invalid hook name ($hook)";
+	if (! ref $functions) {
+	    die "$HOOK: hook '$hook' should be mapped to a reference.\n";
+	} elsif (ref $functions eq 'CODE') {
+	    $functions = [$functions];
+	} elsif (ref $functions ne 'ARRAY') {
+	    die "$HOOK: hook '$hook' should be mapped to a CODE-ref or to an ARRAY of CODE-refs.\n";
+	}
+	foreach my $foo (@$functions) {
+	    ref $foo and ref $foo eq 'CODE'
+		or die "$HOOK: hook '$hook' should be mapped to CODE-refs.\n";
+	    push @{$conf->{$hook}}, $foo;
+	}
+    }
+
+    return 1;
+}
+
+$SVN::Hooks::Inits{$HOOK} = sub {
+    return {};
+};
+
+=head1 AUTHOR
+
+Gustavo Chaves, C<< <gnustavo at cpan.org> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-svn-hooks-updaterepofile at rt.cpan.org>, or through the web
+interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SVN-Hooks>.  I will
+be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+    perldoc SVN::Hooks
+
+You can also look for information at:
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SVN-Hooks>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/SVN-Hooks>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/SVN-Hooks>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/SVN-Hooks>
+
+=back
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2008-2009 CPqD, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1; # End of SVN::Hooks::Generic

Added: branches/upstream/libsvn-hooks-perl/current/t/02-generic.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsvn-hooks-perl/current/t/02-generic.t?rev=65715&op=file
==============================================================================
--- branches/upstream/libsvn-hooks-perl/current/t/02-generic.t (added)
+++ branches/upstream/libsvn-hooks-perl/current/t/02-generic.t Sat Dec 11 06:55:57 2010
@@ -1,0 +1,80 @@
+# -*- cperl -*-
+
+use strict;
+use warnings;
+use lib 't';
+use Test::More;
+
+require "test-functions.pl";
+
+if (can_svn()) {
+    plan tests => 7;
+}
+else {
+    plan skip_all => 'Cannot find or use svn commands.';
+}
+
+my $t = reset_repo();
+
+set_hook(<<'EOS');
+use SVN::Hooks::Generic;
+EOS
+
+set_conf(<<'EOS');
+GENERIC(1);
+EOS
+
+work_nok('odd' => 'odd number of arguments', <<"EOS");
+touch $t/wc/file.txt
+svn add -q --no-auto-props $t/wc/file.txt
+svn ci -mx $t/wc/file.txt
+EOS
+
+set_conf(<<'EOS');
+GENERIC('non_hook' => sub {});
+EOS
+
+work_nok('non hook' => 'invalid hook name', <<"EOS");
+svn ci -mx $t/wc/file.txt
+EOS
+
+set_conf(<<'EOS');
+GENERIC('start-commit' => 'non ref');
+EOS
+
+work_nok('non ref' => 'should be mapped to a reference', <<"EOS");
+svn ci -mx $t/wc/file.txt
+EOS
+
+set_conf(<<'EOS');
+GENERIC('start-commit' => {});
+EOS
+
+work_nok('non array' => 'should be mapped to a CODE-ref or to an ARRAY of CODE-refs', <<"EOS");
+svn ci -mx $t/wc/file.txt
+EOS
+
+set_conf(<<'EOS');
+GENERIC('start-commit' => ['non code']);
+EOS
+
+work_nok('non code' => 'should be mapped to CODE-refs', <<"EOS");
+svn ci -mx $t/wc/file.txt
+EOS
+
+set_conf(<<'EOS');
+GENERIC('start-commit' => sub { die "died from within"; });
+EOS
+
+work_nok('died from within' => 'died from within', <<"EOS");
+svn ci -mx $t/wc/file.txt
+EOS
+
+set_conf(<<'EOS');
+GENERIC('start-commit' => sub { return 1; });
+EOS
+
+work_ok('ok', <<"EOS");
+svn ci -mx $t/wc/file.txt
+EOS
+

Propchange: branches/upstream/libsvn-hooks-perl/current/t/02-generic.t
------------------------------------------------------------------------------
    svn:executable = *




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