Make the ciabot scripts completely self-configuring in the normal case.

Signed-off-by: Eric S. Raymond <esr@thyrsus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric S. Raymond committed Aug 23, 2012 at 01:21 UTC df1effa6909d07c859e4ade03dbea3e32e5595b4
4 files changed +72 -37
contrib/ciabot/INSTALL
+21 -5
@@ -8,22 +8,38 @@ It is no longer necessary to modify the script in order to put it
8 in place; in fact, this is now discouraged. It is entirely
9 configurable with the following git config variables:
10
11 -ciabot.project = name of the project (required)
11 +ciabot.project = name of the project
12 ciabot.repo = name of the project repo for gitweb/cgit purposes
13 -ciabot.xmlrpc = if true (default), ship notifications via XML-RPC
13 +ciabot.xmlrpc = if true, ship notifications via XML-RPC
14 ciabot.revformat = format in which the revision is shown
15
16 -The ciabot.repo value defaults to ciabot.project lowercased.
17 -
16 The revformat variable may have the following values
17 raw -> full hex ID of commit
18 short -> first 12 chars of hex ID
19 describe -> describe relative to last tag, falling back to short
22 -The default is 'describe'.
20 +
21 +ciabot.project defaults to the directory name of the repository toplevel.
22 +ciabot.repo defaults to ciabot.project lowercased.
23 +ciabot.xmlrpc defaults to True
24 +ciabot.revformat defaults to 'describe'.
25 +
26 +This means that in the normal case you need not do any configuration at all,
27 +however setting ciabot.project will allow the hook to run slightly faster.
28
29 Once you've set these variables, try your script with -n to see the
30 notification message dumped to stdout and verify that it looks sane.
31
32 +To live-test these scripts, your project needs to have been registered with
33 +the CIA site. Here are the steps:
34 +
35 +1. Open an IRC window on irc://freenode/commits or your registered
36 + project IRC channel.
37 +
38 +2. Run ciabot.py and/or ciabot.sh from any directory under git
39 + control.
40 +
41 +You should see a notification on the channel for your most recent commit.
42 +
43 After verifying correct function, install one of these scripts either
44 in a post-commit hook or in an update hook.
45
contrib/ciabot/README
-11
@@ -8,15 +8,4 @@ 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 -To test these scripts, your project needs to have been registered with
12 -the CIA site. Here are the steps:
13 -
14 -1. Open an IRC window on irc://freenode/commits or your registered
15 - project IRC channel.
16 -
17 -2. Run ciabot.py and/or ciabot.sh from any directory under git
18 - control, using the -p option to pass in your project name.
19 -
20 -You should see a notification on the channel for your most recent commit.
21 -
11 See the file INSTALL for installation instructions.
contrib/ciabot/ciabot.py
+21 -11
@@ -10,11 +10,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 and repo with config variables and
15 -# avoid having to modify this script. Try it with -n to see the
16 -# notification mail dumped to stdout and verify that it looks
17 -# sane. With -V it dumps its version and exits.
13 +# update hook. Try it with -n to see the notification mail dumped to
14 +# stdout and verify that it looks sane. With -V it dumps its version
15 +# and exits.
16 #
17 # In post-commit, run it without arguments. It will query for
18 # current HEAD and the latest commit ID to get the information it
@@ -27,12 +25,17 @@
25 # /path/to/ciabot.py ${refname} $(git rev-list ${oldhead}..${newhead} | tac)
26 #
27 # Configuration variables affecting this script:
30 -# ciabot.project = name of the project (required)
28 +#
29 +# ciabot.project = name of the project
30 # ciabot.repo = name of the project repo for gitweb/cgit purposes
31 # ciabot.xmlrpc = if true (default), ship notifications via XML-RPC
32 # ciabot.revformat = format in which the revision is shown
33 #
35 -# The ciabot.repo value defaults to ciabot.project lowercased.
34 +# ciabot.project defaults to the directory name of the repository toplevel.
35 +# ciabot.repo defaults to ciabot.project lowercased.
36 +#
37 +# This means that in the normal case you need not do any configuration at all,
38 +# but setting the project name will speed it up slightly.
39 #
40 # The revformat variable may have the following values
41 # raw -> full hex ID of commit
@@ -102,7 +105,7 @@ toaddr = "cia@cia.vc"
105 # Identify the generator script.
106 # Should only change when the script itself gets a new home and maintainer.
107 generator = "http://www.catb.org/~esr/ciabot.py"
105 -version = "3.5"
108 +version = "3.6"
109
110 def do(command):
111 return commands.getstatusoutput(command)[1]
@@ -192,10 +195,17 @@ if __name__ == "__main__":
195 print "ciabot.py: version", version
196 sys.exit(0)
197
195 - # Cough and die if user has not specified a project
198 + # The project variable defaults to the name of the repository toplevel.
199 if not project:
197 - sys.stderr.write("ciabot.py: no project specified, bailing out.\n")
198 - sys.exit(1)
200 + here = os.getcwd()
201 + while True:
202 + if os.path.exists(os.path.join(here, ".git")):
203 + project = os.path.basename(here)
204 + break
205 + elif here == '/':
206 + sys.stderr.write("ciabot.py: no .git below root!\n")
207 + sys.exit(1)
208 + here = os.path.dirname(here)
209
210 if not repo:
211 repo = project.lower()
contrib/ciabot/ciabot.sh
+30 -10
@@ -21,11 +21,9 @@
21 # usage: ciabot.sh [-V] [-n] [-p projectname] [refname commit]
22 #
23 # This script is meant to be run either in a post-commit hook or in an
24 -# update hook. If there's nothing unusual about your hosting setup,
25 -# you can specify the project name and repo with config variables and
26 -# avoid having to modify this script. Try it with -n to see the
27 -# notification mail dumped to stdout and verify that it looks
28 -# sane. With -V it dumps its version and exits.
24 +# update hook. Try it with -n to see the notification mail dumped to
25 +# stdout and verify that it looks sane. With -V it dumps its version
26 +# and exits.
27 #
28 # In post-commit, run it without arguments. It will query for
29 # current HEAD and the latest commit ID to get the information it
@@ -44,11 +42,16 @@
42 # most recent to least - better to ship notifactions from oldest to newest.
43 #
44 # Configuration variables affecting this script:
47 -# ciabot.project = name of the project (makes -p option unnecessary)
45 +#
46 +# ciabot.project = name of the project
47 # ciabot.repo = name of the project repo for gitweb/cgit purposes
48 # ciabot.revformat = format in which the revision is shown
49 #
51 -# The ciabot.repo defaults to ciabot.project lowercased.
50 +# ciabot.project defaults to the directory name of the repository toplevel.
51 +# ciabot.repo defaults to ciabot.project lowercased.
52 +#
53 +# This means that in the normal case you need not do any configuration at all,
54 +# but setting the project name will speed it up slightly.
55 #
56 # The revformat variable may have the following values
57 # raw -> full hex ID of commit
@@ -64,10 +67,27 @@
67 # shpped from an update in their actual order.)
68 #
69
67 -# The project as known to CIA. You can also hardwire this or set it with a
68 -# -p option.
70 +# The project as known to CIA. You can set this with a -p option,
71 +# or let it default to the directory name of the repo toplevel.
72 project=$(git config --get ciabot.project)
73
74 +if [ -z $project ]
75 +then
76 + here=`pwd`;
77 + while :; do
78 + if [ -d $here/.git ]
79 + then
80 + project=`basename $here`
81 + break
82 + elif [ $here = '/' ]
83 + then
84 + echo "ciabot.sh: no .git below root!"
85 + exit 1
86 + fi
87 + here=`dirname $here`
88 + done
89 +fi
90 +
91 # Name of the repo for gitweb/cgit purposes
92 repo=$(git config --get ciabot.repo)
93 [ -z $repo] && repo=$(echo "${project}" | tr '[A-Z]' '[a-z]')
@@ -100,7 +120,7 @@ urlprefix="http://${host}/cgi-bin/cgit.cgi/${repo}/commit/?id="
120 # Identify the script. The 'generator' variable should change only
121 # when the script itself gets a new home and maintainer.
122 generator="http://www.catb.org/~esr/ciabot/ciabot.sh"
103 -version=3.4
123 +version=3.5
124
125 # Addresses for the e-mail
126 from="CIABOT-NOREPLY@${hostname}"