Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 19 additions & 0 deletions lib/Github/Api/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ 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
*
* @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.
*
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