]> sipb.mit.edu Git - snippets/.git/blob - rt/Scrips/zephyr.pl
zephyr-post-receive: Translate Git trailing space highlighting
[snippets/.git] / rt / Scrips / zephyr.pl
1 my $class = 'scripts-test';
2 my $instance_prefix = 'rt.';
3 my @zwrite = ('/usr/local/bin/zwrite', '-d', '-O', 'auto', '-c', $class);
4
5 # RT-to-Zephyr notification scrip
6 # http://snippets.scripts.mit.edu/gitweb.cgi/.git/blob/HEAD:/rt/Scrips/zephyr.pl
7 #
8 # Copyright © 2010 Anders Kaseorg <andersk@mit.edu>
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # General Public License for more details.
19 #
20 # Usage: configure $class and $instance_prefix above, and create a
21 # scrip as follows.
22 #
23 #   Description: Send Zephyr
24 #   Condition: On Transaction
25 #   Action: User Defined
26 #   Template: Global template: Blank
27 #   Stage: TransactionCreate
28 #   Custom action preparation code:
29 #     1;
30 #   Custom action cleanup code:
31 #     [insert this code]
32
33 sub send_notice {
34     my ($instance, $body, $extra) = @_;
35     open my $out, '|-', @zwrite, '-i', $instance, defined $extra ? ('-s', $extra) : ();
36     print $out $body;
37     close $out;
38 };
39
40 local $SIG{__DIE__} = sub {
41     my ($err) = @_;
42     $err =~ s/@/@@/g;
43     send_notice "${instance_prefix}error", "Internal error in Zephyr scrip:\n$err";
44 };
45
46 (my $id = $self->TransactionObj->Ticket) =~ s/@/@@/g;
47 (my $description = $self->TransactionObj->Description) =~ s/@/@@/g;
48 (my $subject = $self->TransactionObj->TicketObj->Subject) =~ s/@/@@/g;
49
50 send_notice "$instance_prefix$id", $description, $subject;
51 1;