Bugzilla 2.x integration with Subversion

Filed in: Perl Add comments

To install Bugzilla on FC6:

yum install perl-DBD-MySQL perl-TimeDate perl-MIME-tools
perl-AppConfig perl-Template-Toolkit

Optional:

yum install perl-PatchReader perl-GD perl-Chart perl-GDGraph perl-Template-GD

Configuring Subversion to send email upon commit

Copy the /usr/share/doc/subversion-1.4.X/tools/hook-scripts/commit-email.pl to hooks directory and patch it with my changes:

--- commit-email.pl.orig  2007-02-07 11:57:50.000000000 +0200
+++ commit-email.pl     2007-08-01 16:31:40.000000000 +0300
@@ -347,6 +347,7 @@
 # $author - declared above for use as a command line parameter in
 #   revprop-change mode.  In commit mode, gets filled in below.
 
+my @log;
 if ($mode eq 'commit')
   {
     ######################################################################
@@ -357,7 +358,7 @@
     $author = shift @infolines;
     my $date = shift @infolines;
     shift @infolines;
-    my @log = map { "$_\n" } @infolines;
+    @log = map { "$_\n" } @infolines;
 
     ######################################################################
     # Modified directory name collapsing.
@@ -516,6 +517,11 @@
     my $subject         = $subject_base;
     my $diff_wanted     = ($project->{show_diff} and $mode eq 'commit');
 
+    if (join('', @log) =~ /bug.*?(\d+)/im)
+    {
+           $subject_prefix = "[Bug $1]";
+    }
+
     if ($subject_prefix =~ /\w/)
       {
         $subject = "$subject_prefix $subject";

Edit the post-commit file under hooks directory in subversion repository:

/home/svn/hooks/commit-email.pl "$REPOS" "$REV" -h domain.example.com --diff n bugzilla@bugzilla.host

Configuring sendmail to send the mail to the Bugzilla email gateway

Install perl-MIME-tools package:

yum install perl-MIME-tools

Patch /usr/local/bugzilla/contrib/bugzilla_email_append.pl :

--- bugzilla_email_append.pl.orig       2007-08-01 16:05:01.000000000 +0300
+++ bugzilla_email_append.pl        2007-08-02 10:43:53.000000000 +0300
@@ -32,7 +32,7 @@
 use MIME::Parser;
 
 BEGIN {
-  chdir "..";        # this script lives in contrib, change to main
+  chdir '/usr/local/bugzilla';
   push @INC, "contrib";
   push @INC, "."; # this script lives in contrib
 }
@@ -91,6 +91,7 @@
 print "The subject is $Subject\n";
 
 my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/);
+exit 0 unless $bugid;
 print "The bugid is $bugid\n";
 
 # make sure the bug exists
@@ -122,6 +123,11 @@
 SendSQL($long_desc_query);
 
+# I'll exit at this point, since Bugzilla::BugMail::Send yields:
+# Can't call method "active_names" on an undefined value at globals.pl line 203.
+# and this make the sendmail filter fail miserably.
+exit 0;
+
 Bugzilla::BugMail::Send( $found_id, { changer => $SenderShort } );
 
 sub DealWithError {

Make this script trusted by sendmail:

cd /etc/smrsh; ln -s /usr/local/bugzilla/contrib/bugzilla_email_append.pl .

Edit /etc/aliases and add:

bugzilla:       |bugzilla_email_append.pl

Then don’t forget to run newaliases.

Change user to the “mail” user (you’ll need to change its shell for this test), and try running the bugzilla_email_append.pl.
Change permissions in /usr/local/bugzilla for files and/or directories it complains about (if it does).

That’s it. When there will be commit with ‘Bug 123’ in the comment, the bug will be updated with this information (including the files involved).

Leave a Reply

Pages

Adsense