Code

git-notify: Truncate summary after 50 characters
[nagiosplug.git] / tools / git-notify
index 9ab012e34d36a7847b335ffcf2b5a3010ef6ab99..39abd66e173e219d831fd765181c27cacdb0824b 100755 (executable)
@@ -127,6 +127,20 @@ sub git_rev_list(@)
     return $revlist;
 }
 
+# truncate the given string if it exceeds the specified number of characters
+sub truncate_str($$)
+{
+    my ($str, $max) = @_;
+
+    if (length($str) > $max)
+    {
+        $str = substr($str, 0, $max);
+        $str =~ s/\s+\S+$//;
+        $str .= " ...";
+    }
+    return $str;
+}
+
 # right-justify the left column of "left: right" elements, omit undefined elements
 sub format_table(@)
 {
@@ -338,7 +352,7 @@ sub send_commit_notice($$)
     }
 
     mail_notification($commitlist_address,
-        $info{"author_name"} . ": " . ${$info{"log"}}[0],
+        $info{"author_name"} . ": " . truncate_str(${$info{"log"}}[0], 50),
         "text/plain; charset=UTF-8", @notice);
     $sent_notices++;
 }