diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 11:44:33 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 11:44:33 +0200 |
commit | a5fa304ce3fefdbdeb9f447c08234dd33d8f454a (patch) | |
tree | 3ca40658d6eab622712b65e2e74350cf8a5951d0 /tools | |
parent | 709d238041a590b42c598ee5099d252f4352c3c0 (diff) | |
download | monitoring-plugins-a5fa304ce3fefdbdeb9f447c08234dd33d8f454a.tar.gz |
git-notify: Send notifications on ref changes, too
Do not only generate notifications on commits, but also if a branch head
or lightweight tag was created, removed, or modified. Notifications on
branch head updates are omitted if one or more commit notification have
been generated and the branch head now references a descendant of the
originally referenced commit (which should be the usual case).
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/git-notify | 90 |
1 files changed, 68 insertions, 22 deletions
diff --git a/tools/git-notify b/tools/git-notify index 6d5a564c..9ab012e3 100755 --- a/tools/git-notify +++ b/tools/git-notify @@ -47,6 +47,9 @@ my $cia_address = "cia\@cia.navi.cx"; # debug mode my $debug = 0; +# number of generated (non-CIA) notifications +my $sent_notices = 0; + # configuration parameters # base URL of the gitweb repository browser (can be set with the -u option) @@ -272,6 +275,28 @@ sub get_object_info($) return %info; } +# send a ref change notice to a mailing list +sub send_ref_notice($$@) +{ + my ($ref, $action, @notice) = @_; + my ($reftype, $refname) = ($ref =~ /^refs\/(head|tag)s\/(.+)/); + + $reftype =~ s/^head$/branch/; + + @notice = (format_table( + "Module: $repos_name", + ($reftype eq "tag" ? "Tag:" : "Branch:") . $refname, + @notice, + ($action ne "removed" and $gitweb_url) + ? "URL: $gitweb_url/?a=shortlog;h=$ref" : undef), + "", + "The $refname $reftype has been $action."); + + mail_notification($commitlist_address, "$refname $reftype $action", + "text/plain; charset=us-ascii", @notice); + $sent_notices++; +} + # send a commit notice to a mailing list sub send_commit_notice($$) { @@ -315,6 +340,7 @@ sub send_commit_notice($$) mail_notification($commitlist_address, $info{"author_name"} . ": " . ${$info{"log"}}[0], "text/plain; charset=UTF-8", @notice); + $sent_notices++; } # send a commit notice to the CIA server @@ -383,44 +409,64 @@ sub send_global_notice($$$) } mail_notification($commitlist_address, "New commits on branch $ref", "text/plain; charset=UTF-8", @$notice); + $sent_notices++; } # send all the notices sub send_all_notices($$$) { my ($old_sha1, $new_sha1, $ref) = @_; + my ($reftype, $refname, $action, @notice); - $ref =~ s/^refs\/heads\///; + return if ($ref =~ /^refs\/remotes\// + or (@include_list && !grep {$_ eq $ref} @include_list)); + die "The name \"$ref\" doesn't sound like a local branch or tag" + if not (($reftype, $refname) = ($ref =~ /^refs\/(head|tag)s\/(.+)/)); - return if (@include_list && !grep {$_ eq $ref} @include_list); - - if ($old_sha1 eq '0' x 40) # new ref + if ($new_sha1 eq '0' x 40) { - send_commit_notice( $ref, $new_sha1 ) if $commitlist_address; - return; + $action = "removed"; + @notice = ( "Old SHA1: $old_sha1" ); } - - my @commits = (); - - open LIST, "-|" or exec "git", "rev-list", @revlist_options, "^$old_sha1", "$new_sha1", @exclude_list or die "cannot exec git-rev-list"; - while (<LIST>) + elsif ($old_sha1 eq '0' x 40) { - chomp; - die "invalid commit $_" unless /^[0-9a-f]{40}$/; - unshift @commits, $_; + $action = "created"; + @notice = ( "SHA1: $new_sha1" ); } - close LIST; - - if (@commits > $max_individual_notices) + elsif ($reftype eq "tag") + { + $action = "updated"; + @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" ); + } + elsif (not grep( $_ eq $old_sha1, @{ git_rev_list( $new_sha1, "--full-history" ) } )) { - send_global_notice( $ref, $old_sha1, $new_sha1 ) if $commitlist_address; - return; + $action = "rewritten"; + @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" ); } - foreach my $commit (@commits) + send_ref_notice( $ref, $action, @notice ) if ($commitlist_address and $action); + + unless ($reftype eq "tag" or $new_sha1 eq '0' x 40) { - send_commit_notice( $ref, $commit ) if $commitlist_address; - send_cia_notice( $ref, $commit ) if $cia_project_name; + my $commits = get_new_commits ( $old_sha1, $new_sha1 ); + + if (@$commits > $max_individual_notices) + { + send_global_notice( $refname, $old_sha1, $new_sha1 ) if $commitlist_address; + } + else + { + foreach my $commit (@$commits) + { + send_commit_notice( $refname, $commit ) if $commitlist_address; + send_cia_notice( $refname, $commit ) if $cia_project_name; + } + } + if ($sent_notices == 0 and $commitlist_address) + { + @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" ); + send_ref_notice( $ref, "modified", @notice ); + } } } |