From d7da83de6d739378f980de1db606ffe93916f124 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 17 Dec 2020 20:21:48 +0100 Subject: [PATCH 1/3] new def and spec: key_by_fingerprint --- lib/gitlab/client/keys.rb | 12 ++++++++++++ spec/gitlab/client/keys_spec.rb | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/gitlab/client/keys.rb b/lib/gitlab/client/keys.rb index cbba34f89..7dbe9d9a9 100644 --- a/lib/gitlab/client/keys.rb +++ b/lib/gitlab/client/keys.rb @@ -4,6 +4,7 @@ class Gitlab::Client # Defines methods related to keys. # @see https://docs.gitlab.com/ce/api/keys.html module Keys + # Gets information about a key. # # @example @@ -14,5 +15,16 @@ module Keys 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/spec/gitlab/client/keys_spec.rb b/spec/gitlab/client/keys_spec.rb index aa639e1c0..441882864 100644 --- a/spec/gitlab/client/keys_spec.rb +++ b/spec/gitlab/client/keys_spec.rb @@ -18,4 +18,21 @@ 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 From 852f572607fdcd6794c40f7aef4c3d6bba22d952 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Mon, 21 Dec 2020 13:12:21 +0100 Subject: [PATCH 2/3] fix rubocop offences --- lib/gitlab/client/keys.rb | 3 +-- spec/gitlab/client/keys_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/gitlab/client/keys.rb b/lib/gitlab/client/keys.rb index 7dbe9d9a9..21c6dce33 100644 --- a/lib/gitlab/client/keys.rb +++ b/lib/gitlab/client/keys.rb @@ -4,7 +4,6 @@ class Gitlab::Client # Defines methods related to keys. # @see https://docs.gitlab.com/ce/api/keys.html module Keys - # Gets information about a key. # # @example @@ -24,7 +23,7 @@ def key(id) # @param [String] fingerprint The Fingerprint of a key. # @return [Gitlab::ObjectifiedHash] def key_by_fingerprint(fingerprint) - get('/keys/', query: {fingerprint: fingerprint}) + get('/keys/', query: { fingerprint: fingerprint }) end end end diff --git a/spec/gitlab/client/keys_spec.rb b/spec/gitlab/client/keys_spec.rb index 441882864..9ae339846 100644 --- a/spec/gitlab/client/keys_spec.rb +++ b/spec/gitlab/client/keys_spec.rb @@ -22,7 +22,7 @@ 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") + @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 @@ -34,5 +34,4 @@ expect(@key.title).to eq('narkoz@helium') end end - end From d291712d116be3d88614bd9f6a8fe2ee3b93b9b6 Mon Sep 17 00:00:00 2001 From: Pim Snel Date: Thu, 31 Dec 2020 16:04:15 +0100 Subject: [PATCH 3/3] remove trailing slash --- lib/gitlab/client/keys.rb | 2 +- spec/gitlab/client/keys_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/client/keys.rb b/lib/gitlab/client/keys.rb index 21c6dce33..e3384d8b0 100644 --- a/lib/gitlab/client/keys.rb +++ b/lib/gitlab/client/keys.rb @@ -23,7 +23,7 @@ def key(id) # @param [String] fingerprint The Fingerprint of a key. # @return [Gitlab::ObjectifiedHash] def key_by_fingerprint(fingerprint) - get('/keys/', query: { fingerprint: fingerprint }) + get('/keys', query: { fingerprint: fingerprint }) end end end diff --git a/spec/gitlab/client/keys_spec.rb b/spec/gitlab/client/keys_spec.rb index 9ae339846..673c71d94 100644 --- a/spec/gitlab/client/keys_spec.rb +++ b/spec/gitlab/client/keys_spec.rb @@ -21,12 +21,12 @@ 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') + 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 + 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