From b987f199040136ff046d29ecea65bfa24161ea69 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 13 May 2021 09:44:05 +0200 Subject: [PATCH 1/3] Add endpoint for approve workflow run --- doc/repo/actions/workflow_runs.md | 8 ++++++++ .../Api/Repository/Actions/WorkflowRuns.php | 16 ++++++++++++++++ .../Repository/Actions/WorkflowRunsTest.php | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/doc/repo/actions/workflow_runs.md b/doc/repo/actions/workflow_runs.md index 59b09f4c657..4b879ca5b98 100644 --- a/doc/repo/actions/workflow_runs.md +++ b/doc/repo/actions/workflow_runs.md @@ -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); +``` diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php index 06d3e559605..dc78c249143 100644 --- a/lib/Github/Api/Repository/Actions/WorkflowRuns.php +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -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->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/approve'); + } } diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php index 27155148ce0..42ebcd18f3f 100644 --- a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php @@ -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->assertEquals($expectedValue, $api->approve('KnpLabs', 'php-github-api', 374473304)); + } + protected function getApiClass() { return WorkflowRuns::class; From cd1b74b29af669cb26faebcfbbeebb40f55a3b83 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 13 May 2021 09:49:48 +0200 Subject: [PATCH 2/3] Bugfix --- lib/Github/Api/Repository/Actions/WorkflowRuns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Repository/Actions/WorkflowRuns.php b/lib/Github/Api/Repository/Actions/WorkflowRuns.php index dc78c249143..d6f95f1ed94 100644 --- a/lib/Github/Api/Repository/Actions/WorkflowRuns.php +++ b/lib/Github/Api/Repository/Actions/WorkflowRuns.php @@ -150,6 +150,6 @@ public function deleteLogs(string $username, string $repository, int $runId) */ public function approve(string $username, string $repository, int $runId) { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/approve'); + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/runs/'.$runId.'/approve'); } } From ec0ae3b6106c0976354f031aa592c6a56adb2d13 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Thu, 20 May 2021 10:42:32 +0200 Subject: [PATCH 3/3] Use asertSame() --- test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php index 42ebcd18f3f..1c5af0badc9 100644 --- a/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php +++ b/test/Github/Tests/Api/Repository/Actions/WorkflowRunsTest.php @@ -213,7 +213,7 @@ public function shouldApproveWorkflowRunLogs() ->with('/repos/KnpLabs/php-github-api/actions/runs/374473304/approve') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->approve('KnpLabs', 'php-github-api', 374473304)); + $this->assertSame($expectedValue, $api->approve('KnpLabs', 'php-github-api', 374473304)); } protected function getApiClass()