-
Notifications
You must be signed in to change notification settings - Fork 3
Compare commits #67
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
Compare commits #67
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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; | ||
use function React\Promise\all; | ||
|
||
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->compareCommits($argv[3] ?? '1434d8af925bc7f487005595a791d2554102862e', $argv[4] ?? 'HEAD')->then(function (Repository\Compare $compare) { | ||
resource_pretty_print($compare, 2, true); | ||
$compare->refresh()->then(function (Repository\Compare $compare) { | ||
resource_pretty_print($compare, 2, true); | ||
})->done(null, 'display_throwable'); | ||
}, function ($error) { | ||
echo (string)$error; | ||
}); | ||
})->done(null, 'display_throwable'); | ||
|
||
$loop->run(); | ||
|
||
displayState($client->getRateLimitState()); |
54 changes: 54 additions & 0 deletions
54
src/CommandBus/Command/Repository/CompareCommitsCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ApiClients\Client\Github\CommandBus\Command\Repository; | ||
|
||
use ApiClients\Client\Github\Resource\RepositoryInterface; | ||
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler; | ||
|
||
/** | ||
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\CompareCommitsHandler") | ||
*/ | ||
final class CompareCommitsCommand | ||
{ | ||
/** | ||
* @var RepositoryInterface | ||
*/ | ||
private $repository; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $base; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $head; | ||
|
||
/** | ||
* @param RepositoryInterface $repository | ||
* @param string $base | ||
* @param string $head | ||
*/ | ||
public function __construct(RepositoryInterface $repository, string $base, string $head) | ||
{ | ||
$this->repository = $repository; | ||
$this->base = $base; | ||
$this->head = $head; | ||
} | ||
|
||
public function getRepository(): RepositoryInterface | ||
{ | ||
return $this->repository; | ||
} | ||
|
||
public function getBase(): string | ||
{ | ||
return $this->base; | ||
} | ||
|
||
public function getHead(): string | ||
{ | ||
return $this->head; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/CommandBus/Handler/Repository/CompareCommitsHandler.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ApiClients\Client\Github\CommandBus\Handler\Repository; | ||
|
||
use ApiClients\Client\Github\CommandBus\Command\Repository\CompareCommitsCommand; | ||
use ApiClients\Client\Github\Resource\Repository\CompareInterface; | ||
use ApiClients\Tools\Services\Client\FetchAndHydrateService; | ||
use React\Promise\PromiseInterface; | ||
|
||
final class CompareCommitsHandler | ||
{ | ||
/** | ||
* @var FetchAndHydrateService | ||
*/ | ||
private $service; | ||
|
||
/** | ||
* @param FetchAndHydrateService $service | ||
*/ | ||
public function __construct(FetchAndHydrateService $service) | ||
{ | ||
$this->service = $service; | ||
} | ||
|
||
/** | ||
* Fetch the given repository and hydrate it. | ||
* | ||
* @param CompareCommitsCommand $command | ||
* @return PromiseInterface | ||
*/ | ||
public function handle(CompareCommitsCommand $command): PromiseInterface | ||
{ | ||
return $this->service->fetch( | ||
'repos/' . $command->getRepository()->fullName() . '/compare/' . $command->getBase() . '...' . $command->getHead(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line exceeds 120 characters; contains 127 characters |
||
'', | ||
CompareInterface::HYDRATE_CLASS | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ApiClients\Client\Github\Resource\Async\Repository; | ||
|
||
use ApiClients\Client\Github\CommandBus\Command\RefreshCommand; | ||
use ApiClients\Client\Github\Resource\Repository\Compare as BaseCompare; | ||
use React\Promise\PromiseInterface; | ||
|
||
class Compare extends BaseCompare | ||
{ | ||
public function refresh(): PromiseInterface | ||
{ | ||
return $this->handleCommand(new RefreshCommand($this)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
use ApiClients\Client\Github\Resource\Repository\EmptyCompare as BaseEmptyCompare; | ||
|
||
class EmptyCompare extends BaseEmptyCompare | ||
{ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ApiClients\Client\Github\Resource\Repository; | ||
|
||
use ApiClients\Foundation\Hydrator\Annotation\Collection; | ||
use ApiClients\Foundation\Hydrator\Annotation\EmptyResource; | ||
use ApiClients\Foundation\Hydrator\Annotation\Nested; | ||
use ApiClients\Foundation\Resource\AbstractResource; | ||
|
||
/** | ||
* @Collection( | ||
* commits="Repository\Commit", | ||
* files="Repository\Commit\File" | ||
* ) | ||
* @Nested( | ||
* base_commit="Repository\Commit", | ||
* merge_base_commit="Repository\Commit" | ||
* ) | ||
* @EmptyResource("Repository\EmptyCompare") | ||
*/ | ||
abstract class Compare extends AbstractResource implements CompareInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* @var Repository\Commit | ||
*/ | ||
protected $base_commit; | ||
|
||
/** | ||
* @var Repository\Commit | ||
*/ | ||
protected $merge_base_commit; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $status; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $ahead_by; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $behind_by; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $total_commits; | ||
|
||
/** | ||
* @var Repository\Commit | ||
*/ | ||
protected $commits; | ||
|
||
/** | ||
* @var Repository\Commit\File | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function url(): string | ||
{ | ||
return $this->url; | ||
} | ||
|
||
/** | ||
* @return Repository\Commit | ||
*/ | ||
public function baseCommit(): Repository\Commit | ||
{ | ||
return $this->base_commit; | ||
} | ||
|
||
/** | ||
* @return Repository\Commit | ||
*/ | ||
public function mergeBaseCommit(): Repository\Commit | ||
{ | ||
return $this->merge_base_commit; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function status(): string | ||
{ | ||
return $this->status; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function aheadBy(): int | ||
{ | ||
return $this->ahead_by; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function behindBy(): int | ||
{ | ||
return $this->behind_by; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function totalCommits(): int | ||
{ | ||
return $this->total_commits; | ||
} | ||
|
||
/** | ||
* @return Repository\Commit | ||
*/ | ||
public function commits(): Repository\Commit | ||
{ | ||
return $this->commits; | ||
} | ||
|
||
/** | ||
* @return Repository\Commit\File | ||
*/ | ||
public function files(): Repository\Commit\File | ||
{ | ||
return $this->files; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace ApiClients\Client\Github\Resource\Repository; | ||
|
||
use ApiClients\Foundation\Resource\ResourceInterface; | ||
|
||
interface CompareInterface extends ResourceInterface | ||
{ | ||
const HYDRATE_CLASS = 'Repository\\Compare'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function url(): string; | ||
|
||
/** | ||
* @return Repository\Commit | ||
*/ | ||
public function baseCommit(): Repository\Commit; | ||
|
||
/** | ||
* @return Repository\Commit | ||
*/ | ||
public function mergeBaseCommit(): Repository\Commit; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function status(): string; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function aheadBy(): int; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function behindBy(): int; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function totalCommits(): int; | ||
|
||
/** | ||
* @return Repository\Commit | ||
*/ | ||
public function commits(): Repository\Commit; | ||
|
||
/** | ||
* @return Repository\Commit\File | ||
*/ | ||
public function files(): Repository\Commit\File; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line exceeds 120 characters; contains 154 characters