Version bump for release.
[irker.git] / irkerhook.xml
1 <!DOCTYPE refentry PUBLIC 
2    "-//OASIS//DTD DocBook XML V4.1.2//EN"
3    "docbook/docbookx.dtd">
4 <refentry id='irkerhook.1'>
5 <refmeta>
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>
12 </refmeta>
13 <refnamediv id='name'>
14 <refname>irkerhook</refname>
15 <refpurpose>repository hook script issuing irker notifications</refpurpose>
16 </refnamediv>
17 <refsynopsisdiv id='synopsis'>
18
19 <cmdsynopsis>
20   <command>irkerhook.py</command>
21      <arg>-n</arg>
22      <arg>-V</arg>
23      <group><arg rep='repeat'><replaceable>--variable=value</replaceable></arg></group>
24      <group><arg rep='repeat'><replaceable>commit-id</replaceable></arg></group>
25 </cmdsynopsis>
26 </refsynopsisdiv>
27
28 <refsect1 id='description'><title>DESCRIPTION</title>
29
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>
36
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>
41
42 <orderedlist>
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>
50 </orderedlist>
51
52 <para>The following variables are general to all supported VCSes:</para>
53
54 <variablelist>
55 <varlistentry>
56 <term>project</term>
57 <listitem>
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>
60 </listitem>
61 </varlistentry>
62 <varlistentry>
63 <term>repo</term>
64 <listitem>
65 <para>The name of the repository top-level directory.  If not
66 specified, defaults to a lowercased copy of the project name.</para>
67 </listitem>
68 </varlistentry>
69 <varlistentry>
70 <term>channels</term>
71 <listitem>
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 default is the freenode #commits channel.</para>
75 </listitem>
76 </varlistentry>
77 <varlistentry>
78 <term>server</term>
79 <listitem>
80 <para>The host on which the notification-relaying irker daemon is expected
81 to reside. Defaults to "localhost".</para>
82 </listitem>
83 </varlistentry>
84 <varlistentry>
85 <term>email</term>
86 <listitem>
87 <para>If set, use email for communication rather than TCP or UDP.
88 The value is used as the target mail address.</para>
89 </listitem>
90 </varlistentry>
91 <varlistentry>
92 <term>tcp</term>
93 <listitem>
94 <para>If "true", use TCP for communication; if "false", use UDP.
95 Defaults to "false".</para>
96 </listitem>
97 </varlistentry>
98 <varlistentry>
99 <term>urlprefix</term>
100 <listitem>
101 <para>Changeset URL prefix for your repo. When the commit ID is appended
102 to this, it should point at a CGI that will display the commit
103 through cgit, gitweb or something similar. The defaults will probably
104 work if you have a typical gitweb/cgit setup.</para>
105
106 <para>If the value of this variable is "None", generation of the URL
107 field in commit notifications will be suppressed. Other magic values
108 are "cgit", "gitweb", and "viewcvs", which expand to URL templates
109 that will usually work with those systems.</para>
110
111 <para>The magic cookies "%(host)s" and %(repo)s" may occur in this
112 URL.  The former is expanded to the FQDN of the host on which
113 <application>irkerhook.py</application> is running; the latter is
114 expanded to the value of the "repo" variable.</para>
115 </listitem>
116 </varlistentry>
117 <varlistentry>
118 <term>tinyifier</term>
119 <listitem>
120 <para>URL template pointing to a service for compressing URLs so they
121 will take up less space in the notification line. If the value of this
122 variable is "None", no compression will be attempted.</para>
123 </listitem>
124 </varlistentry>
125 <varlistentry>
126 <term>color</term>
127 <listitem>
128 <para>If "mIRC", highlight notification fields with mIRC color codes.
129 If "ANSI", highlight notification fields with ANSI color escape
130 sequences.  Defaults to "none" (no colors). ANSI codes are supported
131 in Chatzilla, irssi, ircle, and BitchX; mIRC codes only are recognized
132 in mIRC, XChat, KVirc, Konversation, or weechat.</para>
133
134 <para>Note: if you turn this on and notifications stop appearing on
135 your channel, you need to turn off IRC's color filter on that channel.
136 To do this you will need op privileges; issue the command "/mode
137 &lt;channel&gt; -c" with &lt;channel&gt; replaced by your channel name.
138 You may need to first issue the command "/msg chanserv set
139 &lt;channel&gt; MLOCK +nt-slk".</para>
140 </listitem>
141 </varlistentry>
142 <varlistentry>
143 <term>maxchannels</term>
144 <listitem>
145 <para>Interpreted as an integer. If not zero, limits the number of
146 channels the hook will interpret from the "channels" variable.</para>
147
148 <para>This variable cannot be set through VCS configuration variables
149 or <filename>irker.conf</filename>; it can only be set with a command-line
150 argument.  Thus, on a forge site in which repository owners are not
151 allowed to modify their post-commit scripts, a site administrator can set it 
152 to prevent shotgun spamming by malicious project owners.  Setting it to
153 a value less than 2, however, would probably be unwise.</para>
154 </listitem>
155 </varlistentry>
156 <varlistentry>
157 <term>cialike</term>
158 <listitem>
159 <para>If not empty and not "None", this emulates the old CIA behavior
160 of dropping long lists of files in favor of a summary of the form (N
161 files in M directories). The value must be numeric giving a threshold
162 value for the length of the file list in characters.</para>
163 </listitem>
164 </varlistentry>
165 </variablelist>
166
167 <refsect2 id="git"><title>git</title>
168
169 <para>Under git, the normal way to invoke this hook (from within the
170 update hook) passes with a refname followed by a list of commits.  Because 
171 <command>git rev-list</command> normally lists from most recent to oldest,
172 you'll want to use --reverse to make notifications be omitted in chronological
173 order. In a normal update script, the invocation should look like this</para>
174
175 <programlisting>
176 refname=$1
177 old=$2
178 new=$3
179 irkerhook.py --refname=${refname} $(git rev-list --reverse ${old}..${new})
180 </programlisting>
181
182 <para>except that you'll need an absolute path for irkerhook.py.</para>
183
184 <para>For testing purposes and backward compatibility, if you invoke
185 <application>irkerhook.py</application> with no arguments (as in a
186 post-commit hook) it will behave as though it had been called like
187 this:</para>
188
189 <programlisting>
190 irkerhook.py --refname=refs/heads/master HEAD
191 </programlisting>
192
193 <para>However, this will not give the right result when you push to 
194 a non-default branch of a bare repo.</para>
195
196 <para>A typical way to install this hook is actually in the
197 <filename>post-receive</filename> hook, because it gets all the
198 necessary details and will not abort the push on failure. Use the
199 following script:</para>
200
201 <programlisting>
202 #!/bin/sh
203
204 echo "sending IRC notification"
205 while read old new refname; do
206     irkerhook --refname=${refname} $(git rev-list --reverse ${old}..${new})
207 done
208 </programlisting>
209
210 <para>Preferences may be set in the repo <filename>config</filename>
211 file in an [irker] section. Here is an example of what that can look
212 like:</para>
213
214 <programlisting>
215 [irker]
216     project = gpsd
217     color = ANSI
218     channels = irc://chat.freenode.net/gpsd,irc://chat.freenode.net/commits
219 </programlisting>
220
221 <para> You should not set the "repository" variable (an equivalent
222 will be computed). No attempt is made to interpret an
223 <filename>irker.conf</filename> file.</para>
224
225 <para>The default value of the "project" variable is the basename
226 of the repository directory. The default value of the "urlprefix"
227 variable is "cgit".</para>
228
229 <para>There is one git-specific variable, "revformat", controlling
230 the format of the commit identifier in a notification. It
231 may have the following values:</para>
232
233 <variablelist>
234 <varlistentry>
235 <term>raw</term>
236 <listitem><para>full hex ID of commit</para></listitem>
237 </varlistentry>
238 <varlistentry>
239 <term>short</term>
240 <listitem><para>first 12 chars of hex ID</para></listitem>
241 </varlistentry>
242 <varlistentry>
243 <term>describe</term>
244 <listitem><para>describe relative to last tag, falling back to short</para></listitem>
245 </varlistentry>
246 </variablelist>
247
248 <para>The default is 'describe'.</para>
249 </refsect2>
250
251 <refsect2 id="svn"><title>Subversion</title>
252
253 <para>Under Subversion, <application>irkerhook.py</application>
254 accepts a --repository option with value (the absolute pathname of the
255 Subversion repository) and a commit argument (the numeric revision level of
256 the commit).  The defaults are the current working directory and HEAD,
257 respectively.</para>
258
259 <para>Note, however, that you <emphasis>cannot</emphasis> default the
260 repository argument inside a Subversion post-commit hook; this is
261 because of a limitation of Subversion, which is that getting the
262 current directory is not reliable inside these hooks.  Instead, the
263 values must be the two arguments that Subversion passes to that hook
264 as arguments. Thus, a typical invocation in the post-commit script
265 will look like this:</para>
266
267 <programlisting>
268 REPO=$1
269 REV=$2
270 irkerhook.py --repository=$REPO $REV
271 </programlisting>
272
273 <para>Other --variable=value settings may also be
274 given on the command line, and will override any settings in an
275 <filename>irker.conf</filename> file.</para>
276
277 <para>The default for the project variable is the basename of the
278 repository. The default value of the "urlprefix" variable is
279 "viewcvs".</para>
280
281 <para>If an <filename>irker.conf</filename> file exists in the repository
282 root directory (not the checkout directory but where internals such as the
283 "format" file live) the hook will interpret variable settings from it.  Here
284 is an example of what such a file might look like:</para>
285
286 <programlisting>
287 # irkerhook variable settings for the irker project
288 project = irker
289 channels  = irc://chat.freenode/irker,irc://chat.freenode/commits
290 tcp = false
291 </programlisting>
292
293 <para>Don't set the "repository" or "commit" variables in this file;
294 that would have unhappy results.</para>
295
296 <para>There are no Subversion-specific variables.</para>
297
298 </refsect2>
299
300 <refsect2 id="hg"><title>Mercurial</title>
301
302 <para>Under Mercurial, <application>irkerhook.py</application> can be
303 invoked in two ways: either as a Python hook (preferred) or as a
304 script.</para>
305
306 <para>To call it as a Python hook, add the collowing to the 
307 "commit" or "incoming" hook declaration in your Mercurial
308 repository:</para>
309
310 <programlisting>
311 [hooks]
312         incoming.irker = python:/path/to/irkerhook.py:hg_hook
313 </programlisting>
314
315 <para>When called as a script, the hook accepts a --repository option
316 with value (the absolute pathname of the Mercurial repository) and can
317 take a commit argument (the Mercurial hash ID of the commit or a
318 reference to it). The default for the repository argument is the 
319 current directory. The default commit argument is '-1', designating
320 the current tip commit.</para>
321
322 <para>As for git, in both cases all variables may be set in the repo
323 <filename>hgrc</filename> file in an [irker] section.  Command-line
324 variable=value arguments are accepted but not required for script
325 invocation.  No attempt is made to interpret an
326 <filename>irker.conf</filename> file.</para>
327
328 <para>The default value of the "project" variable is the basename
329 of the repository directory. The default value of the "urlprefix"
330 variable is the value of the "web.baseurl" config value, if it
331 exists.</para>
332
333 </refsect2>
334
335 <refsect2 id="filter"><title>Filtering</title>
336
337 <para>It is possible to filter commits before sending them to
338 <application>irkerd</application>.</para>
339
340 <para>You have to specify the <option>filtercmd</option> option, which
341 will be the command <application>irkerhook.py</application> will
342 run. This command should accept one arguments, which is a JSON
343 representation of commit and extractor metadata (including the
344 channels variable). The command should emit to standard output a JSON
345 representation of (possibly altered) metadata.</para>
346
347 <para>Below is an example filter:</para>
348
349 <programlisting>
350 #!/usr/bin/env python
351 # This is a trivial example of a metadata filter.
352 # All it does is change the name of the commit's author.
353
354 import sys, json
355 metadata = json.loads(sys.argv[1])
356
357 metadata['author'] = "The Great and Powerful Oz"
358
359 print json.dumps(metadata)
360 # end
361 </programlisting>
362
363 <para>Standard error is available to the hook for progress and
364 error messages.</para>
365
366 </refsect2>
367
368 </refsect1>
369
370 <refsect1 id='options'><title>OPTIONS</title>
371
372 <para><application>irkerhook.py</application> takes the following
373 options:</para>
374
375 <variablelist>
376 <varlistentry>
377 <term>-n</term>
378 <listitem><para>Suppress transmission to a daemon. Instead, dump the
379 generated JSON request to standard output. Useful for
380 debugging.</para></listitem>
381 </varlistentry>
382 <varlistentry>
383 <term>-V</term>
384 <listitem><para>Write the program version to stdout and
385 terminate.</para></listitem>
386 </varlistentry>
387 </variablelist>
388
389 </refsect1>
390
391 <refsect1 id='see_also'><title>SEE ALSO</title>
392 <para>
393 <citerefentry><refentrytitle>irkerd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
394 </para>
395 </refsect1>
396
397 <refsect1 id='authors'><title>AUTHOR</title>
398 <para>Eric S. Raymond <email>esr@snark.thyrsus.com</email>.  See the
399 project page at <ulink
400 url='http://www.catb.org/~esr/irker'>http://www.catb.org/~esr/irker</ulink>
401 for updates and other resources.</para>
402 </refsect1>
403 </refentry>
404