Skip to content

Commit

Permalink
Merge pull request #265 from Soullivaneuh/add-deploy-key-can-push-option
Browse files Browse the repository at this point in the history
Add can_push option to deploy key creation
  • Loading branch information
fbourigault authored Oct 8, 2017
2 parents 395f25d + 963339c commit f139e4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/Gitlab/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,15 @@ public function deployKey($project_id, $key_id)
* @param int $project_id
* @param string $title
* @param string $key
* @param bool $canPush
* @return mixed
*/
public function addDeployKey($project_id, $title, $key)
public function addDeployKey($project_id, $title, $key, $canPush = false)
{
return $this->post($this->getProjectPath($project_id, 'deploy_keys'), array(
'title' => $title,
'key' => $key
'key' => $key,
'can_push' => $canPush
));
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Gitlab/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,12 @@ public function deployKey($key_id)
/**
* @param string $title
* @param string $key
* @param bool $canPush
* @return Key
*/
public function addDeployKey($title, $key)
public function addDeployKey($title, $key, $canPush = false)
{
$data = $this->client->projects()->addDeployKey($this->id, $title, $key);
$data = $this->client->projects()->addDeployKey($this->id, $title, $key, $canPush);

return Key::fromArray($this->getClient(), $data);
}
Expand Down
21 changes: 19 additions & 2 deletions test/Gitlab/Tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,35 @@ public function shouldGetDeployKey()
*/
public function shouldAddKey()
{
$expectedArray = array('id' => 3, 'title' => 'new-key');
$expectedArray = array('id' => 3, 'title' => 'new-key', 'can_push' => false);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/deploy_keys', array('title' => 'new-key', 'key' => '...'))
->with('projects/1/deploy_keys', array('title' => 'new-key', 'key' => '...', 'can_push' => false))
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->addDeployKey(1, 'new-key', '...'));
}

/**
* @test
*/
public function shouldAddKeyWithPushOption()
{
$expectedArray = array('id' => 3, 'title' => 'new-key', 'can_push' => true);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/deploy_keys', array('title' => 'new-key', 'key' => '...', 'can_push' => true))
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->addDeployKey(1, 'new-key', '...', true));
}

/**
* @test
*/
Expand Down

0 comments on commit f139e4e

Please sign in to comment.