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..35724a7d112 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->get('/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->get('/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->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations'); + } } 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 */