Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/gitlab/client/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,55 @@ def add_ldap_group_links(id, commonname, group_access, provider)
def delete_ldap_group_links(id, commonname, provider)
delete("/groups/#{url_encode id}/ldap_group_links/#{url_encode provider}/#{url_encode commonname}")
end

# Gets group custom_attributes.
#
# @example
# Gitlab.group_custom_attributes(2)
#
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::ObjectifiedHash]
def group_custom_attributes(group_id)
get("/groups/#{group_id}/custom_attributes")
end

# Gets single group custom_attribute.
#
# @example
# Gitlab.group_custom_attribute('key', 2)
#
# @param [String] key The custom_attributes key
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::ObjectifiedHash]
def group_custom_attribute(key, group_id)
get("/groups/#{group_id}/custom_attributes/#{key}")
end

# Creates a new custom_attribute
#
# @example
# Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
#
# @param [String] key The custom_attributes key
# @param [String] value The custom_attributes value
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::ObjectifiedHash]
def add_group_custom_attribute(key, value, group_id)
url = "/groups/#{group_id}/custom_attributes/#{key}"
put(url, body: { value: value })
end

# Delete custom_attribute
# Will delete a custom_attribute
#
# @example
# Gitlab.delete_group_custom_attribute('somekey', 2)
#
# @param [String] key The custom_attribute key to delete
# @param [Integer] group_id The ID of a group.
# @return [Boolean]
def delete_group_custom_attribute(key, group_id = nil)
delete("/groups/#{group_id}/custom_attributes/#{key}")
end
end
end
50 changes: 50 additions & 0 deletions lib/gitlab/client/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,5 +640,55 @@ def archive_project(id)
def unarchive_project(id)
post("/projects/#{url_encode id}/unarchive")
end

# Gets project custom_attributes.
#
# @example
# Gitlab.project_custom_attributes(2)
#
# @param [Integer] project_id The ID of a project.
# @return [Gitlab::ObjectifiedHash]
def project_custom_attributes(project_id)
get("/projects/#{project_id}/custom_attributes")
end

# Gets single project custom_attribute.
#
# @example
# Gitlab.project_custom_attribute(key, 2)
#
# @param [String] key The custom_attributes key
# @param [Integer] project_id The ID of a project.
# @return [Gitlab::ObjectifiedHash]
def project_custom_attribute(key, project_id)
get("/projects/#{project_id}/custom_attributes/#{key}")
end

# Creates a new custom_attribute
#
# @example
# Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
#
# @param [String] key The custom_attributes key
# @param [String] value The custom_attributes value
# @param [Integer] project_id The ID of a project.
# @return [Gitlab::ObjectifiedHash]
def add_project_custom_attribute(key, value, project_id)
url = "/projects/#{project_id}/custom_attributes/#{key}"
put(url, body: { value: value })
end

# Delete custom_attribute
# Will delete a custom_attribute
#
# @example
# Gitlab.delete_project_custom_attribute('somekey', 2)
#
# @param [String] key The custom_attribute key to delete
# @param [Integer] project_id The ID of a project.
# @return [Boolean]
def delete_project_custom_attribute(key, project_id = nil)
delete("/projects/#{project_id}/custom_attributes/#{key}")
end
end
end
50 changes: 50 additions & 0 deletions lib/gitlab/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,55 @@ def user_search(search, options = {})
options[:search] = search
get('/users', query: options)
end

# Gets user custom_attributes.
#
# @example
# Gitlab.user_custom_attributes(2)
#
# @param [Integer] user_id The ID of a user.
# @return [Gitlab::ObjectifiedHash]
def user_custom_attributes(user_id)
get("/users/#{user_id}/custom_attributes")
end

# Gets single user custom_attribute.
#
# @example
# Gitlab.user_custom_attribute(key, 2)
#
# @param [String] key The custom_attributes key
# @param [Integer] user_id The ID of a user.
# @return [Gitlab::ObjectifiedHash]
def user_custom_attribute(key, user_id)
get("/users/#{user_id}/custom_attributes/#{key}")
end

# Creates a new custom_attribute
#
# @example
# Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2)
#
# @param [String] key The custom_attributes key
# @param [String] value The custom_attributes value
# @param [Integer] user_id The ID of a user.
# @return [Gitlab::ObjectifiedHash]
def add_user_custom_attribute(key, value, user_id)
url = "/users/#{user_id}/custom_attributes/#{key}"
put(url, body: { value: value })
end

# Delete custom_attribute
# Will delete a custom_attribute
#
# @example
# Gitlab.delete_user_custom_attribute('somekey', 2)
#
# @param [String] key The custom_attribute key to delete
# @param [Integer] user_id The ID of a user.
# @return [Boolean]
def delete_user_custom_attribute(key, user_id)
delete("/users/#{user_id}/custom_attributes/#{key}")
end
end
end
1 change: 1 addition & 0 deletions spec/fixtures/group_custom_attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"key":"some_new_key","value":"some_new_value"}
1 change: 1 addition & 0 deletions spec/fixtures/group_custom_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}]
1 change: 1 addition & 0 deletions spec/fixtures/project_custom_attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"key":"some_new_key","value":"some_new_value"}
1 change: 1 addition & 0 deletions spec/fixtures/project_custom_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}]
1 change: 1 addition & 0 deletions spec/fixtures/user_custom_attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"key":"some_new_key","value":"some_new_value"}
1 change: 1 addition & 0 deletions spec/fixtures/user_custom_attributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}]
69 changes: 69 additions & 0 deletions spec/gitlab/client/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,73 @@
expect(a_delete('/groups/1/ldap_group_links/ldap/all')).to have_been_made
end
end

