| 1 | package Dist::Zilla::Plugin::GitLab::Update 1.0002; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use URL::Encode qw(url_encode_utf8); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | extends 'Dist::Zilla::Plugin::GitLab'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | with 'Dist::Zilla::Role::AfterRelease'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub after_release { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after_release: called CC=9 SCAR=26.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | return if ( !$self->_has_credentials ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $repo_name = $self->_get_repo_name( $self->_credentials->{login} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | if ( not $repo_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $self->log('cannot update GitLab repository info'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | my $params = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | name => ( $repo_name =~ /\/(.*)$/ )[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | description => $self->zilla->abstract, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | $self->log('Updating GitLab repository info'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my $url = $self->api . '/projects/' . url_encode_utf8($repo_name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $current = $self->_current_params($url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | if ( $current | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition30%3/10
$current and ($current->{"name"} || "") eq $params->{"name"} and ($current->{"description"} || "") eq $params->{"description"}
$current and ($current->{"name"} || "") eq $params->{"name"}
$current->{'name'} || ''
$current->{'description'} || ''
MC/DC0%0/3
$current and ($current->{"name"} || "") eq $params->{"name"} and ($current->{"description"} || "") eq $params->{"description"}
$current
$current->{'name'}
$current->{'description'}
Truth table25%1/4
A and B and C
A= $currentB= $current->{'name'}C= $current->{'description'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | && ( $current->{name} || q{} ) eq $params->{name} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | && ( $current->{description} || q{} ) eq $params->{description} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->log('GitLab repo info is up to date'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $headers = $self->_auth_headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | $headers->{'content-type'} = 'application/json'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | $self->log_debug("Sending PUT $url"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $response = HTTP::Tiny->new->request( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'PUT', $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | content => encode_json($params), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my $repo = $self->_check_response($response); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | return if not $repo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub _current_params { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_current_params: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | my ($url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my $http = HTTP::Tiny->new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $self->log_debug("Sending GET $url"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $response = $http->request( 'GET', $url ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | return $self->_check_response($response); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Dist::Zilla::Plugin::GitLab::Update - Update a GitLab repo's info on release | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | version 1.0002 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Configure git with your GitLab login name: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | $ git config --global gitlab.user LoginName | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | $ git config --global gitlab.token AccessToken | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | Set up an access token on GitLab, in your profile under "Personal Access Tokens." You | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | must grant the token the C<api> scope! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | then, in your F<dist.ini>: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # default config | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | [GitLab::Update] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # to override the repo name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | [GitLab::Update] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | repo = SomeRepo | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | See L</ATTRIBUTES> for more options. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | This Dist::Zilla plugin updates the information of the GitLab repository | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | when C<dzil release> is run. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =item C<remote> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | Specifies the git remote name to be used when guessing the repo name (default C<origin>). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | =item C<repo> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | The name of the GitLab repository. By default the name will be extracted from | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | the URL of the remote specified in the C<remote> option, and if that fails the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | dist name (from dist.ini) is used. It can also be in the form C<user/repo> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | when it belongs to another GitLab user/organization. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | D Ruth Holloway <ruth@hiruthie.me> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | This software is copyright (c) 2022 by D Ruth Holloway. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||