diff --git a/examples/user-repositories-compare-commits-async.php b/examples/user-repositories-compare-commits-async.php new file mode 100644 index 0000000000..ce08c4289b --- /dev/null +++ b/examples/user-repositories-compare-commits-async.php @@ -0,0 +1,33 @@ +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()); diff --git a/src/CommandBus/Command/Repository/CompareCommitsCommand.php b/src/CommandBus/Command/Repository/CompareCommitsCommand.php new file mode 100644 index 0000000000..837a384671 --- /dev/null +++ b/src/CommandBus/Command/Repository/CompareCommitsCommand.php @@ -0,0 +1,54 @@ +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; + } +} diff --git a/src/CommandBus/Handler/Repository/CompareCommitsHandler.php b/src/CommandBus/Handler/Repository/CompareCommitsHandler.php new file mode 100644 index 0000000000..8520791cfd --- /dev/null +++ b/src/CommandBus/Handler/Repository/CompareCommitsHandler.php @@ -0,0 +1,39 @@ +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(), + '', + CompareInterface::HYDRATE_CLASS + ); + } +} diff --git a/src/Resource/Async/Repository.php b/src/Resource/Async/Repository.php index b9a6804992..f29d0a2c58 100644 --- a/src/Resource/Async/Repository.php +++ b/src/Resource/Async/Repository.php @@ -11,6 +11,7 @@ use ApiClients\Client\Github\CommandBus\Command\Repository\CommitCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\CommitsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand; +use ApiClients\Client\Github\CommandBus\Command\Repository\CompareCommitsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\Contents\FileUploadCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\DetailedCommitCommand; @@ -146,6 +147,11 @@ public function pullRequests(): ObservableInterface )); } + public function compareCommits(string $base, string $head): PromiseInterface + { + return $this->handleCommand(new CompareCommitsCommand($this, $base, $head)); + } + public function addWebHook( string $name, array $config, diff --git a/src/Resource/Async/Repository/Compare.php b/src/Resource/Async/Repository/Compare.php new file mode 100644 index 0000000000..3f35576540 --- /dev/null +++ b/src/Resource/Async/Repository/Compare.php @@ -0,0 +1,15 @@ +handleCommand(new RefreshCommand($this)); + } +} diff --git a/src/Resource/Async/Repository/EmptyCompare.php b/src/Resource/Async/Repository/EmptyCompare.php new file mode 100644 index 0000000000..ce670b4f45 --- /dev/null +++ b/src/Resource/Async/Repository/EmptyCompare.php @@ -0,0 +1,9 @@ +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; + } +} diff --git a/src/Resource/Repository/CompareInterface.php b/src/Resource/Repository/CompareInterface.php new file mode 100644 index 0000000000..f4e71cc5bf --- /dev/null +++ b/src/Resource/Repository/CompareInterface.php @@ -0,0 +1,55 @@ +wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (CompareInterface $compare) { + return $compare->refresh(); + })); + } +} diff --git a/src/Resource/Sync/Repository/EmptyCompare.php b/src/Resource/Sync/Repository/EmptyCompare.php new file mode 100644 index 0000000000..2bba6f48bc --- /dev/null +++ b/src/Resource/Sync/Repository/EmptyCompare.php @@ -0,0 +1,9 @@ +