Skip to content

Commit 713592b

Browse files
authored
Merge pull request #63 from php-api-clients/fetch-check-runs
Basic check (runs) support
2 parents a432b79 + 361a65d commit 713592b

File tree

13 files changed

+643
-0
lines changed

13 files changed

+643
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types=1);
2+
use ApiClients\Client\Github\AsyncClient;
3+
use ApiClients\Client\Github\Resource\Async\Repository;
4+
use ApiClients\Client\Github\Resource\Async\User;
5+
use function ApiClients\Foundation\resource_pretty_print;
6+
use React\EventLoop\Factory;
7+
8+
require \dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'vendor/autoload.php';
9+
10+
$loop = Factory::create();
11+
12+
$client = AsyncClient::create($loop, require 'resolve_token.php');
13+
14+
$client->user($argv[1] ?? 'php-api-clients')->then(function (User $user) use ($argv) {
15+
resource_pretty_print($user);
16+
17+
return $user->repository($argv[2] ?? 'github');
18+
})->then(function (Repository $repository) {
19+
resource_pretty_print($repository, 1, true);
20+
$repository->commits()->take(1)->flatMap(function (Repository\Commit $commit) {
21+
resource_pretty_print($commit, 2, true);
22+
23+
return $commit->checks();
24+
})->subscribe(function (Repository\Commit\Check $check) {
25+
resource_pretty_print($check, 3, true);
26+
}, 'display_throwable');
27+
})->done(null, 'display_throwable');
28+
29+
$loop->run();
30+
31+
displayState($client->getRateLimitState());

src/AcceptHeader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
final class AcceptHeader
66
{
77
const PRESET_DEFAULT = [
8+
self::CHECK_RUNS,
89
self::LICENSE,
910
self::TOPICS,
1011
self::DEFAULT,
@@ -27,6 +28,9 @@ final class AcceptHeader
2728
// Topics on repository object: https://developer.github.com/v3/repos/#repositories
2829
const TOPICS = 'application/vnd.github.mercy-preview+json';
2930

31+
// Topics on repository object: https://developer.github.com/v3/repos/#repositories
32+
const CHECK_RUNS = 'application/vnd.github.antiope-preview+json';
33+
3034
public static function getHeader(array $chunks): string
3135
{
3236
return \implode('; ', $chunks);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Command\Repository\Commit;
4+
5+
use ApiClients\Client\Github\Resource\Async\Repository\Commit;
6+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
7+
8+
/**
9+
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\Commit\ChecksHandler")
10+
*/
11+
final class ChecksCommand
12+
{
13+
/**
14+
* @var Commit
15+
*/
16+
private $commit;
17+
18+
/**
19+
* @param Commit $commit
20+
*/
21+
public function __construct(Commit $commit)
22+
{
23+
$this->commit = $commit;
24+
}
25+
26+
/**
27+
* @return Commit
28+
*/
29+
public function getCommit(): Commit
30+
{
31+
return $this->commit;
32+
}
33+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Handler\Repository\Commit;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\ChecksCommand;
6+
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\StatusesCommand;
7+
use ApiClients\Client\Github\Resource\Repository\Commit\CheckInterface;
8+
use ApiClients\Client\Github\Resource\Repository\Commit\StatusInterface;
9+
use ApiClients\Client\Github\Service\IteratePagesService;
10+
use ApiClients\Foundation\Hydrator\Hydrator;
11+
use ApiClients\Tools\Services\Client\FetchAndIterateService;
12+
use function ApiClients\Tools\Rx\observableFromArray;
13+
use React\Promise\PromiseInterface;
14+
use function React\Promise\resolve;
15+
16+
final class ChecksHandler
17+
{
18+
/**
19+
* @var FetchAndIterateService
20+
*/
21+
private $fetchAndIterateService;
22+
23+
/**
24+
* @var Hydrator
25+
*/
26+
private $hydrator;
27+
28+
/**
29+
* @param FetchAndIterateService $fetchAndIterateService
30+
* @param Hydrator $hydrator
31+
*/
32+
public function __construct(FetchAndIterateService $fetchAndIterateService, Hydrator $hydrator)
33+
{
34+
$this->fetchAndIterateService = $fetchAndIterateService;
35+
$this->hydrator = $hydrator;
36+
}
37+
38+
/**
39+
* @param ChecksCommand $command
40+
* @return PromiseInterface
41+
*/
42+
public function handle(ChecksCommand $command): PromiseInterface
43+
{
44+
return resolve(
45+
$this->fetchAndIterateService->iterate(
46+
$command->getCommit()->url() . '/check-runs',
47+
'check_runs',
48+
CheckInterface::HYDRATE_CLASS
49+
)
50+
);
51+
}
52+
}

src/Resource/Async/Repository/Commit.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ApiClients\Client\Github\Resource\Async\Repository;
44

55
use ApiClients\Client\Github\CommandBus\Command\RefreshCommand;
6+
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\ChecksCommand;
67
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\CreateStatusCommand;
78
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\StatusCommand;
89
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\StatusesCommand;
@@ -34,6 +35,13 @@ public function statuses(): ObservableInterface
3435
));
3536
}
3637

38+
public function checks(): ObservableInterface
39+
{
40+
return unwrapObservableFromPromise($this->handleCommand(
41+
new ChecksCommand($this)
42+
));
43+
}
44+
3745
public function createStatus(string $state, ?string $targetUrl = null, ?string $description = null, ?string $context = null): PromiseInterface
3846
{
3947
return $this->handleCommand(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async\Repository\Commit;
4+
5+
use ApiClients\Client\Github\Resource\Repository\Commit\Check as BaseCheck;
6+
7+
class Check extends BaseCheck
8+
{
9+
public function refresh(): Check
10+
{
11+
throw new \Exception('TODO: create refresh method!');
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async\Repository\Commit;
4+
5+
use ApiClients\Client\Github\Resource\Repository\Commit\EmptyCheck as BaseEmptyCheck;
6+
7+
class EmptyCheck extends BaseEmptyCheck
8+
{
9+
}

0 commit comments

Comments
 (0)