Skip to content

Commit df1effa

Browse files
eric-s-raymondgitster
authored andcommitted
Make the ciabot scripts completely self-configuring in the normal case.
Signed-off-by: Eric S. Raymond <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6484070 commit df1effa

File tree

4 files changed

+72
-37
lines changed

4 files changed

+72
-37
lines changed

contrib/ciabot/INSTALL

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,38 @@ It is no longer necessary to modify the script in order to put it
88
in place; in fact, this is now discouraged. It is entirely
99
configurable with the following git config variables:
1010

11-
ciabot.project = name of the project (required)
11+
ciabot.project = name of the project
1212
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
1414
ciabot.revformat = format in which the revision is shown
1515

16-
The ciabot.repo value defaults to ciabot.project lowercased.
17-
1816
The revformat variable may have the following values
1917
raw -> full hex ID of commit
2018
short -> first 12 chars of hex ID
2119
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.
2328

2429
Once you've set these variables, try your script with -n to see the
2530
notification message dumped to stdout and verify that it looks sane.
2631

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+
2743
After verifying correct function, install one of these scripts either
2844
in a post-commit hook or in an update hook.
2945

contrib/ciabot/README

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,4 @@ You probably want the Python version; it's faster, more capable, and
88
better documented. The shell version is maintained only as a fallback
99
for use on hosting sites that don't permit Python hook scripts.
1010

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-
2211
See the file INSTALL for installation instructions.

contrib/ciabot/ciabot.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
# usage: ciabot.py [-V] [-n] [-p projectname] [refname [commits...]]
1111
#
1212
# 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.
1816
#
1917
# In post-commit, run it without arguments. It will query for
2018
# current HEAD and the latest commit ID to get the information it
@@ -27,12 +25,17 @@
2725
# /path/to/ciabot.py ${refname} $(git rev-list ${oldhead}..${newhead} | tac)
2826
#
2927
# Configuration variables affecting this script:
30-
# ciabot.project = name of the project (required)
28+
#
29+
# ciabot.project = name of the project
3130
# ciabot.repo = name of the project repo for gitweb/cgit purposes
3231
# ciabot.xmlrpc = if true (default), ship notifications via XML-RPC
3332
# ciabot.revformat = format in which the revision is shown
3433
#
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.
3639
#
3740
# The revformat variable may have the following values
3841
# raw -> full hex ID of commit
@@ -102,7 +105,7 @@
102105
# Identify the generator script.
103106
# Should only change when the script itself gets a new home and maintainer.
104107
generator = "http://www.catb.org/~esr/ciabot.py"
105-
version = "3.5"
108+
version = "3.6"
106109

107110
def do(command):
108111
return commands.getstatusoutput(command)[1]
@@ -192,10 +195,17 @@ def report(refname, merged, xmlrpc=True):
192195
print "ciabot.py: version", version
193196
sys.exit(0)
194197

195-
# Cough and die if user has not specified a project
198+
# The project variable defaults to the name of the repository toplevel.
196199
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)
199209

200210
if not repo:
201211
repo = project.lower()

contrib/ciabot/ciabot.sh

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
# usage: ciabot.sh [-V] [-n] [-p projectname] [refname commit]
2222
#
2323
# 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.
2927
#
3028
# In post-commit, run it without arguments. It will query for
3129
# current HEAD and the latest commit ID to get the information it
@@ -44,11 +42,16 @@
4442
# most recent to least - better to ship notifactions from oldest to newest.
4543
#
4644
# Configuration variables affecting this script:
47-
# ciabot.project = name of the project (makes -p option unnecessary)
45+
#
46+
# ciabot.project = name of the project
4847
# ciabot.repo = name of the project repo for gitweb/cgit purposes
4948
# ciabot.revformat = format in which the revision is shown
5049
#
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.
5255
#
5356
# The revformat variable may have the following values
5457
# raw -> full hex ID of commit
@@ -64,10 +67,27 @@
6467
# shpped from an update in their actual order.)
6568
#
6669

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.
6972
project=$(git config --get ciabot.project)
7073

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+
7191
# Name of the repo for gitweb/cgit purposes
7292
repo=$(git config --get ciabot.repo)
7393
[ -z $repo] && repo=$(echo "${project}" | tr '[A-Z]' '[a-z]')
@@ -100,7 +120,7 @@ urlprefix="http://${host}/cgi-bin/cgit.cgi/${repo}/commit/?id="
100120
# Identify the script. The 'generator' variable should change only
101121
# when the script itself gets a new home and maintainer.
102122
generator="http://www.catb.org/~esr/ciabot/ciabot.sh"
103-
version=3.4
123+
version=3.5
104124

105125
# Addresses for the e-mail
106126
from="CIABOT-NOREPLY@${hostname}"

0 commit comments

Comments
 (0)