From 955fd97dfb8311dd72327242d465ad0d0a8c6126 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sat, 17 Jun 2017 20:20:46 +0200 Subject: [PATCH 1/5] List tags from repository --- examples/user-repositories-tags-async.php | 29 ++++++++ .../Command/Repository/TagsCommand.php | 32 +++++++++ .../Handler/Repository/TagsHandler.php | 50 ++++++++++++++ src/Resource/Async/Repository.php | 8 +++ src/Resource/Async/Repository/EmptyTag.php | 9 +++ src/Resource/Async/Repository/Tag.php | 13 ++++ src/Resource/Repository/EmptyTag.php | 40 +++++++++++ src/Resource/Repository/Tag.php | 68 +++++++++++++++++++ src/Resource/Repository/TagInterface.php | 30 ++++++++ src/Resource/Sync/Repository/EmptyTag.php | 9 +++ src/Resource/Sync/Repository/Tag.php | 17 +++++ .../Handler/Repository/TagsHandlerTest.php | 39 +++++++++++ .../Async/Repository/EmptyTagTest.php | 19 ++++++ tests/Resource/Async/Repository/TagTest.php | 25 +++++++ .../Resource/Sync/Repository/EmptyTagTest.php | 19 ++++++ tests/Resource/Sync/Repository/TagTest.php | 25 +++++++ yaml/repository-tag.yml | 9 +++ 17 files changed, 441 insertions(+) create mode 100644 examples/user-repositories-tags-async.php create mode 100644 src/CommandBus/Command/Repository/TagsCommand.php create mode 100644 src/CommandBus/Handler/Repository/TagsHandler.php create mode 100644 src/Resource/Async/Repository/EmptyTag.php create mode 100644 src/Resource/Async/Repository/Tag.php create mode 100644 src/Resource/Repository/EmptyTag.php create mode 100644 src/Resource/Repository/Tag.php create mode 100644 src/Resource/Repository/TagInterface.php create mode 100644 src/Resource/Sync/Repository/EmptyTag.php create mode 100644 src/Resource/Sync/Repository/Tag.php create mode 100644 tests/CommandBus/Handler/Repository/TagsHandlerTest.php create mode 100644 tests/Resource/Async/Repository/EmptyTagTest.php create mode 100644 tests/Resource/Async/Repository/TagTest.php create mode 100644 tests/Resource/Sync/Repository/EmptyTagTest.php create mode 100644 tests/Resource/Sync/Repository/TagTest.php create mode 100644 yaml/repository-tag.yml diff --git a/examples/user-repositories-tags-async.php b/examples/user-repositories-tags-async.php new file mode 100644 index 0000000000..45bc8f3ee2 --- /dev/null +++ b/examples/user-repositories-tags-async.php @@ -0,0 +1,29 @@ +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->tags()->subscribe(function ($tag) { + resource_pretty_print($tag, 2, true); + }, function ($error) { + echo (string)$error; + }); +})->done(null, 'display_throwable'); + +$loop->run(); + +displayState($client->getRateLimitState()); diff --git a/src/CommandBus/Command/Repository/TagsCommand.php b/src/CommandBus/Command/Repository/TagsCommand.php new file mode 100644 index 0000000000..368077771c --- /dev/null +++ b/src/CommandBus/Command/Repository/TagsCommand.php @@ -0,0 +1,32 @@ +fullName = $fullName; + } + + /** + * @return string + */ + public function getFullName(): string + { + return $this->fullName; + } +} diff --git a/src/CommandBus/Handler/Repository/TagsHandler.php b/src/CommandBus/Handler/Repository/TagsHandler.php new file mode 100644 index 0000000000..ab2bc669a2 --- /dev/null +++ b/src/CommandBus/Handler/Repository/TagsHandler.php @@ -0,0 +1,50 @@ +iteratePagesService = $iteratePagesService; + $this->hydrator = $hydrator; + } + + /** + * @param TagsCommand $command + * @return PromiseInterface + */ + public function handle(TagsCommand $command): PromiseInterface + { + return resolve( + $this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/tags') + ->flatMap(function ($labels) { + return observableFromArray($labels); + })->map(function ($label) { + return $this->hydrator->hydrate(TagInterface::HYDRATE_CLASS, $label); + }) + ); + } +} diff --git a/src/Resource/Async/Repository.php b/src/Resource/Async/Repository.php index a1c2746390..4951a2acb5 100644 --- a/src/Resource/Async/Repository.php +++ b/src/Resource/Async/Repository.php @@ -9,6 +9,7 @@ use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand; +use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand; use ApiClients\Client\Github\Resource\Repository as BaseRepository; use React\Promise\PromiseInterface; use Rx\Observable; @@ -67,4 +68,11 @@ public function communityHealth(): PromiseInterface new CommunityHealthCommand($this->fullName()) ); } + + public function tags(): ObservableInterface + { + return unwrapObservableFromPromise($this->handleCommand( + new TagsCommand($this->fullName()) + )); + } } diff --git a/src/Resource/Async/Repository/EmptyTag.php b/src/Resource/Async/Repository/EmptyTag.php new file mode 100644 index 0000000000..f4f368ccaa --- /dev/null +++ b/src/Resource/Async/Repository/EmptyTag.php @@ -0,0 +1,9 @@ +name; + } + + /** + * @return Tree + */ + public function commit(): Tree + { + return $this->commit; + } + + /** + * @return string + */ + public function zipballUrl(): string + { + return $this->zipball_url; + } + + /** + * @return string + */ + public function tarballUrl(): string + { + return $this->tarball_url; + } +} diff --git a/src/Resource/Repository/TagInterface.php b/src/Resource/Repository/TagInterface.php new file mode 100644 index 0000000000..4a4db387b9 --- /dev/null +++ b/src/Resource/Repository/TagInterface.php @@ -0,0 +1,30 @@ +wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (TagInterface $tag) { + return $tag->refresh(); + })); + } +} diff --git a/tests/CommandBus/Handler/Repository/TagsHandlerTest.php b/tests/CommandBus/Handler/Repository/TagsHandlerTest.php new file mode 100644 index 0000000000..b69c09c20d --- /dev/null +++ b/tests/CommandBus/Handler/Repository/TagsHandlerTest.php @@ -0,0 +1,39 @@ + 'bar', + ]; + $tag = $this->prophesize(Tag::class)->reveal(); + + $command = new TagsCommand('api-clients/github'); + + $iteratePagesService = $this->prophesize(IteratePagesService::class); + $iteratePagesService->iterate('repos/api-clients/github/tags')->shouldBeCalled()->willReturn(Observable::fromArray([[$tagArray]])); + + $hydrator = $this->prophesize(Hydrator::class); + $hydrator->hydrate(TagInterface::HYDRATE_CLASS, $tagArray)->shouldBeCalled()->wilLReturn($tag); + + $tagsHandler = new TagsHandler( + $iteratePagesService->reveal(), + $hydrator->reveal() + ); + + self::assertSame($tag, $this->await(Promise::fromObservable($this->await($tagsHandler->handle($command))))); + } +} diff --git a/tests/Resource/Async/Repository/EmptyTagTest.php b/tests/Resource/Async/Repository/EmptyTagTest.php new file mode 100644 index 0000000000..05b0220cec --- /dev/null +++ b/tests/Resource/Async/Repository/EmptyTagTest.php @@ -0,0 +1,19 @@ + Date: Sun, 18 Jun 2017 00:57:23 +0200 Subject: [PATCH 2/5] Line length --- src/Resource/Sync/Repository/Tag.php | 10 +++++++--- .../CommandBus/Handler/Repository/TagsHandlerTest.php | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Resource/Sync/Repository/Tag.php b/src/Resource/Sync/Repository/Tag.php index 53e0e66f95..7bccb4aee7 100644 --- a/src/Resource/Sync/Repository/Tag.php +++ b/src/Resource/Sync/Repository/Tag.php @@ -10,8 +10,12 @@ class Tag extends BaseTag { public function refresh(): Tag { - return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (TagInterface $tag) { - return $tag->refresh(); - })); + return $this->wait( + $this->handleCommand( + new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) + )->then(function (TagInterface $tag) { + return $tag->refresh(); + }) + ); } } diff --git a/tests/CommandBus/Handler/Repository/TagsHandlerTest.php b/tests/CommandBus/Handler/Repository/TagsHandlerTest.php index b69c09c20d..24a5746fcc 100644 --- a/tests/CommandBus/Handler/Repository/TagsHandlerTest.php +++ b/tests/CommandBus/Handler/Repository/TagsHandlerTest.php @@ -24,7 +24,9 @@ public function testCommand() $command = new TagsCommand('api-clients/github'); $iteratePagesService = $this->prophesize(IteratePagesService::class); - $iteratePagesService->iterate('repos/api-clients/github/tags')->shouldBeCalled()->willReturn(Observable::fromArray([[$tagArray]])); + $iteratePagesService->iterate('repos/api-clients/github/tags') + ->shouldBeCalled() + ->willReturn(Observable::fromArray([[$tagArray]])); $hydrator = $this->prophesize(Hydrator::class); $hydrator->hydrate(TagInterface::HYDRATE_CLASS, $tagArray)->shouldBeCalled()->wilLReturn($tag); From 334cdc5c6b34b2b5ef8b10df8525b2c3e95ff681 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 18 Jun 2017 01:18:29 +0200 Subject: [PATCH 3/5] Release resource --- examples/user-repositories-releases-async.php | 29 ++++ .../Command/Repository/ReleasesCommand.php | 32 ++++ .../Handler/Repository/ReleasesHandler.php | 52 ++++++ src/Resource/Async/Repository.php | 8 + .../Async/Repository/EmptyRelease.php | 9 + src/Resource/Async/Repository/Release.php | 13 ++ src/Resource/Repository/EmptyRelease.php | 97 +++++++++++ src/Resource/Repository/Release.php | 160 ++++++++++++++++++ src/Resource/Repository/ReleaseInterface.php | 66 ++++++++ src/Resource/Sync/Repository/EmptyRelease.php | 9 + src/Resource/Sync/Repository/Release.php | 19 +++ .../Async/Repository/EmptyReleaseTest.php | 19 +++ .../Resource/Async/Repository/ReleaseTest.php | 25 +++ .../Sync/Repository/EmptyReleaseTest.php | 19 +++ .../Resource/Sync/Repository/ReleaseTest.php | 25 +++ yaml/repository-release.yml | 16 ++ 16 files changed, 598 insertions(+) create mode 100644 examples/user-repositories-releases-async.php create mode 100644 src/CommandBus/Command/Repository/ReleasesCommand.php create mode 100644 src/CommandBus/Handler/Repository/ReleasesHandler.php create mode 100644 src/Resource/Async/Repository/EmptyRelease.php create mode 100644 src/Resource/Async/Repository/Release.php create mode 100644 src/Resource/Repository/EmptyRelease.php create mode 100644 src/Resource/Repository/Release.php create mode 100644 src/Resource/Repository/ReleaseInterface.php create mode 100644 src/Resource/Sync/Repository/EmptyRelease.php create mode 100644 src/Resource/Sync/Repository/Release.php create mode 100644 tests/Resource/Async/Repository/EmptyReleaseTest.php create mode 100644 tests/Resource/Async/Repository/ReleaseTest.php create mode 100644 tests/Resource/Sync/Repository/EmptyReleaseTest.php create mode 100644 tests/Resource/Sync/Repository/ReleaseTest.php create mode 100644 yaml/repository-release.yml diff --git a/examples/user-repositories-releases-async.php b/examples/user-repositories-releases-async.php new file mode 100644 index 0000000000..e9839d24ad --- /dev/null +++ b/examples/user-repositories-releases-async.php @@ -0,0 +1,29 @@ +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->releases()->subscribe(function ($release) { + resource_pretty_print($release, 2, true); + }, function ($error) { + echo (string)$error; + }); +})->done(null, 'display_throwable'); + +$loop->run(); + +displayState($client->getRateLimitState()); diff --git a/src/CommandBus/Command/Repository/ReleasesCommand.php b/src/CommandBus/Command/Repository/ReleasesCommand.php new file mode 100644 index 0000000000..8ffc828295 --- /dev/null +++ b/src/CommandBus/Command/Repository/ReleasesCommand.php @@ -0,0 +1,32 @@ +fullName = $fullName; + } + + /** + * @return string + */ + public function getFullName(): string + { + return $this->fullName; + } +} diff --git a/src/CommandBus/Handler/Repository/ReleasesHandler.php b/src/CommandBus/Handler/Repository/ReleasesHandler.php new file mode 100644 index 0000000000..17cd815237 --- /dev/null +++ b/src/CommandBus/Handler/Repository/ReleasesHandler.php @@ -0,0 +1,52 @@ +iteratePagesService = $iteratePagesService; + $this->hydrator = $hydrator; + } + + /** + * @param TagsCommand $command + * @return PromiseInterface + */ + public function handle(ReleasesCommand $command): PromiseInterface + { + return resolve( + $this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/releases') + ->flatMap(function ($labels) { + return observableFromArray($labels); + })->map(function ($label) { + return $this->hydrator->hydrate(ReleaseInterface::HYDRATE_CLASS, $label); + }) + ); + } +} diff --git a/src/Resource/Async/Repository.php b/src/Resource/Async/Repository.php index 4951a2acb5..af1a229b57 100644 --- a/src/Resource/Async/Repository.php +++ b/src/Resource/Async/Repository.php @@ -9,6 +9,7 @@ use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand; +use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand; use ApiClients\Client\Github\Resource\Repository as BaseRepository; use React\Promise\PromiseInterface; @@ -75,4 +76,11 @@ public function tags(): ObservableInterface new TagsCommand($this->fullName()) )); } + + public function releases(): ObservableInterface + { + return unwrapObservableFromPromise($this->handleCommand( + new ReleasesCommand($this->fullName()) + )); + } } diff --git a/src/Resource/Async/Repository/EmptyRelease.php b/src/Resource/Async/Repository/EmptyRelease.php new file mode 100644 index 0000000000..c6c8686c2a --- /dev/null +++ b/src/Resource/Async/Repository/EmptyRelease.php @@ -0,0 +1,9 @@ +id; + } + + /** + * @return string + */ + public function tagName(): string + { + return $this->tag_name; + } + + /** + * @return string + */ + public function targetCommitish(): string + { + return $this->target_commitish; + } + + /** + * @return string + */ + public function name(): string + { + return $this->name; + } + + /** + * @return string + */ + public function body(): string + { + return $this->body; + } + + /** + * @return bool + */ + public function draft(): bool + { + return $this->draft; + } + + /** + * @return bool + */ + public function prerelease(): bool + { + return $this->prerelease; + } + + /** + * @return DateTimeInterface + */ + public function createdAt(): DateTimeInterface + { + return $this->created_at; + } + + /** + * @return DateTimeInterface + */ + public function updatedAt(): DateTimeInterface + { + return $this->updated_at; + } + + /** + * @return User + */ + public function author(): User + { + return $this->author; + } + + /** + * @return array + */ + public function assets(): array + { + return $this->assets; + } +} diff --git a/src/Resource/Repository/ReleaseInterface.php b/src/Resource/Repository/ReleaseInterface.php new file mode 100644 index 0000000000..4cd3e72eaa --- /dev/null +++ b/src/Resource/Repository/ReleaseInterface.php @@ -0,0 +1,66 @@ +wait($this->handleCommand( + new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) + )->then(function (ReleaseInterface $release) { + return $release->refresh(); + })); + } +} diff --git a/tests/Resource/Async/Repository/EmptyReleaseTest.php b/tests/Resource/Async/Repository/EmptyReleaseTest.php new file mode 100644 index 0000000000..1f6f1fffcc --- /dev/null +++ b/tests/Resource/Async/Repository/EmptyReleaseTest.php @@ -0,0 +1,19 @@ + Date: Sun, 18 Jun 2017 12:55:30 +0200 Subject: [PATCH 4/5] Removed unused use --- src/CommandBus/Handler/Repository/ReleasesHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CommandBus/Handler/Repository/ReleasesHandler.php b/src/CommandBus/Handler/Repository/ReleasesHandler.php index 17cd815237..835634c7bf 100644 --- a/src/CommandBus/Handler/Repository/ReleasesHandler.php +++ b/src/CommandBus/Handler/Repository/ReleasesHandler.php @@ -5,7 +5,6 @@ use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand; use ApiClients\Client\Github\Resource\Repository\ReleaseInterface; -use ApiClients\Client\Github\Resource\Repository\TagInterface; use ApiClients\Client\Github\Service\IteratePagesService; use ApiClients\Foundation\Hydrator\Hydrator; use React\Promise\PromiseInterface; From fe0e6f298434e4e6341f13b80612d70eb61fdc01 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Sun, 18 Jun 2017 12:59:42 +0200 Subject: [PATCH 5/5] Release asset resource --- .../Async/Repository/Release/Asset.php | 13 ++ .../Async/Repository/Release/EmptyAsset.php | 9 + src/Resource/Repository/Release.php | 6 +- src/Resource/Repository/Release/Asset.php | 173 ++++++++++++++++++ .../Repository/Release/AssetInterface.php | 71 +++++++ .../Repository/Release/EmptyAsset.php | 105 +++++++++++ .../Sync/Repository/Release/Asset.php | 19 ++ .../Sync/Repository/Release/EmptyAsset.php | 9 + yaml/repository-release-asset.yml | 17 ++ yaml/repository-release.yml | 5 +- 10 files changed, 425 insertions(+), 2 deletions(-) create mode 100644 src/Resource/Async/Repository/Release/Asset.php create mode 100644 src/Resource/Async/Repository/Release/EmptyAsset.php create mode 100644 src/Resource/Repository/Release/Asset.php create mode 100644 src/Resource/Repository/Release/AssetInterface.php create mode 100644 src/Resource/Repository/Release/EmptyAsset.php create mode 100644 src/Resource/Sync/Repository/Release/Asset.php create mode 100644 src/Resource/Sync/Repository/Release/EmptyAsset.php create mode 100644 yaml/repository-release-asset.yml diff --git a/src/Resource/Async/Repository/Release/Asset.php b/src/Resource/Async/Repository/Release/Asset.php new file mode 100644 index 0000000000..52ba32b579 --- /dev/null +++ b/src/Resource/Async/Repository/Release/Asset.php @@ -0,0 +1,13 @@ +url; + } + + /** + * @return string + */ + public function browserDownloadUrl(): string + { + return $this->browser_download_url; + } + + /** + * @return int + */ + public function id(): int + { + return $this->id; + } + + /** + * @return string + */ + public function name(): string + { + return $this->name; + } + + /** + * @return string + */ + public function label(): string + { + return $this->label; + } + + /** + * @return string + */ + public function state(): string + { + return $this->state; + } + + /** + * @return string + */ + public function contentType(): string + { + return $this->content_type; + } + + /** + * @return int + */ + public function size(): int + { + return $this->size; + } + + /** + * @return int + */ + public function downloadCount(): int + { + return $this->download_count; + } + + /** + * @return DateTimeInterface + */ + public function createdAt(): DateTimeInterface + { + return $this->created_at; + } + + /** + * @return DateTimeInterface + */ + public function updatedAt(): DateTimeInterface + { + return $this->updated_at; + } + + /** + * @return User + */ + public function uploader(): User + { + return $this->uploader; + } +} diff --git a/src/Resource/Repository/Release/AssetInterface.php b/src/Resource/Repository/Release/AssetInterface.php new file mode 100644 index 0000000000..243c3e5a47 --- /dev/null +++ b/src/Resource/Repository/Release/AssetInterface.php @@ -0,0 +1,71 @@ +wait($this->handleCommand( + new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this) + )->then(function (AssetInterface $asset) { + return $asset->refresh(); + })); + } +} diff --git a/src/Resource/Sync/Repository/Release/EmptyAsset.php b/src/Resource/Sync/Repository/Release/EmptyAsset.php new file mode 100644 index 0000000000..677ded1a3b --- /dev/null +++ b/src/Resource/Sync/Repository/Release/EmptyAsset.php @@ -0,0 +1,9 @@ +