14 package BarnOwl::Module::RT;
18 our $VERSION = '1.0.1';
22 "((?:set|add|del)\\s.*)", "edit ticket/\$t \$1",
23 "status\\s(deleted|resolved|rejected|open|new|waiting)", "edit ticket/\$t set status=\$1",
24 "(d|del|delete)", "edit ticket/\$t set status=deleted",
25 "(r|res|resolve)", "edit ticket/\$t set status=resolved",
26 "show", "show -l ticket/\$t/history",
27 "show (\\d+)", "show -l ticket/\$1/history",
28 "list", 'rt list -o +Created "((Status=new or Status=stalled or Status=open) and (Queue=\'$q\'))"',
29 "list (\\w+)", 'rt list -o +Created "((Status=new or Status=stalled or Status=open) and (Queue=\'\$1\'))"',
30 "merge (\\d+)", "rt merge \$t \$1",
31 "(take|untake|steal)", "rt \$1 \$t",
32 "(?:owner|give)\\s(\\w+)", "edit ticket/\$t set owner=\$1",
37 my $cfg = BarnOwl::get_config_dir();
38 my $file_path = "$cfg/rtqueuemap";
40 open(my $fh, "<:encoding(UTF-8)", "$file_path") or die("Unable to read $file_path:$!\n");
41 while(defined(my $line = <$fh>)) {
42 next if $line =~ /^\s+#/;
43 next if $line =~ /^\s+$/;
44 my ($class, $q) = quotewords('\s+', 0, $line);
45 $queuemap{lc($class)} = $q;
50 my $file_path = "$cfg/rtcommands";
52 open(my $fh, "<:encoding(UTF-8)", "$file_path") or die("Unable to read $file_path:$!\n");
53 while(defined(my $line = <$fh>)) {
54 next if $line =~ /^\s+#/;
55 next if $line =~ /^\s+$/;
56 my ($match, $command) = quotewords('\s+', 0, $line);
57 $commands{$match} = $command;
66 my $args = join(' ', @_);
67 my $m = owl::getcurmsg();
68 my ($ticket) = $m->instance =~ m/^\D*(\d{7})\D*$/;
69 my ($class) = $m->class =~ /^(?:un)*(.+?)(?:[.]d)*$/i;
70 my $queue = $queuemap{$class};
72 for my $key (keys %commands)
74 my $value = $commands{$key};
75 if($args =~ m/^\s*$key\s*$/){
78 #my $match = qr/\Q$key\E/
81 BarnOwl::error("Command 'rt " . $args . "' requires a message with ticket number selected");
84 $match =~ s/\$t/$ticket/;
88 BarnOwl::error("Command 'rt " . $args . "' requires a class in rtqueuemap selected");
91 $match =~ s/\$q/$queue/;
93 for my $digit ($value =~ m/\$(\d)/g){
94 $args =~ m/^\s*$key\s*$/;
95 my $replace = substr($args, $-[$digit], $+[$digit] - $-[$digit]);
96 $match =~ s/\$$digit/$replace/;
98 return run_rt_command( quotewords('\s+', 0, $match) );
102 BarnOwl::error("No Matching RT command found for: '" . $args . "'" );
107 my @args = ("athrun","tooltime","rt");
109 local(*IN, *OUT, *ERR);
110 my $pid = open3(*IN, *OUT, *ERR, @args) || die("RT threw $!");
112 my $out = do { local $/; <OUT> };
114 $out .= do { local $/; <ERR> };
119 if (($out =~ tr/\n//) eq 1){
122 BarnOwl::popless_text($out);
126 BarnOwl::new_command("rt",
129 summary => "rt commands in barnowl",
130 usage => "rt <args>",
131 description => <<END_DESCR
134 rt [set|add|del] <args> - runs rt (set|add|del) with relevent args - Dangerous if not careful
135 rt [d|del|delete] - mark a ticket deleted
136 rt [r|res|resolve] - mark a ticked resolved
137 rt status [deleted|resolved|new|open|waiting|rejected] - set status of a ticket
138 rt show - show detailed history of selected ticket
139 rt show <ticket> - show history of <ticket>
140 rt list - list open tickets of current queue
141 rt list <queue> - lists open tickets of <queue>
142 rt merge <ticket> - merges current ticket with <ticket>
143 rt [take|untake|steal] - takes, untakes, or steals ticket
144 rt [owner|give] <user> - gives selected ticket to <user>
147 Go to help.mit.edu to set you rt password
149 In ~\/.rtrc add the following lines:
155 ~\/.owl\/rtqueuemap is a list of queues in the form of
157 which is used for the queue in commands like the rt list function which select the current queue
158 help "Some Help Queue"
160 ~\/.owl\/rtcommands is a file where you can put custom
161 commands to map the barnowl rt module with the rt command
164 It is a good place to put custom queries which will be used frequently.
166 "list-owner (\w+)" "rt list -o +Created \"((Status=new or Status=stalled or Status=open) and (Queue='\$q') and 'Owner='\$1')\""
168 \$t is the current ticket
169 \$q is the current queue
170 \$[digit] matches control groups in the first reg-exp
177 my $type = "comment";
178 if ($cmd eq "rt-reply"){
179 $type = "correspond";
182 my $m = owl::getcurmsg();
183 my ($ticket) = $m->instance =~ m/^\D*(\d{7})\D*$/;
185 BarnOwl::error("Command: '" . $cmd . "' requires a message with a ticket number selected");
190 return run_rt_command("rt", $type, "-m", join(" ", @_), $ticket);
192 return BarnOwl::start_edit_win($cmd . " ticket " . $ticket, sub {run_rt_command("rt", $type, "-m", @_, $ticket)});
196 BarnOwl::new_command("rt-reply",
199 summary => "Reply to current ticket",
200 usage => "rt-reply [message]",
201 description => <<END_DESCR
202 Replies to the currently selected ticket.
206 BarnOwl::new_command("rt-comment",
209 summary => "Comment on the current ticket",
210 usage => "rt-reply [message]",
211 description => <<END_DESCR
212 Comments on the currently selected ticket.
217 #owl::command('bindkey recv "M-r" command reply-un');