Integrate version 3 ciabot scripts into contrib/.
These have been extensively live-tested in the last week. The version 2 ciabot.sh maintainer has passed the baton to me; ciabot.py is original. Signed-off-by: Eric S. Raymond <esr@thyrsus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Raymond committed
Apr 2, 2010 at 06:10 UTC
2c4dc02346c05eead81fa526a9c06212e63dd30e
3 files changed
+426
contrib/ciabot/README
new
+12
@@ -0,0 +1,12 @@
1
+These are hook scripts for the CIA notification service at <http://cia.vc/>
2
+
3
+They are maintained by Eric S. Raymond <esr@thyrsus.com>. There is an
4
+upstream resource page for them at <http://www.catb.org/esr/ciabot/>,
5
+but they are unlikely to change rapidly.
6
+
7
+You probably want the Python version; it's faster, more capable, and
8
+better documented. The shell version is maintained only as a fallback
9
+for use on hosting sites that don't permit Python hook scripts.
10
+
11
+You will find installation instructions for each script in its comment
12
+header.
contrib/ciabot/ciabot.py
new
+222
@@ -0,0 +1,222 @@
1
+#!/usr/bin/env python
2
+# Copyright (c) 2010 Eric S. Raymond <esr@thyrsus.com>
3
+# Distributed under BSD terms.
4
+#
5
+# This script contains porcelain and porcelain byproducts.
6
+# It's Python because the Python standard libraries avoid portability/security
7
+# issues raised by callouts in the ancestral Perl and sh scripts. It should
8
+# be compatible back to Python 2.1.5
9
+#
10
+# usage: ciabot.py [-V] [-n] [-p projectname] [refname [commits...]]
11
+#
12
+# This script is meant to be run either in a post-commit hook or in an
13
+# update hook. If there's nothing unusual about your hosting setup,
14
+# you can specify the project name with a -p option and avoid having
15
+# to modify this script. Try it with -n to see the notification mail
16
+# dumped to stdout and verify that it looks sane. With -V it dumps its
17
+# version and exits.
18
+#
19
+# In post-commit, run it without arguments (other than possibly a -p
20
+# option). It will query for current HEAD and the latest commit ID to
21
+# get the information it needs.
22
+#
23
+# In update, call it with a refname followed by a list of commits:
24
+# You want to reverse the order git rev-list emits becxause it lists
25
+# from most recent to oldest.
26
+#
27
+# /path/to/ciabot.py ${refname} $(git rev-list ${oldhead}..${newhead} | tac)
28
+#
29
+# Note: this script uses mail, not XML-RPC, in order to avoid stalling
30
+# until timeout when the CIA XML-RPC server is down.
31
+#
32
+
33
+#
34
+# The project as known to CIA. You will either want to change this
35
+# or invoke the script with a -p option to set it.
36
+#
37
+project=None
38
+
39
+#
40
+# You may not need to change these:
41
+#
42
+import os, sys, commands, socket, urllib
43
+
44
+# Name of the repository.
45
+# You can hardwire this to make the script faster.
46
+repo = os.path.basename(os.getcwd())
47
+
48
+# Fully-qualified domain name of this host.
49
+# You can hardwire this to make the script faster.
50
+host = socket.getfqdn()
51
+
52
+# Changeset URL prefix for your repo: when the commit ID is appended
53
+# to this, it should point at a CGI that will display the commit
54
+# through gitweb or something similar. The defaults will probably
55
+# work if you have a typical gitweb/cgit setup.
56
+#
57
+#urlprefix="http://%(host)s/cgi-bin/gitweb.cgi?p=%(repo)s;a=commit;h="
58
+urlprefix="http://%(host)s/cgi-bin/cgit.cgi/%(repo)s/commit/?id="
59
+
60
+# The service used to turn your gitwebbish URL into a tinyurl so it
61
+# will take up less space on the IRC notification line.
62
+tinyifier = "http://tinyurl.com/api-create.php?url="
63
+
64
+# The template used to generate the XML messages to CIA. You can make
65
+# visible changes to the IRC-bot notification lines by hacking this.
66
+# The default will produce a notfication line that looks like this:
67
+#
68
+# ${project}: ${author} ${repo}:${branch} * ${rev} ${files}: ${logmsg} ${url}
69
+#
70
+# By omitting $files you can collapse the files part to a single slash.
71
+xml = '''\
72
+<message>
73
+ <generator>
74
+ <name>CIA Python client for Git</name>
75
+ <version>%(gitver)s</version>
76
+ <url>%(generator)s</url>
77
+ </generator>
78
+ <source>
79
+ <project>%(project)s</project>
80
+ <branch>%(repo)s:%(branch)s</branch>
81
+ </source>
82
+ <timestamp>%(ts)s</timestamp>
83
+ <body>
84
+ <commit>
85
+ <author>%(author)s</author>
86
+ <revision>%(rev)s</revision>
87
+ <files>
88
+ %(files)s
89
+ </files>
90
+ <log>%(logmsg)s %(url)s</log>
91
+ <url>%(url)s</url>
92
+ </commit>
93
+ </body>
94
+</message>
95
+'''
96
+
97
+#
98
+# No user-serviceable parts below this line:
99
+#
100
+
101
+# Addresses for the e-mail. The from address is a dummy, since CIA
102
+# will never reply to this mail.
103
+fromaddr = "CIABOT-NOREPLY@" + host
104
+toaddr = "cia@cia.navi.cx"
105
+
106
+# Identify the generator script.
107
+# Should only change when the script itself gets a new home and maintainer.
108
+generator="http://www.catb.org/~esr/ciabot.py"
109
+
110
+def do(command):
111
+ return commands.getstatusoutput(command)[1]
112
+
113
+def report(refname, merged):
114
+ "Generate a commit notification to be reported to CIA"
115
+
116
+ # Try to tinyfy a reference to a web view for this commit.
117
+ try:
118
+ url = open(urllib.urlretrieve(tinyifier + urlprefix + merged)[0]).read()
119
+ except:
120
+ url = urlprefix + merged
121
+
122
+ branch = os.path.basename(refname)
123
+
124
+ # Compute a shortnane for the revision
125
+ rev = do("git describe ${merged} 2>/dev/null") or merged[:12]
126
+
127
+ # Extract the neta-information for the commit
128
+ rawcommit = do("git cat-file commit " + merged)
129
+ files=do("git diff-tree -r --name-only '"+ merged +"' | sed -e '1d' -e 's-.*-<file>&</file>-'")
130
+ inheader = True
131
+ headers = {}
132
+ logmsg = ""
133
+ for line in rawcommit.split("\n"):
134
+ if inheader:
135
+ if line:
136
+ fields = line.split()
137
+ headers[fields[0]] = " ".join(fields[1:])
138
+ else:
139
+ inheader = False
140
+ else:
141
+ logmsg = line
142
+ break
143
+ (author, ts) = headers["author"].split(">")
144
+
145
+ # This discards the part of the authors addrsss after @.
146
+ # Might be bnicece to ship the full email address, if not
147
+ # for spammers' address harvesters - getting this wrong
148
+ # would make the freenode #commits channel into harvester heaven.
149
+ author = author.replace("<", "").split("@")[0].split()[-1]
150
+
151
+ # This ignores the timezone. Not clear what to do with it...
152
+ ts = ts.strip().split()[0]
153
+
154
+ context = locals()
155
+ context.update(globals())
156
+
157
+ out = xml % context
158
+
159
+ message = '''\
160
+Message-ID: <%(merged)s.%(author)s@%(project)s>
161
+From: %(fromaddr)s
162
+To: %(toaddr)s
163
+Content-type: text/xml
164
+Subject: DeliverXML
165
+
166
+%(out)s''' % locals()
167
+
168
+ return message
169
+
170
+if __name__ == "__main__":
171
+ import getopt
172
+
173
+ try:
174
+ (options, arguments) = getopt.getopt(sys.argv[1:], "np:V")
175
+ except getopt.GetoptError, msg:
176
+ print "ciabot.py: " + str(msg)
177
+ raise SystemExit, 1
178
+
179
+ mailit = True
180
+ for (switch, val) in options:
181
+ if switch == '-p':
182
+ project = val
183
+ elif switch == '-n':
184
+ mailit = False
185
+ elif switch == '-V':
186
+ print "ciabot.py: version 3.2"
187
+ sys.exit(0)
188
+
189
+ # Cough and die if user has not specified a project
190
+ if not project:
191
+ sys.stderr.write("ciabot.py: no project specified, bailing out.\n")
192
+ sys.exit(1)
193
+
194
+ # We'll need the git version number.
195
+ gitver = do("git --version").split()[0]
196
+
197
+ urlprefix = urlprefix % globals()
198
+
199
+ # The script wants a reference to head followed by the list of
200
+ # commit ID to report about.
201
+ if len(arguments) == 0:
202
+ refname = do("git symbolic-ref HEAD 2>/dev/null")
203
+ merges = [do("git rev-parse HEAD")]
204
+ else:
205
+ refname = arguments[0]
206
+ merges = arguments[1:]
207
+
208
+ if mailit:
209
+ import smtplib
210
+ server = smtplib.SMTP('localhost')
211
+
212
+ for merged in merges:
213
+ message = report(refname, merged)
214
+ if mailit:
215
+ server.sendmail(fromaddr, [toaddr], message)
216
+ else:
217
+ print message
218
+
219
+ if mailit:
220
+ server.quit()
221
+
222
+#End
contrib/ciabot/ciabot.sh
new
+192
@@ -0,0 +1,192 @@
1
+#!/bin/sh
2
+# Distributed under the terms of the GNU General Public License v2
3
+# Copyright (c) 2006 Fernando J. Pereda <ferdy@gentoo.org>
4
+# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>
5
+# Copyright (c) 2010 Eric S. Raymond <esr@thyrsus.com>
6
+#
7
+# This is a version 3.x of ciabot.sh; use -V to find the exact
8
+# version. Versions 1 and 2 were shipped in 2006 and 2008 and are not
9
+# version-stamped. The version 2 maintainer has passed the baton.
10
+#
11
+# Note: This script should be considered obsolete.
12
+# There is a faster, better-documented rewrite in Python: find it as ciabot.py
13
+# Use this only if your hosting site forbids Python hooks.
14
+#
15
+# Originally based on Git ciabot.pl by Petr Baudis.
16
+# This script contains porcelain and porcelain byproducts.
17
+#
18
+# usage: ciabot.sh [-V] [-n] [-p projectname] [refname commit]
19
+#
20
+# This script is meant to be run either in a post-commit hook or in an
21
+# update hook. If there's nothing unusual about your hosting setup,
22
+# you can specify the project name with a -p option and avoid having
23
+# to modify this script. Try it with -n first to see the notification
24
+# mail dumped to stdout and verify that it looks sane. Use -V to dump
25
+# the version and exit.
26
+#
27
+# In post-commit, run it without arguments (other than possibly a -p
28
+# option). It will query for current HEAD and the latest commit ID to
29
+# get the information it needs.
30
+#
31
+# In 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
+# The reason for the tac call ids that git rev-list emits commits from
41
+# most recent to least - better to ship notifactions from oldest to newest.
42
+#
43
+# Note: this script uses mail, not XML-RPC, in order to avoid stalling
44
+# until timeout when the CIA XML-RPC server is down.
45
+#
46
+
47
+#
48
+# The project as known to CIA. You will either want to change this
49
+# or set the project name with a -p option.
50
+#
51
+project=
52
+
53
+#
54
+# You may not need to change these:
55
+#
56
+
57
+# Name of the repository.
58
+# You can hardwire this to make the script faster.
59
+repo="`basename ${PWD}`"
60
+
61
+# Fully qualified domain name of the repo host.
62
+# You can hardwire this to make the script faster.
63
+host=`hostname --fqdn`
64
+
65
+# Changeset URL prefix for your repo: when the commit ID is appended
66
+# to this, it should point at a CGI that will display the commit
67
+# through gitweb or something similar. The defaults will probably
68
+# work if you have a typical gitweb/cgit setup.
69
+#urlprefix="http://${host}/cgi-bin/gitweb.cgi?p=${repo};a=commit;h="
70
+urlprefix="http://${host}/cgi-bin/cgit.cgi/${repo}/commit/?id="
71
+
72
+#
73
+# You probably will not need to change the following:
74
+#
75
+
76
+# Identify the script. Should change only when the script itself
77
+# gets a new home and maintainer.
78
+generator="http://www.catb.org/~esr/ciabot/ciabot.sh"
79
+
80
+# Addresses for the e-mail
81
+from="CIABOT-NOREPLY@${host}"
82
+to="cia@cia.navi.cx"
83
+
84
+# SMTP client to use - may need to edit the absolute pathname for your system
85
+sendmail="sendmail -t -f ${from}"
86
+
87
+#
88
+# No user-serviceable parts below this line:
89
+#
90
+
91
+# Should include all places sendmail is likely to lurk.
92
+PATH="$PATH:/usr/sbin/"
93
+
94
+mode=mailit
95
+while getopts pnV opt
96
+do
97
+ case $opt in
98
+ p) project=$2; shift ; shift ;;
99
+ n) mode=dumpit; shift ;;
100
+ V) echo "ciabot.sh: version 3.2"; exit 0; shift ;;
101
+ esac
102
+done
103
+
104
+# Cough and die if user has not specified a project
105
+if [ -z "$project" ]
106
+then
107
+ echo "ciabot.sh: no project specified, bailing out." >&2
108
+ exit 1
109
+fi
110
+
111
+if [ $# -eq 0 ] ; then
112
+ refname=$(git symbolic-ref HEAD 2>/dev/null)
113
+ merged=$(git rev-parse HEAD)
114
+else
115
+ refname=$1
116
+ merged=$2
117
+fi
118
+
119
+# This tries to turn your gitwebbish URL into a tinyurl so it will take up
120
+# less space on the IRC notification line. Some repo sites (I'm looking at
121
+# you, berlios.de!) forbid wget calls for security reasons. On these,
122
+# the code will fall back to the full un-tinyfied URL.
123
+longurl=${urlprefix}${merged}
124
+url=$(wget -O - -q http://tinyurl.com/api-create.php?url=${longurl} 2>/dev/null)
125
+if [ -z "$url" ]; then
126
+ url="${longurl}"
127
+fi
128
+
129
+refname=${refname##refs/heads/}
130
+
131
+gitver=$(git --version)
132
+gitver=${gitver##* }
133
+
134
+rev=$(git describe ${merged} 2>/dev/null)
135
+# ${merged:0:12} was the only bashism left in the 2008 version of this
136
+# script, according to checkbashisms. Replace it with ${merged} here
137
+# because it was just a fallback anyway, and it's worth accepting a
138
+# longer fallback for faster execution and removing the bash
139
+# dependency.
140
+[ -z ${rev} ] && rev=${merged}
141
+
142
+# This discards the part of the author's address after @.
143
+# Might be nice to ship the full email address, if not
144
+# for spammers' address harvesters - getting this wrong
145
+# would make the freenode #commits channel into harvester heaven.
146
+rawcommit=$(git cat-file commit ${merged})
147
+author=$(echo "$rawcommit" | sed -n -e '/^author .*<\([^@]*\).*$/s--\1-p')
148
+logmessage=$(echo "$rawcommit" | sed -e '1,/^$/d' | head -n 1)
149
+logmessage=$(echo "$logmessage" | sed 's/\&/&\;/g; s/</<\;/g; s/>/>\;/g')
150
+ts=$(echo "$rawcommit" | sed -n -e '/^author .*> \([0-9]\+\).*$/s--\1-p')
151
+files=$(git diff-tree -r --name-only ${merged} | sed -e '1d' -e 's-.*-<file>&</file>-')
152
+
153
+out="
154
+<message>
155
+ <generator>
156
+ <name>CIA Shell client for Git</name>
157
+ <version>${gitver}</version>
158
+ <url>${generator}</url>
159
+ </generator>
160
+ <source>
161
+ <project>${project}</project>
162
+ <branch>$repo:${refname}</branch>
163
+ </source>
164
+ <timestamp>${ts}</timestamp>
165
+ <body>
166
+ <commit>
167
+ <author>${author}</author>
168
+ <revision>${rev}</revision>
169
+ <files>
170
+ ${files}
171
+ </files>
172
+ <log>${logmessage} ${url}</log>
173
+ <url>${url}</url>
174
+ </commit>
175
+ </body>
176
+</message>"
177
+
178
+if [ "$mode" = "dumpit" ]
179
+then
180
+ sendmail=cat
181
+fi
182
+
183
+${sendmail} << EOM
184
+Message-ID: <${merged}.${author}@${project}>
185
+From: ${from}
186
+To: ${to}
187
+Content-type: text/xml
188
+Subject: DeliverXML
189
+${out}
190
+EOM
191
+
192
+# vim: set tw=70 :