Skip to content

Deployments: added missing 'delete deployment' endpoint #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions doc/repo/deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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'));
Expand Down
15 changes: 15 additions & 0 deletions lib/Github/Api/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ 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
*
* @return mixed null on success, array on error with 'message'
*/
public function remove(string $username, string $repository, int $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id);
}

/**
* Updates a deployment by creating a new status update.
*
Expand Down
16 changes: 15 additions & 1 deletion test/Github/Tests/Api/DeploymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function shouldGetAllDeploymentsWithFilterParameters()
/**
* @test
*/
public function shouldShowProject()
public function shouldShowDeployment()
{
$expectedValue = ['id' => 123, 'ref' => 'master'];

Expand All @@ -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
*/
Expand Down