blib/lib/Bot/BasicBot/Pluggable/Module/JIRA.pm

filter: Statementstmt 22.8% 51 / 223 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 21.0% 12 / 57 Podpod 18.1% 2 / 11 totaltotal 17.4% 65 / 372 CC 37 SCAR 27.5
CC
37
Cov
17%
_build_client
56.0
said
56.0
init_dbh
30.0
CRAP 15.7
↑ Summary
1 package Bot::BasicBot::Pluggable::Module::JIRA;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $Bot::BasicBot::Pluggable::Module::JIRA::VERSION = '0.03';
4 }
5  
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Bot::BasicBot::Pluggable::Module::JIRA - Access JIRA via IRC!
12  
13 =head1 VERSION
14  
15 This POD describes version 0.02
16  
17 =cut
18  
19 =head1 SYNOPSIS
20  
21 You will need to load the module into your instance:
22  
23 $bot->load('JIRA');
24  
25 Then feel free to interrogate the shit out of her:
26  
27 <diz> purl: what's going on with PRJ-284?
28 <purl> diz: PRJ-284 (add jira support to bot) is unresolved - http://jira.domain.com/issue/284
29 <diz> purl: who fixed PRJ-284?
30 <purl> diz: gphat marked PRJ-284 as fixed in changeset bbb6a0f9
31  
32 =head1 CONFIGURATION
33  
34 =head2 uri
35  
36 The location of the JIRA instance. (Ex, http://jira.domain.com)
37  
38 =head2 username
39  
40 User to authenticate against JIRA with. This is configured in JIRA.
41 Note that the user will need permissions to view issues in order to
42 send getIssue requests over the SOAP interface.
43  
44 =head2 password
45  
46 The password to use for the user during authentication. Also setup in
47 JIRA (or LDAP if you're using the LDAP linkage).
48  
49 =head2 db_dsn (optional)
50  
51 =head2 db_user (optional)
52  
53 =head2 db_pass (optional)
54  
55 The SOAP API in JIRA is hit or miss. It exposes functionality that
56 I'll never use while omitting other functionality that makes the API
57 seem downright useless.
58  
59 One of the particular egregious omissions happens to be the lack of a
60 remote interface for retrieving the ChangeHistory for an issue. If,
61 however, you configure db_dsn, db_user, and db_pass, this module will
62 attempt to extract that information directly from the database. This
63 isn't recommended and has only been tested with 4.1.2.
64  
65 =head2 status_verbs
66  
67 The default inquiry format reports issue status by referring to the
68 last status change in the past tense. By default, the reply uses
69 "changed to" prepended to the status name. Instead of this, you may
70 want the bot to respond using more colloquial language. You may do
71 this by setting status_verbs to a hashref mapping status names to
72 status verb phrases. (ie, { Open => 'opened' }) Any missing pairs
73 default to "changed to".
74  
75 =head2 status_colors
76  
77 This one is fun. You may map issue status names to individual IRC
78 colors by setting status_colors to a hashref containing the map. The
79 following colors are understood:
80  
81 =over 2
82  
83 =item * bold
84  
85 =item * white
86  
87 =item * black
88  
89 =item * blue
90  
91 =item * green
92  
93 =item * red
94  
95 =item * brown
96  
97 =item * purple
98  
99 =item * orange
100  
101 =item * yellow
102  
103 =item * light_green
104  
105 =item * teal
106  
107 =item * cyan
108  
109 =item * light_blue
110  
111 =item * pink
112  
113 =item * gray
114  
115 =back
116  
117 =head2 formats
118  
119 Inquiry responses may be custom formatted. The formats configuration
120 item is expected to be a hashref containing key/value pairs for each
121 class of inquiry. The format is rendered using Text::Xslate. Several
122 convienient xslate functions have also been provided. In addition to
123 a function for each of the individual color names above, the following
124 functions are available:
125  
126 =over 2
127  
128 =item * colorize
129  
130 colors the given text according to the configured status_colors
131  
132 =back
133  
134 The RemoteIssue object returned by JIRA::CLient is the root context of
135 the template rendering, with the following keys added to the hashref:
136  
137 =over 2
138  
139 =item * issue (shortcut for key)
140  
141 =item * version (shortcut for the first fixVersion listed)
142  
143 =item * status_name (the issue's current status)
144  
145 =item * status_verb (the issue's current status in the past tense)
146  
147 =back
148  
149 If you've enabled the DBI options above, these are also available to
150 you:
151  
152 =over 2
153  
154 =item * status_last_changed_user (user that most recently changed the issue status)
155  
156 =item * status_last_changed_datetime (DateTime object for the most recent status change)
157  
158 =back
159  
160 More details on the RemoteIssue object may be found in the JIRA docs:
161  
162 http://docs.atlassian.com/rpc-jira-plugin/4.1-1/com/atlassian/jira/rpc/soap/beans/RemoteIssue.html
163  
164 Most all accessors methods on the RemoteIssue object are available in
165 the stash as keys of the hashref. For example, getAssignee may be
166 accessed in xslate like:
167  
168 <: $assignee :>
169  
170 The getComponents method, which returns a list of components, may be
171 accessed using similar perl/xslate idioms:
172  
173 <: $components.0 :>
174  
175 The default inquiry format is:
176  
177 <: colorize($issue) :> [<: $version :>] <: bold($summary) :> for <: $assignee :>
178  
179 which produces replies such as:
180  
181 <purl> PRJ-284 [Unscheduled] add jira to bot for diz
182  
183 The default status format is:
184  
185 <: $issue :> [<: $version :>] was <: $status_verb :> by <: $status_last_changed_user :> on <: $status_last_changed_datetime.strftime("%Y %b %d (%a) at %l:%M %P") :>
186  
187 which produces replies such as:
188  
189 <purl> PRJ-284 [Unscheduled] was closed by diz on 2010 Sep 13 (Mon) at 1:26 pm
190  
191 =cut
192  
193 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
194 2 ▶use MooseX::Traits;
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
197 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
198  
199 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
200 2 ▶use DateTime::Format::MySQL;
Subroutine BEGIN: called CC=1 SCAR=0.0
201 2 ▶use Lingua::StopWords::EN;
Subroutine BEGIN: called CC=1 SCAR=0.0
202 2 ▶use JIRA::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
203 2 ▶use Text::Xslate;
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 #use Data::Dump qw(dd pp);
206  
207 #$Data::Dump::INDENT = '';
208  
209 2 extends 'Bot::BasicBot::Pluggable::Module';
210  
211 has log =>
212 is => 'ro',
213 isa => 'Log::Log4perl::Logger',
214 lazy => 1,
215 0 ▶ default => sub { Log::Log4perl->get_logger(__PACKAGE__) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
216  
217 2 has xslate =>
218 is => 'ro',
219 isa => 'Text::Xslate',
220 lazy_build => 1;
221  
222 2 has client =>
223 is => 'ro',
224 lazy_build => 1;
225  
226 2 has dbh =>
227 is => 'rw',
228 isa => 'Maybe[DBI::db]';
229  
230 2 has sths =>
231 is => 'rw',
232 isa => 'HashRef[DBI::st]';
233  
234 2 has projects =>
235 is => 'ro',
236 isa => 'ArrayRef[RemoteProject]',
237 lazy_build => 1;
238  
239 2 has project_keys =>
240 is => 'ro',
241 isa => 'ArrayRef[Str]',
242 lazy_build => 1;
243  
244 2 has context =>
245 is => 'rw',
246 isa => 'RemoteIssue';
247  
248 2 has statuses =>
249 is => 'ro',
250 isa => 'HashRef',
251 lazy_build => 1,
252 traits => [ 'Hash' ],
253 handles => { get_status_name => 'get', get_statuses => 'values' };
254  
255 2 has status_verbs =>
256 is => 'ro',
257 isa => 'HashRef',
258 lazy_build => 1,
259 traits => [ 'Hash' ],
260 handles => { get_verb_for_status => 'get' };
261  
262 2 has status_colors =>
263 is => 'ro',
264 isa => 'HashRef',
265 lazy_build => 1,
266 traits => [ 'Hash' ],
267 handles => { get_color_for_status => 'get' };
268  
269 2 has formats =>
270 is => 'ro',
271 isa => 'HashRef',
272 lazy_build => 1,
273 traits => [ 'Hash' ],
274 handles => { get_format_for_inquiry => 'get' };
275  
276 has stopwords =>
277 is => 'ro',
278 isa => 'HashRef',
279 lazy => 1,
280 0 ▶ default => sub { Lingua::StopWords::EN->getStopWords };
Subroutine __ANON__: not called CC=1 SCAR=1.2
281  
282 2 has regex =>
283 is => 'ro',
284 lazy_build => 1;
285  
286 has handlers =>
287 is => 'ro',
288 isa => 'ArrayRef',
289 traits => [ 'Array' ],
290 lazy => 1,
291 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
292 2 handles => { add_handler => 'push' };
293  
294 sub _build_xslate
295 0 ▶{
Subroutine _build_xslate: not called CC=1 SCAR=6.9
296 0 my $self = shift;
297  
298 my $colorizers =
299 {
300 0 ▶ bold => sub { "$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
301 0 ▶ white => sub { "0$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
302 0 ▶ black => sub { "1$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
303 0 ▶ blue => sub { "2$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
304 0 ▶ green => sub { "3$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
305 0 ▶ red => sub { "4$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
306 0 ▶ brown => sub { "5$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
307 0 ▶ purple => sub { "6$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
308 0 ▶ orange => sub { "7$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
309 0 ▶ yellow => sub { "8$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
310 0 ▶ light_green => sub { "9$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
311 0 ▶ teal => sub { "10$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
312 0 ▶ cyan => sub { "11$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
313 0 ▶ light_blue => sub { "12$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
314 0 ▶ pink => sub { "13$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
315 0 ▶ gray => sub { "14$_[0]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
316 0 };
317  
318 new Text::Xslate
319 function =>
320 {
321 %$colorizers,
322  
323 0 ▶ colorize => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
324 0 my $status = $self->get_status_name($self->context->{status});
325 0 ▶ my $color = $self->get_color_for_status($status) || '';
Condition0%0/2
$self->get_color_for_status($status) || ''
l!l
00
MC/DC0%0/1
$self->get_color_for_status($status) || ''
$self->get_color_for_status($status)
Truth table0%0/2
A
A= $self->get_color_for_status($status)
Aresult
11
00
326 0 my $colorizer = $colorizers->{$color};
327  
328 0 ▶ return $colorizer ? $colorizer->($_[0]) : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
$colorizer ? : 0 0 0
329 }
330 0 };
331 }
332  
333 sub _build_client
334 0 ▶{
Subroutine _build_client: not called CC=7 SCAR=40.3
335 0 my $self = shift;
336  
337 # we have to use the Store directly since Moose already
338 # defines a get method for us.
339  
340 0 my $uri = $self->store->get(JIRA => 'uri');
341 0 my $user = $self->store->get(JIRA => 'username');
342 0 my $pass = $self->store->get(JIRA => 'password');
343 0 my $client = undef;
344  
345 0 ▶ $self->log->warn('missing configuration item "uri"') if not $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 0 0
346 0 ▶ $self->log->warn('missing configuration item "username"') if not $user;
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 0 0
347 0 ▶ $self->log->warn('missing configuration item "password"') if not $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless $pass 0 0 0
348  
349 0 ▶ return undef unless $uri and $user and $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri and $user and $pass 0 0 0
Condition0%0/6
$uri and $user and $pass
!ll&&!rl&&r
000
$uri and $user
!ll&&!rl&&r
000
MC/DC0%0/3
$uri and $user and $pass
$uri $user $pass
Truth table0%0/4
A and B and C
A= $uriB= $userC= $pass
ABCresult
0XX0
10X0
1100
1111
350  
351 0 my $meta = Class::MOP::Class->initialize('JIRA::Client');
352  
353 0 ▶ $meta->add_around_method_modifier(AUTOLOAD => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
354 0 my $next = shift;
355 0 my $self = shift;
356 0 my @args = @_;
357 0 my $res = undef;
358  
359 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
360 0 $res = $self->$next(@args);
361 0 ▶ } catch {
Subroutine __ANON__: not called CC=3 SCAR=24.8
362 0 ▶ if (/RemoteAuthenticationException/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/RemoteAuthenticationException/) { } 0 0 0
363 0 my $auth = $self->{soap}->login($user, $pass);
364  
365 0 ▶ die $auth->faultcode . ': ' . $auth->faultstring
Branch: 1 branch
BranchTrueFalseTotal
if defined $auth->fault 0 0 0
366 if defined $auth->fault;
367  
368 0 $self->{auth} = $auth->result;
369 0 $res = $self->$next(@args);
370 } else {
371 0 die $_;
372 }
373 0 };
374  
375 0 return $res;
376 0 });
377  
378 0 return new JIRA::Client $uri, $user, $pass;
379 }
380  
381 sub _build_projects
382 0 ▶{
Subroutine _build_projects: not called CC=2 SCAR=17.9
383 0 my $self = shift;
384  
385 0 ▶ return $self->client
Branch: 1 branch
BranchTrueFalseTotal
$self->client ? : 0 0 0
386 ? $self->client->getProjectsNoSchemes
387 : [];
388 }
389  
390 sub _build_project_keys
391 0 ▶{
Subroutine _build_project_keys: not called CC=1 SCAR=6.9
392 0 my $self = shift;
393  
394 0 my @keys = map { $_->{key} } @{ $self->projects };
395  
396 0 return \@keys;
397 }
398  
399 sub _build_statuses
400 0 ▶{
Subroutine _build_statuses: not called CC=1 SCAR=6.9
401 0 my $self = shift;
402  
403 0 my $statuses = { map { $_->{id} => $_->{name} } @{ $self->client->getStatuses } };
404  
405 #foreach my $status (values %$statuses) {
406 # $status =~ s/under quality review/submitted for QA/;
407 # $status =~ s/under technical review/submitted for review/;
408 #}
409  
410 0 return $statuses;
411 }
412  
413 sub _build_status_verbs
414 0 ▶{
Subroutine _build_status_verbs: not called CC=4 SCAR=30.0
415 0 my $self = shift;
416  
417 0 my $verbs = $self->store->get(JIRA => 'status_verbs');
418  
419 0 ▶ $verbs = {} unless ref($verbs) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $verbs eq "HASH" 0 0 0
420  
421 0 foreach my $status ($self->get_statuses) {
422 0 ▶ $verbs->{$status} ||= "changed to $status";
Condition0%0/2
$verbs->{$status} ||= "changed to $status"
l!l
00
MC/DC0%0/1
$verbs->{$status} ||= "changed to $status"
$verbs->{$status}
Truth table0%0/2
A
A= $verbs->{$status}
Aresult
11
00
423 }
424  
425 0 return $verbs;
426 }
427  
428 sub _build_status_colors
429 0 ▶{
Subroutine _build_status_colors: not called CC=2 SCAR=17.9
430 0 my $self = shift;
431  
432 0 my $colors = $self->store->get(JIRA => 'status_colors');
433  
434 0 ▶ $colors = {} unless ref($colors) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $colors eq "HASH" 0 0 0
435  
436 0 return $colors;
437 }
438  
439 sub _build_formats
440 0 ▶{
Subroutine _build_formats: not called CC=2 SCAR=17.9
441 0 my $self = shift;
442  
443 0 my $formats = $self->store->get(JIRA => 'formats');
444  
445 0 ▶ $formats = {} unless ref($formats) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $formats eq "HASH" 0 0 0
446  
447 return
448 {
449 0 default => '<: colorize($issue) :> [<: $version :>] <: bold($summary) :> for <: $assignee :>',
450 status => '<: $issue :> [<: $version :>] was <: $status_verb :> by <: $status_last_changed_user :> on <: $status_last_changed_datetime.strftime("%Y %b %d (%a) at %l:%M %P") :>',
451 %$formats
452 #my $date = $dt->strftime('%Y %b %d (%a)');
453 #my $time = $dt->strftime('%l:%M %P');
454 }
455 }
456  
457 sub _build_regex
458 0 ▶{
Subroutine _build_regex: not called CC=1 SCAR=6.9
459 0 my $self = shift;
460  
461 0 my $keys = join '|', @{ $self->project_keys };
462 0 my $re = qr/([a-zA-Z]*)\s*((?:$keys)-[0-9]+)/;
463  
464 0 return $re;
465 }
466  
467 sub init
468 0 ▶{
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
469 0 my $self = shift;
470  
471 0 $self->init_dbh;
472  
473 0 $self->add_handler([ qr/fix(ed|es)/ => \&inquiry_fixed ]);
474 0 $self->add_handler([ qr/closed/ => \&inquiry_closed ]);
475 0 $self->add_handler([ qr/opened|reported/ => \&inquiry_reporter ]);
476 0 $self->add_handler([ qr/status/ => \&inquiry_status ]);
477 #$self->add_handler([ qr/details/ => \&inquiry_details ]);
478 0 $self->add_handler([ qr/.?/ => \&inquiry_default ]);
479 }
480  
481 sub init_dbh
482 0 ▶{
Subroutine init_dbh: not called CC=5 SCAR=34.0
Pod undocumented
483 0 my $self = shift;
484  
485 0 my $dsn = $self->store->get(JIRA => 'db_dsn');
486 0 my $user = $self->store->get(JIRA => 'db_user');
487 0 my $pass = $self->store->get(JIRA => 'db_pass');
488  
489 0 ▶ return unless $dsn and $user and $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless $dsn and $user and $pass 0 0 0
Condition0%0/6
$dsn and $user and $pass
!ll&&!rl&&r
000
$dsn and $user
!ll&&!rl&&r
000
MC/DC0%0/3
$dsn and $user and $pass
$dsn $user $pass
Truth table0%0/4
A and B and C
A= $dsnB= $userC= $pass
ABCresult
0XX0
10X0
1100
1111
490  
491 0 $self->dbh(DBI->connect($dsn, $user, $pass));
492  
493 0 $self->sths({
494 last_status_modification_info => $self->dbh->prepare('SELECT cg.created, cg.author FROM changegroup cg JOIN changeitem ci ON ci.groupid=cg.ID JOIN jiraissue ji ON ji.id=cg.issueid WHERE ji.pkey=? AND ci.field="status" ORDER BY cg.created DESC LIMIT 1')
495 });
496  
497 0 foreach my $name (keys %{ $self->sths }) {
498 0 ▶ my $coderef = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
499 0 my $self = shift;
500 0 my $issue = shift;
501  
502 0 $self->sths->{$name}->execute($issue);
503 0 $self->sths->{$name}->fetch;
504 0 };
505  
506 0 $self->meta->add_method("get_$name" => $coderef);
507 }
508 }
509  
510 sub inquiry_fixed
511 0 ▶{
Subroutine inquiry_fixed: not called CC=1 SCAR=0.0
Pod undocumented
512 }
513  
514 sub inquiry_closed
515 0 ▶{
Subroutine inquiry_closed: not called CC=1 SCAR=0.0
Pod undocumented
516 }
517  
518 sub inquiry_reporter
519 0 ▶{
Subroutine inquiry_reporter: not called CC=1 SCAR=0.0
Pod undocumented
520 }
521  
522 sub inquiry_details
523 0 ▶{
Subroutine inquiry_details: not called CC=4 SCAR=30.0
Pod undocumented
524 0 my $self = shift;
525 0 my $issue = shift;
526 0 my $callback = shift;
527  
528 # IDEA: using the stopword filter, pull out text at
529 # random out of the description and display it. kinda
530 # neat. multiple calls will return different things,
531 # exposing information about the ticket without flooding
532 # the channel
533  
534 0 my $href = $self->client->getIssue($issue);
535  
536 0 ▶ return unless defined $href;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $href 0 0 0
537  
538 0 ▶ my $ver = $href->{fixVersions}->[0] ? $href->{fixVersions}->[0]->{name} : '';
Branch: 1 branch
BranchTrueFalseTotal
$href->{'fixVersions'}[0] ? : 0 0 0
539 0 my $details = '';
540  
541 0 ▶ if ($href->{description} < 80) {
Branch: 1 branch
BranchTrueFalseTotal
if ($href->{'description'} < 80) { } 0 0 0
542 0 $details = $href->{description};
543 } else {
544 0 my @tokens = grep { not exists $self->stopwords->{$_} }
545 0 split /\s+/, $href->{description};
546 0 my %keywords = map { $tokens[int rand $#tokens] => 1 } (1 .. 10);
547  
548 0 $details = join ', ', keys %keywords;
549 }
550  
551 0 $callback->("$issue [$ver] details: $details");
552 }
553  
554 sub inquiry_status
555 0 ▶{
Subroutine inquiry_status: not called CC=2 SCAR=17.9
Pod undocumented
556 0 my $self = shift;
557 0 my $key = shift;
558 0 my $callback = shift;
559  
560 0 my $issue = $self->get_issue($key);
561  
562 0 ▶ return unless defined $issue;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $issue 0 0 0
563  
564 #my $status = $self->get_status_name($issue->{status});
565 #my $color = $self->get_color_for_status($status);
566 #my $verb = $self->get_verb_for_status($status);
567 #my $aref = $self->get_last_status_modification_info($issue);
568 #my $dt = DateTime::Format::MySQL->parse_datetime($aref->[0]);
569 #my $user = $aref->[1];
570 #my $date = $dt->strftime('%Y %b %d (%a)');
571 #my $time = $dt->strftime('%l:%M %P');
572  
573 #$time =~ s/^ //;
574  
575 0 $callback->($self->render(status => $issue));
576  
577 #$callback->("$issue [$ver] was $sverb by $user on $date at $time");
578 }
579  
580 sub get_issue
581 0 ▶{
Subroutine get_issue: not called CC=5 SCAR=34.0
Pod undocumented
582 0 my $self = shift;
583 0 my $key = shift;
584  
585 0 my $issue = $self->client->getIssue($key);
586  
587 0 ▶ if ($issue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($issue) 0 0 0
588 0 my $status = $self->get_status_name($issue->{status});
589 0 my $color = $self->get_color_for_status($status);
590  
591 0 $issue->{issue} = $issue->{key};
592 0 $issue->{status_name} = $status;
593 0 $issue->{status_verb} = $self->get_verb_for_status($status);
594  
595 0 ▶ if ($self->meta->has_method('get_last_status_modification_info')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->meta->has_method("get_last_status_modification_info")) 0 0 0
596 0 ▶ if (my $aref = $self->get_last_status_modification_info($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $aref = $self->get_last_status_modification_info($key)) 0 0 0
597 0 my $dt = DateTime::Format::MySQL->parse_datetime($aref->[0]);
598 0 my $user = $aref->[1];
599  
600 0 $issue->{status_last_changed_user} = $aref->[1];
601 0 $issue->{status_last_changed_datetime} = $dt;
602 }
603 }
604  
605 $issue->{version} = $issue->{fixVersions}->[0]
606 ? $issue->{fixVersions}->[0]->{name}
607 0 ▶ : 'Unscheduled';
Branch: 1 branch
BranchTrueFalseTotal
$issue->{'fixVersions'}[0] ? : 0 0 0
608  
609 0 $self->context($issue);
610 }
611  
612 0 return $issue;
613 }
614  
615 sub inquiry_default
616 0 ▶{
Subroutine inquiry_default: not called CC=2 SCAR=17.9
Pod undocumented
617 0 my $self = shift;
618 0 my $key = shift;
619 0 my $callback = shift;
620  
621 0 my $issue = $self->get_issue($key);
622  
623 0 ▶ return unless defined $issue;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $issue 0 0 0
624 #dd $issue;
625  
626 #my $msg = $self->xslate->render_string($self->get_format_for_inquiry('default'), $issue);
627  
628 0 $callback->($self->render(default => $issue));
629 }
630  
631 sub render
632 0 ▶{
Subroutine render: not called CC=1 SCAR=6.9
Pod undocumented
633 0 my $self = shift;
634 0 my $format = shift;
635 0 my $issue = shift;
636  
637 0 return $self->xslate->render_string($self->get_format_for_inquiry($format), $issue);
638 }
639  
640 sub said
641 0 ▶{
Subroutine said: not called CC=7 SCAR=40.3
Pod documented
642 0 my $self = shift;
643 0 my $msg = shift;
644 0 my $pri = shift;
645  
646 #dd { priority => $pri, %$msg};
647  
648 0 ▶ return if $pri == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pri == 0 0 0 0
649  
650 #$self->log->info("said(pri => $pri)");
651  
652 0 my $re = $self->regex;
653 0 my @tokens = grep { not exists $self->stopwords->{$_} } split /\s+/, $msg->{body};
654 0 my $body = join ' ', @tokens;
655  
656 0 my @response = ();
657 0 ▶ my $callback = sub { push @response, $_[0] ? $_[0] : () };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
658  
659 # strip shit out of the message
660 #$body =~ s/\?//g;
661  
662 0 ▶ if (my @pairs = ($body =~ /$re/g)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@pairs) = $body =~ /$re/g) 0 0 0
663 #$callback->('match');
664  
665 0 ▶ while (my ($inquiry, $issue) = splice @pairs, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@pairs, 0, 2)) 0 0 0
666 0 my $handler = [ grep { $inquiry =~ $_->[0] } @{ $self->handlers } ]->[0]->[1];
667  
668 0 ▶ $handler->($self, $issue, $callback) if $handler and $self->client;
Branch: 1 branch
BranchTrueFalseTotal
if $handler and $self->client 0 0 0
Condition0%0/3
$handler and $self->client
!ll&&!rl&&r
000
MC/DC0%0/2
$handler and $self->client
$handler $self->client
Truth table0%0/3
A and B
A= $handlerB= $self->client
ABresult
0X0
100
111
669 }
670 }
671  
672 0 $self->say(%$msg, body => $_) foreach @response[0..$#response-1];
673  
674 0 return $response[$#response];
675 }
676  
677 =head1 BUGS
678  
679 Probably a lot of them. The test suite does nothing beyond what
680 Module::Starter already provides.
681  
682 =head1 AUTHOR
683  
684 Mike Eldridge, C<< <diz at cpan.org> >>
685  
686 =head1 LICENSE AND COPYRIGHT
687  
688 Copyright 2010 Mike Eldridge
689  
690 This program is free software; you can redistribute it and/or modify it
691 under the terms of either: the GNU General Public License as published
692 by the Free Software Foundation; or the Artistic License.
693  
694 See http://dev.perl.org/licenses/ for more information.
695  
696 =head1 SEE ALSO
697  
698 =over 2
699  
700 =item * L<Bot::BasicBot::Pluggable>
701  
702 =item * L<JIRA::Client>
703  
704 =back
705  
706 =cut
707  
708 2 1;
709  
↑ Summary