An attempt at making irk clean up after itself.
[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>Preferences may be set in the repo <filename>config</filename>
197 file in an [irker] section. Here is an example of what that can look
198 like:</para>
199
200 <programlisting>
201 [irker]
202     project = gpsd
203     color = ANSI
204     channels = irc://chat.freenode.net/gpsd,irc://chat.freenode.net/commits
205 </programlisting>
206
207 <para> You should not set the "repository" variable (an equivalent
208 will be computed). No attempt is made to interpret an
209 <filename>irker.conf</filename> file.</para>
210
211 <para>The default value of the "project" variable is the basename
212 of the repository directory. The default value of the "urlprefix"
213 variable is "cgit".</para>
214
215 <para>There is one git-specific variable, "revformat", controlling
216 the format of the commit identifier in a notification. It
217 may have the following values:</para>
218
219 <variablelist>
220 <varlistentry>
221 <term>raw</term>
222 <listitem><para>full hex ID of commit</para></listitem>
223 </varlistentry>
224 <varlistentry>
225 <term>short</term>
226 <listitem><para>first 12 chars of hex ID</para></listitem>
227 </varlistentry>
228 <varlistentry>
229 <term>describe</term>
230 <listitem><para>describe relative to last tag, falling back to short</para></listitem>
231 </varlistentry>
232 </variablelist>
233
234 <para>The default is 'describe'.</para>
235 </refsect2>
236
237 <refsect2 id="svn"><title>Subversion</title>
238
239 <para>Under Subversion, <application>irkerhook.py</application>
240 accepts a --repository option with value (the absolute pathname of the
241 Subversion repository) and a commit argument (the numeric revision level of
242 the commit).  The defaults are the current working directory and HEAD,
243 respectively.</para>
244
245 <para>Note, however, that you <emphasis>cannot</emphasis> default the
246 repository argument inside a Subversion post-commit hook; this is
247 because of a limitation of Subversion, which is that getting the
248 current directory is not reliable inside these hooks.  Instead, the
249 values must be the two arguments that Subversion passes to that hook
250 as arguments. Thus, a typical invocation in the post-commit script
251 will look like this:</para>
252
253 <programlisting>
254 REPO=$1
255 REV=$2
256 irkerhook.py --repository=$REPO $REV
257 </programlisting>
258
259 <para>Other --variable=value settings may also be
260 given on the command line, and will override any settings in an
261 <filename>irker.conf</filename> file.</para>
262
263 <para>The default for the project variable is the basename of the
264 repository. The default value of the "urlprefix" variable is
265 "viewcvs".</para>
266
267 <para>If an <filename>irker.conf</filename> file exists in the repository
268 root directory (not the checkout directory but where internals such as the
269 "format" file live) the hook will interpret variable settings from it.  Here
270 is an example of what such a file might look like:</para>
271
272 <programlisting>
273 # irkerhook variable settings for the irker project
274 project = irker
275 channels  = irc://chat.freenode/irker,irc://chat.freenode/commits
276 tcp = false
277 </programlisting>
278
279 <para>Don't set the "repository" or "commit" variables in this file;
280 that would have unhappy results.</para>
281
282 <para>There are no Subversion-specific variables.</para>
283
284 </refsect2>
285
286 <refsect2 id="hg"><title>Mercurial</title>
287
288 <para>Under Mercurial, <application>irkerhook.py</application> can be
289 invoked in two ways: either as a Python hook (preferred) or as a
290 script.</para>
291
292 <para>To call it as a Python hook, add the collowing to the 
293 "commit" or "incoming" hook declaration in your Mercurial
294 repository:</para>
295
296 <programlisting>
297 [hooks]
298         incoming.irker = python:/path/to/irkerhook.py:hg_hook
299 </programlisting>
300
301 <para>When called as a script, the hook accepts a --repository option
302 with value (the absolute pathname of the Mercurial repository) and can
303 take a commit argument (the Mercurial hash ID of the commit or a
304 reference to it). The default for the repository argument is the 
305 current directory. The default commit argument is '-1', designating
306 the current tip commit.</para>
307
308 <para>As for git, in both cases all variables may be set in the repo
309 <filename>hgrc</filename> file in an [irker] section.  Command-line
310 variable=value arguments are accepted but not required for script
311 invocation.  No attempt is made to interpret an
312 <filename>irker.conf</filename> file.</para>
313
314 <para>The default value of the "project" variable is the basename
315 of the repository directory. The default value of the "urlprefix"
316 variable is the value of the "web.baseurl" config value, if it
317 exists.</para>
318
319 </refsect2>
320
321 <refsect2 id="filter"><title>Filtering</title>
322
323 <para>It is possible to filter commits before sending them to
324 <application>irkerd</application>.</para>
325
326 <para>You have to specify the <option>filtercmd</option> option, which
327 will be the command <application>irkerhook.py</application> will
328 run. This command should accept one arguments, which is a JSON
329 representation of commit and extractor metadata (including the
330 channels variable). The command should emit to standard output a JSON
331 representation of (possibly altered) metadata.</para>
332
333 <para>Below is an example filter:</para>
334
335 <programlisting>
336 #!/usr/bin/env python
337 # This is a trivial example of a metadata filter.
338 # All it does is change the name of the commit's author.
339
340 import sys, json
341 metadata = json.loads(sys.argv[1])
342
343 metadata['author'] = "The Great and Powerful Oz"
344
345 print json.dumps(metadata)
346 # end
347 </programlisting>
348
349 <para>Standard error is available to the hook for progress and
350 error messages.</para>
351
352 </refsect2>
353
354 </refsect1>
355
356 <refsect1 id='options'><title>OPTIONS</title>
357
358 <para><application>irkerhook.py</application> takes the following
359 options:</para>
360
361 <variablelist>
362 <varlistentry>
363 <term>-n</term>
364 <listitem><para>Suppress transmission to a daemon. Instead, dump the
365 generated JSON request to standard output. Useful for
366 debugging.</para></listitem>
367 </varlistentry>
368 <varlistentry>
369 <term>-V</term>
370 <listitem><para>Write the program version to stdout and
371 terminate.</para></listitem>
372 </varlistentry>
373 </variablelist>
374
375 </refsect1>
376
377 <refsect1 id='see_also'><title>SEE ALSO</title>
378 <para>
379 <citerefentry><refentrytitle>irkerd</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
380 </para>
381 </refsect1>
382
383 <refsect1 id='authors'><title>AUTHOR</title>
384 <para>Eric S. Raymond <email>esr@snark.thyrsus.com</email>.  See the
385 project page at <ulink
386 url='http://www.catb.org/~esr/irker'>http://www.catb.org/~esr/irker</ulink>
387 for updates and other resources.</para>
388 </refsect1>
389 </refentry>
390