From 47c2d778959f45e831e1d8df646ab4d9e1a40aa5 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Fri, 11 Dec 2020 15:12:27 +0100 Subject: [PATCH 01/14] delete user custom attribute --- lib/gitlab/client/users.rb | 40 ++++++++++++++++++++++ spec/gitlab/client/users_spec.rb | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index 696aaa9e1..543d530f2 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -279,5 +279,45 @@ 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) + url = "/users/#{user_id}/custom_attributes" + get(url) + end + + # Creates a new custom_attribute + # + # @example + # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2) + # + # @param [String] custom_attributes key + # @param [String] 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.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 = nil) + url = "/users/#{user_id}/custom_attributes/#{key}" + delete(url) + end end end diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index 893bad520..908dd3be6 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -478,4 +478,62 @@ expect(@users.last.id).to eq(2) end end + + describe '.user_custom_attributes' do + before do + stub_get('/users/2/custom_attributes', 'user_custom_attributes') + @custom_attributes = Gitlab.user_custom_attributes(2) + end + + it 'gets the correct resource' do + expect(a_get('/users/2/custom_attributes')).to have_been_made + end + + it 'returns a information about a custom_attribute of user' do + expect(@custom_attributes.first.key).to eq "somekey" + expect(@custom_attributes.last.value).to eq('somevalue2') + end + end + + describe '.add_custom_attribute' do + + describe 'with user ID' do + before do + + stub_put('/users/2/custom_attributes/some_new_key', 'user_custom_attribute') + @custom_attribute = Gitlab.add_user_custom_attribute('some_new_key','some_new_value', 2) + end + +# it 'gets the correct resource' do +# body = { key: 'some_new_key', value: 'some_new_value' } +# expect(a_put('/users/2/custom_attributes/some_new_key').with(body: body)).to have_been_made +# end + + it 'returns information about a new email' 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 user ID' do + before do + stub_delete('/users/2/custom_attributes/some_new_key', 'user_custom_attribute') + @custom_attribute = Gitlab.delete_user_custom_attribute("some_new_key", 2) + end + + it 'gets the correct resource' do + expect(a_delete('/users/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 From 1686c669e0e2f991cd9501769561464ca413e2b6 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Fri, 11 Dec 2020 15:12:46 +0100 Subject: [PATCH 02/14] delete user custom attribute --- spec/fixtures/user_custom_attribute.json | 1 + spec/fixtures/user_custom_attributes.json | 1 + 2 files changed, 2 insertions(+) create mode 100644 spec/fixtures/user_custom_attribute.json create mode 100644 spec/fixtures/user_custom_attributes.json diff --git a/spec/fixtures/user_custom_attribute.json b/spec/fixtures/user_custom_attribute.json new file mode 100644 index 000000000..71f3d9896 --- /dev/null +++ b/spec/fixtures/user_custom_attribute.json @@ -0,0 +1 @@ +{"key":"some_new_key","value":"some_new_value"} diff --git a/spec/fixtures/user_custom_attributes.json b/spec/fixtures/user_custom_attributes.json new file mode 100644 index 000000000..c26f1c78a --- /dev/null +++ b/spec/fixtures/user_custom_attributes.json @@ -0,0 +1 @@ +[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}] From 29b42108215c45b0b6b735096deab5a53a93235f Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Fri, 11 Dec 2020 16:11:19 +0100 Subject: [PATCH 03/14] add group and project custom attributes --- lib/gitlab/client/groups.rb | 55 ++++++++++++++ lib/gitlab/client/projects.rb | 54 ++++++++++++++ lib/gitlab/client/users.rb | 17 ++++- spec/fixtures/group_custom_attribute.json | 1 + spec/fixtures/group_custom_attributes.json | 1 + spec/fixtures/project_custom_attribute.json | 1 + spec/fixtures/project_custom_attributes.json | 1 + spec/gitlab/client/groups_spec.rb | 75 ++++++++++++++++++++ spec/gitlab/client/projects_spec.rb | 75 ++++++++++++++++++++ spec/gitlab/client/users_spec.rb | 27 +++++-- 10 files changed, 300 insertions(+), 7 deletions(-) create mode 100644 spec/fixtures/group_custom_attribute.json create mode 100644 spec/fixtures/group_custom_attributes.json create mode 100644 spec/fixtures/project_custom_attribute.json create mode 100644 spec/fixtures/project_custom_attributes.json diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 4c08b30b7..d557bd660 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -270,5 +270,60 @@ 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) + url = "/groups/#{group_id}/custom_attributes" + get(url) + 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) + url = "/groups/#{group_id}/custom_attributes/#{key}" + get(url) + 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.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) + url = "/groups/#{group_id}/custom_attributes/#{key}" + delete(url) + end + + end end diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 400f75e00..7b71d05b7 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -640,5 +640,59 @@ 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) + url = "/projects/#{project_id}/custom_attributes" + get(url) + 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) + url = "/projects/#{project_id}/custom_attributes/#{key}" + get(url) + 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.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) + url = "/projects/#{project_id}/custom_attributes/#{key}" + delete(url) + end + end end diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index 543d530f2..ae35dbd2a 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -292,13 +292,26 @@ def user_custom_attributes(user_id) get(url) 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) + url = "/users/#{user_id}/custom_attributes/#{key}" + get(url) + end + # Creates a new custom_attribute # # @example # Gitlab.add_custom_attribute('some_new_key', 'some_new_value', 2) # - # @param [String] custom_attributes key - # @param [String] custom_attributes value + # @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) diff --git a/spec/fixtures/group_custom_attribute.json b/spec/fixtures/group_custom_attribute.json new file mode 100644 index 000000000..71f3d9896 --- /dev/null +++ b/spec/fixtures/group_custom_attribute.json @@ -0,0 +1 @@ +{"key":"some_new_key","value":"some_new_value"} diff --git a/spec/fixtures/group_custom_attributes.json b/spec/fixtures/group_custom_attributes.json new file mode 100644 index 000000000..c26f1c78a --- /dev/null +++ b/spec/fixtures/group_custom_attributes.json @@ -0,0 +1 @@ +[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}] diff --git a/spec/fixtures/project_custom_attribute.json b/spec/fixtures/project_custom_attribute.json new file mode 100644 index 000000000..71f3d9896 --- /dev/null +++ b/spec/fixtures/project_custom_attribute.json @@ -0,0 +1 @@ +{"key":"some_new_key","value":"some_new_value"} diff --git a/spec/fixtures/project_custom_attributes.json b/spec/fixtures/project_custom_attributes.json new file mode 100644 index 000000000..c26f1c78a --- /dev/null +++ b/spec/fixtures/project_custom_attributes.json @@ -0,0 +1 @@ +[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}] diff --git a/spec/gitlab/client/groups_spec.rb b/spec/gitlab/client/groups_spec.rb index 69a7e9b50..21aa65dda 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -345,4 +345,79 @@ 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 = { key: 'some_new_key', 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 diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index 3f8bd0722..c6d9d5013 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -840,4 +840,79 @@ 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 = { key: 'some_new_key', 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 diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index 908dd3be6..6db2ebc43 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -495,6 +495,22 @@ end end + describe '.user_custom_attribute' do + before do + stub_get('/users/2/custom_attributes/some_new_key', 'user_custom_attribute') + @custom_attribute = Gitlab.user_custom_attribute("some_new_key",2) + end + + it 'gets the correct resource' do + expect(a_get('/users/2/custom_attributes/some_new_key')).to have_been_made + end + + it 'returns a information about the single custom_attribute of user' 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 user ID' do @@ -504,12 +520,13 @@ @custom_attribute = Gitlab.add_user_custom_attribute('some_new_key','some_new_value', 2) end -# it 'gets the correct resource' do -# body = { key: 'some_new_key', value: 'some_new_value' } -# expect(a_put('/users/2/custom_attributes/some_new_key').with(body: body)).to have_been_made -# end + it 'gets the correct resource' do + #body = { key: 'some_new_key', value: 'some_new_value' } + #expect(a_put('/users/2/custom_attributes/some_new_key').with(body: body)).to have_been_made + expect(a_put('/users/2/custom_attributes/some_new_key')).to have_been_made + end - it 'returns information about a new email' do + 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 From 1b8308d665c5957373e2aa369687f7a8d4883172 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Mon, 21 Dec 2020 12:49:40 +0100 Subject: [PATCH 04/14] add working test for all custom_attributes --- spec/gitlab/client/groups_spec.rb | 4 ++-- spec/gitlab/client/projects_spec.rb | 4 ++-- spec/gitlab/client/users_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/gitlab/client/groups_spec.rb b/spec/gitlab/client/groups_spec.rb index 21aa65dda..e36cfeca0 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -388,8 +388,8 @@ end it 'gets the correct resource' do - #body = { key: 'some_new_key', value: 'some_new_value' } - #expect(a_put('/groups/2/custom_attributes/some_new_key').with(body: body)).to have_been_made + 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 diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index c6d9d5013..cc3cc59ac 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -883,8 +883,8 @@ end it 'gets the correct resource' do - #body = { key: 'some_new_key', value: 'some_new_value' } - #expect(a_put('/projects/2/custom_attributes/some_new_key').with(body: body)).to have_been_made + 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 diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index 6db2ebc43..fd11cb66c 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -521,8 +521,8 @@ end it 'gets the correct resource' do - #body = { key: 'some_new_key', value: 'some_new_value' } - #expect(a_put('/users/2/custom_attributes/some_new_key').with(body: body)).to have_been_made + body = { value: 'some_new_value' } + expect(a_put('/users/2/custom_attributes/some_new_key').with(body: body)).to have_been_made expect(a_put('/users/2/custom_attributes/some_new_key')).to have_been_made end From fa6a99bce6e7f7babf47aba398740414a92fd5fb Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Mon, 21 Dec 2020 16:07:22 +0100 Subject: [PATCH 05/14] fix rubocop problems --- lib/gitlab/client/groups.rb | 10 +++------- lib/gitlab/client/projects.rb | 3 +-- lib/gitlab/client/users.rb | 11 ++++------- spec/gitlab/client/groups_spec.rb | 16 +++++----------- spec/gitlab/client/projects_spec.rb | 16 +++++----------- spec/gitlab/client/users_spec.rb | 16 +++++----------- 6 files changed, 23 insertions(+), 49 deletions(-) diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index d557bd660..8d723596e 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -279,8 +279,7 @@ def delete_ldap_group_links(id, commonname, provider) # @param [Integer] group_id The ID of a group. # @return [Gitlab::ObjectifiedHash] def group_custom_attributes(group_id) - url = "/groups/#{group_id}/custom_attributes" - get(url) + get("/groups/#{group_id}/custom_attributes") end # Gets single group custom_attribute. @@ -292,8 +291,7 @@ def group_custom_attributes(group_id) # @param [Integer] group_id The ID of a group. # @return [Gitlab::ObjectifiedHash] def group_custom_attribute(key, group_id) - url = "/groups/#{group_id}/custom_attributes/#{key}" - get(url) + get("/groups/#{group_id}/custom_attributes/#{key}") end # Creates a new custom_attribute @@ -306,7 +304,7 @@ def group_custom_attribute(key, group_id) # @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}" + url = "/groups/#{group_id}/custom_attributes/#{key}" put(url, body: { value: value }) end @@ -323,7 +321,5 @@ def delete_group_custom_attribute(key, group_id = nil) url = "/groups/#{group_id}/custom_attributes/#{key}" delete(url) end - - end end diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 7b71d05b7..2eda91058 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -676,7 +676,7 @@ def project_custom_attribute(key, project_id) # @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}" + url = "/projects/#{project_id}/custom_attributes/#{key}" put(url, body: { value: value }) end @@ -693,6 +693,5 @@ def delete_project_custom_attribute(key, project_id = nil) url = "/projects/#{project_id}/custom_attributes/#{key}" delete(url) end - end end diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index ae35dbd2a..f8b5bdd42 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -288,8 +288,7 @@ def user_search(search, options = {}) # @param [Integer] user_id The ID of a user. # @return [Gitlab::ObjectifiedHash] def user_custom_attributes(user_id) - url = "/users/#{user_id}/custom_attributes" - get(url) + get("/users/#{user_id}/custom_attributes") end # Gets single user custom_attribute. @@ -301,8 +300,7 @@ def user_custom_attributes(user_id) # @param [Integer] user_id The ID of a user. # @return [Gitlab::ObjectifiedHash] def user_custom_attribute(key, user_id) - url = "/users/#{user_id}/custom_attributes/#{key}" - get(url) + get("/users/#{user_id}/custom_attributes/#{key}") end # Creates a new custom_attribute @@ -315,7 +313,7 @@ def user_custom_attribute(key, user_id) # @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}" + url = "/users/#{user_id}/custom_attributes/#{key}" put(url, body: { value: value }) end @@ -329,8 +327,7 @@ def add_user_custom_attribute(key, value, user_id) # @param [Integer] user_id The ID of a user. # @return [Boolean] def delete_user_custom_attribute(key, user_id = nil) - url = "/users/#{user_id}/custom_attributes/#{key}" - delete(url) + delete("/users/#{user_id}/custom_attributes/#{key}") end end end diff --git a/spec/gitlab/client/groups_spec.rb b/spec/gitlab/client/groups_spec.rb index e36cfeca0..95c2fde53 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -357,7 +357,7 @@ end it 'returns a information about a custom_attribute of group' do - expect(@custom_attributes.first.key).to eq "somekey" + expect(@custom_attributes.first.key).to eq 'somekey' expect(@custom_attributes.last.value).to eq('somevalue2') end end @@ -365,7 +365,7 @@ 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) + @custom_attribute = Gitlab.group_custom_attribute('some_new_key', 2) end it 'gets the correct resource' do @@ -373,18 +373,16 @@ 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.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) + @custom_attribute = Gitlab.add_group_custom_attribute('some_new_key', 'some_new_value', 2) end it 'gets the correct resource' do @@ -401,11 +399,10 @@ 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) + @custom_attribute = Gitlab.delete_group_custom_attribute('some_new_key', 2) end it 'gets the correct resource' do @@ -417,7 +414,4 @@ end end end - - - end diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index cc3cc59ac..f1d15cfaf 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -852,7 +852,7 @@ end it 'returns a information about a custom_attribute of project' do - expect(@custom_attributes.first.key).to eq "somekey" + expect(@custom_attributes.first.key).to eq 'somekey' expect(@custom_attributes.last.value).to eq('somevalue2') end end @@ -860,7 +860,7 @@ 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) + @custom_attribute = Gitlab.project_custom_attribute('some_new_key', 2) end it 'gets the correct resource' do @@ -868,18 +868,16 @@ 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.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) + @custom_attribute = Gitlab.add_project_custom_attribute('some_new_key', 'some_new_value', 2) end it 'gets the correct resource' do @@ -896,11 +894,10 @@ 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) + @custom_attribute = Gitlab.delete_project_custom_attribute('some_new_key', 2) end it 'gets the correct resource' do @@ -912,7 +909,4 @@ end end end - - - end diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index fd11cb66c..9ea60c4ea 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -490,7 +490,7 @@ end it 'returns a information about a custom_attribute of user' do - expect(@custom_attributes.first.key).to eq "somekey" + expect(@custom_attributes.first.key).to eq 'somekey' expect(@custom_attributes.last.value).to eq('somevalue2') end end @@ -498,7 +498,7 @@ describe '.user_custom_attribute' do before do stub_get('/users/2/custom_attributes/some_new_key', 'user_custom_attribute') - @custom_attribute = Gitlab.user_custom_attribute("some_new_key",2) + @custom_attribute = Gitlab.user_custom_attribute('some_new_key', 2) end it 'gets the correct resource' do @@ -506,18 +506,16 @@ end it 'returns a information about the single custom_attribute of user' do - expect(@custom_attribute.key).to eq "some_new_key" + 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 user ID' do before do - stub_put('/users/2/custom_attributes/some_new_key', 'user_custom_attribute') - @custom_attribute = Gitlab.add_user_custom_attribute('some_new_key','some_new_value', 2) + @custom_attribute = Gitlab.add_user_custom_attribute('some_new_key', 'some_new_value', 2) end it 'gets the correct resource' do @@ -534,11 +532,10 @@ end describe '.delete_custom_attribute' do - describe 'with user ID' do before do stub_delete('/users/2/custom_attributes/some_new_key', 'user_custom_attribute') - @custom_attribute = Gitlab.delete_user_custom_attribute("some_new_key", 2) + @custom_attribute = Gitlab.delete_user_custom_attribute('some_new_key', 2) end it 'gets the correct resource' do @@ -550,7 +547,4 @@ end end end - - - end From f90e158af3b5a121c068531026971880a2273393 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:18:06 +0100 Subject: [PATCH 06/14] review suggestion Co-authored-by: Nihad Abbasov --- lib/gitlab/client/groups.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 8d723596e..9f8b8549d 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -285,7 +285,7 @@ def group_custom_attributes(group_id) # Gets single group custom_attribute. # # @example - # Gitlab.group_custom_attribute(key, 2) + # Gitlab.group_custom_attribute('key', 2) # # @param [String] key The custom_attributes key # @param [Integer] group_id The ID of a group. From 6cdf71c57482c4211d4314ac51c04eb55808e27c Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:18:43 +0100 Subject: [PATCH 07/14] review suggestion Co-authored-by: Nihad Abbasov --- lib/gitlab/client/groups.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 9f8b8549d..a344e60a3 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -312,7 +312,7 @@ def add_group_custom_attribute(key, value, group_id) # Will delete a custom_attribute # # @example - # Gitlab.custom_attribute("somekey", 2) + # 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. From b0677781ea18d93fb0155eda85d08b27915bec52 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:19:18 +0100 Subject: [PATCH 08/14] Update lib/gitlab/client/groups.rb Co-authored-by: Nihad Abbasov --- lib/gitlab/client/groups.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index a344e60a3..63afb1a9c 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -318,8 +318,7 @@ def add_group_custom_attribute(key, value, group_id) # @param [Integer] group_id The ID of a group. # @return [Boolean] def delete_group_custom_attribute(key, group_id = nil) - url = "/groups/#{group_id}/custom_attributes/#{key}" - delete(url) + delete("/groups/#{group_id}/custom_attributes/#{key}") end end end From e8574be924f88f18ec733e49e5c153c802094719 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:19:33 +0100 Subject: [PATCH 09/14] Update lib/gitlab/client/projects.rb Co-authored-by: Nihad Abbasov --- lib/gitlab/client/projects.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 2eda91058..2c2bb7987 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -649,8 +649,7 @@ def unarchive_project(id) # @param [Integer] project_id The ID of a project. # @return [Gitlab::ObjectifiedHash] def project_custom_attributes(project_id) - url = "/projects/#{project_id}/custom_attributes" - get(url) + get("/projects/#{project_id}/custom_attributes") end # Gets single project custom_attribute. From b45d5b9415701aee054513dce17a3bc45cbd5b5a Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:19:43 +0100 Subject: [PATCH 10/14] Update lib/gitlab/client/projects.rb Co-authored-by: Nihad Abbasov --- lib/gitlab/client/projects.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 2c2bb7987..b820a7256 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -661,8 +661,7 @@ def project_custom_attributes(project_id) # @param [Integer] project_id The ID of a project. # @return [Gitlab::ObjectifiedHash] def project_custom_attribute(key, project_id) - url = "/projects/#{project_id}/custom_attributes/#{key}" - get(url) + get("/projects/#{project_id}/custom_attributes/#{key}") end # Creates a new custom_attribute From 49007711ae4ea52d402f89f68a372eb5809a2706 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:20:40 +0100 Subject: [PATCH 11/14] review suggestion Co-authored-by: Nihad Abbasov --- lib/gitlab/client/projects.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index b820a7256..549999d3c 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -682,7 +682,7 @@ def add_project_custom_attribute(key, value, project_id) # Will delete a custom_attribute # # @example - # Gitlab.custom_attribute("somekey", 2) + # 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. From c5522aede081a19e928eeea68be751bebfd45a85 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:21:07 +0100 Subject: [PATCH 12/14] review suggestion Co-authored-by: Nihad Abbasov --- lib/gitlab/client/projects.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 549999d3c..b51f59d89 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -688,8 +688,7 @@ def add_project_custom_attribute(key, value, project_id) # @param [Integer] project_id The ID of a project. # @return [Boolean] def delete_project_custom_attribute(key, project_id = nil) - url = "/projects/#{project_id}/custom_attributes/#{key}" - delete(url) + delete("/projects/#{project_id}/custom_attributes/#{key}") end end end From d2df666b44696f28446afd90203b785d60d48c66 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:21:22 +0100 Subject: [PATCH 13/14] Update lib/gitlab/client/users.rb Co-authored-by: Nihad Abbasov --- lib/gitlab/client/users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index f8b5bdd42..e9d69b212 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -321,7 +321,7 @@ def add_user_custom_attribute(key, value, user_id) # Will delete a custom_attribute # # @example - # Gitlab.custom_attribute("somekey", 2) + # 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. From d92c335d89f0a9a3ce032d4c61b43284bd9235b5 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:24:46 +0100 Subject: [PATCH 14/14] remove default value --- lib/gitlab/client/users.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index e9d69b212..500a0145b 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -326,7 +326,7 @@ def add_user_custom_attribute(key, value, user_id) # @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 = nil) + def delete_user_custom_attribute(key, user_id) delete("/users/#{user_id}/custom_attributes/#{key}") end end