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.
3 # fbi-announce — announce Git commits to the FBI mail-to-IRC gateway
5 # Copyright (c) 2006 Fernando J. Pereda <ferdy@gentoo.org>
6 # Copyright (c) 2008 Joerg Jaspert <joerg@debian.org>
7 # Copyright © 2009–2010 martin f. krafft <madduck@debian.org>
9 # Distributed under the terms of the GNU General Public License v2
11 # This script is based on Git ciabot.pl by Petr Baudis.
15 # The script is meant to be configured using git-config with the following keys:
16 # hooks.fbi-project the project name known to FBI
17 # hooks.fbi-component an optional component name
18 # hooks.fbi-url-template the template to the gitweb URL (containing @@sha1@@)
19 # hooks.fbi-emailsender the sender address to use in the email
20 # hooks.fbi-refwidth the width of references to show (default 7)
21 # hooks.fbi-noisy include the entire log message in the announcement
22 # hooks.fbi-msg-template the template for the message to be sent (default:
23 # [@@component@@/]@@project@@: @@author@@: \
24 # @@logmessage@@ [@@ref@@] @@url@@)
26 # The hook is meant ot be run from the Git post-receive hook.
30 # we need to ensure we know $GIT_DIR for the git-config calls
31 GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
32 if [ -z "$GIT_DIR" ]; then
33 echo >&2 "E: post-receive: GIT_DIR not set"
38 project=$(git config hooks.fbi-project 2>/dev/null) || {
39 echo >&2 "E: FBI project not set (hooks.fbi-project)"
42 component=$(git config hooks.fbi-component 2>/dev/null ||:)
43 url=$(git config hooks.fbi-url-template 2>/dev/null ||:)
44 noisy=$(git config hooks.fbi-noisy 2>/dev/null || echo false)
45 from=$(git config hooks.fbi-emailsender 2>/dev/null ||:)
46 to="commit@commit.ganneff.de" #TODO: possibly factor out to config
48 # mail submission client to use
49 if [ -n "${FBI_ANNOUNCE_TO_STDOUT:-}" ]; then
51 echo >&2 'I: outputting to stdout since $FBI_ANNOUNCE_TO_STDOUT is set.'
53 sendmail="/usr/sbin/sendmail -t"
56 if [ $# -eq 0 ] ; then
57 # figure out refs from HEAD since they aren't passed
58 refname=$(git symbolic-ref HEAD 2>/dev/null)
59 merged=$(git rev-parse HEAD)
62 merged=$(git rev-parse $2)
64 refname=${refname##refs/heads/}
65 refwidth=$(git config hooks.fbi-refwidth 2>/dev/null || echo 7)
66 ref=$(git describe ${merged} 2>/dev/null || echo ${merged} | cut -c1-${refwidth})
68 url=$(echo "$url" | sed -e "s,@@sha1@@,${merged},")
70 rawcommit=$(git cat-file commit ${merged})
71 author=$(echo "${rawcommit}" | sed -rne 's,^author (.+) <.*,\1,p')
72 logmessage=$(echo "${rawcommit}" | sed -e '1,/^$/d;s,&,\&,g;s,<,\<,g;s,>,\>,g')
73 ${noisy} || logmessage=$(echo "${logmessage}" | head -n2)
75 ts=$(echo "${rawcommit}" | sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p')
76 ts=$(date -d "@${ts}")
78 msg=$(git config hooks.fbi-msg-template 2>/dev/null ||:)
79 if [ -z "${msg}" ]; then
80 msg="${component:+$component/}${refname}: ${author}: ${logmessage} [${ref}] ${url}"
82 msg=$(echo "$msg" | sed -re 's,@@([^@]+)@@,${\1},g')
89 Subject: Announce ${project}
90 Message-Id: <fbi-announce.${project}.${ref}@$(hostname --fqdn)>