diff --git a/lib/Gitlab/Api/Projects.php b/lib/Gitlab/Api/Projects.php index 2dbd55a76..710a3e6a1 100644 --- a/lib/Gitlab/Api/Projects.php +++ b/lib/Gitlab/Api/Projects.php @@ -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 )); } diff --git a/lib/Gitlab/Model/Project.php b/lib/Gitlab/Model/Project.php index ae0bccc38..3b62a9f7c 100644 --- a/lib/Gitlab/Model/Project.php +++ b/lib/Gitlab/Model/Project.php @@ -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); } diff --git a/test/Gitlab/Tests/Api/ProjectsTest.php b/test/Gitlab/Tests/Api/ProjectsTest.php index 6087fb9dc..07f0f9f3d 100644 --- a/test/Gitlab/Tests/Api/ProjectsTest.php +++ b/test/Gitlab/Tests/Api/ProjectsTest.php @@ -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 */