Skip to content

Commit f139e4e

Browse files
authored
Merge pull request #265 from Soullivaneuh/add-deploy-key-can-push-option
Add can_push option to deploy key creation
2 parents 395f25d + 963339c commit f139e4e

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lib/Gitlab/Api/Projects.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,15 @@ public function deployKey($project_id, $key_id)
381381
* @param int $project_id
382382
* @param string $title
383383
* @param string $key
384+
* @param bool $canPush
384385
* @return mixed
385386
*/
386-
public function addDeployKey($project_id, $title, $key)
387+
public function addDeployKey($project_id, $title, $key, $canPush = false)
387388
{
388389
return $this->post($this->getProjectPath($project_id, 'deploy_keys'), array(
389390
'title' => $title,
390-
'key' => $key
391+
'key' => $key,
392+
'can_push' => $canPush
391393
));
392394
}
393395

lib/Gitlab/Model/Project.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,12 @@ public function deployKey($key_id)
330330
/**
331331
* @param string $title
332332
* @param string $key
333+
* @param bool $canPush
333334
* @return Key
334335
*/
335-
public function addDeployKey($title, $key)
336+
public function addDeployKey($title, $key, $canPush = false)
336337
{
337-
$data = $this->client->projects()->addDeployKey($this->id, $title, $key);
338+
$data = $this->client->projects()->addDeployKey($this->id, $title, $key, $canPush);
338339

339340
return Key::fromArray($this->getClient(), $data);
340341
}

test/Gitlab/Tests/Api/ProjectsTest.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -577,18 +577,35 @@ public function shouldGetDeployKey()
577577
*/
578578
public function shouldAddKey()
579579
{
580-
$expectedArray = array('id' => 3, 'title' => 'new-key');
580+
$expectedArray = array('id' => 3, 'title' => 'new-key', 'can_push' => false);
581581

582582
$api = $this->getApiMock();
583583
$api->expects($this->once())
584584
->method('post')
585-
->with('projects/1/deploy_keys', array('title' => 'new-key', 'key' => '...'))
585+
->with('projects/1/deploy_keys', array('title' => 'new-key', 'key' => '...', 'can_push' => false))
586586
->will($this->returnValue($expectedArray))
587587
;
588588

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

592+
/**
593+
* @test
594+
*/
595+
public function shouldAddKeyWithPushOption()
596+
{
597+
$expectedArray = array('id' => 3, 'title' => 'new-key', 'can_push' => true);
598+
599+
$api = $this->getApiMock();
600+
$api->expects($this->once())
601+
->method('post')
602+
->with('projects/1/deploy_keys', array('title' => 'new-key', 'key' => '...', 'can_push' => true))
603+
->will($this->returnValue($expectedArray))
604+
;
605+
606+
$this->assertEquals($expectedArray, $api->addDeployKey(1, 'new-key', '...', true));
607+
}
608+
592609
/**
593610
* @test
594611
*/

0 commit comments

Comments
 (0)