Skip to content

Basic check (runs) support #63

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

Merged
merged 1 commit into from
Oct 12, 2019
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
31 changes: 31 additions & 0 deletions examples/user-repositories-commit-checks-async.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);
use ApiClients\Client\Github\AsyncClient;
use ApiClients\Client\Github\Resource\Async\Repository;
use ApiClients\Client\Github\Resource\Async\User;
use function ApiClients\Foundation\resource_pretty_print;
use React\EventLoop\Factory;

require \dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'vendor/autoload.php';

$loop = Factory::create();

$client = AsyncClient::create($loop, require 'resolve_token.php');

$client->user($argv[1] ?? 'php-api-clients')->then(function (User $user) use ($argv) {
resource_pretty_print($user);

return $user->repository($argv[2] ?? 'github');
})->then(function (Repository $repository) {
resource_pretty_print($repository, 1, true);
$repository->commits()->take(1)->flatMap(function (Repository\Commit $commit) {
resource_pretty_print($commit, 2, true);

return $commit->checks();
})->subscribe(function (Repository\Commit\Check $check) {
resource_pretty_print($check, 3, true);
}, 'display_throwable');
})->done(null, 'display_throwable');

$loop->run();

displayState($client->getRateLimitState());
4 changes: 4 additions & 0 deletions src/AcceptHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
final class AcceptHeader
{
const PRESET_DEFAULT = [
self::CHECK_RUNS,
self::LICENSE,
self::TOPICS,
self::DEFAULT,
Expand All @@ -27,6 +28,9 @@ final class AcceptHeader
// Topics on repository object: https://developer.github.com/v3/repos/#repositories
const TOPICS = 'application/vnd.github.mercy-preview+json';

// Topics on repository object: https://developer.github.com/v3/repos/#repositories
const CHECK_RUNS = 'application/vnd.github.antiope-preview+json';

public static function getHeader(array $chunks): string
{
return \implode('; ', $chunks);
Expand Down
33 changes: 33 additions & 0 deletions src/CommandBus/Command/Repository/Commit/ChecksCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Command\Repository\Commit;

use ApiClients\Client\Github\Resource\Async\Repository\Commit;
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;

/**
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\Commit\ChecksHandler")
*/
final class ChecksCommand
{
/**
* @var Commit
*/
private $commit;

/**
* @param Commit $commit
*/
public function __construct(Commit $commit)
{
$this->commit = $commit;
}

/**
* @return Commit
*/
public function getCommit(): Commit
{
return $this->commit;
}
}
52 changes: 52 additions & 0 deletions src/CommandBus/Handler/Repository/Commit/ChecksHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Handler\Repository\Commit;

use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\ChecksCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\StatusesCommand;
use ApiClients\Client\Github\Resource\Repository\Commit\CheckInterface;
use ApiClients\Client\Github\Resource\Repository\Commit\StatusInterface;
use ApiClients\Client\Github\Service\IteratePagesService;
use ApiClients\Foundation\Hydrator\Hydrator;
use ApiClients\Tools\Services\Client\FetchAndIterateService;
use function ApiClients\Tools\Rx\observableFromArray;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

final class ChecksHandler
{
/**
* @var FetchAndIterateService
*/
private $fetchAndIterateService;

/**
* @var Hydrator
*/
private $hydrator;

/**
* @param FetchAndIterateService $fetchAndIterateService
* @param Hydrator $hydrator
*/
public function __construct(FetchAndIterateService $fetchAndIterateService, Hydrator $hydrator)
{
$this->fetchAndIterateService = $fetchAndIterateService;
$this->hydrator = $hydrator;
}

/**
* @param ChecksCommand $command
* @return PromiseInterface
*/
public function handle(ChecksCommand $command): PromiseInterface
{
return resolve(
$this->fetchAndIterateService->iterate(
$command->getCommit()->url() . '/check-runs',
'check_runs',
CheckInterface::HYDRATE_CLASS
)
);
}
}
8 changes: 8 additions & 0 deletions src/Resource/Async/Repository/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ApiClients\Client\Github\Resource\Async\Repository;

use ApiClients\Client\Github\CommandBus\Command\RefreshCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\ChecksCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\CreateStatusCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\StatusCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\Commit\StatusesCommand;
Expand Down Expand Up @@ -34,6 +35,13 @@ public function statuses(): ObservableInterface
));
}

public function checks(): ObservableInterface
{
return unwrapObservableFromPromise($this->handleCommand(
new ChecksCommand($this)
));
}

public function createStatus(string $state, ?string $targetUrl = null, ?string $description = null, ?string $context = null): PromiseInterface
{
return $this->handleCommand(
Expand Down
13 changes: 13 additions & 0 deletions src/Resource/Async/Repository/Commit/Check.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Async\Repository\Commit;

use ApiClients\Client\Github\Resource\Repository\Commit\Check as BaseCheck;

class Check extends BaseCheck
{
public function refresh(): Check
{
throw new \Exception('TODO: create refresh method!');
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/Repository/Commit/EmptyCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Async\Repository\Commit;

use ApiClients\Client\Github\Resource\Repository\Commit\EmptyCheck as BaseEmptyCheck;

class EmptyCheck extends BaseEmptyCheck
{
}
Loading