From bb8ae56085cbae9545f8a78d0131bb857f53fbf6 Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Mon, 22 May 2017 15:49:19 +0100 Subject: [PATCH 1/3] Add missing `can_push` parameter to POST /v3/deploy_keys The v3 API documentation claims that `can_push` is supported when adding a deploy_key. https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/deploy_keys.md#add-deploy-key Here we make good on this promise by adding `can_push` as an optional parameter so grape can route it. This was copied from the v4 API. --- lib/api/v3/deploy_keys.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/api/v3/deploy_keys.rb b/lib/api/v3/deploy_keys.rb index bbb174b6003..b90e2061da3 100644 --- a/lib/api/v3/deploy_keys.rb +++ b/lib/api/v3/deploy_keys.rb @@ -41,6 +41,7 @@ module API params do requires :key, type: String, desc: 'The new deploy key' requires :title, type: String, desc: 'The name of the deploy key' + optional :can_push, type: Boolean, desc: "Can deploy key push to the project's repository" end post ":id/#{path}" do params[:key].strip! From 5f7ed486dc71989d12e30e895408da338093940f Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Mon, 22 May 2017 20:39:54 +0100 Subject: [PATCH 2/3] Add changelog entry --- changelogs/unreleased/bugfix-v3-deploy_keys-can_push.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/unreleased/bugfix-v3-deploy_keys-can_push.yml diff --git a/changelogs/unreleased/bugfix-v3-deploy_keys-can_push.yml b/changelogs/unreleased/bugfix-v3-deploy_keys-can_push.yml new file mode 100644 index 00000000000..0306663ac8d --- /dev/null +++ b/changelogs/unreleased/bugfix-v3-deploy_keys-can_push.yml @@ -0,0 +1,4 @@ +--- +title: "Fixed handling of the `can_push` attribute in the v3 deploy_keys api" +merge_request: 11607 +author: Richard Clamp From 00893f31b32bd5118e8d7eea3e0e90fe8fa90cb8 Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Mon, 22 May 2017 20:46:58 +0100 Subject: [PATCH 3/3] Extend spec tests for deploy_key can_push Copied from the v4 tests: https://gitlab.com/gitlab-org/gitlab-ce/blob/v9.2.0/spec/requests/api/deploy_keys_spec.rb#L110-116 --- spec/requests/api/v3/deploy_keys_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/requests/api/v3/deploy_keys_spec.rb b/spec/requests/api/v3/deploy_keys_spec.rb index b61b2b618a6..94f4d93a8dc 100644 --- a/spec/requests/api/v3/deploy_keys_spec.rb +++ b/spec/requests/api/v3/deploy_keys_spec.rb @@ -105,6 +105,15 @@ describe API::V3::DeployKeys do expect(response).to have_http_status(201) end + + it 'accepts can_push parameter' do + key_attrs = attributes_for :write_access_key + + post v3_api("/projects/#{project.id}/#{path}", admin), key_attrs + + expect(response).to have_http_status(201) + expect(json_response['can_push']).to eq(true) + end end describe "DELETE /projects/:id/#{path}/:key_id" do