From 180a860f5bd80f2e74eb37daf4a7b31de674f174 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 5 Nov 2009 02:39:08 +0100 Subject: [PATCH] Girocco::Notify: Add support for CIA notifications --- Girocco/Notify.pm | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Girocco/Project.pm | 1 + 2 files changed, 74 insertions(+) diff --git a/Girocco/Notify.pm b/Girocco/Notify.pm index 32c89bf..12087f6 100644 --- a/Girocco/Notify.pm +++ b/Girocco/Notify.pm @@ -107,6 +107,74 @@ sub json { } +sub cia_commit { + my ($cianame, $proj, $branch, $commit) = @_; + + my @gcmd = ($Girocco::Config::git_bin, '--git-dir='.$proj->{path}); + my $fd; + + open $fd, '-|', @gcmd, 'log', '-1', '--pretty=format:%an <%ae>%n%at%n%s', $commit + or die "cannot do git log: $! $?"; + my @l = <$fd>; + chomp @l; + close $fd; + foreach (@l) { s/&/&/g; s//>/g; } + my ($a, $at, $subj) = @l; + + my @f; + open $fd, '-|', @gcmd, 'diff-tree', '--name-status', '-r', "$commit^", $commit + or die "cannot do git diff-tree: $! $?"; + while (<$fd>) { + chomp; + s/&/&/g; s//>/g; + my ($status, $file) = split(/\t/, $_); + push @f, $file; + } + close $fd; + + my $rev = substr($commit, 0, 12); + + my $msg = < + + Girocco::Notify + 1.0 + + + $cianame +EOT + if ($branch ne 'master') { # XXX: Check HEAD instead + $msg .= "$branch"; + } + $msg .= "\n"; + $msg .= "$at\n"; + $msg .= "$a$rev\n"; + foreach (@f) { $msg .= "$_\n"; } + $msg .= "$subj\n"; + + # print "$msg\n"; + use RPC::XML; + use RPC::XML::Client; + + my $rpc_client = new RPC::XML::Client "http://cia.vc/RPC2"; + my $rpc_request = RPC::XML::request->new('hub.deliver', $msg); + my $rpc_response = $rpc_client->send_request($rpc_request); + ref $rpc_response or print STDERR "XML-RPC Error: $RPC::XML::ERROR\n"; +} + +sub cia { + my ($cianame, $proj, $ref, $oldrev, $newrev) = @_; + + # CIA notifications for branches only + my $branch = $ref; + $branch =~ s#^refs/heads/## or return; + + foreach my $commit (get_commits($proj, $ref, $oldrev, $newrev)) { + cia_commit($cianame, $proj, $branch, $commit); + } +} + + sub get_commits { my ($proj, $ref, $oldrev, $newrev) = @_; @@ -166,6 +234,11 @@ sub ref_change { if ($proj->{notifyjson}) { json($proj->{notifyjson}, $proj, $user, $ref, $oldrev, $newrev); } + + # Also send CIA notifications. + if ($proj->{notifycia}) { + cia($proj->{notifycia}, $proj, $ref, $oldrev, $newrev); + } } diff --git a/Girocco/Project.pm b/Girocco/Project.pm index cabd1ae..64476c6 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -38,6 +38,7 @@ our %propmap = ( hp => ':homepage', notifymail => '%hooks.mailinglist', notifyjson => '%hooks.jsonurl', + notifycia => '%hooks.cianame', ); sub _property_path { -- 2.11.4.GIT