From 1226c9ab79a9de7759e94db6047c903c9c1acbaf Mon Sep 17 00:00:00 2001 From: Martin Parsiegla Date: Sat, 17 Aug 2024 19:05:16 +0200 Subject: [PATCH] Add API to rerequest a check run This change adds a new method to rerequest a check run (see also https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#rerequest-a-check-run). --- doc/repo/check_runs.md | 6 +++++- lib/Github/Api/Repository/Checks/CheckRuns.php | 10 ++++++++++ .../Tests/Api/Repository/Checks/CheckRunsTest.php | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/repo/check_runs.md b/doc/repo/check_runs.md index b0aa4926691..3b7b69b8f86 100644 --- a/doc/repo/check_runs.md +++ b/doc/repo/check_runs.md @@ -62,6 +62,10 @@ $params = [/*...*/]; $checks = $client->api('repo')->checkRuns()->allForReference('KnpLabs', 'php-github-api', $reference, $params); ``` +### Rerequest a check run +https://docs.github.com/en/rest/reference/checks#rerequest-a-check-run - +```php +$checks = $client->api('repo')->checkRuns()->rerequest('KnpLabs', 'php-github-api', $checkRunId); +``` diff --git a/lib/Github/Api/Repository/Checks/CheckRuns.php b/lib/Github/Api/Repository/Checks/CheckRuns.php index 37968a01816..1ddee3770c8 100644 --- a/lib/Github/Api/Repository/Checks/CheckRuns.php +++ b/lib/Github/Api/Repository/Checks/CheckRuns.php @@ -83,4 +83,14 @@ public function allForReference(string $username, string $repository, string $re return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); } + + /** + * @link https://docs.github.com/en/rest/reference/checks#rerequest-a-check-run + * + * @return array + */ + public function rerequest(string $username, string $repository, int $checkRunId) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId.'/rerequest'); + } } diff --git a/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php b/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php index 4b7ff086ec5..66bb5277c4b 100644 --- a/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php +++ b/test/Github/Tests/Api/Repository/Checks/CheckRunsTest.php @@ -102,6 +102,20 @@ public function shouldGetAllChecksForReference() $api->allForReference('KnpLabs', 'php-github-api', 'cb4abc15424c0015b4468d73df55efb8b60a4a3d', $params); } + /** + * @test + */ + public function shouldRerequestCheckRun() + { + /** @var CheckRuns|MockObject $api */ + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/check-runs/123/rerequest'); + + $api->rerequest('KnpLabs', 'php-github-api', 123); + } + protected function getApiClass(): string { return CheckRuns::class;