From bd843d874b69625efaedda9761ef92b5f5ef2719 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 13 Jan 2010 15:22:22 +0000 Subject: Add initial version of git-notify git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@437 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- git-notify | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 git-notify 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 +# # Copyright 1998 Board of Trustees, Leland Stanford Jr. University +# # Copyright 2001, 2003, 2004, 2005 Petr Baudis + +# 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" +# | +# | # +# | #. /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 ") 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 = )) { + 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 = )) { + 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 <> 8) . "\n" unless ($? == 0); + +# vi: set sw=2: -- cgit v1.2.3