File Coverage

blib/lib/App/BitBucketCli/Command/PullRequests.pm
Criterion Covered Total %
statement 15 39 38.4
branch 0 10 0.0
condition 0 19 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 77 28.5


line stmt bran cond sub pod time code
1             package App::BitBucketCli::Command::PullRequests;
2              
3             # Created on: 2018-06-07 08:23:20
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 1     1   5284 use Moo;
  1         3  
  1         7  
10 1     1   352 use warnings;
  1         3  
  1         37  
11 1     1   7 use Carp;
  1         2  
  1         78  
12 1     1   7 use Data::Dumper qw/Dumper/;
  1         2  
  1         44  
13 1     1   6 use English qw/ -no_match_vars /;
  1         1  
  1         7  
14              
15             extends 'App::BitBucketCli';
16              
17             our $VERSION = 0.007;
18              
19             sub options {
20 0     0 1   return [qw/
21             colors|c=s%
22             force|f!
23             author|a=s
24             to_branch|to-branch|t=s
25             from_branch|from-branch|f=s
26             title|T=s
27             state|S=s
28             long|l
29             project|p=s
30             regexp|R
31             remote|m=s
32             repository|r=s
33             sleep|s=i
34             /]
35             }
36              
37             sub pull_requests {
38 0     0 1   my ($self) = @_;
39              
40             my @pull_requests = sort {
41 0           lc $a->id cmp lc $b->id;
42             }
43 0   0       $self->core->pull_requests($self->opt->{project}, $self->opt->{repository}, $self->opt->{state} || 'OPEN');
44              
45 0           my @prs;
46             my %max;
47 0           my $author = $self->opt->author();
48 0           my $to_branch = $self->opt->to_branch();
49 0           my $from_branch = $self->opt->from_branch();
50 0           my $title = $self->opt->title();
51 0           for my $pull_request (@pull_requests) {
52 0 0 0       next if $author && $pull_request->author->{user}{displayName} !~ /$author/;
53 0 0 0       next if $to_branch && $pull_request->toRef->{displayId} !~ /$to_branch/;
54 0 0 0       next if $from_branch && $pull_request->fromRef->{displayId} !~ /$from_branch/;
55 0 0 0       next if $title && $pull_request->title !~ /$title/;
56              
57             push @prs, {
58             id => $pull_request->id,
59             title => $pull_request->title,
60             author => $pull_request->author->{user}{displayName},
61             from => $pull_request->fromRef->{displayId},
62             to => $pull_request->toRef->{displayId},
63 0   0       tasks => $pull_request->{openTasks}->[0] || 0,
64             };
65 0           chomp $prs[-1]{title};
66 0           for my $key (keys %{ $prs[-1] }) {
  0            
67 0 0 0       $max{$key} = length $prs[-1]{$key} if ! $max{$key} || $max{$key} < length $prs[-1]{$key};
68             }
69             }
70              
71 0           for my $pr (@prs) {
72 0           printf "%-$max{id}s ", $pr->{id};
73 0           printf "%-$max{author}s ", $pr->{author};
74 0           printf "%-$max{tasks}s ", $pr->{tasks};
75 0           print "$pr->{title}\n";
76             }
77             }
78              
79             1;
80              
81             __END__
82              
83             =head1 NAME
84              
85             App::BitBucketCli::Command::PullRequests - Show the pull requests of a repository
86              
87             =head1 VERSION
88              
89             This documentation refers to App::BitBucketCli::Command::PullRequests version 0.007
90              
91             =head1 SYNOPSIS
92              
93             bb-cli pull-requests [options]
94              
95             OPTIONS:
96             -c --colors[=]str Change colours used specified as key=value
97             eg --colors disabled=grey22
98             current colour names aborted, disabled and notbuilt
99             -f --force Force action
100             -l --long Show long form data if possible
101             -p --project[=]str
102             For commands that need a project name this is the name to use
103             -R --recipient[=]str
104             ??
105             -R --regexp[=]str ??
106             -m --remote[=]str ??
107             -r --repository[=]str
108             For commands that work on repositories this contains the repository
109             -s --sleep[=]seconds
110             ??
111             -t --test ??
112             -a --author[=]regex
113             Show only pull requests by this author
114             -t --to-branch[=]regex
115             Show only pull requests to this branch
116             -f --from-branch[=]rege
117             Show only pull requests from this branchx
118             -T --title[=]regex
119             Show only pull requests matching this title
120             -S --state[=](OPEN|MERGED|DECLINED|ALL)
121             Show pull requests of this type (Default OPEN)
122              
123             CONFIGURATION:
124             -h --host[=]str Specify the Stash/Bitbucket Servier host name
125             -P --password[=]str
126             The password to connect to the server as
127             -u --username[=]str
128             The username to connect to the server as
129              
130             -v --verbose Show more detailed option
131             --version Prints the version information
132             --help Prints this help information
133             --man Prints the full documentation for bb-cli
134              
135             =head1 DESCRIPTION
136              
137             =head1 SUBROUTINES/METHODS
138              
139             =head2 C<options ()>
140              
141             Returns the command line options
142              
143             =head2 C<pull_requests ()>
144              
145             =head1 DIAGNOSTICS
146              
147             =head1 CONFIGURATION AND ENVIRONMENT
148              
149             =head1 DEPENDENCIES
150              
151             =head1 INCOMPATIBILITIES
152              
153             =head1 BUGS AND LIMITATIONS
154              
155             There are no known bugs in this module.
156              
157             Please report problems to Ivan Wills (ivan.wills@gmail.com).
158              
159             Patches are welcome.
160              
161             =head1 AUTHOR
162              
163             Ivan Wills - (ivan.wills@gmail.com)
164              
165             =head1 LICENSE AND COPYRIGHT
166              
167             Copyright (c) 2018 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
168             All rights reserved.
169              
170             This module is free software; you can redistribute it and/or modify it under
171             the same terms as Perl itself. See L<perlartistic>. This program is
172             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
173             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
174             PARTICULAR PURPOSE.
175              
176             =cut