Git development
 help / color / mirror / Atom feed
From: Abhijit Menon-Sen <ams@toroid.org>
To: "Ask Bjørn Hansen" <ask@develooper.com>
Cc: git@vger.kernel.org
Subject: Re: post-receive-hook emailer
Date: Tue, 22 Jul 2008 16:10:22 +0530	[thread overview]
Message-ID: <20080722104022.GA6621@toroid.org> (raw)
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();

  reply	other threads:[~2008-07-22 10:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-22  9:34 post-receive-hook emailer Ask Bjørn Hansen
2008-07-22 10:40 ` Abhijit Menon-Sen [this message]
2008-07-22 16:45 ` Vincent Kergonna

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080722104022.GA6621@toroid.org \
    --to=ams@toroid.org \
    --cc=ask@develooper.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox