summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2010-01-13 15:22:22 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2010-01-13 15:22:22 +0000
commitbd843d874b69625efaedda9761ef92b5f5ef2719 (patch)
tree92a396ddda9bae79e684ec9424af614b3f89d5ca
parent3ef18c12af40f9b37b5a1382b06a9c66434ed56b (diff)
Add initial version of git-notify
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@437 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rwxr-xr-xgit-notify118
1 files changed, 118 insertions, 0 deletions
diff --git a/git-notify b/git-notify
new file mode 100755
index 0000000..e413a6e
--- /dev/null
+++ b/git-notify
@@ -0,0 +1,118 @@
+#!/usr/bin/perl -w
+
+# based on ciabot.pl:
+# # Loosely based on cvslog by Russ Allbery <rra@stanford.edu>
+# # Copyright 1998 Board of Trustees, Leland Stanford Jr. University
+# # Copyright 2001, 2003, 2004, 2005 Petr Baudis <pasky@ucw.cz>
+
+# Copyright 2010 Peter Palfrader
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License version 2, as published by the
+# Free Software Foundation.
+
+# use in post-receive like that:
+# | tmpfile=`mktemp`
+# | trap "rm -f '$tmpfile'" EXIT
+# |
+# | cwd="`pwd`"
+# | REPO_NAME="`basename "$cwd"`"
+# | while read oldrev newrev refname; do
+# | echo "$oldrev $newrev $refname" >> "$tmpfile"
+# | done
+# |
+# | while read oldrev newrev refname; do
+# | for merged in $(git-rev-list $newrev ^$oldrev | tac); do
+# | ./hooks/nsa-bot "$merged" "$refname" "$REPO_NAME"
+# | done
+# | done < "$tmpfile"
+# |
+# | # <other postrecv stuff>
+# | #. /usr/share/doc/git-core/contrib/hooks/post-receive-email
+
+use strict;
+use POSIX qw(strftime);
+use vars qw ($project $from_email $dest_email $sendmail);
+
+$project = 'weasel';
+$from_email = 'commit@commit.noreply.org';
+$dest_email = 'commit@commit.noreply.org';
+
+$sendmail = '/usr/sbin/sendmail';
+
+die ("Usage: $0 <commit> <branch>") if (scalar @ARGV < 2);
+# The commit stuff
+my $commit = $ARGV[0];
+my $branch = $ARGV[1];
+my $repos = $ARGV[2];
+
+open COMMIT, "git-cat-file commit $commit|" or die "git-cat-file commit $commit: $!";
+my $state = 0;
+my $logmsg = '';
+my $line;
+my $tree;
+my @parent;
+my $author;
+my $timestamp;
+my $committer;
+my @files;
+while (defined ($line = <COMMIT>)) {
+ if ($state == 1) {
+ $logmsg .= $line;
+ $state++;
+ next;
+ } elsif ($state > 1) {
+ next;
+ }
+
+ chomp $line;
+ unless ($line) {
+ $state = 1;
+ next;
+ }
+
+ my ($key, $value) = split(/ /, $line, 2);
+ if ($key eq 'tree') {
+ $tree = $value;
+ } elsif ($key eq 'parent') {
+ push(@parent, $value);
+ } elsif ($key eq 'author') {
+ ($author, $timestamp) = $value =~ /^(.*)\s+([0-9]+)\s+.?[0-9]{4}$/;
+ $author = $value unless $author;
+ } elsif ($key eq 'committer') {
+ $committer = $value;
+ }
+}
+close COMMIT;
+
+die ("Did not learn parent or tree.\n") unless (scalar @parent > 0 and defined $tree);
+
+open DIFF, "git-diff-tree -r $parent[0] $tree|" or die "git-diff-tree $parent[0] $tree: $!";
+while (defined ($line = <DIFF>)) {
+ chomp $line;
+ my @f;
+ (undef, @f) = split(/\t/, $line, 2);
+ push (@files, @f);
+}
+close DIFF;
+
+
+$branch =~ s#refs/heads/##;
+if (defined $repos) {
+ $branch = "$repos/$branch";
+}
+my $message = "$author: ".strftime("%Y-%m-%d %H:%M:%S", gmtime($timestamp))." [$branch]: $logmsg";
+
+open (MAIL, "| $sendmail -t -oi -oem") or die "Cannot execute $sendmail : " . ($?>>8);
+#open (MAIL, "| /bin/cat") or die ("Cannot cat!\n");
+print MAIL <<EOF;
+From: $from_email
+To: $dest_email
+Subject: Announce $project
+
+EOF
+print MAIL $message;
+close MAIL;
+die "$0: sendmail exit status " . ($? >> 8) . "\n" unless ($? == 0);
+
+# vi: set sw=2: