Plugin/GitHub/Update.pm

filter: Statementstmt 77.0% 57 / 74 Branchbran 31.8% 7 / 22 Conditioncond 25.0% 5 / 20 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 58.6% 78 / 133 CC 20 SCAR 40.3
CC
20
Cov
59%
after_release
87.0
__ANON__
3.3
BEGIN
1.0
CRAP 56.5
« Plugin/GitHub/Create.pm ↑ Summary Plugin/GitHub.pm »
1 package Dist::Zilla::Plugin::GitHub::Update;
2 # ABSTRACT: Update a GitHub repo's info on release
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.49';
7  
8 1 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 extends 'Dist::Zilla::Plugin::GitHub';
13  
14 1 with 'Dist::Zilla::Role::AfterRelease';
15  
16 # deprecated and no longer documented. Use 'metacpan' instead!
17 1 has cpan => (
18 is => 'ro',
19 isa => 'Bool',
20 default => 0
21 );
22  
23 1 has p3rl => (
24 is => 'ro',
25 isa => 'Bool',
26 default => 0
27 );
28  
29 1 has metacpan => (
30 is => 'ro',
31 isa => 'Bool',
32 default => 1
33 );
34  
35 1 has meta_home => (
36 is => 'ro',
37 isa => 'Bool',
38 default => 0
39 );
40  
41 #pod =head1 SYNOPSIS
42 #pod
43 #pod Configure git with your GitHub credentials:
44 #pod
45 #pod $ git config --global github.user LoginName
46 #pod $ git config --global github.password GitHubPassword
47 #pod
48 #pod Alternatively you can install L<Config::Identity> and write your credentials
49 #pod in the (optionally GPG-encrypted) C<~/.github> file as follows:
50 #pod
51 #pod login LoginName
52 #pod password GitHubpassword
53 #pod
54 #pod (if only the login name is set, the password will be asked interactively).
55 #pod
56 #pod You can also generate an access token for "full control over repositories" by following
57 #pod L<these instructions|https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/>,
58 #pod
59 #pod then, in your F<dist.ini>:
60 #pod
61 #pod # default config
62 #pod [GitHub::Meta]
63 #pod
64 #pod # to override the repo name
65 #pod [GitHub::Meta]
66 #pod repo = SomeRepo
67 #pod
68 #pod See L</ATTRIBUTES> for more options.
69 #pod
70 #pod =head1 DESCRIPTION
71 #pod
72 #pod This Dist::Zilla plugin updates the information of the GitHub repository
73 #pod when C<dzil release> is run.
74 #pod
75 #pod =cut
76  
77 around dump_config => sub
78 1 ▶{
Subroutine __ANON__: called CC=3 SCAR=11.8
79 1 my ($orig, $self) = @_;
80 1 my $config = $self->$orig;
81  
82 1 ▶ my $option = first { $self->$_ } qw(meta_home metacpan p3rl cpan);
Subroutine __ANON__: called CC=1 SCAR=0.0
83 1 ▶ if ($option eq 'cpan') {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq "cpan") 0 1 1
84 0 $self->log->warn('the \'cpan\' option has been removed: please use \'metacpan\' instead');
85 0 $option = 'metacpan';
86 }
87  
88 1 ▶ $config->{+__PACKAGE__} = {
Branch: 1 branch
BranchTrueFalseTotal
$self->$option ? : 1 0 1
89 $option => ($self->$option ? 1 : 0),
90 };
91  
92 1 return $config;
93 1 };
94  
95 1 ▶sub after_release {
Subroutine after_release: called CC=18 SCAR=44.7
Pod undocumented
96 1 my $self = shift;
97 1 my ($opts) = @_;
98 1 my $dist_name = $self->zilla->name;
99  
100 1 ▶ return if (!$self->_has_credentials);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_credentials 0 1 1
101  
102 1 my $repo_name = $self->_get_repo_name($self->_credentials->{login});
103 1 ▶ if (not $repo_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($repo_name) 0 1 1
104 0 $self->log('cannot update GitHub repository info');
105 0 return;
106 }
107  
108 1 my $params = {
109 name => ($repo_name =~ /\/(.*)$/)[0],
110 description => $self->zilla->abstract,
111 };
112  
113 1 my $with;
114 1 ▶ if ($self->meta_home && (my $meta_home = $self->zilla->distmeta->{resources}{homepage})) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->meta_home and my $meta_home = $self->zilla->distmeta->{'resources'}{'homepage'}) { } 1 0 1
elsif ($self->metacpan) { } 0 0 0
elsif ($self->p3rl) { } 0 0 0
Condition33%1/3
$self->meta_home and my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
!ll&&!rl&&r
001
MC/DC0%0/2
$self->meta_home and my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
$self->meta_home my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
Truth table33%1/3
A and B
A= $self->meta_homeB= my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
ABresult
0X0
100
111
115 1 $with = ' using distmeta URL';
116 1 $params->{homepage} = $meta_home;
117 } elsif ($self->metacpan) {
118 0 $with = ' using MetaCPAN URL';
119 0 $params->{homepage} = "https://metacpan.org/release/$dist_name/";
120 } elsif ($self->p3rl) {
121 0 $with = ' using P3rl URL';
122 0 my $guess_name = $dist_name;
123 0 $guess_name =~ s/\-/\:\:/g;
124 0 $params->{homepage} = "https://p3rl.org/$guess_name";
125 }
126  
127 1 ▶ $self->log('Updating GitHub repository info'.($with // ''));
Condition50%1/2
$with // ""
l!l
10
MC/DC0%0/1
$with // ""
$with
Truth table50%1/2
A
A= $with
Aresult
11
00
128  
129 1 my $url = $self->api."/repos/$repo_name";
130  
131 1 my $current = $self->_current_params($url);
132 1 ▶ if ($current &&
Branch: 1 branch
BranchTrueFalseTotal
if ($current and ($current->{"name"} || "") eq $params->{"name"} and ($current->{"description"} || "") eq $params->{"description"} and ($current->{"homepage"} || "") eq $params->{"homepage"}) 0 1 1
Condition20%3/15
$current and ($current->{"name"} || "") eq $params->{"name"} and ($current->{"description"} || "") eq $params->{"description"} and ($current->{"homepage"} || "") eq $params->{"homepage"}
!ll&&!rl&&r
100
$current and ($current->{"name"} || "") eq $params->{"name"} and ($current->{"description"} || "") eq $params->{"description"}
!ll&&!rl&&r
100
$current and ($current->{"name"} || "") eq $params->{"name"}
!ll&&!rl&&r
100
$current->{'name'} || ''
l!l
00
$current->{'description'} || ''
l!l
00
$current->{'homepage'} || ''
l!l
00
MC/DC0%0/4
$current and ($current->{"name"} || "") eq $params->{"name"} and ($current->{"description"} || "") eq $params->{"description"} and ($current->{"homepage"} || "") eq $params->{"homepage"}
$current $current->{'name'} $current->{'description'} $current->{'homepage'}
Truth table20%1/5
A and B and C and D
A= $currentB= $current->{'name'}C= $current->{'description'}D= $current->{'homepage'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
133 ($current->{name} || '') eq $params->{name} &&
134 ($current->{description} || '') eq $params->{description} &&
135 ($current->{homepage} || '') eq $params->{homepage}) {
136  
137 0 $self->log("GitHub repo info is up to date");
138 0 return;
139 }
140  
141 1 $self->log_debug("Sending PATCH $url");
142 1 my $response = HTTP::Tiny->new->request('PATCH', $url, {
143 content => encode_json($params),
144 headers => $self->_auth_headers,
145 });
146  
147 1 my $repo = $self->_check_response($response);
148  
149 1 ▶ return if not $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless $repo 1 0 1
150  
151 0 ▶ if ($repo eq 'redo') {
Branch: 1 branch
BranchTrueFalseTotal
if ($repo eq "redo") 0 0 0
152 0 $self->log("Retrying with two-factor authentication");
153 0 $self->prompt_2fa(1);
154 0 $repo = $self->after_release($opts);
155 0 ▶ return if not $repo;
Branch: 1 branch
BranchTrueFalseTotal
if not $repo 0 0 0
156 }
157 }
158  
159 1 ▶sub _current_params {
Subroutine _current_params: called CC=1 SCAR=0.0
160 1 my $self = shift;
161 1 my ($url) = @_;
162  
163 1 my $http = HTTP::Tiny->new;
164  
165 1 $self->log_debug("Sending GET $url");
166 1 my $response = $http->request('GET', $url);
167  
168 1 return $self->_check_response($response);
169 }
170  
171 1 __PACKAGE__->meta->make_immutable;
172 1 1; # End of Dist::Zilla::Plugin::GitHub::Update
173  
174 __END__
« Plugin/GitHub/Create.pm ↑ Summary Plugin/GitHub.pm »