Re: post-receive-hook emailer
- From
- Abhijit Menon-Sen <ams@toroid.org>
- Date
- Jul 22, 2008, 10:40 UTC
- Message-ID
- <20080722104022.GA6621@toroid.org>
- In-Reply-To
- <00AEED4D-BD34-4584-B303-32C5F587EF0F@develooper.com>
Hi Ask.
At 2008-07-22 02:34:35 -0700, ask@develooper.com wrote:
> > Anyway - anyone have a mailer that sends diffs and such? :-)
Not quite what you want, but I wrote the attached post-receive hook/hack to send change notifications by Jabber. "hooks.notify.recipients" should contain a list of jabber IDs; and you can change the "git log" line, for example by adding "-p --stat" or something, to change what gets sent.
It should be trivial to change the last twenty-odd lines to send email instead.
-- ams
#!/usr/bin/perl # Abhijit Menon-Sen <ams@oryx.com>
use Net::Jabber;
my $dir; chomp( $dir = qx(git rev-parse --git-dir 2>/dev/null) ); die "GIT_DIR not defined.\n" unless $dir; $ENV{GIT_DIR} = $dir;
my $r; chomp( $r = qx(git config hooks.notify.recipients) ); my @recipients = split /,\s*/, $r;
my @changes;
while ( <> ) {
chomp;
my ( $old, $new, $ref ) = split / /;
$ref =~ s!refs/heads/!!;
next unless $ref eq "some/branch";
my $s = qx(git log --no-merges --reverse --find-copies-harder --raw -r $old..$new);
$s =~ s/^:.*?\t/\t/gsm;
push @changes, $s;
}exit unless @changes; exit unless @recipients;
my $client = new Net::Jabber::Client ();
$client->Connect(
hostname => 'example.com',
) or die "Cannot connect to jabber server: $!.\n";my @r = $client->AuthSend(
username => 'git',
password => 'some-password',
resource => 'git'
);
die "Cannot authenticate (@r).\n" if $r[0] ne "ok";foreach my $c (@changes) {
for my $r (@recipients) {
my $msg = new Net::Jabber::Message ();
$msg->SetMessage(
to => $r,
subject => 'Changes pushed to x:y.git/some/branch',
body => $c
);
$client->Send( $msg );
}
}$client->Disconnect();