{"thread":{"id":"23299","subject":"[PATCH] Integrate version 3 ciabot scripts into contrib/.","startedAt":"2010-04-02T10:10:11Z","lastAt":"2010-04-02T19:05:04Z","messageCount":2,"participants":["Eric Raymond","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"138414","messageId":"20100402101011.GA6806@thyrsus.com","threadId":"23299","inReplyTo":null,"subject":"[PATCH] Integrate version 3 ciabot scripts into contrib/.","fromName":"Eric Raymond","fromEmail":"esr@thyrsus.com","sentAt":"2010-04-02T10:10:11Z","receivedAt":"2010-04-02T10:10:11Z","isPatch":true,"sender":{"key":"esr@thyrsus.com","avatar":"https://avatars.githubusercontent.com/u/727961?v=4"},"body":"These have been extensively live-tested in the last week. The version 2\nciabot.sh maintainer has passed the baton to me; ciabot.py is original.\n\nSigned-off-by: Eric S. Raymond <esr@thyrsus.com>\n---\n contrib/ciabot/README    |   12 +++\n contrib/ciabot/ciabot.py |  222 ++++++++++++++++++++++++++++++++++++++++++++++\n contrib/ciabot/ciabot.sh |  192 +++++++++++++++++++++++++++++++++++++++\n 3 files changed, 426 insertions(+), 0 deletions(-)\n create mode 100644 contrib/ciabot/README\n create mode 100755 contrib/ciabot/ciabot.py\n create mode 100755 contrib/ciabot/ciabot.sh\n\ndiff --git a/contrib/ciabot/README b/contrib/ciabot/README\nnew file mode 100644\nindex 0000000..2d8292e\n--- /dev/null\n+++ b/contrib/ciabot/README\n@@ -0,0 +1,12 @@\n+These are hook scripts for the CIA notification service at <http://cia.vc/>\n+\n+They are maintained by Eric S. Raymond <esr@thyrsus.com>.  There is an\n+upstream resource page for them at <http://www.catb.org/esr/ciabot/>,\n+but they are unlikely to change rapidly.\n+\n+You probably want the Python version; it's faster, more capable, and \n+better documented.  The shell version is maintained only as a fallback \n+for use on hosting sites that don't permit Python hook scripts.\n+\n+You will find installation instructions for each script in its comment\n+header. \ndiff --git a/contrib/ciabot/ciabot.py b/contrib/ciabot/ciabot.py\nnew file mode 100755\nindex 0000000..4b795a3\n--- /dev/null\n+++ b/contrib/ciabot/ciabot.py\n@@ -0,0 +1,222 @@\n+#!/usr/bin/env python\n+# Copyright (c) 2010 Eric S. Raymond <esr@thyrsus.com>\n+# Distributed under BSD terms.\n+#\n+# This script contains porcelain and porcelain byproducts.\n+# It's Python because the Python standard libraries avoid portability/security\n+# issues raised by callouts in the ancestral Perl and sh scripts.  It should\n+# be compatible back to Python 2.1.5\n+#\n+# usage: ciabot.py [-V] [-n] [-p projectname]  [refname [commits...]]\n+#\n+# This script is meant to be run either in a post-commit hook or in an\n+# update hook.  If there's nothing unusual about your hosting setup,\n+# you can specify the project name with a -p option and avoid having\n+# to modify this script.  Try it with -n to see the notification mail\n+# dumped to stdout and verify that it looks sane. With -V it dumps its\n+# version and exits.\n+#\n+# In post-commit, run it without arguments (other than possibly a -p\n+# option). It will query for current HEAD and the latest commit ID to\n+# get the information it needs. \n+#\n+# In update, call it with a refname followed by a list of commits:\n+# You want to reverse the order git rev-list emits becxause it lists\n+# from most recent to oldest.\n+#\n+# /path/to/ciabot.py ${refname} $(git rev-list ${oldhead}..${newhead} | tac)\n+#\n+# Note: this script uses mail, not XML-RPC, in order to avoid stalling\n+# until timeout when the CIA XML-RPC server is down. \n+#\n+\n+#\n+# The project as known to CIA. You will either want to change this\n+# or invoke the script with a -p option to set it.\n+#\n+project=None\n+\n+#\n+# You may not need to change these:\n+#\n+import os, sys, commands, socket, urllib\n+\n+# Name of the repository.\n+# You can hardwire this to make the script faster.\n+repo = os.path.basename(os.getcwd())\n+\n+# Fully-qualified domain name of this host.\n+# You can hardwire this to make the script faster.\n+host = socket.getfqdn()\n+\n+# Changeset URL prefix for your repo: when the commit ID is appended\n+# to this, it should point at a CGI that will display the commit\n+# through gitweb or something similar. The defaults will probably\n+# work if you have a typical gitweb/cgit setup.\n+#\n+#urlprefix=\"http://%(host)s/cgi-bin/gitweb.cgi?p=%(repo)s;a=commit;h=\"\n+urlprefix=\"http://%(host)s/cgi-bin/cgit.cgi/%(repo)s/commit/?id=\"\n+\n+# The service used to turn your gitwebbish URL into a tinyurl so it\n+# will take up less space on the IRC notification line.\n+tinyifier = \"http://tinyurl.com/api-create.php?url=\"\n+\n+# The template used to generate the XML messages to CIA.  You can make\n+# visible changes to the IRC-bot notification lines by hacking this.\n+# The default will produce a notfication line that looks like this:\n+#\n+# ${project}: ${author} ${repo}:${branch} * ${rev} ${files}: ${logmsg} ${url}\n+#\n+# By omitting $files you can collapse the files part to a single slash.\n+xml = '''\\\n+<message>\n+  <generator>\n+    <name>CIA Python client for Git</name>\n+    <version>%(gitver)s</version>\n+    <url>%(generator)s</url>\n+  </generator>\n+  <source>\n+    <project>%(project)s</project>\n+    <branch>%(repo)s:%(branch)s</branch>\n+  </source>\n+  <timestamp>%(ts)s</timestamp>\n+  <body>\n+    <commit>\n+      <author>%(author)s</author>\n+      <revision>%(rev)s</revision>\n+      <files>\n+        %(files)s\n+      </files>\n+      <log>%(logmsg)s %(url)s</log>\n+      <url>%(url)s</url>\n+    </commit>\n+  </body>\n+</message>\n+'''\n+\n+#\n+# No user-serviceable parts below this line:\n+#\n+\n+# Addresses for the e-mail. The from address is a dummy, since CIA\n+# will never reply to this mail.\n+fromaddr = \"CIABOT-NOREPLY@\" + host\n+toaddr = \"cia@cia.navi.cx\"\n+\n+# Identify the generator script.\n+# Should only change when the script itself gets a new home and maintainer.\n+generator=\"http://www.catb.org/~esr/ciabot.py\"\n+\n+def do(command):\n+    return commands.getstatusoutput(command)[1]\n+\n+def report(refname, merged):\n+    \"Generate a commit notification to be reported to CIA\"\n+\n+    # Try to tinyfy a reference to a web view for this commit.\n+    try:\n+        url = open(urllib.urlretrieve(tinyifier + urlprefix + merged)[0]).read()\n+    except:\n+        url = urlprefix + merged\n+\n+    branch = os.path.basename(refname)\n+\n+    # Compute a shortnane for the revision\n+    rev = do(\"git describe ${merged} 2>/dev/null\") or merged[:12]\n+\n+    # Extract the neta-information for the commit\n+    rawcommit = do(\"git cat-file commit \" + merged)\n+    files=do(\"git diff-tree -r --name-only '\"+ merged +\"' | sed -e '1d' -e 's-.*-<file>&</file>-'\")\n+    inheader = True\n+    headers = {}\n+    logmsg = \"\"\n+    for line in rawcommit.split(\"\\n\"):\n+        if inheader:\n+            if line:\n+                fields = line.split()\n+                headers[fields[0]] = \" \".join(fields[1:])\n+            else:\n+                inheader = False\n+        else:\n+            logmsg = line\n+            break\n+    (author, ts) = headers[\"author\"].split(\">\")\n+\n+    # This discards the part of the authors addrsss after @.\n+    # Might be bnicece to ship the full email address, if not\n+    # for spammers' address harvesters - getting this wrong\n+    # would make the freenode #commits channel into harvester heaven.\n+    author = author.replace(\"<\", \"\").split(\"@\")[0].split()[-1]\n+\n+    # This ignores the timezone.  Not clear what to do with it...\n+    ts = ts.strip().split()[0]\n+\n+    context = locals()\n+    context.update(globals())\n+\n+    out = xml % context\n+\n+    message = '''\\\n+Message-ID: <%(merged)s.%(author)s@%(project)s>\n+From: %(fromaddr)s\n+To: %(toaddr)s\n+Content-type: text/xml\n+Subject: DeliverXML\n+\n+%(out)s''' % locals()\n+\n+    return message\n+\n+if __name__ == \"__main__\":\n+    import getopt\n+\n+    try:\n+        (options, arguments) = getopt.getopt(sys.argv[1:], \"np:V\")\n+    except getopt.GetoptError, msg:\n+        print \"ciabot.py: \" + str(msg)\n+        raise SystemExit, 1\n+\n+    mailit = True\n+    for (switch, val) in options:\n+        if switch == '-p':\n+            project = val\n+        elif switch == '-n':\n+            mailit = False\n+        elif switch == '-V':\n+            print \"ciabot.py: version 3.2\"\n+            sys.exit(0)\n+\n+    # Cough and die if user has not specified a project\n+    if not project:\n+        sys.stderr.write(\"ciabot.py: no project specified, bailing out.\\n\")\n+        sys.exit(1)\n+\n+    # We'll need the git version number.\n+    gitver = do(\"git --version\").split()[0]\n+\n+    urlprefix = urlprefix % globals()\n+\n+    # The script wants a reference to head followed by the list of\n+    # commit ID to report about.\n+    if len(arguments) == 0:\n+        refname = do(\"git symbolic-ref HEAD 2>/dev/null\")\n+        merges = [do(\"git rev-parse HEAD\")]\n+    else:\n+        refname = arguments[0]\n+        merges = arguments[1:]\n+\n+    if mailit:\n+        import smtplib\n+        server = smtplib.SMTP('localhost')\n+\n+    for merged in merges:\n+        message = report(refname, merged)\n+        if mailit:\n+            server.sendmail(fromaddr, [toaddr], message)\n+        else:\n+            print message\n+\n+    if mailit:\n+        server.quit()\n+\n+#End\ndiff --git a/contrib/ciabot/ciabot.sh b/contrib/ciabot/ciabot.sh\nnew file mode 100755\nindex 0000000..5a80c46\n--- /dev/null\n+++ b/contrib/ciabot/ciabot.sh\n@@ -0,0 +1,192 @@\n+#!/bin/sh\n+# Distributed under the terms of the GNU General Public License v2\n+# Copyright (c) 2006 Fernando J. Pereda <ferdy@gentoo.org>\n+# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>\n+# Copyright (c) 2010 Eric S. Raymond <esr@thyrsus.com>\n+#\n+# This is a version 3.x of ciabot.sh; use -V to find the exact\n+# version.  Versions 1 and 2 were shipped in 2006 and 2008 and are not\n+# version-stamped.  The version 2 maintainer has passed the baton.\n+#\n+# Note: This script should be considered obsolete.  \n+# There is a faster, better-documented rewrite in Python: find it as ciabot.py\n+# Use this only if your hosting site forbids Python hooks.\n+#\n+# Originally based on Git ciabot.pl by Petr Baudis.\n+# This script contains porcelain and porcelain byproducts.\n+#\n+# usage: ciabot.sh [-V] [-n] [-p projectname] [refname commit]\n+#\n+# This script is meant to be run either in a post-commit hook or in an\n+# update hook.  If there's nothing unusual about your hosting setup,\n+# you can specify the project name with a -p option and avoid having\n+# to modify this script.  Try it with -n first to see the notification\n+# mail dumped to stdout and verify that it looks sane.  Use -V to dump\n+# the version and exit.\n+#\n+# In post-commit, run it without arguments (other than possibly a -p\n+# option). It will query for current HEAD and the latest commit ID to\n+# get the information it needs.\n+#\n+# In update, you have to call it once per merged commit:\n+#\n+#       refname=$1\n+#       oldhead=$2\n+#       newhead=$3\n+#       for merged in $(git rev-list ${oldhead}..${newhead} | tac) ; do\n+#               /path/to/ciabot.bash ${refname} ${merged}\n+#       done\n+#\n+# The reason for the tac call ids that git rev-list emits commits from\n+# most recent to least - better to ship notifactions from oldest to newest.\n+#\n+# Note: this script uses mail, not XML-RPC, in order to avoid stalling\n+# until timeout when the CIA XML-RPC server is down. \n+#\n+\n+#\n+# The project as known to CIA. You will either want to change this\n+# or set the project name with a -p option.\n+#\n+project=\n+\n+#\n+# You may not need to change these:\n+#\n+\n+# Name of the repository.\n+# You can hardwire this to make the script faster.\n+repo=\"`basename ${PWD}`\"\n+\n+# Fully qualified domain name of the repo host.\n+# You can hardwire this to make the script faster.\n+host=`hostname --fqdn`\n+\n+# Changeset URL prefix for your repo: when the commit ID is appended\n+# to this, it should point at a CGI that will display the commit\n+# through gitweb or something similar. The defaults will probably\n+# work if you have a typical gitweb/cgit setup.\n+#urlprefix=\"http://${host}/cgi-bin/gitweb.cgi?p=${repo};a=commit;h=\"\n+urlprefix=\"http://${host}/cgi-bin/cgit.cgi/${repo}/commit/?id=\"\n+\n+#\n+# You probably will not need to change the following:\n+#\n+\n+# Identify the script. Should change only when the script itself \n+# gets a new home and maintainer. \n+generator=\"http://www.catb.org/~esr/ciabot/ciabot.sh\"\n+\n+# Addresses for the e-mail\n+from=\"CIABOT-NOREPLY@${host}\"\n+to=\"cia@cia.navi.cx\"\n+\n+# SMTP client to use - may need to edit the absolute pathname for your system\n+sendmail=\"sendmail -t -f ${from}\"\n+\n+#\n+# No user-serviceable parts below this line:\n+#\n+\n+# Should include all places sendmail is likely to lurk. \n+PATH=\"$PATH:/usr/sbin/\"\n+\n+mode=mailit\n+while getopts pnV opt\n+do\n+    case $opt in\n+        p) project=$2; shift ; shift ;;\n+\tn) mode=dumpit; shift ;;\n+\tV) echo \"ciabot.sh: version 3.2\"; exit 0; shift ;;\n+    esac\n+done\n+\n+# Cough and die if user has not specified a project\n+if [ -z \"$project\" ]\n+then\n+    echo \"ciabot.sh: no project specified, bailing out.\" >&2\n+    exit 1\n+fi\n+\n+if [ $# -eq 0 ] ; then\n+\trefname=$(git symbolic-ref HEAD 2>/dev/null)\n+\tmerged=$(git rev-parse HEAD)\n+else\n+\trefname=$1\n+\tmerged=$2\n+fi\n+\n+# This tries to turn your gitwebbish URL into a tinyurl so it will take up\n+# less space on the IRC notification line. Some repo sites (I'm looking at\n+# you, berlios.de!) forbid wget calls for security reasons.  On these,\n+# the code will fall back to the full un-tinyfied URL.\n+longurl=${urlprefix}${merged}\n+url=$(wget -O - -q http://tinyurl.com/api-create.php?url=${longurl} 2>/dev/null)\n+if [ -z \"$url\" ]; then\n+\turl=\"${longurl}\"\n+fi\n+\n+refname=${refname##refs/heads/}\n+\n+gitver=$(git --version)\n+gitver=${gitver##* }\n+\n+rev=$(git describe ${merged} 2>/dev/null)\n+# ${merged:0:12} was the only bashism left in the 2008 version of this\n+# script, according to checkbashisms.  Replace it with ${merged} here\n+# because it was just a fallback anyway, and it's worth accepting a\n+# longer fallback for faster execution and removing the bash\n+# dependency.\n+[ -z ${rev} ] && rev=${merged}\n+\n+# This discards the part of the author's address after @.\n+# Might be nice to ship the full email address, if not\n+# for spammers' address harvesters - getting this wrong\n+# would make the freenode #commits channel into harvester heaven.\n+rawcommit=$(git cat-file commit ${merged})\n+author=$(echo \"$rawcommit\" | sed -n -e '/^author .*<\\([^@]*\\).*$/s--\\1-p')\n+logmessage=$(echo \"$rawcommit\" | sed -e '1,/^$/d' | head -n 1)\n+logmessage=$(echo \"$logmessage\" | sed 's/\\&/&amp\\;/g; s/</&lt\\;/g; s/>/&gt\\;/g')\n+ts=$(echo \"$rawcommit\" | sed -n -e '/^author .*> \\([0-9]\\+\\).*$/s--\\1-p')\n+files=$(git diff-tree -r --name-only ${merged} | sed -e '1d' -e 's-.*-<file>&</file>-')\n+\n+out=\"\n+<message>\n+  <generator>\n+    <name>CIA Shell client for Git</name>\n+    <version>${gitver}</version>\n+    <url>${generator}</url>\n+  </generator>\n+  <source>\n+    <project>${project}</project>\n+    <branch>$repo:${refname}</branch>\n+  </source>\n+  <timestamp>${ts}</timestamp>\n+  <body>\n+    <commit>\n+      <author>${author}</author>\n+      <revision>${rev}</revision>\n+      <files>\n+        ${files}\n+      </files>\n+      <log>${logmessage} ${url}</log>\n+      <url>${url}</url>\n+    </commit>\n+  </body>\n+</message>\"\n+\n+if [ \"$mode\" = \"dumpit\" ]\n+then\n+    sendmail=cat\n+fi\n+\n+${sendmail} << EOM\n+Message-ID: <${merged}.${author}@${project}>\n+From: ${from}\n+To: ${to}\n+Content-type: text/xml\n+Subject: DeliverXML\n+${out}\n+EOM\n+\n+# vim: set tw=70 :\n-- \n1.6.3.3\n\n\n-- \n\t\t<a href=\"http://www.catb.org/~esr/\">Eric S. Raymond</a>\n"},{"id":"138448","messageId":"7vy6h5ad5r.fsf@alter.siamese.dyndns.org","threadId":"23299","inReplyTo":"20100402101011.GA6806@thyrsus.com","subject":"Re: [PATCH] Integrate version 3 ciabot scripts into contrib/.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-02T19:05:04Z","receivedAt":"2010-04-02T19:05:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"esr@thyrsus.com (Eric Raymond) writes:\n\n> These have been extensively live-tested in the last week. The version 2\n> ciabot.sh maintainer has passed the baton to me; ciabot.py is original.\n\nThanks, will apply.\n"}]}