Skip to content

Commit 9c57106

Browse files
committed
Merge branch '2.x'
* 2.x: Bump 2.x branch alias feature #991 Deployments: added missing 'delete deployment' endpoint (clxmstaab)
2 parents 5c540ae + 6e13e98 commit 9c57106

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"extra": {
5353
"branch-alias": {
54-
"dev-2.x": "2.19.x-dev",
54+
"dev-2.x": "2.20.x-dev",
5555
"dev-master": "3.2.x-dev"
5656
}
5757
}

doc/repo/deployments.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)