Skip to content

Commit 4fa7f3e

Browse files
authored
feature #991 Deployments: added missing 'delete deployment' endpoint (clxmstaab)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- this api endpoint was missing completely from the client. this is the only missing feature in 2.x for me, so it would be really cool this could be merged into 2.x. my php constraints do not allow me to update to 3.x yet. this PR added the endpoint as described in https://docs.github.com/en/rest/reference/repos#delete-a-deployment Commits ------- 095f463 Deployments: added missing 'delete deployment' endpoint 6ee0e0b added test 06787a1 cs 53d5ea3 Update deployments.md fc3e323 removed phpdocs, use native typehints
1 parent e9576a6 commit 4fa7f3e

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

doc/repo/deployments.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $deployments = $client->api('deployment')->all('KnpLabs', 'php-github-api', arra
2121
$deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id);
2222
```
2323

24-
#### Create a new deployments.
24+
#### Create a new deployment.
2525

2626
The `ref` parameter is required.
2727

@@ -31,9 +31,19 @@ $data = $client->api('deployment')->create('KnpLabs', 'php-github-api', array('r
3131

3232
Please note that once a deployment is created it cannot be edited. Only status updates can be created.
3333

34+
#### Delete a existing deployment.
35+
36+
```php
37+
$deployment = $client->api('deployment')->show('KnpLabs', 'php-github-api', $id);
38+
```
39+
40+
Please note that a deployment can only be deleted when in inactive state.
41+
Consider transitioning the status to `inactive` beforehand using `updateStatus`.
42+
43+
3444
#### Create a new status update.
3545

36-
The `state` parameter is required. At the time of writing, this must be pending, success, error, or failure.
46+
The `state` parameter is required. At the time of writing, this must be pending, queued, in_progress, success, inactive, error, or failure.
3747

3848
```php
3949
$data = $client->api('deployment')->updateStatus('KnpLabs', 'php-github-api', 1, array('state' => 'error', 'description' => 'syntax error'));

lib/Github/Api/Deployment.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ public function create($username, $repository, array $params)
6868
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments', $params);
6969
}
7070

71+
/**
72+
* Delete a deployment for the given username and repo.
73+
*
74+
* @link https://docs.github.com/en/rest/reference/repos#delete-a-deployment
75+
*
76+
* Important: Deployments can only be deleted when in inactive state
77+
* @see updateStatus
78+
*
79+
* @return mixed null on success, array on error with 'message'
80+
*/
81+
public function remove(string $username, string $repository, int $id)
82+
{
83+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id);
84+
}
85+
7186
/**
7287
* Updates a deployment by creating a new status update.
7388
*

test/Github/Tests/Api/DeploymentTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function shouldGetAllDeploymentsWithFilterParameters()
5151
/**
5252
* @test
5353
*/
54-
public function shouldShowProject()
54+
public function shouldShowDeployment()
5555
{
5656
$expectedValue = ['id' => 123, 'ref' => 'master'];
5757

@@ -64,6 +64,20 @@ public function shouldShowProject()
6464
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123));
6565
}
6666

67+
/**
68+
* @test
69+
*/
70+
public function shouldDeleteDeployment()
71+
{
72+
$api = $this->getApiMock();
73+
$api->expects($this->once())
74+
->method('delete')
75+
->with('/repos/KnpLabs/php-github-api/deployments/123')
76+
->will($this->returnValue(null));
77+
78+
$this->assertNull($api->remove('KnpLabs', 'php-github-api', 123));
79+
}
80+
6781
/**
6882
* @test
6983
*/

0 commit comments

Comments
 (0)