{"thread":{"id":"31328","subject":"[PATCH] Make the ciabot scripts completely self-configuring in the normal case.","startedAt":"2012-08-23T05:21:53Z","lastAt":"2012-08-23T05:21:53Z","messageCount":1,"participants":["Eric S. Raymond"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"197676","messageId":"20120823052153.GA14585@thyrsus.com","threadId":"31328","inReplyTo":null,"subject":"[PATCH] Make the ciabot scripts completely self-configuring in the normal case.","fromName":"Eric S. Raymond","fromEmail":"esr@thyrsus.com","sentAt":"2012-08-23T05:21:53Z","receivedAt":"2012-08-23T05:21:53Z","isPatch":true,"sender":{"key":"esr@thyrsus.com","avatar":"https://avatars.githubusercontent.com/u/727961?v=4"},"body":"Signed-off-by: Eric S. Raymond <esr@thyrsus.com>\n---\n contrib/ciabot/INSTALL   |   26 +++++++++++++++++++++-----\n contrib/ciabot/README    |   11 -----------\n contrib/ciabot/ciabot.py |   32 +++++++++++++++++++++-----------\n contrib/ciabot/ciabot.sh |   40 ++++++++++++++++++++++++++++++----------\n 4 files changed, 72 insertions(+), 37 deletions(-)\n\ndiff --git a/contrib/ciabot/INSTALL b/contrib/ciabot/INSTALL\nindex dbfd165..428a5b9 100644\n--- a/contrib/ciabot/INSTALL\n+++ b/contrib/ciabot/INSTALL\n@@ -8,22 +8,38 @@ It is no longer necessary to modify the script in order to put it\n in place; in fact, this is now discouraged. It is entirely\n configurable with the following git config variables:\n \n-ciabot.project = name of the project (required)\n+ciabot.project = name of the project\n ciabot.repo = name of the project repo for gitweb/cgit purposes\n-ciabot.xmlrpc  = if true (default), ship notifications via XML-RPC\n+ciabot.xmlrpc  = if true, ship notifications via XML-RPC\n ciabot.revformat = format in which the revision is shown\n \n-The ciabot.repo value defaults to ciabot.project lowercased.\n-\n The revformat variable may have the following values\n raw -> full hex ID of commit\n short -> first 12 chars of hex ID\n describe -> describe relative to last tag, falling back to short\n-The default is 'describe'.\n+\n+ciabot.project defaults to the directory name of the repository toplevel.\n+ciabot.repo defaults to ciabot.project lowercased. \n+ciabot.xmlrpc defaults to True\n+ciabot.revformat defaults to 'describe'.\n+\n+This means that in the normal case you need not do any configuration at all,\n+however setting ciabot.project will allow the hook to run slightly faster.\n \n Once you've set these variables, try your script with -n to see the\n notification message dumped to stdout and verify that it looks sane.\n \n+To live-test these scripts, your project needs to have been registered with\n+the CIA site.  Here are the steps:\n+\n+1. Open an IRC window on irc://freenode/commits or your registered \n+   project IRC channel.  \n+\n+2. Run ciabot.py and/or ciabot.sh from any directory under git\n+   control.\n+\n+You should see a notification on the channel for your most recent commit.\n+\n After verifying correct function, install one of these scripts either\n in a post-commit hook or in an update hook.\n \ndiff --git a/contrib/ciabot/README b/contrib/ciabot/README\nindex 9eccca3..2dfe1f9 100644\n--- a/contrib/ciabot/README\n+++ b/contrib/ciabot/README\n@@ -8,15 +8,4 @@ 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-To test these scripts, your project needs to have been registered with\n-the CIA site.  Here are the steps:\n-\n-1. Open an IRC window on irc://freenode/commits or your registered \n-   project IRC channel.  \n-\n-2. Run ciabot.py and/or ciabot.sh from any directory under git\n-   control, using the -p option to pass in your project name.\n-\n-You should see a notification on the channel for your most recent commit.\n-\n See the file INSTALL for installation instructions.\ndiff --git a/contrib/ciabot/ciabot.py b/contrib/ciabot/ciabot.py\nindex 8ce04eb..6863fea 100755\n--- a/contrib/ciabot/ciabot.py\n+++ b/contrib/ciabot/ciabot.py\n@@ -10,11 +10,9 @@\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 and repo with config variables and\n-# avoid having to modify this script.  Try it with -n to see the\n-# notification mail dumped to stdout and verify that it looks\n-# sane. With -V it dumps its version and exits.\n+# update hook. Try it with -n to see the notification mail dumped to\n+# stdout and verify that it looks sane. With -V it dumps its version\n+# and exits.\n #\n # In post-commit, run it without arguments. It will query for\n # current HEAD and the latest commit ID to get the information it\n@@ -27,12 +25,17 @@\n # /path/to/ciabot.py ${refname} $(git rev-list ${oldhead}..${newhead} | tac)\n #\n # Configuration variables affecting this script:\n-# ciabot.project = name of the project (required)\n+#\n+# ciabot.project = name of the project\n # ciabot.repo = name of the project repo for gitweb/cgit purposes\n # ciabot.xmlrpc  = if true (default), ship notifications via XML-RPC\n # ciabot.revformat = format in which the revision is shown\n #\n-# The ciabot.repo value defaults to ciabot.project lowercased.\n+# ciabot.project defaults to the directory name of the repository toplevel.\n+# ciabot.repo defaults to ciabot.project lowercased.\n+#\n+# This means that in the normal case you need not do any configuration at all,\n+# but setting the project name will speed it up slightly.\n #\n # The revformat variable may have the following values\n # raw -> full hex ID of commit\n@@ -102,7 +105,7 @@ toaddr = \"cia@cia.vc\"\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-version = \"3.5\"\n+version = \"3.6\"\n \n def do(command):\n     return commands.getstatusoutput(command)[1]\n@@ -192,10 +195,17 @@ if __name__ == \"__main__\":\n             print \"ciabot.py: version\", version\n             sys.exit(0)\n \n-    # Cough and die if user has not specified a project\n+    # The project variable defaults to the name of the repository toplevel. \n     if not project:\n-        sys.stderr.write(\"ciabot.py: no project specified, bailing out.\\n\")\n-        sys.exit(1)\n+        here = os.getcwd()\n+        while True:\n+            if os.path.exists(os.path.join(here, \".git\")):\n+                project = os.path.basename(here)\n+                break\n+            elif here == '/':\n+                sys.stderr.write(\"ciabot.py: no .git below root!\\n\")\n+                sys.exit(1)\n+            here = os.path.dirname(here)\n \n     if not repo:\n         repo = project.lower()\ndiff --git a/contrib/ciabot/ciabot.sh b/contrib/ciabot/ciabot.sh\nindex 39afb47..b5583dc 100755\n--- a/contrib/ciabot/ciabot.sh\n+++ b/contrib/ciabot/ciabot.sh\n@@ -21,11 +21,9 @@\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 and repo with config variables and\n-# avoid having to modify this script.  Try it with -n to see the\n-# notification mail dumped to stdout and verify that it looks\n-# sane. With -V it dumps its version and exits.\n+# update hook. Try it with -n to see the notification mail dumped to\n+# stdout and verify that it looks sane. With -V it dumps its version\n+# and exits.\n #\n # In post-commit, run it without arguments. It will query for\n # current HEAD and the latest commit ID to get the information it\n@@ -44,11 +42,16 @@\n # most recent to least - better to ship notifactions from oldest to newest.\n #\n # Configuration variables affecting this script:\n-# ciabot.project = name of the project (makes -p option unnecessary)\n+#\n+# ciabot.project = name of the project\n # ciabot.repo = name of the project repo for gitweb/cgit purposes\n # ciabot.revformat = format in which the revision is shown\n #\n-# The ciabot.repo defaults to ciabot.project lowercased.\n+# ciabot.project defaults to the directory name of the repository toplevel.\n+# ciabot.repo defaults to ciabot.project lowercased.\n+#\n+# This means that in the normal case you need not do any configuration at all,\n+# but setting the project name will speed it up slightly.\n #\n # The revformat variable may have the following values\n # raw -> full hex ID of commit\n@@ -64,10 +67,27 @@\n # shpped from an update in their actual order.)\n #\n \n-# The project as known to CIA. You can also hardwire this or set it with a\n-# -p option.\n+# The project as known to CIA. You can set this with a -p option,\n+# or let it default to the directory name of the repo toplevel.\n project=$(git config --get ciabot.project)\n \n+if [ -z $project ]\n+then\n+    here=`pwd`;\n+    while :; do\n+\tif [ -d $here/.git ]\n+\tthen\n+\t    project=`basename $here`\n+\t    break\n+\telif [ $here = '/' ]\n+\tthen\n+\t    echo \"ciabot.sh: no .git below root!\"\n+\t    exit 1\n+\tfi\n+\there=`dirname $here`\n+    done\n+fi\n+\n # Name of the repo for gitweb/cgit purposes\n repo=$(git config --get ciabot.repo)\n [ -z $repo] && repo=$(echo \"${project}\" | tr '[A-Z]' '[a-z]')\n@@ -100,7 +120,7 @@ urlprefix=\"http://${host}/cgi-bin/cgit.cgi/${repo}/commit/?id=\"\n # Identify the script. The 'generator' variable should change only\n # when the script itself gets a new home and maintainer.\n generator=\"http://www.catb.org/~esr/ciabot/ciabot.sh\"\n-version=3.4\n+version=3.5\n \n # Addresses for the e-mail\n from=\"CIABOT-NOREPLY@${hostname}\"\n-- \n1.7.9.5\n\n\n-- \n\t\t<a href=\"http://www.catb.org/~esr/\">Eric S. Raymond</a>\n"}]}