]> git.madduck.net Git - code/fbi-announce.git/blob - 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:

no need to include author in msgid
[code/fbi-announce.git] / fbi-announce.sh
1 #!/bin/sh
2 #
3 # fbi-announce — announce Git commits to the FBI mail-to-IRC gateway
4 #
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>
8 #
9 # Distributed under the terms of the GNU General Public License v2
10 #
11 # This script is based on Git ciabot.pl by Petr Baudis.
12 #
13 #
14 #
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@@)
25 #
26 # The hook is meant ot be run either from a post-commit hook or an update hook. If run in
27 # a central repository where people push to you want to run it in the update hook!
28 #
29 #   post-commit: It parses latest commit and current HEAD to get the information it needs.
30 #
31 #   update: You have to call it once per merged commit:
32 #
33 #       refname=$1
34 #       oldhead=$2
35 #       newhead=$3
36 #       for merged in $(git rev-list ${oldhead}..${newhead} | tac) ; do
37 #               /path/to/ciabot.bash ${refname} ${merged}
38 #       done
39 #
40 set -eu
41
42 # we need to ensure we know $GIT_DIR for the git-config calls
43 GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
44 if [ -z "$GIT_DIR" ]; then
45   echo >&2 "E: post-receive: GIT_DIR not set"
46   exit 1
47 fi
48 export GIT_DIR
49
50 project=$(git config hooks.fbi-project 2>/dev/null) || {
51   echo >&2 "E: FBI project not set (hooks.fbi-project)"
52   exit 1
53 }
54 component=$(git config hooks.fbi-component 2>/dev/null ||:)
55 url=$(git config hooks.fbi-url-template 2>/dev/null ||:)
56 noisy=$(git config hooks.fbi-noisy 2>/dev/null || echo false)
57 from=$(git config hooks.fbi-emailsender 2>/dev/null ||:)
58 to="commit@commit.ganneff.de" #TODO: possibly factor out to config
59
60 # mail submission client to use
61 if [ -n "$FBI_ANNOUNCE_TO_STDOUT" ]; then
62   sendmail="cat"
63   echo >&2 'I: outputting to stdout since $FBI_ANNOUNCE_TO_STDOUT is set.'
64 else
65   sendmail="/usr/sbin/sendmail -t"
66 fi
67
68 if [ $# -eq 0 ] ; then
69   # figure out refs from HEAD since they aren't passed
70   refname=$(git symbolic-ref HEAD 2>/dev/null)
71   merged=$(git rev-parse HEAD)
72 else
73   refname=$1
74   merged=$(git rev-parse $2)
75 fi
76 refname=${refname##refs/heads/}
77 refwidth=$(git config hooks.fbi-refwidth 2>/dev/null || echo 7)
78 ref=$(git describe ${merged} 2>/dev/null || echo ${merged} | cut -c1-${refwidth})
79
80 url=$(echo "$url" | sed -e "s,@@sha1@@,${merged},")
81
82 rawcommit=$(git cat-file commit ${merged})
83 author=$(echo "${rawcommit}" | sed -rne 's,^author (.+) <.*,\1,p')
84 logmessage=$(echo "${rawcommit}" | sed -e '1,/^$/d;s,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g')
85 ${noisy} || logmessage=$(echo "${logmessage}" | head -n2)
86
87 ts=$(echo "${rawcommit}" | sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p')
88 ts=$(date -d "@${ts}")
89
90 msg=$(git config hooks.fbi-msg-template 2>/dev/null ||:)
91 if [ -z "${msg}" ]; then
92   msg="${component:+$component/}${refname}: ${author}: ${logmessage} [${ref}] ${url}"
93 else
94   msg=$(echo "$msg" | sed -re 's,@@([^@]+)@@,${\1},g')
95   eval "msg=\"$msg\""
96 fi
97
98 ${sendmail} <<_eom
99 ${from:+From: ${from}
100 }To: ${to}
101 Subject: Announce ${project}
102 Message-Id: <fbi-announce.${ref}@${project}>
103
104 ${msg}
105 _eom