From 3d50b433dbb825bd1dab3261d40c99f09b6686cb Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Wed, 22 Apr 2020 13:52:58 -0700 Subject: [PATCH 1/3] add additional check run methods --- doc/repo/checks.md | 33 ++++++++++++++++-- lib/Github/Api/Repository/Checks.php | 52 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/doc/repo/checks.md b/doc/repo/checks.md index 04cd6144bf7..3e24d9b4868 100644 --- a/doc/repo/checks.md +++ b/doc/repo/checks.md @@ -13,7 +13,7 @@ $params = [ 'details_url' => 'https://nimbleci.com/...', 'output' => {...} ]; -$checks = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $params); +$check = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $params); ``` ### Update an existing check on a commit @@ -27,5 +27,34 @@ $params = [ 'details_url' => 'https://nimbleci.com/...', 'output' => {...} ]; -$checks = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $checkRunId, $params); +$check = $client->api('repo')->checks()->create('NimbleCI', 'docker-web-tester-behat', $checkRunId, $params); +``` + +### List check runs for a Git reference + +https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-git-reference + +```php +$params = [ + 'check_name' => 'my check', + 'status' => 'completed', + 'filter' => 'latest', +]; +$checks = $client->api('repo')->checks()->all('NimbleCI', 'docker-web-tester-behat', $ref, $params); +``` + +### Get a check run + +https://developer.github.com/v3/checks/runs/#get-a-check-run + +```php +$check = $client->api('repo')->checks()->show('NimbleCI', 'docker-web-tester-behat', $checkRunId); +``` + +### List check run annotations + +https://developer.github.com/v3/checks/runs/#list-check-run-annotations + +```php +$annotations = $client->api('repo')->checks()->annotations('NimbleCI', 'docker-web-tester-behat', $checkRunId); ``` diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php index fcc7059d2d5..0491b82a473 100644 --- a/lib/Github/Api/Repository/Checks.php +++ b/lib/Github/Api/Repository/Checks.php @@ -55,4 +55,56 @@ public function update($username, $repository, $checkRunId, array $params = []) return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId), $params); } + + /** + * @link https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-git-reference + * + * @param string $username + * @param string $repository + * @param string $ref + * @param array $params + * + * @return array + */ + public function all($username, $repository, $ref, $params = []) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); + } + + /** + * @link https://developer.github.com/v3/checks/runs/#get-a-check-run + * + * @param string $username + * @param string $repository + * @param string $checkRunId + * + * @return array + */ + public function show($username, $repository, $checkRunId) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId)); + } + + /** + * @link https://developer.github.com/v3/checks/runs/#list-check-run-annotations + * + * @param string $username + * @param string $repository + * @param string $checkRunId + * + * @return array + */ + public function annotations($username, $repository, $checkRunId) + { + // This api is in preview mode, so set the correct accept-header. + $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; + + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); + } } From 6b50566f5da7b2ec2a5b9690cf5636d6912369ba Mon Sep 17 00:00:00 2001 From: Bob Eagan Date: Wed, 22 Apr 2020 13:56:47 -0700 Subject: [PATCH 2/3] fix patch to get --- lib/Github/Api/Repository/Checks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Repository/Checks.php b/lib/Github/Api/Repository/Checks.php index 0491b82a473..35724a7d112 100644 --- a/lib/Github/Api/Repository/Checks.php +++ b/lib/Github/Api/Repository/Checks.php @@ -71,7 +71,7 @@ public function all($username, $repository, $ref, $params = []) // This api is in preview mode, so set the correct accept-header. $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params); } /** @@ -88,7 +88,7 @@ public function show($username, $repository, $checkRunId) // This api is in preview mode, so set the correct accept-header. $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId)); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId)); } /** @@ -105,6 +105,6 @@ public function annotations($username, $repository, $checkRunId) // This api is in preview mode, so set the correct accept-header. $this->acceptHeaderValue = 'application/vnd.github.antiope-preview+json'; - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); } } From fb030b4598f68703175337d4b8cae4bf14c31ce7 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sat, 11 Jul 2020 17:35:01 +0200 Subject: [PATCH 3/3] Add tests --- .../Tests/Api/Repository/ChecksTest.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/Github/Tests/Api/Repository/ChecksTest.php b/test/Github/Tests/Api/Repository/ChecksTest.php index dcc0883d8d7..6db5695842c 100644 --- a/test/Github/Tests/Api/Repository/ChecksTest.php +++ b/test/Github/Tests/Api/Repository/ChecksTest.php @@ -71,6 +71,45 @@ public function shouldUpdateCheck() $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', '123', $data)); } + /** + * @test + */ + public function shouldGetAllChecksForRef() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/commits/cb4abc15424c0015b4468d73df55efb8b60a4a3d/check-runs'); + + $api->all('KnpLabs', 'php-github-api', 'cb4abc15424c0015b4468d73df55efb8b60a4a3d'); + } + + /** + * @test + */ + public function shouldShowSingleCheckRun() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/check-runs/14'); + + $api->show('KnpLabs', 'php-github-api', 14); + } + + /** + * @test + */ + public function shouldListCheckRunAnnotations() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/check-runs/14/annotations'); + + $api->annotations('KnpLabs', 'php-github-api', 14); + } + /** * @return string */