diff --git a/.rubocop.yml b/.rubocop.yml index c5aa833..be9600f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,6 +17,9 @@ Exclude: - 'spec/**/*' +Metrics/ParameterLists: + MaxOptionalParameters: 4 + Style/Documentation: Enabled: false diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 4c08b30..63afb1a 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -270,5 +270,55 @@ 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 diff --git a/lib/gitlab/client/keys.rb b/lib/gitlab/client/keys.rb index cbba34f..e3384d8 100644 --- a/lib/gitlab/client/keys.rb +++ b/lib/gitlab/client/keys.rb @@ -14,5 +14,16 @@ def key(id) get("/keys/#{id}") end + + # Gets information about a key by key fingerprint. + # + # @example + # Gitlab.key_by_fingerprint("9f:70:33:b3:50:4d:9a:a3:ef:ea:13:9b:87:0f:7f:7e") + # + # @param [String] fingerprint The Fingerprint of a key. + # @return [Gitlab::ObjectifiedHash] + def key_by_fingerprint(fingerprint) + get('/keys', query: { fingerprint: fingerprint }) + end end end diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index 400f75e..b51f59d 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -640,5 +640,55 @@ 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 diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index 696aaa9..500a014 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -279,5 +279,55 @@ 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 diff --git a/spec/fixtures/group_custom_attribute.json b/spec/fixtures/group_custom_attribute.json new file mode 100644 index 0000000..71f3d98 --- /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 0000000..c26f1c7 --- /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 0000000..71f3d98 --- /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 0000000..c26f1c7 --- /dev/null +++ b/spec/fixtures/project_custom_attributes.json @@ -0,0 +1 @@ +[{"key":"somekey","value":"somevalue"},{"key":"somekey2","value":"somevalue2"}] diff --git a/spec/fixtures/user_custom_attribute.json b/spec/fixtures/user_custom_attribute.json new file mode 100644 index 0000000..71f3d98 --- /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 0000000..c26f1c7 --- /dev/null +++ b/spec/fixtures/user_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 69a7e9b..95c2fde 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -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 diff --git a/spec/gitlab/client/keys_spec.rb b/spec/gitlab/client/keys_spec.rb index aa639e1..673c71d 100644 --- a/spec/gitlab/client/keys_spec.rb +++ b/spec/gitlab/client/keys_spec.rb @@ -18,4 +18,20 @@ expect(@key.title).to eq('narkoz@helium') end end + + describe '.key_by_fingerprint' do + before do + stub_get('/keys?fingerprint=9f:70:33:b3:50:4d:9a:a3:ef:ea:13:9b:87:0f:7f:7e', 'key') + @key = Gitlab.key_by_fingerprint('9f:70:33:b3:50:4d:9a:a3:ef:ea:13:9b:87:0f:7f:7e') + end + + it 'gets the correct resource' do + expect(a_get('/keys?fingerprint=9f:70:33:b3:50:4d:9a:a3:ef:ea:13:9b:87:0f:7f:7e')).to have_been_made + end + + it 'returns information about a key' do + expect(@key.id).to eq(1) + expect(@key.title).to eq('narkoz@helium') + end + end end diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index 3f8bd07..f1d15cf 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -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 diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index 893bad5..9ea60c4 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -478,4 +478,73 @@ 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 '.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 + 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 = { 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 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 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