Permalink
Browse files

Pretty much working

  • Loading branch information...
1 parent 7aa3353 commit 3f85602d6289923e078ec6ab0e24347b74a9908f @rowanj committed Oct 31, 2010
Showing with 49 additions and 20 deletions.
  1. +49 −20 git-logzilla-post-receive.pl
@@ -4,40 +4,69 @@
# License: GPL v2 or later
use strict;
+use List::MoreUtils qw(uniq);
+
my $input = <>;
chomp $input;
my ($oldrev, $newrev, $refname) = split /\s+/, $input;
-#print "oldrev=$oldrev\n";
-#print "newvev=$newrev\n";
-#print "refname=$refname\n";
-my $commit_msg = `git whatchanged $oldrev..$newrev`;
+sub add_comment {
+ my $bug_number = shift;
+ my $comment = shift;
+
+ git-bugz-comment $bug_number "$comment";
+}
+
+# Define a function to add git notes to each bug it modifies
+sub process_commit {
+ my $commit_id = shift;
+
+ print "Proccessing message for commit $commit_id\n";
+
+ my $commit_msg = `git whatchanged -n 1 $oldrev..$newrev`;
#print "base commit_msg=$commit_msg\n";
# author
-my ($author) = ( $commit_msg =~ /^Author:\s+(.*)$/m );
+ my ($author) = ( $commit_msg =~ /^Author:\s+(.*)$/m );
# files
-my @filelist = grep ( /^:/, split( /\n/, $commit_msg ) );
+ my @filelist = grep ( /^:/, split( /\n/, $commit_msg ) );
# prepare comment
-$commit_msg =~ s/^.*?Date://s;# eat everything till the Date: heder
-$commit_msg =~ s/^.*?\n//m;# eat the date line completely
-$commit_msg =~ s/^:.*?$//mg;# eat the file list from the msg.
-chomp $commit_msg;
+ $commit_msg =~ s/^.*?Date://s;# eat everything till the Date: header
+ $commit_msg =~ s/^.*?\n//m;# eat the date line completely
+ $commit_msg =~ s/^:.*?$//mg;# eat the file list from the msg.
+ chomp $commit_msg;
-my $bug_regex = 'bug\s*(?:#|)\s*(?P<bug>\d+)';
-my ($bug_number) = ( $commit_msg =~ /$bug_regex/ );
+ my $bug_regex = 'bug\s*(?:#|)\s*(?P<bug>\d+)';
+ my (@bug_numbers) = uniq(sort( $commit_msg =~ /$bug_regex/gi ));
-my $comment = "----------------------------------------
-$author changed bug $bug_number in $refname
+ my $comment = "----------------------------------------
+$author committed $refname
\t($newrev)
-----------------------------------------";
-$comment .= "$commit_msg";
-$comment .= "----------------------------------------
-Changed:\n";
-$comment .= join("", @filelist) . "\n----------------------------------------\n";
+Tagged with:\n";
+ foreach my $bug_number(@bug_numbers) {
+ $comment .= "\tbug $bug_number\n";
+ }
+ $comment .= "----------------------------------------";
+ $comment .= "$commit_msg";
+ $comment .= "----------------------------------------
+Paths changed:\n";
+ $comment .= join("", @filelist) . "\n----------------------------------------\n";
+
+ foreach my $bug_number(@bug_numbers) {
+ add_comment($bug_number, $comment);
+ }
+}
+
+# Get a list of all commits being added
+my $commit_list = `git log --pretty=oneline $oldrev..$newrev`;
+my @commits = reverse(split("\n", $commit_list));
+foreach my $commit(@commits) {
+ process_commit($commit);
+}
-print "$comment";
+exit 0;
+#

0 comments on commit 3f85602

Please sign in to comment.