From 573e7b054b8abc69800223ecdc0531dfc8a77ed0 Mon Sep 17 00:00:00 2001 From: Akash Srivastava Date: Sun, 24 Feb 2019 20:07:44 +0530 Subject: [PATCH 1/2] Added missing endpoints in Runners API --- lib/gitlab/client/runners.rb | 45 +++++++++++++++++++++ spec/fixtures/register_runner_response.json | 4 ++ spec/gitlab/client/runners_spec.rb | 40 ++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 spec/fixtures/register_runner_response.json diff --git a/lib/gitlab/client/runners.rb b/lib/gitlab/client/runners.rb index 4c66e5526..b95627fd2 100644 --- a/lib/gitlab/client/runners.rb +++ b/lib/gitlab/client/runners.rb @@ -122,5 +122,50 @@ def project_enable_runner(project_id, id) def project_disable_runner(id, runner_id) delete("/projects/#{url_encode id}/runners/#{runner_id}") end + + # Register a new Runner for the instance. + # + # @example + # Gitlab.register_runner('9142c16ea169eaaea3d752313a434a6e') + # Gitlab.register_runner('9142c16ea169eaaea3d752313a434a6e', description: 'Some Description', active: true, locked: false) + # + # @param [String] token Registration token. + # @param [Hash] options A customizable set of options. + # @option options [String] :description Runner description. + # @option options [Hash] :info Runner metadata. + # @option options [Boolean] :active Whether the Runner is active. + # @option options [Boolean] :locked Whether the Runner should be locked for current project. + # @option options [Boolean] :run_untagged Whether the Runner should handle untagged jobs. + # @option options [Array] :tag_list List of Runner tags. + # @option options [Integer] :maximum_timeout Maximum timeout set when this Runner will handle the job. + # @return Response against runner registration + def register_runner(token, options = {}) + body = { token: token }.merge(options) + post('/runners', body: body) + end + + # Deletes a registed Runner. + # + # @example + # Gitlab.delete_registered_runner('9142c16ea169eaaea3d752313a434a6e') + # + # @param [String] token Runner authentication token. + # @return [void] This API call returns an empty response body. + def delete_registered_runner(token) + body = { token: token } + delete('/runners', body: body) + end + + # Validates authentication credentials for a registered Runner. + # + # @example + # Gitlab.verify_auth_registered_runner('9142c16ea169eaaea3d752313a434a6e') + # + # @param [String] token Runner authentication token. + # @return [void] This API call returns an empty response body. + def verify_auth_registered_runner(token) + body = { token: token } + post('/runners/verify', body: body) + end end end diff --git a/spec/fixtures/register_runner_response.json b/spec/fixtures/register_runner_response.json new file mode 100644 index 000000000..f6d3d6ecc --- /dev/null +++ b/spec/fixtures/register_runner_response.json @@ -0,0 +1,4 @@ +{ + "id": "12345", + "token": "6337ff461c94fd3fa32ba3b1ff4125" +} diff --git a/spec/gitlab/client/runners_spec.rb b/spec/gitlab/client/runners_spec.rb index aaadba18c..c28b07938 100644 --- a/spec/gitlab/client/runners_spec.rb +++ b/spec/gitlab/client/runners_spec.rb @@ -191,4 +191,44 @@ expect(@runner.description).to eq('test-1-20150125') end end + + describe '.register_runner' do + before do + stub_post('/runners', 'register_runner_response').with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125', description: 'Some Description', active: true, locked: false }) + @register_runner_response = Gitlab.register_runner('6337ff461c94fd3fa32ba3b1ff4125', description: 'Some Description', active: true, locked: false) + end + + it 'gets the correct resource' do + expect(a_post('/runners') + .with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125', description: 'Some Description', active: true, locked: false })).to have_been_made + end + + it 'returns correct response for the runner registration' do + expect(@register_runner_response.token).to eq('6337ff461c94fd3fa32ba3b1ff4125') + end + end + + describe '.delete_registered_runner' do + before do + stub_delete('/runners', 'empty').with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' }) + Gitlab.delete_registered_runner('6337ff461c94fd3fa32ba3b1ff4125') + end + + it 'gets the correct resource' do + expect(a_delete('/runners') + .with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' })).to have_been_made + end + end + + describe '.verify_auth_registered_runner' do + before do + stub_post('/runners/verify', 'empty').with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' }) + Gitlab.verify_auth_registered_runner('6337ff461c94fd3fa32ba3b1ff4125') + end + + it 'gets the correct resource' do + expect(a_post('/runners/verify') + .with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' })).to have_been_made + end + end end From 5d3f5db3958aeb0d3e84830e840346c528d58dc3 Mon Sep 17 00:00:00 2001 From: Akash Srivastava Date: Sun, 24 Feb 2019 23:35:15 +0530 Subject: [PATCH 2/2] Doc changes in Runners API --- lib/gitlab/client/runners.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/client/runners.rb b/lib/gitlab/client/runners.rb index b95627fd2..056a7f656 100644 --- a/lib/gitlab/client/runners.rb +++ b/lib/gitlab/client/runners.rb @@ -150,7 +150,7 @@ def register_runner(token, options = {}) # Gitlab.delete_registered_runner('9142c16ea169eaaea3d752313a434a6e') # # @param [String] token Runner authentication token. - # @return [void] This API call returns an empty response body. + # @return [nil] This API call returns an empty response body. def delete_registered_runner(token) body = { token: token } delete('/runners', body: body) @@ -162,7 +162,7 @@ def delete_registered_runner(token) # Gitlab.verify_auth_registered_runner('9142c16ea169eaaea3d752313a434a6e') # # @param [String] token Runner authentication token. - # @return [void] This API call returns an empty response body. + # @return [nil] This API call returns an empty response body. def verify_auth_registered_runner(token) body = { token: token } post('/runners/verify', body: body)