Skip to content

Commit 46e9538

Browse files
authored
feature #1006 Add endpoint for approve workflow run (Nyholm)
This PR was squashed before being merged into the 3.3.x-dev branch. Discussion ---------- See https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request Commits ------- b987f19 Add endpoint for approve workflow run cd1b74b Bugfix ec0ae3b Use asertSame()
1 parent 91f2aa4 commit 46e9538

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

doc/repo/actions/workflow_runs.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ https://docs.github.com/en/rest/reference/actions#delete-workflow-run-logs
7474
```php
7575
$client->api('repo')->workflowRuns()->deleteLogs('KnpLabs', 'php-github-api', $runId);
7676
```
77+
78+
### Approve workflow run
79+
80+
https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request
81+
82+
```php
83+
$client->api('repo')->workflowRuns()->approve('KnpLabs', 'php-github-api', $runId);
84+
```

lib/Github/Api/Repository/Actions/WorkflowRuns.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,20 @@ public function deleteLogs(string $username, string $repository, int $runId)
136136
{
137137
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/logs');
138138
}
139+
140+
/**
141+
* @link https://docs.github.com/en/rest/reference/actions#approve-a-workflow-run-for-a-fork-pull-request
142+
*
143+
* @param string $username
144+
* @param string $repository
145+
* @param int $runId
146+
*
147+
* @return array|string
148+
*
149+
* @experimental This endpoint is currently in beta.
150+
*/
151+
public function approve(string $username, string $repository, int $runId)
152+
{
153+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/approve');
154+
}
139155
}

test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ public function shouldDeleteWorkflowRunLogs()
198198
$this->assertEquals($expectedValue, $api->deleteLogs('KnpLabs', 'php-github-api', 374473304));
199199
}
200200

201+
/**
202+
* @test
203+
*/
204+
public function shouldApproveWorkflowRunLogs()
205+
{
206+
$expectedValue = 'response';
207+
208+
/** @var WorkflowRuns|MockObject $api */
209+
$api = $this->getApiMock();
210+
211+
$api->expects($this->once())
212+
->method('post')
213+
->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/approve')
214+
->will($this->returnValue($expectedValue));
215+
216+
$this->assertSame($expectedValue, $api->approve('KnpLabs', 'php-github-api', 374473304));
217+
}
218+
201219
protected function getApiClass()
202220
{
203221
return WorkflowRuns::class;

0 commit comments

Comments
 (0)