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 open3(*IN, *OUT, *ERR, @args) || die("RT threw $!");
112 my $out = do { local $/; <OUT> };
114 $out .= do { local $/; <ERR> };
116 if (($out =~ tr/\n//) eq 1){
119 BarnOwl::popless_text($out);
123 BarnOwl::new_command("rt",
126 summary => "rt commands in barnowl",
127 usage => "rt <args>",
128 description => <<END_DESCR
131 rt [set|add|del] <args> - runs rt (set|add|del) with relevent args - Dangerous if not careful
132 rt [d|del|delete] - mark a ticket deleted
133 rt [r|res|resolve] - mark a ticked resolved
134 rt status [deleted|resolved|new|open|waiting|rejected] - set status of a ticket
135 rt show - show detailed history of selected ticket
136 rt show <ticket> - show history of <ticket>
137 rt list - list open tickets of current queue
138 rt list <queue> - lists open tickets of <queue>
139 rt merge <ticket> - merges current ticket with <ticket>
140 rt [take|untake|steal] - takes, untakes, or steals ticket
141 rt [owner|give] <user> - gives selected ticket to <user>
144 Go to help.mit.edu to set you rt password
146 In ~\/.rtrc add the following lines:
152 ~\/.owl\/rtqueuemap is a list of queues in the form of
154 which is used for the queue in commands like the rt list function which select the current queue
155 help "Some Help Queue"
157 ~\/.owl\/rtcommands is a file where you can put custom
158 commands to map the barnowl rt module with the rt command
161 It is a good place to put custom queries which will be used frequently.
163 "list-owner (\w+)" "rt list -o +Created \"((Status=new or Status=stalled or Status=open) and (Queue='\$q') and 'Owner='\$1')\""
165 \$t is the current ticket
166 \$q is the current queue
167 \$[digit] matches control groups in the first reg-exp
174 my $type = "comment";
175 if ($cmd eq "rt-reply"){
176 $type = "correspond";
179 my $m = owl::getcurmsg();
180 my ($ticket) = $m->instance =~ m/^\D*(\d{7})\D*$/;
182 BarnOwl::error("Command: '" . $cmd . "' requires a message with a ticket number selected");
187 return run_rt_command("rt", $type, "-m", join(" ", @_), $ticket);
189 return BarnOwl::start_edit_win($cmd . " ticket " . $ticket, sub {run_rt_command("rt", $type, "-m", @_, $ticket)});
193 BarnOwl::new_command("rt-reply",
196 summary => "Reply to current ticket",
197 usage => "rt-reply [message]",
198 description => <<END_DESCR
199 Replies to the currently selected ticket.
203 BarnOwl::new_command("rt-comment",
206 summary => "Comment on the current ticket",
207 usage => "rt-reply [message]",
208 description => <<END_DESCR
209 Comments on the currently selected ticket.
214 #owl::command('bindkey recv "M-r" command reply-un');