1 <!DOCTYPE refentry PUBLIC
2 "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "docbook/docbookx.dtd">
4 <refentry id='irkerhook.1'>
6 <refentrytitle>irkerhook</refentrytitle>
7 <manvolnum>1</manvolnum>
8 <refmiscinfo class='date'>Aug 27 2012</refmiscinfo>
9 <refmiscinfo class='source'>irker</refmiscinfo>
10 <refmiscinfo class='product'>irker</refmiscinfo>
11 <refmiscinfo class='manual'>Commands</refmiscinfo>
13 <refnamediv id='name'>
14 <refname>irkerhook</refname>
15 <refpurpose>repository hook script issuing irker notifications</refpurpose>
17 <refsynopsisdiv id='synopsis'>
20 <command>irkerhook.py</command>
23 <group><arg rep='repeat'><replaceable>--variable=value</replaceable></arg></group>
24 <group><arg rep='repeat'><replaceable>commit-id</replaceable></arg></group>
28 <refsect1 id='description'><title>DESCRIPTION</title>
30 <para><application>irkerhook.py</application> is a Python script intended
31 to be called from the post-commit hook of a version-control repository. Its
32 job is to collect information about the commit that fired the hook (and
33 possibly preferences set by the repository owner) and ship that information
34 to an instance of <application>irkerd</application> for forwarding to
35 various announcement channels.</para>
37 <para>The proper invocation and behavior of
38 <application>irkerhook.py</application> varies depending on which
39 VCS (version-control system) is calling it. There are four different places
40 from which it may extract information:</para>
43 <listitem><para>Calls to VCS utilities.</para></listitem>
44 <listitem><para>In VCSes like git that support user-settable configuration
45 variables, variables with the prefix "irker.".</para></listitem>
46 <listitem><para>In other VCSes, a configuration file, "irker.conf", in the
47 repository's internals directory.</para></listitem>
48 <listitem><para>Command-line arguments of the form
49 --variable=value.</para></listitem>
52 <para>The following variables are general to all supported VCSes:</para>
58 <para>The name of the project. Should be a relatively short identifier;
59 will usually appear at the very beginning of a notification.</para>
65 <para>The name of the repository top-level directory. If not
66 specified, defaults to a lowercased copy of the project name.</para>
72 <para>An IRC channel URL, or comma-separated list of same, identifying
73 channels to which notifications are to be sent. If not specified, the
74 defaults channel list id the freenode #commits channel plus the freenode
75 channel named by the project variable.</para>
81 <para>The host on which the notification-relaying irker daemon is expected
82 to reside. Defaults to "localhost".</para>
88 <para>If "true", use TCP for communication; if "false", use UDP.
89 Defaults to "false".</para>
93 <term>urlprefix</term>
95 <para>Changeset URL prefix for your repo. When the commit ID is appended
96 to this, it should point at a CGI that will display the commit
97 through cgit,gitweb or something similar. The defaults will probably
98 work if you have a typical gitweb/cgit setup.</para>
100 <para>If the value of this variable is "None", generation of the URL
101 field in commit notifications will be suppressed. Other magic values
102 are "cgit", "gitweb", and "viewcvs", which expand to URL templates
103 that will usually work with those systems.</para>
105 <para>The magic cookies "%(host)s" and %(repo)s" may occur in this
106 URL. The former is expanded to the FQDN of the host on which
107 <application>irkerhook.py</application> is running; the latter is
108 expanded to the value of the "repo" variable.</para>
112 <term>tinyifier</term>
114 <para>URL template pointing to a service for compressing URLs so they
115 will take up less space in the notification line.</para>
121 <para>If "mIRC", highlight notification fields with mIRC color codes.
122 If "ANSI", highlight notification fields with ANSI color escape sequences.
123 Defaults to "none" (no colors). Note: if you turn this on and
124 notifications stop appearing on your channel, you need to turn off
125 IRC's color filter on that channel. To do this you will need op
126 privileges; issue the command "/mode #irker -c". You may need to
127 first issue the command "/msg chanserv set #irker MLOCK
132 <term>maxchannels</term>
134 <para>Interpreted as an integer. If not zero, limits the number of
135 channels the hook will interpret from the "channels" variable.</para>
137 <para>This variable cannot be set through VCS configuration variables
138 or <filename>irker.conf</filename>; it can only be set with a command-line
139 argument. Thus, on a forge site in which repository owners are not
140 allowed to modify their post-commit scripts, a site administrator can set it
141 to prevent shotgun spamming by malicious project owners. Setting it to
142 a value less than 2, however, would probably be unwise.</para>
147 <refsect2 id="git"><title>git</title>
149 <para>Under git, the normal way to invoke this hook (from within the
150 update hook) passes with a refname followed by a list of commits. Because
151 <command>git rev-list</command> normally lists from most recent to oldest,
152 you'll want to use --reverse to make notifications be omitted in chronological
153 order. In a normal update script, the invocation should look like this</para>
159 irkerhook.py --refname=${refname} $(git rev-list --reverse ${old}..${new})
162 <para>except that you'll need an absolute path for irkerhook.py.</para>
164 <para>For testing purposes and backward compatibility, if you invoke
165 <application>irkerhook.py</application> with no arguments (as in a
166 post-commit hook) it will behave as though it had been called like
170 irkerhook.py --refname=refs/heads/master HEAD
173 <para>However, this will not give the right result when you push to
174 a non-default branch of a bare repo.</para>
176 <para>Preferences may be set in the repo <filename>config</filename>
177 file in an [irker] section. Here is an example of what that can look
184 channels = {irc://chat.freenode.net/gpsd, irc://chat.freenode.net/commits}
187 <para> You should not set the "repository" variable (an equivalent
188 will be computed). No attempt is made to interpret an
189 <filename>irker.conf</filename> file.</para>
191 <para>The default value of the "project" variable is the basename
192 of the repository directory. The default value of the "urlprefix"
193 variable is "cgit".</para>
195 <para>There is one git-specific variable, "revformat", controlling
196 the format of the commit identifier in a notification. It
197 may have the following values:</para>
202 <listitem><para>full hex ID of commit</para></listitem>
206 <listitem><para>first 12 chars of hex ID</para></listitem>
209 <term>describe</term>
210 <listitem><para>describe relative to last tag, falling back to short</para></listitem>
214 <para>The default is 'describe'.</para>
217 <refsect2 id="svn"><title>Subversion</title>
219 <para>Under Subversion, <application>irkerhook.py</application>
220 accepts a --repository option with value (the absolute pathname of the
221 Subversion repository) and a commit argument (the numeric revision level of
222 the commit). The defaults are the current working directory and HEAD,
225 <para>Note, however, that you <emphasis>cannot</emphasis> default the
226 repository argumment inside a Subversion post-commit hook. Instead,
227 the values must be the two arguments that Subversion passes to that
228 hook as arguments. Thus, a typical invocation in the post-commit
229 script will look like this:</para>
234 irkerhook.py --repository=$REPO $REV
237 <para>Other --variable=value settings may also be
238 given on the command line, and will override any settings in an
239 <filename>irker.conf</filename> file.</para>
241 <para>The default for the project variable is the basename of the
242 repository. The default value of the "urlprefix" variable is
245 <para>If an <filename>irker.conf</filename> file exists in the repository
246 root directory (not the checkout directory but where internals such as the
247 "format" file live) the hook will interpret variable settings from it. Here
248 is an example of what such a file might look like:</para>
251 # irkerhook variable settings for the irker project
253 channels = irc://chat.freenode/irker,irc://chat.freenode/commits
257 <para>Don't set the "repository" or "commit" variables in this file;
258 that would have unhappy results.</para>
260 <para>There are no Subversion-specific variables.</para>
264 <refsect2 id="hg"><title>Mercurial</title>
266 <para>Under Mercurial, <application>irkerhook.py</application> can be
267 invoked in two ways: either as a Python hook (preferred) or as a
270 <para>To call it as a Python hook, add the collowing to the
271 "commit" or "incoming" hook declaration in your Mercurial
276 incoming.irker = python:/path/to/irkerhook.py:hg_hook
279 <para>When called as a script, the hook accepts a --repository option
280 with value (the absolute pathname of the Mercurial repository) and can
281 take a commit argument (the Mercurial hash ID of the commit or a
282 reference to it). The default for the repository argument is the
283 current directory. The default commit argument is '-1', designating
284 the current tip commit.</para>
286 <para>As for git, in both cases all variables may be set in the repo
287 <filename>hgrc</filename> file in an [irker] section. Command-line
288 variable=value arguments are accepted but not required for script
289 invocation. No attempt is made to interpret an
290 <filename>irker.conf</filename> file.</para>
292 <para>The default value of the "project" variable is the basename
293 of the repository directory. The default value of the "urlprefix"
294 variable is the value of the "web.baseurl" config value, if it
299 <refsect2 id="filter"><title>Filtering</title>
301 <para>It is possible to filter commits before sending them to
302 <application>irkerd</application>.</para>
304 <para>You have to specify the <option>filtercmd</option> option, which
305 will be the command <application>irkerhook.py</application> will
306 run. This command should accept one arguments, which is a JSON
307 representation of commit and extractor metadata (including the
308 channels variable). The command should emit to standard output a JSON
309 representation of (possibly altered) metadata.</para>
311 <para>Below is an example filter:</para>
314 #!/usr/bin/env python
315 # This is a trivial example of a metadata filter.
316 # All it does is change the name of the commit's author.
319 metadata = json.loads(sys.argv[1])
321 metadata['author'] = "The Great and Powerful Oz"
323 print json.dumps(metadata)
327 <para>Standard error is available to the hook for progress and
328 error messages.</para>
334 <refsect1 id='options'><title>OPTIONS</title>
336 <para><application>irkerhook.py</application> takes the following
342 <listitem><para>Suppress transmission to a daemon. Instead, dump the
343 generated JSON request to standard output. Useful for
344 debugging.</para></listitem>
348 <listitem><para>Write the program version to stdout and
349 terminate.</para></listitem>
355 <refsect1 id='authors'><title>AUTHOR</title>
356 <para>Eric S. Raymond <email>esr@snark.thyrsus.com</email>. See the
357 project page at <ulink
358 url='http://www.catb.org/~esr/irker'>http://www.catb.org/~esr/irker</ulink>
359 for updates and other resources.</para>