Skip to content

Commit

Permalink
Allow to pass options for deploy keys
Browse files Browse the repository at this point in the history
  • Loading branch information
David Dieulivol committed Jul 31, 2018
1 parent e26d583 commit 0f273b2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/gitlab/client/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,15 @@ def deploy_key(project, id)
# Creates a new deploy key.
#
# @example
# Gitlab.create_deploy_key(42, 'My Key', 'Key contents')
# Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)
#
# @param [Integer, String] project The ID or path of a project.
# @param [String] title The title of a deploy key.
# @param [String] key The content of a deploy key.
# @param [Hash] options A customizable set of options.
# @return [Gitlab::ObjectifiedHash] Information about created deploy key.
def create_deploy_key(project, title, key)
post("/projects/#{url_encode project}/deploy_keys", body: { title: title, key: key })
def create_deploy_key(project, title, key, options = {})
post("/projects/#{url_encode project}/deploy_keys", body: { title: title, key: key }.merge(options))
end

# Enables a deploy key at the project.
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/project_key.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": 2,
"title": "Key Title",
"key": "ssh-rsa ...",
"can_push": false,
"created_at": "2013-09-22T18:34:32Z"
}
}
3 changes: 2 additions & 1 deletion spec/fixtures/project_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": 2,
"title": "Key Title",
"key": "ssh-rsa ...",
"can_push": false,
"created_at": "2013-09-22T18:34:32Z"
}]
}]
34 changes: 34 additions & 0 deletions spec/gitlab/client/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,40 @@
end
end

describe ".create_deploy_key" do
context 'no options' do
before do
stub_post("/projects/42/deploy_keys", "project_key")
@deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents')
end

it "gets the correct resource" do
expect(a_post("/projects/42/deploy_keys").
with(body: { title: 'My Key', key: 'Key contents' })).to have_been_made
end

it "returns information about a created key" do
expect(@deploy_key.id).to eq(2)
end
end

context 'some options' do
before do
stub_post("/projects/42/deploy_keys", "project_key")
@deploy_key = Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)
end

it "gets the correct resource" do
expect(a_post("/projects/42/deploy_keys").
with(body: { title: 'My Key', key: 'Key contents', can_push: true })).to have_been_made
end

it "returns information about a created key" do
expect(@deploy_key.id).to eq(2)
end
end
end

describe ".delete_deploy_key" do
before do
stub_delete("/projects/42/deploy_keys/2", "project_key")
Expand Down

0 comments on commit 0f273b2

Please sign in to comment.