Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional check run methods #865

Merged
merged 3 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions doc/repo/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
```
52 changes: 52 additions & 0 deletions lib/Github/Api/Repository/Checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
39 changes: 39 additions & 0 deletions test/Github/Tests/Api/Repository/ChecksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down