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