]> git.madduck.net Git - code/fbi-announce.git/blobdiff - fbi-announce.sh

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

trim message in case url is empty
[code/fbi-announce.git] / fbi-announce.sh
index eb0329c644572aa3062f877f5588265c3c9198cd..7084136cfc726ce7d44ab8c5001cf51da61b521b 100755 (executable)
 #   hooks.fbi-component       an optional component name
 #   hooks.fbi-url-template    the template to the gitweb URL (containing @@sha1@@)
 #   hooks.fbi-emailsender     the sender address to use in the email
 #   hooks.fbi-component       an optional component name
 #   hooks.fbi-url-template    the template to the gitweb URL (containing @@sha1@@)
 #   hooks.fbi-emailsender     the sender address to use in the email
+#   hooks.fbi-emailcc         carbon-copy recipients (comma-separated) if the message
 #   hooks.fbi-refwidth        the width of references to show (default 7)
 #   hooks.fbi-noisy           include the entire log message in the announcement
 #   hooks.fbi-msg-template    the template for the message to be sent (default:
 #   hooks.fbi-refwidth        the width of references to show (default 7)
 #   hooks.fbi-noisy           include the entire log message in the announcement
 #   hooks.fbi-msg-template    the template for the message to be sent (default:
-#                               [@@component@@/]@@project@@: @@author@@: \
-#                               @@logmessage@@ [@@ref@@] @@url@@)
+#                               {@@component@@/}@@project@@[@@ref@@]: @@author@@: \
+#                               @@logmessage@@ [@@url@@])
 #
 # The hook is meant ot be run from the Git post-receive hook.
 #
 #
 # The hook is meant ot be run from the Git post-receive hook.
 #
@@ -44,6 +45,7 @@ url=$(git config hooks.fbi-url-template 2>/dev/null ||:)
 noisy=$(git config hooks.fbi-noisy 2>/dev/null || echo false)
 from=$(git config hooks.fbi-emailsender 2>/dev/null ||:)
 to="commit@commit.ganneff.de" #TODO: possibly factor out to config
 noisy=$(git config hooks.fbi-noisy 2>/dev/null || echo false)
 from=$(git config hooks.fbi-emailsender 2>/dev/null ||:)
 to="commit@commit.ganneff.de" #TODO: possibly factor out to config
+cc=$(git config hooks.fbi-emailcc 2>/dev/null ||:)
 
 # mail submission client to use
 if [ -n "${FBI_ANNOUNCE_TO_STDOUT:-}" ]; then
 
 # mail submission client to use
 if [ -n "${FBI_ANNOUNCE_TO_STDOUT:-}" ]; then
@@ -69,7 +71,7 @@ url=$(echo "$url" | sed -e "s,@@sha1@@,${merged},")
 
 rawcommit=$(git cat-file commit ${merged})
 author=$(echo "${rawcommit}" | sed -rne 's,^author (.+) <.*,\1,p')
 
 rawcommit=$(git cat-file commit ${merged})
 author=$(echo "${rawcommit}" | sed -rne 's,^author (.+) <.*,\1,p')
-logmessage=$(echo "${rawcommit}" | sed -e '1,/^$/d;s,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g')
+logmessage=$(echo "${rawcommit}" | sed -e '1,/^$/d')
 ${noisy} || logmessage=$(echo "${logmessage}" | head -n2)
 
 ts=$(echo "${rawcommit}" | sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p')
 ${noisy} || logmessage=$(echo "${logmessage}" | head -n2)
 
 ts=$(echo "${rawcommit}" | sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p')
@@ -77,17 +79,24 @@ ts=$(date -d "@${ts}")
 
 msg=$(git config hooks.fbi-msg-template 2>/dev/null ||:)
 if [ -z "${msg}" ]; then
 
 msg=$(git config hooks.fbi-msg-template 2>/dev/null ||:)
 if [ -z "${msg}" ]; then
-  msg="${component:+$component/}${refname}: ${author}: ${logmessage} [${ref}] ${url}"
+  msg="${component:+$component/}${refname}[${ref}]: ${author}: ${logmessage} [${url}]"
 else
   msg=$(echo "$msg" | sed -re 's,@@([^@]+)@@,${\1},g')
   eval "msg=\"$msg\""
 fi
 
 else
   msg=$(echo "$msg" | sed -re 's,@@([^@]+)@@,${\1},g')
   eval "msg=\"$msg\""
 fi
 
+# trim $msg of empty []'s in case no URL was provided, might be better done in
+# the above by making the generation conditional, but this will also do for
+# now.
+msg="${msg% []}"
+
 ${sendmail} <<_eom
 ${from:+From: ${from}
 }To: ${to}
 ${sendmail} <<_eom
 ${from:+From: ${from}
 }To: ${to}
-Subject: Announce ${project}
+${cc:+Cc: ${cc}
+}Subject: Announce ${project}
 Message-Id: <fbi-announce.${project}.${ref}@$(hostname --fqdn)>
 Message-Id: <fbi-announce.${project}.${ref}@$(hostname --fqdn)>
+Content-type: text/plain; charset=utf-8
 
 ${msg}
 _eom
 
 ${msg}
 _eom