Skip to content

Commit

Permalink
Split edit_project -> edit_project_multipart
Browse files Browse the repository at this point in the history
$ perl generate.pl > ../lib/GitLab/API/v4.pm

To me, this doesn't align with the function naming convention,
but I couldn't see an elegant way of handling it with generate.pl
  • Loading branch information
g0tmi1k committed Mar 7, 2023
1 parent 36afb88 commit 7fdae18
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
6 changes: 6 additions & 0 deletions author/generate.pl
Expand Up @@ -121,6 +121,12 @@
print " \$options->{$params_key} = \$params if defined \$params;\n";
}

my @code;
@code = split /\n/, $endpoint->{code} if $endpoint->{code};
foreach my $line (@code) {
print " $line\n";
}

print ' ';
print 'return ' if $return;
print "\$self->_call_rest_client( '$verb', '$path', [\@_], \$options );\n";
Expand Down
4 changes: 4 additions & 0 deletions author/sections/projects.yml
Expand Up @@ -6,6 +6,10 @@
- create_project: project = POST projects?
- create_project_for_user: POST projects/user/:user_id?
- edit_project: PUT projects/:project_id?
- method: edit_project_multipart
spec: PUT projects/:project_id?
note: The request will have "multipart/form-data" header set for uploading files.
code: $options->{content}->{file} = $params;
- fork_project: POST projects/:project_id/fork?
- project_forks: forks = GET projects/:project_id/forks?
- start_project: project = POST projects/:project_id/star
Expand Down
37 changes: 27 additions & 10 deletions lib/GitLab/API/v4.pm
Expand Up @@ -7321,7 +7321,6 @@ sub create_project_for_user {
$api->edit_project(
$project_id,
\%params,
\%params_multipart,
);
Sends a C<PUT> request to C<projects/:project_id>.
Expand All @@ -7330,21 +7329,39 @@ Sends a C<PUT> request to C<projects/:project_id>.

sub edit_project {
my $self = shift;
croak 'edit_project must be called with 1 to 3 arguments' if @_ < 1 or @_ > 3;
croak 'edit_project must be called with 1 to 2 arguments' if @_ < 1 or @_ > 2;
croak 'The #1 argument ($project_id) to edit_project must be a scalar' if ref($_[0]) or (!defined $_[0]);
croak 'The #2 argument (\%params) to edit_project must be a hash ref' if defined($_[1]) and ref($_[1]) ne 'HASH';
croak 'The last argument (\%params_multipart) to edit_project must be a hash ref' if defined($_[2]) and ref($_[2]) ne 'HASH';
my $params_multipart = (@_ == 3) ? pop() : undef;
croak 'The last argument (\%params) to edit_project must be a hash ref' if defined($_[1]) and ref($_[1]) ne 'HASH';
my $params = (@_ == 2) ? pop() : undef;
my $options = {};
$options->{decode} = 0;
$options->{content} = $params if defined $params;
$self->_call_rest_client( 'PUT', 'projects/:project_id', [$_[0]], $options );
$self->_call_rest_client( 'PUT', 'projects/:project_id', [@_], $options );
return;
}

if (keys %$params_multipart) {
$options->{content}->{file} = $params_multipart ;
$self->_call_rest_client( 'PUT', 'projects/:project_id', [$_[0]], $options );
}
=item edit_project_multipart
$api->edit_project_multipart(
$project_id,
\%params,
);
Sends a C<PUT> request to C<projects/:project_id>.
The request will have "multipart/form-data" header set for uploading files.
=cut

sub edit_project_multipart {
my $self = shift;
croak 'edit_project_multipart must be called with 1 to 2 arguments' if @_ < 1 or @_ > 2;
croak 'The #1 argument ($project_id) to edit_project_multipart must be a scalar' if ref($_[0]) or (!defined $_[0]);
croak 'The last argument (\%params) to edit_project_multipart must be a hash ref' if defined($_[1]) and ref($_[1]) ne 'HASH';
my $params = (@_ == 2) ? pop() : undef;
my $options = {};
$options->{decode} = 0;
$options->{content}->{file} = $params if defined $params;
$self->_call_rest_client( 'PUT', 'projects/:project_id', [@_], $options );
return;
}

Expand Down

0 comments on commit 7fdae18

Please sign in to comment.