Gitea/API/Repos.pm

filter: Statementstmt 27.4% 17 / 62 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 35.7% 5 / 14 Podpod 100% 7 / 7 totaltotal 26.6% 29 / 109 CC 14 SCAR 21.7
CC
14
Cov
19%
get
12.0
create
12.0
edit
12.0
CRAP 8.8
« Gitea/API/Milestones.pm ↑ Summary Gitea/Role/OpenAPI.pm »
1 package WWW::Gitea::API::Repos;
2  
3 # ABSTRACT: Gitea repositories API
4  
5 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use WWW::Gitea::Repo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 3 has client => (
12 is => 'ro',
13 required => 1,
14 weak_ref => 1,
15 );
16  
17  
18 has openapi_operations => (
19 is => 'lazy',
20 builder => sub {
21 return {
22 0 ▶ 'repos.get' => { method => 'GET', path => '/repos/{owner}/{repo}' },
Subroutine _build_openapi_operations: not called CC=1 SCAR=1.2
Subroutine __ANON__: called CC=1 SCAR=1.2
23 'repos.edit' => { method => 'PATCH', path => '/repos/{owner}/{repo}' },
24 'repos.delete' => { method => 'DELETE', path => '/repos/{owner}/{repo}' },
25 'repos.search' => { method => 'GET', path => '/repos/search' },
26 'repos.fork' => { method => 'POST', path => '/repos/{owner}/{repo}/forks' },
27 'repos.create_current' => { method => 'POST', path => '/user/repos' },
28 'repos.create_org' => { method => 'POST', path => '/orgs/{org}/repos' },
29 'repos.list_current' => { method => 'GET', path => '/user/repos' },
30 'repos.list_user' => { method => 'GET', path => '/users/{username}/repos' },
31 };
32 },
33 3 );
34  
35  
36 3 with 'WWW::Gitea::Role::OpenAPI';
37  
38 sub _wrap {
39 0 ▶ my ($self, $data) = @_;
Subroutine _wrap: not called CC=1 SCAR=6.9
40 0 return WWW::Gitea::Repo->new(client => $self->client, data => $data);
41 }
42  
43 sub get {
44 0 ▶ my ($self, $owner, $repo) = @_;
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
45 0 ▶ croak 'owner required' unless defined $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $owner 0 0 0
46 0 ▶ croak 'repo required' unless defined $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo 0 0 0
47 0 my $data = $self->call_operation('repos.get',
48 path => { owner => $owner, repo => $repo });
49 0 return $self->_wrap($data);
50 }
51  
52  
53 sub create {
54 0 ▶ my ($self, %args) = @_;
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
55 0 ▶ croak 'name required' unless defined $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"name"} 0 0 0
56 0 my $org = delete $args{org};
57 0 my $body = { %args };
58 0 my $data;
59 0 ▶ if (defined $org) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $org) { } 0 0 0
60 0 $data = $self->call_operation('repos.create_org',
61 path => { org => $org }, body => $body);
62 }
63 else {
64 0 $data = $self->call_operation('repos.create_current', body => $body);
65 }
66 0 return $self->_wrap($data);
67 }
68  
69  
70 sub edit {
71 0 ▶ my ($self, $owner, $repo, %args) = @_;
Subroutine edit: not called CC=3 SCAR=24.8
Pod documented
72 0 ▶ croak 'owner required' unless defined $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $owner 0 0 0
73 0 ▶ croak 'repo required' unless defined $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo 0 0 0
74 0 my $data = $self->call_operation('repos.edit',
75 path => { owner => $owner, repo => $repo }, body => \%args);
76 0 return $self->_wrap($data);
77 }
78  
79  
80 sub delete {
81 0 ▶ my ($self, $owner, $repo) = @_;
Subroutine delete: not called CC=3 SCAR=24.8
Pod documented
82 0 ▶ croak 'owner required' unless defined $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $owner 0 0 0
83 0 ▶ croak 'repo required' unless defined $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo 0 0 0
84 0 return $self->call_operation('repos.delete',
85 path => { owner => $owner, repo => $repo });
86 }
87  
88  
89 sub search {
90 0 ▶ my ($self, %query) = @_;
Subroutine search: not called CC=2 SCAR=17.9
Pod documented
91 0 my $data = $self->call_operation('repos.search', query => \%query);
92 0 ▶ return [ map { $self->_wrap($_) } @{ $data->{data} || [] } ];
Branch: 1 branch
BranchTrueFalseTotal
$data->{"data"} or [] 0 0 0
93 }
94  
95  
96 sub fork {
97 0 ▶ my ($self, $owner, $repo, %args) = @_;
Subroutine fork: not called CC=3 SCAR=24.8
Pod documented
98 0 ▶ croak 'owner required' unless defined $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $owner 0 0 0
99 0 ▶ croak 'repo required' unless defined $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo 0 0 0
100 0 my $data = $self->call_operation('repos.fork',
101 path => { owner => $owner, repo => $repo }, body => \%args);
102 0 return $self->_wrap($data);
103 }
104  
105  
106 sub list {
107 0 ▶ my ($self, %args) = @_;
Subroutine list: not called CC=3 SCAR=24.8
Pod documented
108 0 my $username = delete $args{username};
109 0 my $data;
110 0 ▶ if (defined $username) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $username) { } 0 0 0
111 0 $data = $self->call_operation('repos.list_user',
112 path => { username => $username }, query => \%args);
113 }
114 else {
115 0 $data = $self->call_operation('repos.list_current', query => \%args);
116 }
117 0 ▶ return [ map { $self->_wrap($_) } @{ $data || [] } ];
Branch: 1 branch
BranchTrueFalseTotal
$data or [] 0 0 0
118 }
119  
120  
121  
122 3 1;
123  
124 __END__
« Gitea/API/Milestones.pm ↑ Summary Gitea/Role/OpenAPI.pm »