Skip to content

Add endpoint for approve workflow run #1006

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 3 commits into from
May 20, 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
8 changes: 8 additions & 0 deletions doc/repo/actions/workflow_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ https://docs.github.com/en/rest/reference/actions#delete-workflow-run-logs
```php
$client->api('repo')->workflowRuns()->deleteLogs('KnpLabs', 'php-github-api', $runId);
```

### Approve workflow run

https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request

```php
$client->api('repo')->workflowRuns()->approve('KnpLabs', 'php-github-api', $runId);
```
16 changes: 16 additions & 0 deletions lib/Github/Api/Repository/Actions/WorkflowRuns.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,20 @@ public function deleteLogs(string $username, string $repository, int $runId)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs');
}

/**
* @link https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request
*
* @param string $username
* @param string $repository
* @param int $runId
*
* @return array|string
*
* @experimental This endpoint is currently in beta.
*/
public function approve(string $username, string $repository, int $runId)
{
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/approve');
}
}
18 changes: 18 additions & 0 deletions test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ public function shouldDeleteWorkflowRunLogs()
$this->assertEquals($expectedValue, $api->deleteLogs('KnpLabs', 'php-github-api', 374473304));
}

/**
* @test
*/
public function shouldApproveWorkflowRunLogs()
{
$expectedValue = 'response';

/** @var WorkflowRuns|MockObject $api */
$api = $this->getApiMock();

$api->expects($this->once())
->method('post')
->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/approve')
->will($this->returnValue($expectedValue));

$this->assertSame($expectedValue, $api->approve('KnpLabs', 'php-github-api', 374473304));
}

protected function getApiClass()
{
return WorkflowRuns::class;
Expand Down