Skip to content

Commit e867fa6

Browse files
committed
Split edit_project -> edit_project_multipart
$ 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
1 parent 36afb88 commit e867fa6

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

author/generate.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
print " \$options->{$params_key} = \$params if defined \$params;\n";
122122
}
123123

124+
my @code;
125+
@code = split /\n/, $endpoint->{code} if $endpoint->{code};
126+
foreach my $line (@code) {
127+
print " $line\n";
128+
}
129+
124130
print ' ';
125131
print 'return ' if $return;
126132
print "\$self->_call_rest_client( '$verb', '$path', [\@_], \$options );\n";

author/sections/projects.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- create_project: project = POST projects?
77
- create_project_for_user: POST projects/user/:user_id?
88
- edit_project: PUT projects/:project_id?
9+
- method: edit_project_multipart
10+
spec: PUT projects/:project_id?
11+
note: The request will have "multipart/form-data" header set for uploading files.
12+
code: $options->{content}->{file} = $params;
913
- fork_project: POST projects/:project_id/fork?
1014
- project_forks: forks = GET projects/:project_id/forks?
1115
- start_project: project = POST projects/:project_id/star

lib/GitLab/API/v4.pm

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7321,7 +7321,6 @@ sub create_project_for_user {
73217321
$api->edit_project(
73227322
$project_id,
73237323
\%params,
7324-
\%params_multipart,
73257324
);
73267325
73277326
Sends a C<PUT> request to C<projects/:project_id>.
@@ -7330,21 +7329,40 @@ Sends a C<PUT> request to C<projects/:project_id>.
73307329

73317330
sub edit_project {
73327331
my $self = shift;
7333-
croak 'edit_project must be called with 1 to 3 arguments' if @_ < 1 or @_ > 3;
7332+
croak 'edit_project must be called with 1 to 2 arguments' if @_ < 1 or @_ > 2;
73347333
croak 'The #1 argument ($project_id) to edit_project must be a scalar' if ref($_[0]) or (!defined $_[0]);
7335-
croak 'The #2 argument (\%params) to edit_project must be a hash ref' if defined($_[1]) and ref($_[1]) ne 'HASH';
7336-
croak 'The last argument (\%params_multipart) to edit_project must be a hash ref' if defined($_[2]) and ref($_[2]) ne 'HASH';
7337-
my $params_multipart = (@_ == 3) ? pop() : undef;
7334+
croak 'The last argument (\%params) to edit_project must be a hash ref' if defined($_[1]) and ref($_[1]) ne 'HASH';
73387335
my $params = (@_ == 2) ? pop() : undef;
73397336
my $options = {};
73407337
$options->{decode} = 0;
73417338
$options->{content} = $params if defined $params;
7342-
$self->_call_rest_client( 'PUT', 'projects/:project_id', [$_[0]], $options );
7339+
$self->_call_rest_client( 'PUT', 'projects/:project_id', [@_], $options );
7340+
return;
7341+
}
73437342

7344-
if (keys %$params_multipart) {
7345-
$options->{content}->{file} = $params_multipart ;
7346-
$self->_call_rest_client( 'PUT', 'projects/:project_id', [$_[0]], $options );
7347-
}
7343+
=item edit_project_multipart
7344+
7345+
$api->edit_project_multipart(
7346+
$project_id,
7347+
\%params,
7348+
);
7349+
7350+
Sends a C<PUT> request to C<projects/:project_id>.
7351+
7352+
The request will have "multipart/form-data" header set for uploading files.
7353+
=cut
7354+
7355+
sub edit_project_multipart {
7356+
my $self = shift;
7357+
croak 'edit_project_multipart must be called with 1 to 2 arguments' if @_ < 1 or @_ > 2;
7358+
croak 'The #1 argument ($project_id) to edit_project_multipart must be a scalar' if ref($_[0]) or (!defined $_[0]);
7359+
croak 'The last argument (\%params) to edit_project_multipart must be a hash ref' if defined($_[1]) and ref($_[1]) ne 'HASH';
7360+
my $params = (@_ == 2) ? pop() : undef;
7361+
my $options = {};
7362+
$options->{decode} = 0;
7363+
$options->{content} = $params if defined $params;
7364+
$options->{content}->{file} = $params;
7365+
$self->_call_rest_client( 'PUT', 'projects/:project_id', [@_], $options );
73487366
return;
73497367
}
73507368

0 commit comments

Comments
 (0)