From 095f4633eed4d3d20f7dad7b5c2f046410774b02 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 29 Mar 2021 13:52:47 +0200 Subject: [PATCH 1/5] Deployments: added missing 'delete deployment' endpoint per https://docs.github.com/en/rest/reference/repos#delete-a-deployment --- lib/Github/Api/Deployment.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 6fa8700a6da..5aead0b4410 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -66,6 +66,23 @@ public function create($username, $repository, array $params) return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params); } + /** + * Delete a deployment for the given username and repo. + * + * @link https://docs.github.com/en/rest/reference/repos#delete-a-deployment + * + * Important: Deployments can only be deleted when in inactive state + * @see updateStatus + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the deployment + */ + public function remove($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id); + } + /** * Updates a deployment by creating a new status update. * From 6ee0e0b7bdc26e23b2216c6670308bc8f14719b5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 1 Apr 2021 10:15:50 +0200 Subject: [PATCH 2/5] added test --- lib/Github/Api/Deployment.php | 2 ++ test/Github/Tests/Api/DeploymentTest.php | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 5aead0b4410..9f951e64bf5 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -77,6 +77,8 @@ public function create($username, $repository, array $params) * @param string $username the user who owns the repo * @param string $repository the name of the repo * @param int $id the id of the deployment + * + * @return mixed null on success, array on error with 'message' */ public function remove($username, $repository, $id) { diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index 223f3e2fd33..ae839d41549 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -51,7 +51,7 @@ public function shouldGetAllDeploymentsWithFilterParameters() /** * @test */ - public function shouldShowProject() + public function shouldShowDeployment() { $expectedValue = ['id' => 123, 'ref' => 'master']; @@ -64,6 +64,20 @@ public function shouldShowProject() $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); } + /** + * @test + */ + public function shouldDeleteDeployment() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/deployments/123') + ->will($this->returnValue(null)); + + $this->assertNull($api->remove('KnpLabs', 'php-github-api', 123)); + } + /** * @test */ @@ -111,4 +125,4 @@ protected function getApiClass() { return \Github\Api\Deployment::class; } -} +} \ No newline at end of file From 06787a1a8d12505063f3778fe3142739fdba4d9c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 1 Apr 2021 10:16:46 +0200 Subject: [PATCH 3/5] cs --- lib/Github/Api/Deployment.php | 4 ++-- test/Github/Tests/Api/DeploymentTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 9f951e64bf5..980fedca911 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -77,14 +77,14 @@ public function create($username, $repository, array $params) * @param string $username the user who owns the repo * @param string $repository the name of the repo * @param int $id the id of the deployment - * + * * @return mixed null on success, array on error with 'message' */ public function remove($username, $repository, $id) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id); } - + /** * Updates a deployment by creating a new status update. * diff --git a/test/Github/Tests/Api/DeploymentTest.php b/test/Github/Tests/Api/DeploymentTest.php index ae839d41549..88e8c923ce1 100644 --- a/test/Github/Tests/Api/DeploymentTest.php +++ b/test/Github/Tests/Api/DeploymentTest.php @@ -125,4 +125,4 @@ protected function getApiClass() { return \Github\Api\Deployment::class; } -} \ No newline at end of file +} From 53d5ea3c6380040ccc2200cac5bea47d40d1300f Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Tue, 6 Apr 2021 09:47:10 +0200 Subject: [PATCH 4/5] Update deployments.md --- doc/repo/deployments.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/repo/deployments.md b/doc/repo/deployments.md index 740bac4dd0c..8c2ae1a8675 100644 --- a/doc/repo/deployments.md +++ b/doc/repo/deployments.md @@ -21,7 +21,7 @@ $deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api', arra $deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id); ``` -#### Create a new deployments. +#### Create a new deployment. The `ref` parameter is required. @@ -31,9 +31,19 @@ $data = $client->api('deployment')->create('KnpLabs', 'php-github-api', array('r Please note that once a deployment is created it cannot be edited. Only status updates can be created. +#### Delete a existing deployment. + +```php +$deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id); +``` + +Please note that a deployment can only be deleted when in inactive state. +Consider transitioning the status to `inactive` beforehand using `updateStatus`. + + #### Create a new status update. -The `state` parameter is required. At the time of writing, this must be pending, success, error, or failure. +The `state` parameter is required. At the time of writing, this must be pending, queued, in_progress, success, inactive, error, or failure. ```php $data = $client->api('deployment')->updateStatus('KnpLabs', 'php-github-api', 1, array('state' => 'error', 'description' => 'syntax error')); From fc3e323701779fe3db2ef307d2cbdabc858f7b68 Mon Sep 17 00:00:00 2001 From: Markus Staab <47448731+clxmstaab@users.noreply.github.com> Date: Wed, 7 Apr 2021 09:01:48 +0200 Subject: [PATCH 5/5] removed phpdocs, use native typehints --- lib/Github/Api/Deployment.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Github/Api/Deployment.php b/lib/Github/Api/Deployment.php index 980fedca911..4b880cf2cfa 100644 --- a/lib/Github/Api/Deployment.php +++ b/lib/Github/Api/Deployment.php @@ -74,13 +74,9 @@ public function create($username, $repository, array $params) * Important: Deployments can only be deleted when in inactive state * @see updateStatus * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param int $id the id of the deployment - * * @return mixed null on success, array on error with 'message' */ - public function remove($username, $repository, $id) + public function remove(string $username, string $repository, int $id) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id); }