xaizek / pms (License: GPLv3+) (since 2018-12-07)
Older version of Practical Music Search written in C++.
Commit 8ba65b4deb4105978643ab4cef72aa9c666d241c

Remove CIABot script
Author: Kim Tore Jensen
Author date (UTC): 2015-08-30 08:15
Committer name: Kim Tore Jensen
Committer date (UTC): 2015-08-30 08:15
Parent(s): a2c3e35f0bdb351875e957df617b754519db0b02
Signing key:
Tree: 1bc5de8bb965eba2259273c24ee72421daa2e1b6
File Lines added Lines deleted
ciabot.pl 0 288
File ciabot.pl deleted (index 679cdf4..0000000)
1 #!/usr/bin/perl -w
2 #
3 # ciabot -- Mail a git log message to a given address, for the purposes of CIA
4 #
5 # Loosely based on cvslog by Russ Allbery <rra@stanford.edu>
6 # Copyright 1998 Board of Trustees, Leland Stanford Jr. University
7 #
8 # Copyright 2001, 2003, 2004, 2005 Petr Baudis <pasky@ucw.cz>
9 #
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.
13 #
14 # The master location of this file is in the Cogito repository
15 # (see http://www.kernel.org/git/).
16 #
17 # This program is designed to run as the .git/hooks/post-commit hook. It takes
18 # the commit information, massages it and mails it to the address given below.
19 #
20 # The calling convention of the post-commit hook is:
21 #
22 # .git/hooks/post-commit $commit_sha1 $branch_name
23 #
24 # If it does not work, try to disable $xml_rpc in the configuration section
25 # below. Also, remember to make the hook file executable.
26 #
27 #
28 # Note that you can (and it might be actually more desirable) also use this
29 # script as the GIT update hook:
30 #
31 # refname=${1#refs/heads/}
32 # [ "$refname" = "master" ] && refname=
33 # oldhead=$2
34 # newhead=$3
35 # for merged in $(git-rev-list $newhead ^$oldhead | tac); do
36 # /path/to/ciabot.pl $merged $refname
37 # done
38 #
39 # This is useful when you use a remote repository that you only push to. The
40 # update hook will be triggered each time you push into that repository, and
41 # the pushed commits will be reported through CIA.
42
43 use strict;
44 use vars qw ($project $from_email $dest_email $noisy $rpc_uri $sendmail
45 $xml_rpc $ignore_regexp $alt_local_message_target);
46
47
48
49
50 ### Configuration
51
52 # Project name (as known to CIA).
53 $project = 'pmus';
54
55 # The from address in generated mails.
56 $from_email = 'kimtjen@gmail.com';
57
58 # Mail all reports to this address.
59 $dest_email = 'cia@cia.navi.cx';
60
61 # If using XML-RPC, connect to this URI.
62 $rpc_uri = 'http://cia.navi.cx/RPC2';
63
64 # Path to your USCD sendmail compatible binary (your mailer daemon created this
65 # program somewhere).
66 $sendmail = '/usr/sbin/sendmail';
67
68 # If set, the script will send CIA the full commit message. If unset, only the
69 # first line of the commit message will be sent.
70 $noisy = 1;
71
72 # This script can communicate with CIA either by mail or by an XML-RPC
73 # interface. The XML-RPC interface is faster and more efficient, however you
74 # need to have RPC::XML perl module installed, and some large CVS hosting sites
75 # (like Savannah or Sourceforge) might not allow outgoing HTTP connections
76 # while they allow outgoing mail. Also, this script will hang and eventually
77 # not deliver the event at all if CIA server happens to be down, which is
78 # unfortunately not an uncommon condition.
79 $xml_rpc = 0;
80
81 # This variable should contain a regexp, against which each file will be
82 # checked, and if the regexp is matched, the file is ignored. This can be
83 # useful if you do not want auto-updated files, such as e.g. ChangeLog, to
84 # appear via CIA.
85 #
86 # The following example will make the script ignore all changes in two specific
87 # files in two different modules, and everything concerning module 'admin':
88 #
89 # $ignore_regexp = "^(gentoo/Manifest|elinks/src/bfu/inphist.c|admin/)";
90 $ignore_regexp = "";
91
92 # It can be useful to also grab the generated XML message by some other
93 # programs and e.g. autogenerate some content based on it. Here you can specify
94 # a file to which it will be appended.
95 $alt_local_message_target = "";
96
97
98
99
100 ### The code itself
101
102 use vars qw ($commit $tree @parent $author $committer);
103 use vars qw ($user $branch $rev @files $logmsg $message);
104 my $line;
105
106
107
108 ### Input data loading
109
110
111 # The commit stuff
112 $commit = $ARGV[0];
113 $branch = $ARGV[1];
114
115 open COMMIT, "git-cat-file commit $commit|" or die "git-cat-file commit $commit: $!";
116 my $state = 0;
117 $logmsg = '';
118 while (defined ($line = <COMMIT>)) {
119 if ($state == 1) {
120 $logmsg .= $line;
121 $noisy or $state++;
122 next;
123 } elsif ($state > 1) {
124 next;
125 }
126
127 chomp $line;
128 unless ($line) {
129 $state = 1;
130 next;
131 }
132
133 my ($key, $value) = split(/ /, $line, 2);
134 if ($key eq 'tree') {
135 $tree = $value;
136 } elsif ($key eq 'parent') {
137 push(@parent, $value);
138 } elsif ($key eq 'author') {
139 $author = $value;
140 } elsif ($key eq 'committer') {
141 $committer = $value;
142 }
143 }
144 close COMMIT;
145
146
147 open DIFF, "git-diff-tree -r $parent[0] $tree|" or die "git-diff-tree $parent[0] $tree: $!";
148 while (defined ($line = <DIFF>)) {
149 chomp $line;
150 my @f;
151 (undef, @f) = split(/\t/, $line, 2);
152 push (@files, @f);
153 }
154 close DIFF;
155
156
157 # Figure out who is doing the update.
158 # XXX: Too trivial this way?
159 ($user) = $author =~ /<(.*?)@/;
160
161
162 $rev = substr($commit, 0, 12);
163
164
165
166
167 ### Remove to-be-ignored files
168
169 @files = grep { $_ !~ m/$ignore_regexp/; } @files
170 if ($ignore_regexp);
171 exit unless @files;
172
173
174
175 ### Compose the mail message
176
177
178 my ($VERSION) = '1.0';
179 my $ts = time;
180
181 $message = <<EM
182 <message>
183 <generator>
184 <name>CIA Perl client for Git</name>
185 <version>$VERSION</version>
186 </generator>
187 <source>
188 <project>$project</project>
189 EM
190 ;
191 $message .= " <branch>$branch</branch>" if ($branch);
192 $message .= <<EM
193 </source>
194 <timestamp>
195 $ts
196 </timestamp>
197 <body>
198 <commit>
199 <author>$user</author>
200 <revision>$rev</revision>
201 <files>
202 EM
203 ;
204
205 foreach (@files) {
206 s/&/&amp;/g;
207 s/</&lt;/g;
208 s/>/&gt;/g;
209 $message .= " <file>$_</file>\n";
210 }
211
212 $logmsg =~ s/&/&amp;/g;
213 $logmsg =~ s/</&lt;/g;
214 $logmsg =~ s/>/&gt;/g;
215
216 $message .= <<EM
217 </files>
218 <log>
219 $logmsg
220 </log>
221 </commit>
222 </body>
223 </message>
224 EM
225 ;
226
227
228
229 ### Write the message to an alt-target
230
231 if ($alt_local_message_target and open (ALT, ">>$alt_local_message_target")) {
232 print ALT $message;
233 close ALT;
234 }
235
236
237
238 ### Send out the XML-RPC message
239
240
241 if ($xml_rpc) {
242 # We gotta be careful from now on. We silence all the warnings because
243 # RPC::XML code is crappy and works with undefs etc.
244 $^W = 0;
245 $RPC::XML::ERROR if (0); # silence perl's compile-time warning
246
247 require RPC::XML;
248 require RPC::XML::Client;
249
250 my $rpc_client = new RPC::XML::Client $rpc_uri;
251 my $rpc_request = RPC::XML::request->new('hub.deliver', $message);
252 my $rpc_response = $rpc_client->send_request($rpc_request);
253
254 unless (ref $rpc_response) {
255 die "XML-RPC Error: $RPC::XML::ERROR\n";
256 }
257 exit;
258 }
259
260
261
262 ### Send out the mail
263
264
265 # Open our mail program
266
267 open (MAIL, "| $sendmail -t -oi -oem") or die "Cannot execute $sendmail : " . ($?>>8);
268
269
270 # The mail header
271
272 print MAIL <<EOM;
273 From: $from_email
274 To: $dest_email
275 Content-type: text/xml
276 Subject: DeliverXML
277
278 EOM
279
280 print MAIL $message;
281
282
283 # Close the mail
284
285 close MAIL;
286 die "$0: sendmail exit status " . ($? >> 8) . "\n" unless ($? == 0);
287
288 # vi: set sw=2:
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pms

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pms

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master