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

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:

initial checkin
authormartin f. krafft <madduck@madduck.net>
Fri, 21 May 2010 13:40:10 +0000 (15:40 +0200)
committermartin f. krafft <madduck@madduck.net>
Fri, 21 May 2010 13:40:10 +0000 (15:40 +0200)
fbi-announce.sh [new file with mode: 0755]

diff --git a/fbi-announce.sh b/fbi-announce.sh
new file mode 100755 (executable)
index 0000000..abba489
--- /dev/null
@@ -0,0 +1,105 @@
+#!/bin/sh
+#
+# fbi-announce — announce Git commits to the FBI mail-to-IRC gateway
+#
+# Copyright (c) 2006 Fernando J. Pereda <ferdy@gentoo.org>
+# Copyright (c) 2008 Joerg Jaspert <joerg@debian.org>
+# Copyright © 2009–2010 martin f. krafft <madduck@debian.org>
+#
+# Distributed under the terms of the GNU General Public License v2
+#
+# This script is based on Git ciabot.pl by Petr Baudis.
+#
+#
+#
+# The script is meant to be configured using git-config with the following keys:
+#   hooks.fbi-project         the project name known to FBI
+#   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-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@@)
+#
+# The hook is meant ot be run either from a post-commit hook or an update hook. If run in
+# a central repository where people push to you want to run it in the update hook!
+#
+#   post-commit: It parses latest commit and current HEAD to get the information it needs.
+#
+#   update: You have to call it once per merged commit:
+#
+#       refname=$1
+#       oldhead=$2
+#       newhead=$3
+#       for merged in $(git rev-list ${oldhead}..${newhead} | tac) ; do
+#               /path/to/ciabot.bash ${refname} ${merged}
+#       done
+#
+set -eu
+
+# we need to ensure we know $GIT_DIR for the git-config calls
+GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
+if [ -z "$GIT_DIR" ]; then
+  echo >&2 "E: post-receive: GIT_DIR not set"
+  exit 1
+fi
+export GIT_DIR
+
+project=$(git config hooks.fbi-project 2>/dev/null) || {
+  echo >&2 "E: FBI project not set (hooks.fbi-project)"
+  exit 1
+}
+component=$(git config hooks.fbi-component 2>/dev/null ||:)
+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
+
+# mail submission client to use
+if [ -n "$FBI_ANNOUNCE_TO_STDOUT" ]; then
+  sendmail="cat"
+  echo >&2 'I: outputting to stdout since $FBI_ANNOUNCE_TO_STDOUT is set.'
+else
+  sendmail="/usr/sbin/sendmail -t"
+fi
+
+if [ $# -eq 0 ] ; then
+  # figure out refs from HEAD since they aren't passed
+  refname=$(git symbolic-ref HEAD 2>/dev/null)
+  merged=$(git rev-parse HEAD)
+else
+  refname=$1
+  merged=$(git rev-parse $2)
+fi
+refname=${refname##refs/heads/}
+refwidth=$(git config hooks.fbi-refwidth 2>/dev/null || echo 7)
+ref=$(git describe ${merged} 2>/dev/null || echo ${merged} | cut -c1-${refwidth})
+
+url=$(echo "$url" | sed -e "s,@@sha1@@,${merged},")
+
+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')
+${noisy} || logmessage=$(echo "${logmessage}" | head -n2)
+
+ts=$(echo "${rawcommit}" | sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p')
+ts=$(date -d "@${ts}")
+
+msg=$(git config hooks.fbi-msg-template 2>/dev/null ||:)
+if [ -z "${msg}" ]; then
+  msg="${component:+$component/}${refname}: ${author}: ${logmessage} [${ref}] ${url}"
+else
+  msg=$(echo "$msg" | sed -re 's,@@([^@]+)@@,${\1},g')
+  eval "msg=\"$msg\""
+fi
+
+${sendmail} <<_eom
+${from:+From: ${from}
+}To: ${to}
+Subject: Announce ${project}
+Message-ID: <fbi-announce.${ref}.${author}@${project}>
+
+${msg}
+_eom