File Coverage

blib/lib/Net/GitHub/V3/Issues.pm
Criterion Covered Total %
statement 9 56 16.0
branch 0 18 0.0
condition n/a
subroutine 3 15 20.0
pod 3 9 33.3
total 15 98 15.3


line stmt bran cond sub pod time code
1             package Net::GitHub::V3::Issues;
2              
3 1     1   6 use Moo;
  1         2  
  1         5  
4              
5             our $VERSION = '1.03';
6             our $AUTHORITY = 'cpan:FAYLAND';
7              
8 1     1   305 use URI::Escape;
  1         2  
  1         803  
9              
10             with 'Net::GitHub::V3::Query';
11              
12             sub issues {
13 0     0 1   my $self = shift;
14              
15 0           return $self->query(_issues_arg2url(@_));
16             }
17              
18             sub next_issue {
19 0     0 0   my $self = shift;
20              
21 0           return $self->next(_issues_arg2url(@_));
22             }
23              
24             sub close_issue {
25 0     0 0   my $self = shift;
26              
27 0           return $self->close(_issues_arg2url(@_));
28             }
29              
30              
31             sub _issues_arg2url {
32 0 0   0     my $args = @_ % 2 ? shift : { @_ };
33 0           my @p;
34 0           foreach my $p (qw/filter state labels sort direction since/) {
35 0 0         push @p, "$p=" . $args->{$p} if exists $args->{$p};
36             }
37 0           my $u = '/issues';
38 0 0         $u .= '?' . join('&', @p) if @p;
39 0           return $u;
40             }
41              
42             sub repos_issues {
43 0     0 1   my $self = shift;
44              
45 0           return $self->query($self->_repos_issues_arg2url(@_));
46             }
47              
48             sub next_repos_issue {
49 0     0 0   my $self = shift;
50              
51 0           return $self->next($self->_repos_issues_arg2url(@_));
52             }
53              
54             sub close_repos_issue {
55 0     0 0   my $self = shift;
56              
57 0           return $self->close($self->_repos_issues_arg2url(@_));
58             }
59              
60             sub _repos_issues_arg2url {
61 0     0     my $self = shift;
62 0 0         if (@_ < 2) {
63 0           unshift @_, $self->repo;
64 0           unshift @_, $self->u;
65             }
66 0           my ($user, $repos, $args) = @_;
67              
68 0           my @p;
69 0           foreach my $p (qw/milestone state assignee mentioned labels sort direction since/) {
70 0 0         push @p, "$p=" . $args->{$p} if exists $args->{$p};
71             }
72 0           my $u = "/repos/" . uri_escape($user) . "/" . uri_escape($repos) . '/issues';
73 0 0         $u .= '?' . join('&', @p) if @p;
74 0           return $u;
75             }
76              
77             ## build methods on fly
78             my %__methods = (
79              
80             issue => { url => "/repos/%s/%s/issues/%s" },
81             create_issue => { url => "/repos/%s/%s/issues", method => 'POST', args => 1 },
82             update_issue => { url => "/repos/%s/%s/issues/%s", method => 'PATCH', args => 1 },
83              
84             ## http://developer.github.com/v3/issues/comments/
85             comments => { url => "/repos/%s/%s/issues/%s/comments", paginate => 1 },
86             comment => { url => "/repos/%s/%s/issues/comments/%s" },
87             create_comment => { url => "/repos/%s/%s/issues/%s/comments", method => 'POST', args => 1 },
88             update_comment => { url => "/repos/%s/%s/issues/comments/%s", method => 'PATCH', args => 1 },
89             delete_comment => { url => "/repos/%s/%s/issues/comments/%s", method => 'DELETE', check_status => 204 },
90              
91             # http://developer.github.com/v3/issues/events/
92             events => { url => "/repos/%s/%s/issues/%s/events", paginate => 1 },
93             repos_events => { url => "/repos/%s/%s/issues/events" , paginate => 1 },
94             event => { url => "/repos/%s/%s/issues/events/%s" },
95              
96             # http://developer.github.com/v3/issues/labels/
97             labels => { url => "/repos/%s/%s/labels", paginate => 1 },
98             label => { url => "/repos/%s/%s/labels/%s" },
99             create_label => { url => "/repos/%s/%s/labels", method => 'POST', args => 1 },
100             update_label => { url => "/repos/%s/%s/labels/%s", method => 'PATCH', args => 1 },
101             delete_label => { url => "/repos/%s/%s/labels/%s", method => 'DELETE', check_status => 204 },
102             issue_labels => { url => "/repos/%s/%s/issues/%s/labels", paginate => 1 },
103             create_issue_label => { url => "/repos/%s/%s/issues/%s/labels", method => 'POST', args => 1 },
104             delete_issue_label => { url => "/repos/%s/%s/issues/%s/labels/%s", method => 'DELETE', check_status => 204 },
105             replace_issue_label => { url => "/repos/%s/%s/issues/%s/labels", method => 'PUT', args => 1 },
106             delete_issue_labels => { url => "/repos/%s/%s/issues/%s/labels", method => 'DELETE', check_status => 204 },
107             milestone_labels => { url => "/repos/%s/%s/milestones/%s/labels", paginate => 1 },
108              
109             # http://developer.github.com/v3/issues/milestones/
110             milestone => { url => "/repos/%s/%s/milestones/%s" },
111             create_milestone => { url => "/repos/%s/%s/milestones", method => 'POST', args => 1 },
112             update_milestone => { url => "/repos/%s/%s/milestones/%s", method => 'PATCH', args => 1 },
113             delete_milestone => { url => "/repos/%s/%s/milestones/%s", method => 'DELETE', check_status => 204 },
114              
115             );
116             __build_methods(__PACKAGE__, %__methods);
117              
118             ## http://developer.github.com/v3/issues/milestones/
119             sub milestones {
120 0     0 1   my $self = shift;
121              
122 0           return $self->query($self->_milestones_arg2url(@_));
123             }
124              
125             sub next_milestone {
126 0     0 0   my $self = shift;
127              
128 0           return $self->next($self->_milestones_arg2url(@_));
129             }
130              
131             sub close_milestone {
132 0     0 0   my $self = shift;
133              
134 0           return $self->close($self->_milestones_arg2url(@_));
135             }
136              
137             sub _milestones_arg2url {
138 0     0     my $self = shift;
139              
140 0 0         if (@_ < 3) {
141 0           unshift @_, $self->repo;
142 0           unshift @_, $self->u;
143             }
144 0           my ($user, $repos, $args) = @_;
145              
146 0           my @p;
147 0           foreach my $p (qw/state sort direction/) {
148 0 0         push @p, "$p=" . $args->{$p} if exists $args->{$p};
149             }
150 0           my $u = "/repos/" . uri_escape($user) . "/" . uri_escape($repos) . '/milestones';
151 0 0         $u .= '?' . join('&', @p) if @p;
152 0           return $u;
153             }
154              
155 1     1   7 no Moo;
  1         2  
  1         4  
156              
157             1;
158             __END__