Re: post-receive-hook emailer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ask.

At 2008-07-22 02:34:35 -0700, ask@xxxxxxxxxxxxxx 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@xxxxxxxx>

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();
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux