Skip to content

Commit 49e774a

Browse files
committed
Improve checks api implementation
1 parent e1c5dca commit 49e774a

File tree

10 files changed

+486
-2
lines changed

10 files changed

+486
-2
lines changed

doc/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ v3 APIs:
4848
* [Reviews](pull_request/reviews.md)
4949
* [Rate Limits](rate_limits.md)
5050
* [Repositories](repos.md)
51-
* [Checks](repo/checks.md)
51+
* [Check Runs](repo/check_runs.md)
52+
* [Check Suites](repo/check_suites.md)
5253
* [Contents](repo/contents.md)
5354
* [Deployments](repo/deployments.md)
5455
* [Labels](repo/labels.md)

doc/repo/check_runs.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Repo / Checks runs API
2+
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)
3+
4+
### Create a check run
5+
6+
[Visit GitHub for a full of list of parameters and their descriptions.](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run)
7+
8+
```php
9+
$params = [
10+
'name' => 'my check', # required
11+
'head_sha' => $commitSha, # required
12+
'status' => 'queued',
13+
'output' => [/*...*/]
14+
];
15+
$check = $client->api('repo')->checkRuns()->create('KnpLabs', 'php-github-api', $params);
16+
```
17+
18+
### Get a check run
19+
20+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-run
21+
22+
```php
23+
$check = $client->api('repo')->checkRuns()->show('KnpLabs', 'php-github-api', $checkRunId);
24+
```
25+
26+
### Update an existing check run
27+
28+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-a-check-run
29+
30+
```php
31+
$params = [
32+
'name' => 'my check',
33+
'status' => 'in_progress',
34+
'output' => [/*...*/]
35+
];
36+
$check = $client->api('repo')->checkRuns()->update('KnpLabs', 'php-github-api', $checkRunId, $params);
37+
```
38+
39+
### List check run annotations
40+
41+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations
42+
43+
```php
44+
$annotations = $client->api('repo')->checkRuns()->annotations('KnpLabs', 'php-github-api', $checkRunId);
45+
```
46+
47+
### List check runs for a check suite
48+
49+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-in-a-check-suite
50+
51+
```php
52+
$params = [/*...*/];
53+
$checks = $client->api('repo')->checkRuns()->allForCheckSuite('KnpLabs', 'php-github-api', $checkSuiteId, $params);
54+
```
55+
56+
### List check runs for a Git reference
57+
58+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-for-a-git-reference
59+
60+
```php
61+
$params = [/*...*/];
62+
$checks = $client->api('repo')->checkRuns()->allForReference('KnpLabs', 'php-github-api', $reference, $params);
63+
```
64+
65+
66+
67+

doc/repo/check_suites.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Repo / Check suites API
2+
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)
3+
4+
### Create a check suite
5+
6+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-suite
7+
8+
```php
9+
$params = [
10+
'head_sha' => $commitSha, # required
11+
];
12+
$check = $client->api('repo')->checkSuites()->create('KnpLabs', 'php-github-api', $params);
13+
```
14+
15+
### Update check suite preferences
16+
17+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-repository-preferences-for-check-suites
18+
19+
```php
20+
$params = [/*...*/];
21+
$check = $client->api('repo')->checkSuites()->updatePreferences('KnpLabs', 'php-github-api', $params);
22+
```
23+
24+
### Get a check suite
25+
26+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-suite
27+
28+
```php
29+
$check = $client->api('repo')->checkSuites()->getCheckSuite('KnpLabs', 'php-github-api', $checkSuiteId);
30+
```
31+
32+
### Rerequest a check suite
33+
34+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#rerequest-a-check-suite
35+
36+
```php
37+
$annotations = $client->api('repo')->checkSuites()->rerequest('KnpLabs', 'php-github-api', $checkSuiteId);
38+
```
39+
40+
41+
### List check suites for a Git reference
42+
43+
https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-suites-for-a-git-reference
44+
45+
```php
46+
$params = [/*...*/];
47+
$checks = $client->api('repo')->checkSuites()->allForReference('KnpLabs', 'php-github-api', $reference, $params);
48+
```

doc/repo/checks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Repo / Checks API
22
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)
33

4+
**This API class is deprecated use the [Check runs](check_runs.md) and the [Check suites](check_suites.md) api classes.**
5+
46
### Create a check for a commit
57

68
[Visit GitHub for a full of list of parameters and their descriptions.](https://developer.github.com/v3/checks/runs/#create-a-check-run)

lib/Github/Api/Repo.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Github\Api;
44

55
use Github\Api\Repository\Checks;
6+
use Github\Api\Repository\Checks\CheckRuns;
7+
use Github\Api\Repository\Checks\CheckSuites;
68
use Github\Api\Repository\Collaborators;
79
use Github\Api\Repository\Comments;
810
use Github\Api\Repository\Commits;
@@ -335,14 +337,33 @@ public function commits()
335337
* Manage checks on a repository.
336338
*
337339
* @link https://developer.github.com/v3/checks/
340+
* @deprecated since 2.17 and will be removed in 3.0. Use the "checkRuns" or "checkSuites" api's instead.
338341
*
339342
* @return Checks
340343
*/
341344
public function checks()
342345
{
346+
@trigger_error(sprintf('The "%s" is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "checkRuns" or "checkSuites" api\'s instead.', __METHOD__), E_USER_DEPRECATED);
347+
343348
return new Checks($this->client);
344349
}
345350

351+
/**
352+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-runs
353+
*/
354+
public function checkRuns(): CheckRuns
355+
{
356+
return new CheckRuns($this->client);
357+
}
358+
359+
/**
360+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#check-suites
361+
*/
362+
public function checkSuites(): CheckSuites
363+
{
364+
return new CheckSuites($this->client);
365+
}
366+
346367
/**
347368
* Manage the content of a repository.
348369
*

lib/Github/Api/Repository/Checks.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use Github\Exception\MissingArgumentException;
88

99
/**
10-
* @link https://developer.github.com/v3/checks/
10+
* @link https://developer.github.com/v3/checks/
11+
* @deprecated since 2.17 and will be removed in 3.0. Use the "Github\Api\Repository\Checks\CheckRuns" or "Github\Api\Repository\Checks\CheckSuits" api classes instead.
1112
*
1213
* @author Zack Galbreath <zack.galbreath@kitware.com>
1314
*/
@@ -29,6 +30,8 @@ class Checks extends AbstractApi
2930
*/
3031
public function create($username, $repository, array $params = [])
3132
{
33+
@trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::create" method instead.', __METHOD__), E_USER_DEPRECATED);
34+
3235
if (!isset($params['name'], $params['head_sha'])) {
3336
throw new MissingArgumentException(['name', 'head_sha']);
3437
}
@@ -48,6 +51,8 @@ public function create($username, $repository, array $params = [])
4851
*/
4952
public function update($username, $repository, $checkRunId, array $params = [])
5053
{
54+
@trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::update" method instead.', __METHOD__), E_USER_DEPRECATED);
55+
5156
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId), $params);
5257
}
5358

@@ -63,6 +68,8 @@ public function update($username, $repository, $checkRunId, array $params = [])
6368
*/
6469
public function all($username, $repository, $ref, $params = [])
6570
{
71+
@trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::allForReference" method instead.', __METHOD__), E_USER_DEPRECATED);
72+
6673
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params);
6774
}
6875

@@ -77,6 +84,8 @@ public function all($username, $repository, $ref, $params = [])
7784
*/
7885
public function show($username, $repository, $checkRunId)
7986
{
87+
@trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::show" method instead.', __METHOD__), E_USER_DEPRECATED);
88+
8089
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId));
8190
}
8291

@@ -91,6 +100,8 @@ public function show($username, $repository, $checkRunId)
91100
*/
92101
public function annotations($username, $repository, $checkRunId)
93102
{
103+
@trigger_error(sprintf('The "%s" method is deprecated since knp-labs/php-github-api 2.17 and will be removed in knp-labs/php-github-api 3.0. Use the "Github\Api\Repository\Checks\CheckRuns::annotations" method instead.', __METHOD__), E_USER_DEPRECATED);
104+
94105
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.rawurlencode($checkRunId).'/annotations');
95106
}
96107
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace Github\Api\Repository\Checks;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks
9+
*/
10+
class CheckRuns extends AbstractApi
11+
{
12+
/**
13+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-run
14+
*
15+
* @return array
16+
*/
17+
public function create(string $username, string $repository, array $params = [])
18+
{
19+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs', $params);
20+
}
21+
22+
/**
23+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-run
24+
*
25+
* @return array
26+
*/
27+
public function show(string $username, string $repository, int $checkRunId)
28+
{
29+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId);
30+
}
31+
32+
/**
33+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-a-check-run
34+
*
35+
* @return array
36+
*/
37+
public function update(string $username, string $repository, int $checkRunId, array $params = [])
38+
{
39+
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId, $params);
40+
}
41+
42+
/**
43+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-run-annotations
44+
*
45+
* @return array
46+
*/
47+
public function annotations(string $username, string $repository, int $checkRunId)
48+
{
49+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-runs/'.$checkRunId.'/annotations');
50+
}
51+
52+
/**
53+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-in-a-check-suite
54+
*
55+
* @return array
56+
*/
57+
public function allForCheckSuite(string $username, string $repository, int $checkSuiteId, array $params = [])
58+
{
59+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId.'/check-runs', $params);
60+
}
61+
62+
/**
63+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-runs-for-a-git-reference
64+
*
65+
* @return array
66+
*/
67+
public function allForReference(string $username, string $repository, string $ref, array $params = [])
68+
{
69+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-runs', $params);
70+
}
71+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Github\Api\Repository\Checks;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks
9+
*/
10+
class CheckSuites extends AbstractApi
11+
{
12+
/**
13+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#create-a-check-suite
14+
*
15+
* @return array
16+
*/
17+
public function create(string $username, string $repository, array $params = [])
18+
{
19+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites', $params);
20+
}
21+
22+
/**
23+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#update-repository-preferences-for-check-suites
24+
*
25+
* @return array
26+
*/
27+
public function updatePreferences(string $username, string $repository, array $params = [])
28+
{
29+
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/preferences', $params);
30+
}
31+
32+
/**
33+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#get-a-check-suite
34+
*
35+
* @return array
36+
*/
37+
public function getCheckSuite(string $username, string $repository, int $checkSuiteId)
38+
{
39+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId);
40+
}
41+
42+
/**
43+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#rerequest-a-check-suite
44+
*
45+
* @return array
46+
*/
47+
public function rerequest(string $username, string $repository, int $checkSuiteId)
48+
{
49+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/check-suites/'.$checkSuiteId.'/rerequest');
50+
}
51+
52+
/**
53+
* @link https://docs.github.com/en/free-pro-team@latest/rest/reference/checks#list-check-suites-for-a-git-reference
54+
*
55+
* @return array
56+
*/
57+
public function allForReference(string $username, string $repository, string $ref, array $params = [])
58+
{
59+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/commits/'.rawurlencode($ref).'/check-suites', $params);
60+
}
61+
}

0 commit comments

Comments
 (0)