-
Notifications
You must be signed in to change notification settings - Fork 1
/
ciabot_cvs_1.12.pl
executable file
·348 lines (258 loc) · 9.2 KB
/
ciabot_cvs_1.12.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/usr/bin/perl -w
#
# ciabot -- Mail a CVS log message to a given address, for the purposes of CIA
#
# Loosely based on cvslog by Russ Allbery <rra@stanford.edu>
# Copyright 1998 Board of Trustees, Leland Stanford Jr. University
#
# Copyright 2001, 2003, 2004 Petr Baudis <pasky@ucw.cz>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2, as published by the
# Free Software Foundation.
#
# The master location of this file is
# http://pasky.or.cz/~pasky/dev/cvs/ciabot.pl.
#
# This version has been modified a bit, and is available on CIA's web site:
# http://cia.navi.cx/clients/cvs/ciabot_cvs.pl
#
# This program is designed to run from the loginfo CVS administration file. It
# takes a log message, massaging it and mailing it to the address given below.
#
# Its record in the loginfo file should look like:
#
# ALL /usr/bin/perl $CVSROOT/CVSROOT/ciabot_cvs.pl %p %{s} %n $USER project from_email dest_email ignore_regexp
#
# IMPORTANT: The loginfo line has been changed to bring it into compliance
# with the new 'common format' used in CVS administrative files.
#
# Make sure that you add the script to 'checkoutlist' and give it
# 0755 permissions -before- committing it or adding it.
#
# Note that the last four parameters are optional, you can alternatively
# change the defaults below in the configuration section.
#
use strict;
use vars qw ($project $from_email $dest_email $rpc_uri $sendmail $sync_delay
$xml_rpc $ignore_regexp $alt_local_message_target);
### Configuration
# Project name (as known to CIA).
$project = 'mediawiki';
# The from address in generated mails.
$from_email = 'lists@wikidev.net';
# Mail all reports to this address.
#$dest_email = 'cia@cia.navi.cx';
$dest_email = 'lists@wikidev.net';
# If using XML-RPC, connect to this URI.
$rpc_uri = 'http://cia.navi.cx/RPC2';
# Path to your USCD sendmail compatible binary (your mailer daemon created this
# program somewhere).
$sendmail = '/usr/sbin/sendmail';
# Number of seconds to wait for possible concurrent instances. CVS calls up
# this script for each involved directory separately and this is the sync
# delay. 5s looks as a safe value, but feel free to increase if you are running
# this on a slower (or overloaded) machine or if you have really a lot of
# directories.
# Increasing this could be a very good idea if you're on Sourceforge ;)
$sync_delay = 5;
# This script can communicate with CIA either by mail or by an XML-RPC
# interface. The XML-RPC interface is faster and more efficient, however you
# need to have RPC::XML perl module installed, and some large CVS hosting sites
# (like Savannah or Sourceforge) might not allow outgoing HTTP connections
# while they allow outgoing mail. Also, this script will hang and eventually
# not deliver the event at all if CIA server happens to be down, which is
# unfortunately not an uncommon condition.
$xml_rpc = 0;
# You can make this bot to totally ignore events concerning the objects
# specified below. Each object is composed of <module>/<path>/<filename>,
# therefore file Manifest in root directory of module gentoo will be called
# "gentoo/Manifest", while file src/bfu/inphist.c of module elinks will be
# called "elinks/src/bfu/inphist.c". Easy, isn't it?
#
# This variable should contain regexp, against which will each object be
# checked, and if the regexp is matched, the file is ignored. Therefore ie. to
# ignore all changes in the two files above and everything concerning module
# 'admin', use:
#
# $ignore_regexp = "^(gentoo/Manifest|elinks/src/bfu/inphist.c|admin/)";
$ignore_regexp = "";
# It can be useful to also grab the generated XML message by some other
# programs and ie. autogenerate some content based on it. Here you can specify
# a file to which it will be appended.
$alt_local_message_target = "";
### The code itself
use vars qw ($user $module $tag @files $logmsg $message);
my @dir; # This array stores all the affected directories
my @dirfiles; # This array is mapped to the @dir array and contains files
# affected in each directory
# A nice nonprinting character we can use as a separator relatively safely.
# The commas in loginfo above give us 4 commas and a space between file
# names given to us on the command line. This is the separator used internally.
# Now we can handle filenames containing spaces, and probably anything except
# strings of 4 commas or the ASCII bell character.
#
# This was inspired by the suggestion in:
# http://mail.gnu.org/archive/html/info-cvs/2003-04/msg00267.html
#
$" = "\7";
### Input data loading
# These arguments are from %s; first the relative path in the repository
# and then the list of files modified.
# Modified by jcarlyle for cvs 1.12 (30-May-04)
$dir[0] = shift @ARGV or die "$0: no directory specified\n";
while($ARGV[0])
{
push @files, shift @ARGV;
}
$dirfiles[0] = "@files" or die "$0: no files specified\n";
# Guess module name.
$module = $dir[0]; $module =~ s#/.*##;
# Figure out who is doing the update.
$user = $ARGV[1];
# Use the optional parameters, if supplied.
$project = $ARGV[2] if $ARGV[2];
$from_email = $ARGV[3] if $ARGV[3];
$dest_email = $ARGV[4] if $ARGV[4];
$ignore_regexp = $ARGV[5] if $ARGV[5];
# Parse stdin (what's interesting is the tag and log message)
while (<STDIN>) {
$tag = $1 if /^\s*Tag: ([a-zA-Z0-9_-]+)/;
last if /^Log Message/;
}
$logmsg = "";
while (<STDIN>) {
next unless ($_ and $_ ne "\n" and $_ ne "\r\n");
s/&/&/g;
s/</</g;
s/>/>/g;
$logmsg .= $_;
}
### Remove to-be-ignored files
$dirfiles[0] = join (' ',
grep {
my $f = "$module/$dir[0]/$_";
$f !~ m/$ignore_regexp/;
} split (/\s+/, $dirfiles[0])
) if ($ignore_regexp);
exit unless $dirfiles[0];
### Sync between the multiple instances potentially being ran simultanously
my $sum; # _VERY_ simple hash of the log message. It is really weak, but I'm
# lazy and it's really sorta exceptional to even get more commits
# running simultanously anyway.
$sum = 0;
map { $sum += ord $_ } split(//, $logmsg);
my $syncfile; # Name of the file used for syncing
$syncfile = "/tmp/cvscia.$project.$module.$sum";
if (-f $syncfile and -w $syncfile) {
# The synchronization file for this file already exists, so we are not the
# first ones. So let's just dump what we know and exit.
open(FF, ">>$syncfile") or die "aieee... can't log, can't log! $syncfile blocked!";
print FF "$dirfiles[0]!@!$dir[0]\n";
close(FF);
exit;
} else {
# We are the first one! Thus, we'll fork, exit the original instance, and
# wait a bit with the new one. Then we'll grab what the others collected and
# go on.
# We don't need to care about permissions since all the instances of the one
# commit will obviously live as the same user.
# system("touch") in a different way
open(FF, ">>$syncfile") or die "aieee... can't log, can't log! $syncfile blocked!";
close(FF);
exit if (fork);
sleep($sync_delay);
open(FF, $syncfile);
my ($dirnum) = 1; # 0 is the one we got triggerred for
while (<FF>) {
chomp;
($dirfiles[$dirnum], $dir[$dirnum]) = split(/!@!/);
$dirnum++;
}
close(FF);
unlink($syncfile);
}
### Compose the mail message
my ($VERSION) = '2.3';
my ($URL) = 'http://cia.navi.cx/clients/cvs/ciabot_cvs.pl';
my $ts = time;
$message = <<EM
<message>
<generator>
<name>CIA Perl client for CVS</name>
<version>$VERSION</version>
<url>$URL</url>
</generator>
<source>
<project>$project</project>
<module>$module</module>
EM
;
$message .= " <branch>$tag</branch>" if ($tag);
$message .= <<EM
</source>
<timestamp>
$ts
</timestamp>
<body>
<commit>
<author>$user</author>
<files>
EM
;
for (my $dirnum = 0; $dirnum < @dir; $dirnum++) {
map {
$_ = $dir[$dirnum] . '/' . $_;
s#^.*?/##; # weed out the module name
s/&/&/g;
s/</</g;
s/>/>/g;
$message .= " <file>$_</file>\n";
} split($", $dirfiles[$dirnum]);
}
$message .= <<EM
</files>
<log>
$logmsg
</log>
</commit>
</body>
</message>
EM
;
### Write the message to an alt-target
if ($alt_local_message_target and open (ALT, ">>$alt_local_message_target")) {
print ALT $message;
close ALT;
}
### Send out the XML-RPC message
if ($xml_rpc) {
# We gotta be careful from now on. We silence all the warnings because
# RPC::XML code is crappy and works with undefs etc.
$^W = 0;
$RPC::XML::ERROR if (0); # silence perl's compile-time warning
require RPC::XML;
require RPC::XML::Client;
my $rpc_client = new RPC::XML::Client $rpc_uri;
my $rpc_request = RPC::XML::request->new('hub.deliver', $message);
my $rpc_response = $rpc_client->send_request($rpc_request);
unless (ref $rpc_response) {
die "XML-RPC Error: $RPC::XML::ERROR\n";
}
exit;
}
### Send out the mail
# Open our mail program
open (MAIL, "| $sendmail -t -oi -oem") or die "Cannot execute $sendmail : " . ($?>>8);
# The mail header
print MAIL <<EOM;
From: $from_email
To: $dest_email
Content-type: text/xml
Subject: DeliverXML
EOM
print MAIL $message;
# Close the mail
close MAIL;
die "$0: sendmail exit status " . ($? >> 8) . "\n" unless ($? == 0);
# vi: set sw=2: