blib/lib/App/GitHub/update.pm

filter: Statementstmt 24.0% 19 / 79 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 63.6% 7 / 11 Podpod 0.0% 0 / 4 totaltotal 18.5% 26 / 140 CC 20 SCAR 37.8
CC
20
Cov
16%
update
90.0
run
56.0
usage
20.0
CRAP 44.0
↑ Summary
1 package App::GitHub::update;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $App::GitHub::update::VERSION = '0.0011';
4 }
5 # ABSTRACT: Update a github repository (description, homepage, etc.) from the commandline
6  
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Config::Identity::GitHub;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Getopt::Long qw/ GetOptions /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 my $agent = LWP::UserAgent->new;
15  
16 0 ▶sub update {
Subroutine update: not called CC=9 SCAR=45.0
Pod undocumented
17 0 my $self = shift;
18 0 my %given = @_;
19 0 my ( $login, $token, $repository, $description, $homepage );
20  
21 0 ( $repository, $description, $homepage ) = @given{qw/ repository description homepage /};
22 0 ▶ defined $_ && length $_ or die "Missing repository\n" for $repository;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and length $_ or die "Missing repository\n" 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
23  
24 0 ( $login, $token ) = @given{qw/ login token /};
25 0 ▶ unless( defined $token && length $token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token and length $token) 0 0 0
Condition0%0/3
defined $token and length $token
!ll&&!rl&&r
000
MC/DC0%0/2
defined $token and length $token
defined $token length $token
Truth table0%0/3
A and B
A= defined $tokenB= length $token
ABresult
0X0
100
111
26 0 my %identity = Config::Identity::GitHub->load;
27 0 ( $login, $token ) = @identity{qw/ login token /};
28 }
29  
30 0 my @arguments;
31 0 ▶ push @arguments, 'values[description]' => $description if defined $description;
Branch: 1 branch
BranchTrueFalseTotal
if defined $description 0 0 0
32 0 ▶ push @arguments, 'values[homepage]' => $homepage if defined $homepage;
Branch: 1 branch
BranchTrueFalseTotal
if defined $homepage 0 0 0
33  
34 0 my $uri = "https://github.com/api/v2/json/repos/show/$login/$repository";
35 0 my $response = $agent->post( $uri,
36 [ login => $login, token => $token, @arguments ] );
37  
38 0 ▶ unless ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
39 0 die $response->status_line, "\n", $response->decoded_content, "\n";
40 }
41  
42 0 return $response;
43 }
44  
45 0 ▶sub usage (;$) {
Subroutine usage: not called CC=4 SCAR=30.0
Pod undocumented
46 0 my $error = shift;
47 0 my $exit = 0;
48 0 ▶ if ( defined $error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 0 0
49 0 ▶ if ( $error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
50 0 ▶ if ( $error =~ m/^\-?\d+$/ ) { $exit = $error }
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^\-?\d+$/) { } 0 0 0
51 else {
52 0 chomp $error;
53 0 warn $error, "\n";
54 0 $exit = -1;
55 }
56 }
57 }
58 0 warn <<_END_;
59  
60 Usage: github-update [opt]
61  
62 --login ... Your github login
63 --token ... The github token associated with the given login
64  
65 Although required, if a login/token are not given,
66 github-create will attempt to load it from
67 \$HOME/.github or \$HOME/.github-identity (see
68 Config::Identity for more information)
69  
70 --repository ... The repository to update
71  
72 --description ... The new description of the repository
73 --homepage ... A homepage for the repository
74  
75 --help, -h, -? This help
76  
77  
78 _END_
79  
80 # --dzpl Guess repository and description from Dist::Dzpl
81 # configuration (name and abstract, respectively)
82  
83 0 exit $exit;
84 }
85  
86 0 ▶sub guess_dzpl {
Subroutine guess_dzpl: not called CC=3 SCAR=23.5
Pod undocumented
87 0 my $self = shift;
88 0 my %guess;
89  
90 0 eval {
91 # Oh god this is hacky
92 package App::GitHub::update::Sandbox;
93 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
94 1 $App::GitHub::update::Sandbox::VERSION = '0.0011';
95 }
96 0 local @ARGV;
97 0 do './dzpl';
98 0 my $dzpl = $Dzpl::dzpl;
99 0 $dzpl = $Dzpl::dzpl;
100 0 $dzpl->zilla->_setup_default_plugins;
101 0 $_->gather_files for ( @{ $dzpl->zilla->plugins_with(-FileGatherer) } );
102 0 $guess{repository} = $dzpl->zilla->name;
103 0 $guess{description} = $dzpl->zilla->abstract;
104 };
105 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
106  
107 0 return %guess;
108 }
109  
110 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod undocumented
111 0 my $self = shift;
112 0 my @arguments = @_;
113  
114 0 ▶ usage 0 unless @arguments;
Branch: 1 branch
BranchTrueFalseTotal
unless @arguments 0 0 0
115  
116 0 my ( $login, $token, $repository, $dzpl, $help );
117 0 my ( $homepage, $description );
118 {
119 0 local @ARGV = @arguments;
120 0 GetOptions(
121 'help|h|?' => \$help,
122  
123 'login=s' => \$login,
124 'token=s' => \$token,
125 'repository=s' => \$repository,
126  
127 'dzpl' => \$dzpl,
128  
129 'description=s' => \$description,
130 'homepage=s' => \$homepage,
131 );
132 }
133  
134 0 ▶ usage 0 if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 0 0
135  
136 0 ▶ if ( $dzpl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dzpl) 0 0 0
137 0 my %guess = $self->guess_dzpl;
138 0 ▶ $repository ||= $guess{repository};
Condition0%0/3
$repository ||= $guess{"repository"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$repository ||= $guess{"repository"}
$repository $guess{"repository"}
Truth table0%0/3
A ||= B
A= $repositoryB= $guess{"repository"}
ABresult
1X1
011
000
139 0 ▶ $description ||= $guess{description};
Condition0%0/3
$description ||= $guess{"description"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$description ||= $guess{"description"}
$description $guess{"description"}
Truth table0%0/3
A ||= B
A= $descriptionB= $guess{"description"}
ABresult
1X1
011
000
140 }
141
142 0 eval {
143 0 my $response = $self->update(
144 login => $login, token => $token, repository => $repository,
145 description => $description, homepage => $homepage,
146 );
147  
148 0 print $response->as_string, "\n";
149 };
150 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
151 0 usage <<_END_;
152 github-update: $@
153 _END_
154 }
155 }
156  
157 1 1;
158  
159 __END__
↑ Summary