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 version has been modified a bit, and is available on CIA's web site:
18 # http://cia.navi.cx/clients/cvs/ciabot_cvs.pl
20 # This program is designed to run from the loginfo CVS administration file. It
21 # takes a log message, massaging it and mailing it to the address given below.
23 # Its record in the loginfo file should look like:
25 # ALL /usr/bin/perl $CVSROOT/CVSROOT/ciabot_cvs.pl %{,,,s} $USER project from_email dest_email ignore_regexp
27 # IMPORTANT: The %{,,,s} in loginfo is new, and is required for proper operation.
29 # Make sure that you add the script to 'checkoutlist' before
30 # committing it. You may need to change /usr/bin/perl to point to your
31 # system's perl binary.
33 # Note that the last four parameters are optional, you can alternatively
34 # change the defaults below in the configuration section.
38 use vars qw ($project $from_email $dest_email $rpc_uri $sendmail $sync_delay
39 $xml_rpc $ignore_regexp $alt_local_message_target);
44 # Project name (as known to CIA).
46 # NOTE: This shouldn't be a long description of your project. Ideally
47 # it is a short identifier with no spaces, punctuation, or
48 # unnecessary capitalization. This will be used in URLs related
49 # to your project, as an internal identifier, and in IRC messages.
50 # If you want a longer name shown for your project on the web
51 # interface, please use the "title" metadata key rather than
54 $project = 'phpeclipse';
56 # The from address in generated mails.
57 $from_email = 'bananeweizen@sourceforge.net';
59 # Mail all reports to this address.
60 $dest_email = 'cia@cia.navi.cx';
62 # If using XML-RPC, connect to this URI.
63 $rpc_uri = 'http://cia.navi.cx/RPC2';
65 # Path to your USCD sendmail compatible binary (your mailer daemon created this
67 $sendmail = '/usr/sbin/sendmail';
69 # Number of seconds to wait for possible concurrent instances. CVS calls up
70 # this script for each involved directory separately and this is the sync
71 # delay. 5s looks as a safe value, but feel free to increase if you are running
72 # this on a slower (or overloaded) machine or if you have really a lot of
74 # Increasing this could be a very good idea if you're on Sourceforge ;)
77 # This script can communicate with CIA either by mail or by an XML-RPC
78 # interface. The XML-RPC interface is faster and more efficient, however you
79 # need to have RPC::XML perl module installed, and some large CVS hosting sites
80 # (like Savannah or Sourceforge) might not allow outgoing HTTP connections
81 # while they allow outgoing mail. Also, this script will hang and eventually
82 # not deliver the event at all if CIA server happens to be down, which is
83 # unfortunately not an uncommon condition.
86 # You can make this bot to totally ignore events concerning the objects
87 # specified below. Each object is composed of <module>/<path>/<filename>,
88 # therefore file Manifest in root directory of module gentoo will be called
89 # "gentoo/Manifest", while file src/bfu/inphist.c of module elinks will be
90 # called "elinks/src/bfu/inphist.c". Easy, isn't it?
92 # This variable should contain regexp, against which will each object be
93 # checked, and if the regexp is matched, the file is ignored. Therefore ie. to
94 # ignore all changes in the two files above and everything concerning module
97 # $ignore_regexp = "^(gentoo/Manifest|elinks/src/bfu/inphist.c|admin/)";
100 # It can be useful to also grab the generated XML message by some other
101 # programs and ie. autogenerate some content based on it. Here you can specify
102 # a file to which it will be appended.
103 $alt_local_message_target = "";
110 use vars qw ($user $module $tag @files $logmsg $message);
112 my @dir; # This array stores all the affected directories
113 my @dirfiles; # This array is mapped to the @dir array and contains files
114 # affected in each directory
117 # A nice nonprinting character we can use as a separator relatively safely.
118 # The commas in loginfo above give us 4 commas and a space between file
119 # names given to us on the command line. This is the separator used internally.
120 # Now we can handle filenames containing spaces, and probably anything except
121 # strings of 4 commas or the ASCII bell character.
123 # This was inspired by the suggestion in:
124 # http://mail.gnu.org/archive/html/info-cvs/2003-04/msg00267.html
128 ### Input data loading
131 # These arguments are from %s; first the relative path in the repository
132 # and then the list of files modified.
134 @files = split (' ,,,', ($ARGV[0] or ''));
135 $dir[0] = shift @files or die "$0: no directory specified\n";
136 $dirfiles[0] = "@files" or die "$0: no files specified\n";
141 $module = $dir[0]; $module =~ s#/.*##;
144 # Figure out who is doing the update.
149 # Use the optional parameters, if supplied.
151 $project = $ARGV[2] if $ARGV[2];
152 $from_email = $ARGV[3] if $ARGV[3];
153 $dest_email = $ARGV[4] if $ARGV[4];
154 $ignore_regexp = $ARGV[5] if $ARGV[5];
157 # Parse stdin (what's interesting is the tag and log message)
160 $tag = $1 if /^\s*Tag: ([a-zA-Z0-9_-]+)/;
161 last if /^Log Message/;
166 next unless ($_ and $_ ne "\n" and $_ ne "\r\n");
173 ### Remove to-be-ignored files
175 $dirfiles[0] = join (' ',
177 my $f = "$dir[0]/$_";
178 $f !~ m/$ignore_regexp/;
179 } split (/\s+/, $dirfiles[0])
180 ) if ($ignore_regexp);
181 exit unless $dirfiles[0];
185 ### Sync between the multiple instances potentially being ran simultanously
187 my $sum; # _VERY_ simple hash of the log message. It is really weak, but I'm
188 # lazy and it's really sorta exceptional to even get more commits
189 # running simultanously anyway.
191 map { $sum += ord $_ } split(//, $logmsg);
193 my $syncfile; # Name of the file used for syncing
194 $syncfile = "/tmp/cvscia.$project.$module.$sum";
197 if (-f $syncfile and -w $syncfile) {
198 # The synchronization file for this file already exists, so we are not the
199 # first ones. So let's just dump what we know and exit.
201 open(FF, ">>$syncfile") or die "aieee... can't log, can't log! $syncfile blocked!";
202 print FF "$dirfiles[0]!@!$dir[0]\n";
207 # We are the first one! Thus, we'll fork, exit the original instance, and
208 # wait a bit with the new one. Then we'll grab what the others collected and
211 # We don't need to care about permissions since all the instances of the one
212 # commit will obviously live as the same user.
214 # system("touch") in a different way
215 open(FF, ">>$syncfile") or die "aieee... can't log, can't log! $syncfile blocked!";
222 my ($dirnum) = 1; # 0 is the one we got triggerred for
225 ($dirfiles[$dirnum], $dir[$dirnum]) = split(/!@!/);
235 ### Compose the mail message
238 my ($VERSION) = '2.4';
239 my ($URL) = 'http://cia.navi.cx/clients/cvs/ciabot_cvs.pl';
245 <name>CIA Perl client for CVS</name>
246 <version>$VERSION</version>
250 <project>$project</project>
251 <module>$module</module>
254 $message .= " <branch>$tag</branch>" if ($tag);
262 <author>$user</author>
267 for (my $dirnum = 0; $dirnum < @dir; $dirnum++) {
269 $_ = $dir[$dirnum] . '/' . $_;
270 s#^.*?/##; # weed out the module name
274 $message .= " <file>$_</file>\n";
275 } split($", $dirfiles[$dirnum]);
291 ### Write the message to an alt-target
293 if ($alt_local_message_target and open (ALT, ">>$alt_local_message_target")) {
300 ### Send out the XML-RPC message
304 # We gotta be careful from now on. We silence all the warnings because
305 # RPC::XML code is crappy and works with undefs etc.
307 $RPC::XML::ERROR if (0); # silence perl's compile-time warning
310 require RPC::XML::Client;
312 my $rpc_client = new RPC::XML::Client $rpc_uri;
313 my $rpc_request = RPC::XML::request->new('hub.deliver', $message);
314 my $rpc_response = $rpc_client->send_request($rpc_request);
316 unless (ref $rpc_response) {
317 die "XML-RPC Error: $RPC::XML::ERROR\n";
324 ### Send out the mail
327 # Open our mail program
329 open (MAIL, "| $sendmail -t -oi -oem") or die "Cannot execute $sendmail : " . ($?>>8);
337 Content-type: text/xml
348 die "$0: sendmail exit status " . ($? >> 8) . "\n" unless ($? == 0);