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