summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2009-10-24 09:44:21 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2009-10-24 09:44:21 (GMT)
commit56c46014d063b8f9714db7644d2b2c2cda89e906 (patch)
tree6e73cca1dc57fa5b31cafa869cb7818201e2299d /tools
parentdb63fbfa036f5cd757aedf4547fef9e195a8c285 (diff)
downloadmonitoring-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')
-rwxr-xr-xtools/git-notify37
1 files changed, 32 insertions, 5 deletions
diff --git a/tools/git-notify b/tools/git-notify
index ccde4be..0c2f739 100755
--- a/tools/git-notify
+++ b/tools/git-notify
@@ -102,6 +102,33 @@ sub xml_escape($)
102 return $str; 102 return $str;
103} 103}
104 104
105# right-justify the left column of "left: right" elements, omit undefined elements
106sub format_table(@)
107{
108 my @lines = @_;
109 my @table;
110 my $max = 0;
111
112 foreach my $line (@lines)
113 {
114 next if not defined $line;
115 my $pos = index($line, ":");
116
117 $max = $pos if $pos > $max;
118 }
119
120 foreach my $line (@lines)
121 {
122 next if not defined $line;
123 my ($left, $right) = split(/: */, $line, 2);
124
125 push @table, (defined $left and defined $right)
126 ? sprintf("%*s: %s", $max + 1, $left, $right)
127 : $line;
128 }
129 return @table;
130}
131
105# format an integer date + timezone as string 132# format an integer date + timezone as string
106# algorithm taken from git's date.c 133# algorithm taken from git's date.c
107sub format_date($$) 134sub format_date($$)
@@ -236,15 +263,15 @@ sub send_commit_notice($$)
236 263
237 return if length($diff) == 0; 264 return if length($diff) == 0;
238 265
239 push @notice, 266 push @notice, format_table(
240 "Module: $repos_name", 267 "Module: $repos_name",
241 "Branch: $ref", 268 "Branch: $ref",
242 "Commit: $obj", 269 "Commit: $obj",
243 $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj\n" : "", 270 $gitweb_url ? "URL: $gitweb_url/?a=commit;h=$obj" : undef),
244 "Author: " . $info{"author"}, 271 "Author:" . $info{"author"},
245 "Date: " . format_date($info{"author_date"},$info{"author_tz"}), 272 "Date:" . format_date($info{"author_date"},$info{"author_tz"}),
246 "", 273 "",
247 join "\n", @{$info{"log"}}, 274 @{$info{"log"}},
248 "", 275 "",
249 "---", 276 "---",
250 ""; 277 "";