3 # ciabot -- Mail a CVS log message to a given address, for the purposes of CIA
5 # Loosely based on cvslog by Russ Allbery <rra@stanford.edu>
6 # Copyright 1998 Board of Trustees, Leland Stanford Jr. University
8 # Copyright 2001, 2003, 2004 Petr Baudis <pasky@ucw.cz>
10 # This program is free software; you can redistribute it and/or modify it under
11 # the terms of the GNU General Public License version 2, as published by the
12 # Free Software Foundation.
14 # The master location of this file is
15 # http://pasky.or.cz/~pasky/dev/cvs/ciabot.pl.
17 # This program is designed to run from the loginfo CVS administration file. It
18 # takes a log message, massaging it and mailing it to the address given below.
20 # Its record in the loginfo file should look like:
22 # ALL $CVSROOT/CVSROOT/ciabot.pl %s $USER project from_email dest_email ignore_regexp
24 # Note that the last four parameters are optional, you can alternatively change
25 # the defaults below in the configuration section.
27 # If it does not work, try to disable $xml_rpc in the configuration section
30 # ciabot.pl,v 1.110 2004/01/09 17:40:13 pasky
34 use vars qw
($project $from_email $dest_email $rpc_uri $sendmail $sync_delay
35 $xml_rpc $ignore_regexp $alt_local_message_target);
42 # Project name (as known to CIA).
45 # The from address in generated mails.
46 $from_email = 'pasky@ucw.cz';
48 # Mail all reports to this address.
49 $dest_email = 'cia@navi.cx';
51 # If using XML-RPC, connect to this URI.
52 $rpc_uri = 'http://cia.navi.cx/RPC2';
54 # Path to your USCD sendmail compatible binary (your mailer daemon created this
56 $sendmail = '/usr/sbin/sendmail';
58 # Number of seconds to wait for possible concurrent instances. CVS calls up
59 # this script for each involved directory separately and this is the sync
60 # delay. 5s looks as a safe value, but feel free to increase if you are running
61 # this on a slower (or overloaded) machine or if you have really a lot of
65 # This script can communicate with CIA either by mail or by an XML-RPC
66 # interface. The XML-RPC interface is faster and more efficient, however you
67 # need to have RPC::XML perl module installed, and some large CVS hosting sites
68 # (like Savannah or Sourceforge) might not allow outgoing HTTP connections
69 # while they allow outgoing mail. Also, this script will hang and eventually
70 # not deliver the event at all if CIA server happens to be down, which is
71 # unfortunately not an uncommon condition.
74 # You can make this bot to totally ignore events concerning the objects
75 # specified below. Each object is composed of <module>/<path>/<filename>,
76 # therefore file Manifest in root directory of module gentoo will be called
77 # "gentoo/Manifest", while file src/bfu/inphist.c of module elinks will be
78 # called "elinks/src/bfu/inphist.c". Easy, isn't it?
80 # This variable should contain regexp, against which will each object be
81 # checked, and if the regexp is matched, the file is ignored. Therefore ie. to
82 # ignore all changes in the two files above and everything concerning module
85 #$ignore_regexp = "^(gentoo/Manifest|elinks/src/bfu/inphist.c|admin/)";
86 $ignore_regexp = "/Manifest\$";
88 # It can be useful to also grab the generated XML message by some other
89 # programs and ie. autogenerate some content based on it. Here you can specify
90 # a file to which it will be appended.
91 $alt_local_message_target = "";
98 use vars qw
($user $module $tag @files $logmsg $message);
100 my @dir; # This array stores all the affected directories
101 my @dirfiles; # This array is mapped to the @dir array and contains files
102 # affected in each directory
106 ### Input data loading
109 # These arguments are from %s; first the relative path in the repository
110 # and then the list of files modified.
112 @files = split (' ', ($ARGV[0] or ''));
113 $dir[0] = shift @files or die "$0: no directory specified\n";
114 $dirfiles[0] = "@files" or die "$0: no files specified\n";
119 $module = $dir[0]; $module =~ s
#/.*##;
122 # Figure out who is doing the update.
127 # Use the optional parameters, if supplied.
129 $project = $ARGV[2] if $ARGV[2];
130 $from_email = $ARGV[3] if $ARGV[3];
131 $dest_email = $ARGV[4] if $ARGV[4];
132 $ignore_regexp = $ARGV[5] if $ARGV[5];
135 # Parse stdin (what's interesting is the tag and log message)
138 $tag = $1 if /^\s*Tag: ([a-zA-Z0-9_-]+)/;
139 last if /^Log Message/;
143 next unless ($_ and $_ ne "\n" and $_ ne "\r\n");
152 ### Remove to-be-ignored files
154 $dirfiles[0] = join (' ',
156 my $f = "$module/$dir[0]/$_";
157 $f !~ m/$ignore_regexp/;
158 } split (/\s+/, $dirfiles[0])
159 ) if ($ignore_regexp);
160 exit unless $dirfiles[0];
164 ### Sync between the multiple instances potentially being ran simultanously
166 my $sum; # _VERY_ simple hash of the log message. It is really weak, but I'm
167 # lazy and it's really sorta exceptional to even get more commits
168 # running simultanously anyway.
169 map { $sum += ord $_ } split(//, $logmsg);
171 my $syncfile; # Name of the file used for syncing
172 $syncfile = "/tmp/cvscia.$project.$module.$sum";
175 if (-f
$syncfile and -w
$syncfile) {
176 # The synchronization file for this file already exists, so we are not the
177 # first ones. So let's just dump what we know and exit.
179 open(FF
, ">>$syncfile") or die "aieee... can't log, can't log! $syncfile blocked!";
180 print FF
"$dirfiles[0]!@!$dir[0]\n";
185 # We are the first one! Thus, we'll fork, exit the original instance, and
186 # wait a bit with the new one. Then we'll grab what the others collected and
189 # We don't need to care about permissions since all the instances of the one
190 # commit will obviously live as the same user.
192 # system("touch") in a different way
193 open(FF
, ">>$syncfile") or die "aieee... can't log, can't log! $syncfile blocked!";
200 my ($dirnum) = 1; # 0 is the one we got triggerred for
203 ($dirfiles[$dirnum], $dir[$dirnum]) = split(/!@!/);
213 ### Compose the mail message
216 my ($VERSION) = '$Revision$' =~ / (\d+\.\d+) /;
222 <name>CIA Perl client for CVS</name>
223 <version>$VERSION</version>
224 <url>http://pasky.or.cz/~pasky/dev/cvs/ciabot.pl</url>
227 <project>$project</project>
228 <module>$module</module>
231 $message .= " <branch>$tag</branch>" if ($tag);
239 <author>$user</author>
244 for (my $dirnum = 0; $dirnum < @dir; $dirnum++) {
246 $_ = $dir[$dirnum] . '/' . $_;
247 s
#^.*?/##; # weed out the module name
251 $message .= " <file>$_</file>\n";
252 } split(/ /, $dirfiles[$dirnum]);
268 ### Write the message to an alt-target
270 if ($alt_local_message_target and open (ALT
, ">>$alt_local_message_target")) {
277 ### Send out the XML-RPC message
281 # We gotta be careful from now on. We silence all the warnings because
282 # RPC::XML code is crappy and works with undefs etc.
284 $RPC::XML
::ERROR
if (0); # silence perl's compile-time warning
287 require RPC
::XML
::Client
;
289 my $rpc_client = new RPC
::XML
::Client
$rpc_uri;
290 my $rpc_request = RPC
::XML
::request
->new('hub.deliver', $message);
291 my $rpc_response = $rpc_client->send_request($rpc_request);
293 unless (ref $rpc_response) {
294 die "XML-RPC Error: $RPC::XML::ERROR\n";
301 ### Send out the mail
304 # Open our mail program
306 open (MAIL
, "| $sendmail -t -oi -oem") or die "Cannot execute $sendmail : " . ($?
>>8);
314 Content-type: text/xml
325 die "$0: sendmail exit status " . ($?
>> 8) . "\n" unless ($?
== 0);
This page took 0.062896 seconds and 5 git commands to generate.