1 package Girocco
::Notify
;
13 # This Perl code creates json payload within post-receive hook.
16 my ($proj, $commit) = @_;
18 my @gcmd = ($Girocco::Config
::git_bin
, '--git-dir='.$proj->{path
});
21 open $fd, '-|', @gcmd, 'log', '-1', '--pretty=format:%ae %an%n%ai%n%s%n%n%b', $commit
22 or die "cannot do git log: $! $?";
26 my ($ae, $an) = ($l[0] =~ /^(.*?) (.*)$/);
28 my $msg = join("\n", splice(@l, 2));
29 # Up to three trailing newlines in case of no body.
30 chomp $msg; chomp $msg; chomp $msg;
32 my ($rf, $af, $mf) = ([], [], []);
33 open $fd, '-|', @gcmd, 'diff-tree', '--name-status', '-r', "$commit^", $commit
34 or die "cannot do git diff-tree: $! $?";
37 my ($s, $file) = split(/\t/, $_);
54 "url" => $Girocco::Config
::gitweburl
."/".$proj->{name
}.".git/commit/".$commit,
55 "author" => { "name" => $an, "email" => $ae },
61 my ($url, $proj, $ref, $oldrev, $newrev) = @_;
65 foreach my $commit (get_commits
($proj, $ref, $oldrev, $newrev)) {
66 push @
$commits, json_commit
($proj, $commit);
69 my $payload = encode_json
{
75 "name" => $proj->{name
},
76 # Girocco extension: full_name is full project name,
77 # equivalent to GitHub's "owner[name]/name".
78 "full_name" => $proj->{name
}.".git",
80 "url" => $Girocco::Config
::gitweburl
.'/'.$proj->{name
}.".git",
81 # Girocco extension: Pull URL.
82 "pull_url" => $Girocco::Config
::gitpullurl
.'/'.$proj->{name
}.".git",
84 "owner" => { "name" => "", "email" => $proj->{email
} }
90 my $ua = LWP
::UserAgent
->new;
92 $ua->post($url, { payload
=> $payload });
97 my ($proj, $ref, $oldrev, $newrev) = @_;
99 my @gcmd = ($Girocco::Config
::git_bin
, '--git-dir='.$proj->{path
});
102 open $fd, '-|', @gcmd, 'for-each-ref', '--format=%(refname)', 'refs/heads/'
103 or die "cannot do git for-each-ref: $! $?";
104 my @refs = grep { $_ ne $ref } <$fd>;
110 print "--not @refs\n";
111 open $fd, '-|', @gcmd, 'rev-list', '--not', @refs
112 or die "cannot do git rev-list for revlims: $! $?";
118 my $revspec = (($oldrev =~ /^0+$/) ?
$newrev : "$oldrev..$newrev");
119 open $fd, '-|', @gcmd, 'rev-list', @revlims, $revspec
120 or die "cannot do git rev-list: $! $?";
130 my ($proj, $ref, $oldrev, $newrev) = @_;
132 chdir($proj->{path
});
134 # First, possibly send out various mails
135 if ($proj->{notifymail
}) {
136 system($Girocco::Config
::basedir
.'/taskd/mail.sh',
137 "$ref", "$oldrev", "$newrev")
138 and warn "mail.sh failed";
141 # Next, send JSON packet to given URL if enabled.
142 if ($proj->{notifyjson
}) {
143 json
($proj->{notifyjson
}, $proj, $ref, $oldrev, $newrev);