App/github/cmd.pm

filter: Statementstmt 35.2% 30 / 85 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 33.3% 4 / 12 Podpod 100% 7 / 7 totaltotal 28.4% 41 / 144 CC 13 SCAR 24.4
CC
13
Cov
26%
repo_exists
30.0
_init
12.0
create_repo
12.0
CRAP 11.5
« Perinci/CmdLine/github/cmd.pm ↑ Summary
1 package App::github::cmd;
2  
3 1 our $DATE = '2020-04-08'; # DATE
4 1 our $VERSION = '0.008'; # VERSION
5  
6 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our %SPEC;
12  
13 1 $SPEC{':package'} = {
14 summary => 'Yet another github CLI',
15 v => 1.1,
16 };
17  
18 1 our %args_common = (
19 login => {
20 schema => 'str*',
21 tags => ['common'],
22 },
23 pass => {
24 schema => 'str*',
25 tags => ['common'],
26 },
27 access_token => {
28 schema => 'str*',
29 tags => ['common'],
30 },
31 );
32 1 our %argsrels_common = (
33 choose_all => [qw/login pass/],
34 req_one => [qw/login access_token/],
35 );
36 1 our %arg0_user = (
37 user => {
38 schema => 'str*',
39 req => 1,
40 pos => 0,
41 },
42 );
43 1 our %argopt0_user = (
44 user => {
45 schema => 'str*',
46 pos => 0,
47 },
48 );
49 1 our %argopt_user = (
50 user => {
51 schema => 'str*',
52 },
53 );
54 1 our %arg0_repo = (
55 repo => {
56 schema => 'str*',
57 req => 1,
58 pos => 0,
59 },
60 );
61 1 our %argopt_detail = (
62 detail => {
63 schema => 'bool*',
64 cmdline_aliases => {l=>{}},
65 },
66 );
67  
68 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
69 0 my $args = shift;
70 0 state $state = {};
71  
72 0 ▶ unless ($state->{_github}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->{"_github"}) 0 0 0
73 0 require Net::GitHub;
74 0 my %ngargs;
75 0 ▶ if ($args->{access_token}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'access_token'}) { } 0 0 0
76 0 $ngargs{access_token} = $args->{access_token};
77 } else {
78 0 $ngargs{login} = $args->{login};
79 0 $ngargs{pass} = $args->{pass};
80 }
81 0 $state->{github} = Net::GitHub->new(%ngargs);
82 }
83 0 $state;
84 }
85  
86 $SPEC{get_user} = {
87 1 v => 1.1,
88 summary => 'Get information about a user',
89 args => {
90 %args_common,
91 %argopt0_user,
92 },
93 args_rels => {
94 %argsrels_common,
95 },
96 };
97 0 ▶sub get_user {
Subroutine get_user: not called CC=1 SCAR=6.9
Pod documented
98 0 my %args = @_;
99 0 my $state = _init(\%args);
100 0 my $github = $state->{github};
101  
102 0 my $user = $github->user->show($args{user});
103 0 [200, "OK", $user];
104 }
105  
106 $SPEC{get_repo} = {
107 1 v => 1.1,
108 summary => 'Get information about a repository',
109 args => {
110 %args_common,
111 %argopt_user,
112 %arg0_repo,
113 },
114 args_rels => {
115 %argsrels_common,
116 },
117 };
118 0 ▶sub get_repo {
Subroutine get_repo: not called CC=2 SCAR=17.9
Pod documented
119 0 my %args = @_;
120 0 my $state = _init(\%args);
121 0 my $github = $state->{github};
122  
123 0 ▶ my $repo = $github->repos->get($args{user} // $args{login}, $args{repo});
Condition0%0/3
$args{"user"} // $args{"login"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"user"} // $args{"login"}
$args{"user"} $args{"login"}
Truth table0%0/3
A // B
A= $args{"user"}B= $args{"login"}
ABresult
1X1
011
000
124 0 [200, "OK", $repo];
125 }
126  
127 $SPEC{repo_exists} = {
128 1 v => 1.1,
129 summary => 'Check whether a repository exists',
130 args => {
131 %args_common,
132 %argopt_user,
133 %arg0_repo,
134 },
135 args_rels => {
136 %argsrels_common,
137 },
138 };
139 0 ▶sub repo_exists {
Subroutine repo_exists: not called CC=5 SCAR=34.0
Pod documented
140 0 my %args = @_;
141 0 my $state = _init(\%args);
142 0 my $github = $state->{github};
143  
144 0 my $repo;
145 0 eval {
146 0 ▶ $repo = $github->repos->get($args{user} // $args{login}, $args{repo});
Condition0%0/3
$args{"user"} // $args{"login"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"user"} // $args{"login"}
$args{"user"} $args{"login"}
Truth table0%0/3
A // B
A= $args{"user"}B= $args{"login"}
ABresult
1X1
011
000
147 };
148 0 my $err = $@;
149 0 ▶ my $exists = $err && $err =~ /Not Found/ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$err && $err =~ /Not Found/ ? : 0 0 0
Condition0%0/3
$err and $err =~ /Not Found/
!ll&&!rl&&r
000
MC/DC0%0/2
$err and $err =~ /Not Found/
$err $err =~ /Not Found/
Truth table0%0/3
A and B
A= $errB= $err =~ /Not Found/
ABresult
0X0
100
111
150 0 ▶ [200, "OK", $exists, {'cmdline.exit_code' => $exists ? 0:1}];
Branch: 1 branch
BranchTrueFalseTotal
$exists ? : 0 0 0
151 }
152  
153 $SPEC{list_repos} = {
154 1 v => 1.1,
155 summary => "List user's repositories",
156 args => {
157 %args_common,
158 %argopt_detail,
159 start => {
160 schema => 'nonnegint*',
161 default => 0,
162 },
163 },
164 args_rels => {
165 %argsrels_common,
166 },
167 };
168 0 ▶sub list_repos {
Subroutine list_repos: not called CC=2 SCAR=17.9
Pod documented
169 0 my %args = @_;
170 0 my $state = _init(\%args);
171 0 my $github = $state->{github};
172  
173 0 my @repos = $github->repos->list($args{start});
174 0 ▶ unless ($args{detail}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"detail"}) 0 0 0
175 0 @repos = map { $_->{name} } @repos;
176 }
177 0 [200, "OK", \@repos];
178 }
179  
180 $SPEC{create_repo} = {
181 1 v => 1.1,
182 summary => 'Create a repository',
183 args => {
184 %args_common,
185 %arg0_repo,
186 description => {
187 schema => 'str*',
188 },
189 homepage => {
190 schema => 'url*',
191 },
192 },
193 args_rels => {
194 %argsrels_common,
195 },
196 };
197 0 ▶sub create_repo {
Subroutine create_repo: not called CC=3 SCAR=24.8
Pod documented
198 0 my %args = @_;
199 0 my $state = _init(\%args);
200 0 my $github = $state->{github};
201  
202 my $repo = $github->repos->create({
203 name => $args{repo},
204 description => $args{description} // '(No description)',
205 0 ▶ homepage => $args{homepage} ? "$args{homepage}" : 'https://github.com',
Branch: 1 branch
BranchTrueFalseTotal
$args{'homepage'} ? : 0 0 0
Condition0%0/2
$args{"description"} // "(No description)"
l!l
00
MC/DC0%0/1
$args{"description"} // "(No description)"
$args{"description"}
Truth table0%0/2
A
A= $args{"description"}
Aresult
11
00
206 });
207 0 [200, "OK", $repo];
208 }
209  
210 $SPEC{delete_repo} = {
211 1 v => 1.1,
212 args => {
213 %args_common,
214 %argopt_user,
215 %arg0_repo,
216 },
217 args_rels => {
218 %argsrels_common,
219 },
220 };
221 0 ▶sub delete_repo {
Subroutine delete_repo: not called CC=2 SCAR=17.9
Pod documented
222 0 my %args = @_;
223 0 my $state = _init(\%args);
224 0 my $github = $state->{github};
225  
226 0 ▶ $github->repos->delete($args{user} // $args{login}, $args{repo});
Condition0%0/3
$args{"user"} // $args{"login"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"user"} // $args{"login"}
$args{"user"} $args{"login"}
Truth table0%0/3
A // B
A= $args{"user"}B= $args{"login"}
ABresult
1X1
011
000
227 0 [200, "OK"];
228 }
229  
230 $SPEC{rename_repo} = {
231 1 v => 1.1,
232 summary => 'Rename a repository',
233 args => {
234 %args_common,
235 %argopt_user,
236 %arg0_repo,
237 new_name => {
238 schema => 'str*',
239 req => 1,
240 pos => 1,
241 },
242 },
243 args_rels => {
244 %argsrels_common,
245 },
246 };
247 0 ▶sub rename_repo {
Subroutine rename_repo: not called CC=2 SCAR=17.9
Pod documented
248 0 my %args = @_;
249 0 my $state = _init(\%args);
250 0 my $github = $state->{github};
251  
252 0 my $rp;
253  
254 0 ▶ $rp = $github->repos->set_default_user_repo($args{user} // $args{login}, $args{repo});
Condition0%0/3
$args{"user"} // $args{"login"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"user"} // $args{"login"}
$args{"user"} $args{"login"}
Truth table0%0/3
A // B
A= $args{"user"}B= $args{"login"}
ABresult
1X1
011
000
255 0 $rp = $github->repos->update({ name => $args{new_name} });
256 0 [200, "OK", $rp];
257 }
258  
259 1 1;
260 # ABSTRACT: Yet another github CLI
261  
262 __END__
« Perinci/CmdLine/github/cmd.pm ↑ Summary