8000 Get detailed commit from branch by WyriHaximus · Pull Request #60 · php-api-clients/github · GitHub
[go: up one dir, main page]

Skip to content

Get detailed commit from branch #60

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
7 changes: 5 additions & 2 deletions examples/user-repositories-branches-async.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
return $user->repository($argv[2] ?? 'github');
})->then(function (Repository $repository) {
resource_pretty_print($repository, 1, true);
$repository->branches()->subscribe(function ($labels) {
resource_pretty_print($labels, 2, true);
$repository->branches()->subscribe(function (Repository\Branch $branch) {
resource_pretty_print($branch, 2, true);
$branch->detailedCommit()->then(function (Repository\Commit $commit) {
resource_pretty_print($commit);
})->done(null, 'display_throwable');
}, function ($error) {
echo (string)$error;
});
Expand Down
47 changes: 47 additions & 0 deletions src/CommandBus/Command/Repository/DetailedCommitCommand.php
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types=1);

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

use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;

/**
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\DetailedCommitHandler")
*/
final class DetailedCommitCommand
{
/**
* @var string
*/
private $fullName;

/**
* @var string
*/
private $sha;

/**
* @param string $fullName
* @param string $sha
*/
public function __construct(string $fullName, string $sha)
{
$this->fullName = $fullName;
$this->sha = $sha;
}

/**
* @return string
*/
public function getFullName(): string
{
return $this->fullName;
}

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

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

use ApiClients\Client\Github\CommandBus\Command\Repository\DetailedCommitCommand;
use ApiClients\Client\Github\Resource\Repository\CommitInterface;
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
use React\Promise\PromiseInterface;

final class DetailedCommitHandler
{
/**
* @var FetchAndHydrateService
*/
private $fetchAndHydrateService;

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

/**
* @param DetailedCommitCommand $command
* @return PromiseInterface
*/
public function handle(DetailedCommitCommand $command): PromiseInterface
{
return $this->fetchAndHydrateService->fetch(
'repos/' . $command->getFullName() . '/commits/' . $command->getSha(),
'',
CommitInterface::HYDRATE_CLASS
);
}
}
10 changes: 10 additions & 0 deletions src/Resource/Async/Repository/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

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

use ApiClients\Client\Github\CommandBus\Command\Repository\DetailedCommitCommand;
use ApiClients\Client\Github\Resource\Repository\Branch as BaseBranch;
use React\Promise\PromiseInterface;

class Branch extends BaseBranch
{
public function refresh(): Branch
{
throw new \Exception('TODO: create refresh method!');
}

public function detailedCommit(): PromiseInterface
{
return $this->handleCommand(new DetailedCommitCommand(
\str_replace('/branches/' . $this->name . '/protection', '', \explode('/repos/', $this->protection_url)[1]),
$this->commit->sha()
));
}
}
0