diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 11:44:21 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2009-10-24 11:44:21 +0200 |
commit | 56c46014d063b8f9714db7644d2b2c2cda89e906 (patch) | |
tree | 6e73cca1dc57fa5b31cafa869cb7818201e2299d /tools/git-notify | |
parent | db63fbfa036f5cd757aedf4547fef9e195a8c285 (diff) | |
download | monitoring-plugins-56c46014d063b8f9714db7644d2b2c2cda89e906.tar.gz |
git-notify: New subroutine for column alignment
Most notifications include an ASCII "table" with two columns. The
formatting of these columns is now handled by the new format_table()
subroutine, so that the alignment can easily be changed in the future.
Diffstat (limited to 'tools/git-notify')
-rwxr-xr-x | tools/git-notify | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/tools/git-notify b/tools/git-notify index ccde4bee..0c2f7395 100755 --- a/tools/git-notify +++ b/tools/git-notify @@ -102,6 +102,33 @@ sub xml_escape($) return $str; } +# right-justify the left column of "left: right" elements, omit undefined elements +sub format_table(@) +{ + my @lines = @_; + my @table; + my $max = 0; + + foreach my $line (@lines) + { + next if not defined $line; + my $pos = index($line, ":"); + + $max = $pos if $pos > $max; + } + + foreach my $line (@lines) + { + next if not defined $line; + my ($left, $right) = split(/: */, $line, 2); + + push @table, (defined $left and defined $right) + ? sprintf("%*s: %s", $max + 1, $left, $right) + : $line; + } + return @table; +} + # format an integer date + timezone as string # algorithm taken from git's date.c sub format_date($$) @@ -236,15 +263,15 @@ sub send_commit_notice($$) return if length($diff) == 0; - push @notice, + push @notice, format_table( "Module: $repos_name", "Branch: $ref", "Commit: $obj", - $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj\n" : "", - "Author: " . $info{"author"}, - "Date: " . format_date($info{"author_date"},$info{"author_tz"}), + $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj" : undef), + "Author:" . $info{"author"}, + "Date:" . format_date($info{"author_date"},$info{"author_tz"}), "", - join "\n", @{$info{"log"}}, + @{$info{"log"}}, "", "---", ""; |