describe '.group_custom_attributes' do
before do
stub_get('/groups/2/custom_attributes', 'group_custom_attributes')
@custom_attributes = Gitlab.group_custom_attributes(2)
end

it 'gets the correct resource' do
expect(a_get('/groups/2/custom_attributes')).to have_been_made
end

it 'returns a information about a custom_attribute of group' do
expect(@custom_attributes.first.key).to eq 'somekey'
expect(@custom_attributes.last.value).to eq('somevalue2')
end
end

describe '.group_custom_attribute' do
before do
stub_get('/groups/2/custom_attributes/some_new_key', 'group_custom_attribute')
@custom_attribute = Gitlab.group_custom_attribute('some_new_key', 2)
end

it 'gets the correct resource' do
expect(a_get('/groups/2/custom_attributes/some_new_key')).to have_been_made
end

it 'returns a information about the single custom_attribute of group' do
expect(@custom_attribute.key).to eq 'some_new_key'
expect(@custom_attribute.value).to eq('some_new_value')
end
end

describe '.add_custom_attribute' do
describe 'with group ID' do
before do
stub_put('/groups/2/custom_attributes/some_new_key', 'group_custom_attribute')
@custom_attribute = Gitlab.add_group_custom_attribute('some_new_key', 'some_new_value', 2)
end

it 'gets the correct resource' do
body = { value: 'some_new_value' }
expect(a_put('/groups/2/custom_attributes/some_new_key').with(body: body)).to have_been_made
expect(a_put('/groups/2/custom_attributes/some_new_key')).to have_been_made
end

it 'returns information about a new custom attribute' do
expect(@custom_attribute.key).to eq 'some_new_key'
expect(@custom_attribute.value).to eq 'some_new_value'
end
end
end

describe '.delete_custom_attribute' do
describe 'with group ID' do
before do
stub_delete('/groups/2/custom_attributes/some_new_key', 'group_custom_attribute')
@custom_attribute = Gitlab.delete_group_custom_attribute('some_new_key', 2)
end

it 'gets the correct resource' do
expect(a_delete('/groups/2/custom_attributes/some_new_key')).to have_been_made
end

it 'returns information about a deleted custom_attribute' do
expect(@custom_attribute).to be_truthy
end
end
end
end
69 changes: 69 additions & 0 deletions spec/gitlab/client/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,73 @@
expect(@unarchived_project.archived).to eq(false)
end
end

describe '.project_custom_attributes' do
before do
stub_get('/projects/2/custom_attributes', 'project_custom_attributes')
@custom_attributes = Gitlab.project_custom_attributes(2)
end

it 'gets the correct resource' do
expect(a_get('/projects/2/custom_attributes')).to have_been_made
end

it 'returns a information about a custom_attribute of project' do
expect(@custom_attributes.first.key).to eq 'somekey'
expect(@custom_attributes.last.value).to eq('somevalue2')
end
end

describe '.project_custom_attribute' do
before do
stub_get('/projects/2/custom_attributes/some_new_key', 'project_custom_attribute')
@custom_attribute = Gitlab.project_custom_attribute('some_new_key', 2)
end

it 'gets the correct resource' do
expect(a_get('/projects/2/custom_attributes/some_new_key')).to have_been_made
end

it 'returns a information about the single custom_attribute of project' do
expect(@custom_attribute.key).to eq 'some_new_key'
expect(@custom_attribute.value).to eq('some_new_value')
end
end

describe '.add_custom_attribute' do
describe 'with project ID' do
before do
stub_put('/projects/2/custom_attributes/some_new_key', 'project_custom_attribute')
@custom_attribute = Gitlab.add_project_custom_attribute('some_new_key', 'some_new_value', 2)
end

it 'gets the correct resource' do
body = { value: 'some_new_value' }
expect(a_put('/projects/2/custom_attributes/some_new_key').with(body: body)).to have_been_made
expect(a_put('/projects/2/custom_attributes/some_new_key')).to have_been_made
end

it 'returns information about a new custom attribute' do
expect(@custom_attribute.key).to eq 'some_new_key'
expect(@custom_attribute.value).to eq 'some_new_value'
end
end
end

describe '.delete_custom_attribute' do
describe 'with project ID' do
before do
stub_delete('/projects/2/custom_attributes/some_new_key', 'project_custom_attribute')
@custom_attribute = Gitlab.delete_project_custom_attribute('some_new_key', 2)
end

it 'gets the correct resource' do
expect(a_delete('/projects/2/custom_attributes/some_new_key')).to have_been_made
end

it 'returns information about a deleted custom_attribute' do
expect(@custom_attribute).to be_truthy
end
end
end
end
Loading