Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Roman Lacko
gitlab_api
Commits
46c0f8a4
Commit
46c0f8a4
authored
Jan 08, 2018
by
Roman Lacko
Browse files
add CustomAttributes API
parent
2dc2d186
Changes
1
Hide whitespace changes
Inline
Side-by-side
GitLab/CustomAttributes.pm
0 → 100644
View file @
46c0f8a4
package
GitLab::
CustomAttributes
;
use
utf8
;
use
strict
;
use
warnings
;
use
vars
qw($VERSION)
;
use
GitLab::
API
;
use
Log::
Any
qw($log)
;
our
$VERSION
=
v10
.3.3
;
my
$requests
=
{
# User attributes
"
<ENTITY>_custom_attributes
"
=>
{
method
=>
"
GET
",
path
=>
"
/<ENTITY>s/<id>/custom_attributes
",
},
"
<ENTITY>_get_custom_attribute
"
=>
{
method
=>
"
GET
",
path
=>
"
/<ENTITY>s/<id>/custom_attributes/<key>
",
},
"
<ENTITY>_set_custom_attribute
"
=>
{
method
=>
"
PUT
",
path
=>
"
/<ENTITY>s/<id>/custom_attributes/<key>
",
required
=>
[
qw(
value
)
],
},
"
<ENTITY>_delete_custom_attribute
"
=>
{
method
=>
"
DELETE
",
path
=>
"
/<ENTITY>s/<id>/custom_attributes/<key>
",
},
};
sub
import
{
$log
->
debug
("
initializing
"
.
__PACKAGE__
);
my
$emap
=
{
user
=>
"
uid
",
group
=>
"
gid
",
project
=>
"
id
",
};
while
(
my
(
$name
,
$tmpl
)
=
each
(
%$requests
))
{
foreach
my
$entity
(
keys
%$emap
)
{
my
$copy
=
{
%$tmpl
};
$copy
->
{
name
}
=
$name
unless
exists
$copy
->
{
name
};
foreach
my
$v
(
values
%$copy
)
{
$v
=~
s/<ENTITY>/$entity/g
;
$v
=~
s/<id>/<$emap->{$entity}>/g
;
}
GitLab::
API
->
register
(
$copy
);
}
}
}
1
;
__END__
=head1 NAME
GitLab::CustomAttributes - implements custom attributes API
See L<GitLab API -- Custom Attributes|https://docs.gitlab.com/ce/api/custom_attributes.html>
for details and response formats.
=head1 VERSION
Implements API calls for GitLab CE C<v10.3.3>.
=head1 DESCRIPTION
B<All of these methods require administrator permissions.>
The methods behave same for users, groups and projects.
=over
=item L<List custom attributes|https://docs.gitlab.com/ce/api/custom_attributes.html#list-custom-attributes>
$attributes = $gitlab->user_custom_attributes( :uid );
$attributes = $gitlab->group_custom_attributes( :gid );
$attributes = $gitlab->project_custom_attributes( :id );
Returns a list of custom attributes.
=item L<Single custom attribute|https://docs.gitlab.com/ce/api/custom_attributes.html#single-custom-attribute>
$attribute = $gitlab->user_get_custom_attribute( :uid, :key );
$attribute = $gitlab->group_get_custom_attribute( :gid, :key );
$attribute = $gitlab->project_get_custom_attribute( :id, :key );
Retrieves a single attribute.
=item L<Set custom attribute|https://docs.gitlab.com/ce/api/custom_attributes.html#set-custom-attribute>
$gitlab->user_set_custom_attribute( :uid, :key, :value );
$gitlab->group_set_custom_attribute( :gid, :key, :value );
$gitlab->project_set_custom_attribute( :id, :key, :value );
Sets the custom attribute to the given value. The attribute will be created
if necessary.
=item L<Delete custom attribute|https://docs.gitlab.com/ce/api/custom_attributes.html#delete-custom-attribute>
$gitlab->user_delete_custom_attribute( :uid, :key );
$gitlab->group_delete_custom_attribute( :gid, :key );
$gitlab->project_delete_custom_attribute( :id, :key );
Deletes a custom attribute.
=back
=head1 AUTHOR
Roman Lacko <L<xlacko1@fi.muni.cz>>
=head1 SEE ALSO
=over
=item L<GitLab>
Wrapper around L<GitLab::API> and other C<GitLab::*> modules.
=back
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment