lib/App/gh/API.pm

filter: Statementstmt 21.5% 28 / 130 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 32.1% 9 / 28 Podpod 47.3% 9 / 19 totaltotal 18.2% 46 / 252 CC 26 SCAR 21.5
CC
26
Cov
15%
issue_edit
20.0
user_info
12.0
pullreq_send
12.0
CRAP 8.6
« lib/App/gh/Command/Push.pm ↑ Summary blib/lib/App/gh/Command/Issue/List.pm »
1 package App::gh::API;
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use App::gh::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Net::GitHub;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub new_ua {
Subroutine new_ua: not called CC=1 SCAR=6.9
Pod undocumented
13 0 my $class = shift;
14 0 my $ua = LWP::UserAgent->new; # TODO: make this switchable. better client ? Furl ?
15 0 $ua->timeout(10);
16 0 $ua->env_proxy;
17 0 return $ua;
18 }
19  
20 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod undocumented
21 0 my ( $class, $verb, $query , %args ) = @_;
22 0 die('v2 API is deprecated from github');
23 }
24  
25 0 ▶sub search {
Subroutine search: not called CC=1 SCAR=6.9
Pod documented
26 0 my ( $class, $query, %args ) = @_;
27 0 return $class->request(GET => qq{repos/search/$query}, %args);
28 }
29  
30 0 ▶sub fork {
Subroutine fork: not called CC=2 SCAR=17.9
Pod documented
31 0 my ( $class, $user, $repo) = @_;
32 0 ▶ Carp::croak("Missing mandatory parameter: user") unless defined $user;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $user 0 0 0
33 0 my $gh_id = App::gh->config->github_id;
34 0 my $gh_password = App::gh->config->github_password;
35  
36 0 my $gh = Net::GitHub->new(
37 version => 3,
38 login => App::gh->config->github_id,
39 pass => App::gh->config->github_password,
40 );
41  
42 0 my $repos = $gh->repos;
43 0 $repos->set_default_user_repo( $user, $repo );
44  
45 0 return $repos->create_fork;
46 }
47  
48 0 ▶sub repo_network {
Subroutine repo_network: not called CC=1 SCAR=6.9
Pod documented
49 0 my ( $class, $user, $repo ) = @_;
50 0 my $ret = $class->request(GET => qq(repos/show/$user/$repo/network));
51 0 return $ret->{network};
52 }
53  
54 0 ▶sub repo_info {
Subroutine repo_info: not called CC=2 SCAR=17.9
Pod documented
55 0 my ( $class, $user, $repo ) = @_;
56 0 my $ret = $class->request(GET => qq{repos/show/$user/$repo});
57 0 ▶ return $ret->{repository} if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
58 }
59  
60 0 ▶sub repo_create {
Subroutine repo_create: not called CC=2 SCAR=17.9
Pod documented
61 0 my ($class,%args) = @_;
62 0 my $ret = $class->request(POST => qq{repos/create} , %args);
63 0 ▶ return $ret->{repository} if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
64 }
65  
66 0 ▶sub user_info {
Subroutine user_info: not called CC=3 SCAR=24.8
Pod documented
67 0 my ($class,$user,$page) = @_;
68 0 ▶ $page ||= 1;
Condition0%0/2
$page ||= 1
l!l
00
MC/DC0%0/1
$page ||= 1
$page
Truth table0%0/2
A
A= $page
Aresult
11
00
69 0 my $ret = $class->request(GET => qq{repos/show/$user?page=$page});
70 0 ▶ return $ret if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
71 }
72  
73 0 ▶sub user_repos {
Subroutine user_repos: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my ($class,$user) = @_;
75 0 my @repos;
76 0 my $page = 1;
77 0 while (1) {
78 0 my $ret = $class->user_info( $user, $page++ );
79 0 ▶ last unless @{$ret->{repositories}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$ret->{"repositories"};} 0 0 0
80 0 push @repos, @{$ret->{repositories}};
81 }
82 0 return \@repos;
83 }
84  
85 # Added by RCT
86 0 ▶sub repo_set_public {
Subroutine repo_set_public: not called CC=2 SCAR=17.9
Pod documented
87 0 my ( $class, $user, $repo, $public ) = @_;
88 0 ▶ my $visibility = $public ? "public" : "private";
Branch: 1 branch
BranchTrueFalseTotal
$public ? : 0 0 0
89 0 my $ret = $class->request(POST => qq{repos/set/$visibility/$user/$repo});
90 0 return $ret;
91 }
92  
93 0 ▶sub repo_set_info {
Subroutine repo_set_info: not called CC=2 SCAR=17.9
Pod documented
94 0 my ( $class, $user, $repo, %args ) = @_;
95 0 ▶ if (exists $args{public}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"public"}) 0 0 0
96 0 $class->repo_set_public( $user, $repo, $args{public} );
97 0 delete $args{public};
98 }
99 # Keys must be in the form 'values[key]'
100 0 %args = map { ("values[$_]" => $args{$_}) } (keys %args);
101 0 my $ret = $class->request(POST => qq{repos/show/$user/$repo} , %args);
102 0 return $ret->{repository};
103 }
104  
105 0 ▶sub pullreq_send {
Subroutine pullreq_send: not called CC=3 SCAR=24.8
Pod undocumented
106 0 my ( $class, $user, $repo, $local_branch, $remote_branch, $title, $body) = @_;
107 0 my $gh_id = App::gh->config->github_id;
108 0 my $gh_token = App::gh->config->github_token;
109 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
110 0 die "Github authtoken not found. Can not send pull request.\n";
111 }
112 0 return $class->request(POST => sprintf("pulls/%s/%s?login=%s&token=%s", $user, $repo, $gh_id, $gh_token),
113 'pull[base]' => $remote_branch,
114 'pull[head]' => "$gh_id:$local_branch",
115 'pull[title]' => $title,
116 'pull[body]' => $body,
117 );
118 }
119  
120 0 ▶sub pullreq_list {
Subroutine pullreq_list: not called CC=3 SCAR=24.8
Pod documented
121 0 my ( $class, $user, $repo) = @_;
122 0 my $gh_id = App::gh->config->github_id;
123 0 my $gh_token = App::gh->config->github_token;
124 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
125 0 die "Github authtoken not found. Can not get pull requests.\n";
126 }
127 0 return $class->request(GET => sprintf("pulls/%s/%s?login=%s&token=%s", $user, $repo, $gh_id, $gh_token));
128 }
129  
130 0 ▶sub pullreq_get {
Subroutine pullreq_get: not called CC=3 SCAR=24.8
Pod undocumented
131 0 my ( $class, $user, $repo, $number) = @_;
132 0 my $gh_id = App::gh->config->github_id;
133 0 my $gh_token = App::gh->config->github_token;
134 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
135 0 die "Github authtoken not found. Can not get pull request.\n";
136 }
137 0 return $class->request(GET => sprintf("pulls/%s/%s/%s?login=%s&token=%s", $user, $repo, scalar $number, $gh_id, $gh_token));
138 }
139  
140 0 ▶sub issue_edit {
Subroutine issue_edit: not called CC=4 SCAR=30.0
Pod undocumented
141 0 my ( $class, $user, $repo, $number, $title, $body) = @_;
142 0 my $gh_id = App::gh->config->github_id;
143 0 my $gh_token = App::gh->config->github_token;
144 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
145 0 die "Github authtoken not found. Can not edit issue.\n";
146 }
147 0 ▶ if ($number) {
Branch: 1 branch
BranchTrueFalseTotal
if ($number) { } 0 0 0
148 0 return $class->request(POST => sprintf("issues/edit/%s/%s/%s?login=%s&token=%s", $user, $repo, $gh_id, $gh_token, $number), "$title\n$body");
149 } else {
150 0 return $class->request(POST => sprintf("issues/open/%s/%s?login=%s&token=%s", $user, $repo, $gh_id, $gh_token), "$title\n$body");
151 }
152 }
153  
154 0 ▶sub issue_list {
Subroutine issue_list: not called CC=3 SCAR=24.8
Pod undocumented
155 0 my ( $class, $user, $repo) = @_;
156 0 my $gh_id = App::gh->config->github_id;
157 0 my $gh_token = App::gh->config->github_token;
158 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
159 0 die "Github authtoken not found. Can not get issues.\n";
160 }
161 0 return $class->request(GET => sprintf("issues/list/%s/%s/open?login=%s&token=%s", $user, $repo, $gh_id, $gh_token));
162 }
163  
164 0 ▶sub issue_get {
Subroutine issue_get: not called CC=3 SCAR=24.8
Pod undocumented
165 0 my ( $class, $user, $repo, $number) = @_;
166 0 my $gh_id = App::gh->config->github_id;
167 0 my $gh_token = App::gh->config->github_token;
168 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
169 0 die "Github authtoken not found. Can not get issues.\n";
170 }
171 0 return $class->request(GET => sprintf("issues/show/%s/%s/%s?login=%s&token=%s", $user, $repo, scalar $number, $gh_id, $gh_token));
172 }
173  
174 0 ▶sub issue_get_comments {
Subroutine issue_get_comments: not called CC=3 SCAR=24.8
Pod undocumented
175 0 my ( $class, $user, $repo, $number) = @_;
176 0 my $gh_id = App::gh->config->github_id;
177 0 my $gh_token = App::gh->config->github_token;
178 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
179 0 die "Github authtoken not found. Can not get issue comments.\n";
180 }
181 0 return $class->request(GET => sprintf("issues/comments/%s/%s/%s?login=%s&token=%s", $user, $repo, scalar $number, $gh_id, $gh_token));
182 }
183  
184 0 ▶sub issue_comment {
Subroutine issue_comment: not called CC=3 SCAR=24.8
Pod undocumented
185 0 my ( $class, $user, $repo, $number, $body) = @_;
186 0 my $gh_id = App::gh->config->github_id;
187 0 my $gh_token = App::gh->config->github_token;
188 0 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
189 0 die "Github authtoken not found. Can not comment to issue.\n";
190 }
191 0 return $class->request(POST => sprintf("issues/comment/%s/%s/%s?login=%s&token=%s", $user, $repo, $number, $gh_id, $gh_token),
192 comment => $body,
193 );
194 }
195  
196 2 1;
197 __END__
« lib/App/gh/Command/Push.pm ↑ Summary blib/lib/App/gh/Command/Issue/List.pm »