diff --git a/examples/user-repositories-milestones-async.php b/examples/user-repositories-milestones-async.php new file mode 100644 index 0000000000..94fe73423e --- /dev/null +++ b/examples/user-repositories-milestones-async.php @@ -0,0 +1,32 @@ +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->milestones()->subscribe(function (Repository\Milestone $milestone) { + resource_pretty_print($milestone); + $milestone->refresh()->then(function (Repository\Milestone $milestone) { + resource_pretty_print($milestone); + }); + }, function ($error) { + echo (string)$error; + }); +})->done(null, 'display_throwable'); + +$loop->run(); + +displayState($client->getRateLimitState()); diff --git a/src/CommandBus/Command/Repository/MilestonesCommand.php b/src/CommandBus/Command/Repository/MilestonesCommand.php new file mode 100644 index 0000000000..bbdf0e257c --- /dev/null +++ b/src/CommandBus/Command/Repository/MilestonesCommand.php @@ -0,0 +1,32 @@ +fullName = $fullName; + } + + /** + * @return string + */ + public function getFullName(): string + { + return $this->fullName; + } +} diff --git a/src/CommandBus/Handler/Repository/MilestonesHandler.php b/src/CommandBus/Handler/Repository/MilestonesHandler.php new file mode 100644 index 0000000000..2ecd0b4bb6 --- /dev/null +++ b/src/CommandBus/Handler/Repository/MilestonesHandler.php @@ -0,0 +1,52 @@ +iteratePagesService = $iteratePagesService; + $this->hydrator = $hydrator; + } + + /** + * @param MilestonesCommand $command + * @return PromiseInterface + */ + public function handle(MilestonesCommand $command): PromiseInterface + { + return resolve( + $this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/milestones') + ->flatMap(function ($milestones) { + return observableFromArray($milestones); + })->map(function ($milestone) { + return $this->hydrator->hydrate(MilestoneInterface::HYDRATE_CLASS, $milestone); + }) + ); + } +} diff --git a/src/Resource/Async/Repository.php b/src/Resource/Async/Repository.php index f54ca40a2a..f2a9ea0ee5 100644 --- a/src/Resource/Async/Repository.php +++ b/src/Resource/Async/Repository.php @@ -15,6 +15,7 @@ use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\LanguagesCommand; +use ApiClients\Client\Github\CommandBus\Command\Repository\MilestonesCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\RefCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand; use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand; @@ -119,6 +120,13 @@ public function webHooks(): ObservableInterface )); } + public function milestones(): ObservableInterface + { + return unwrapObservableFromPromise($this->handleCommand( + new MilestonesCommand($this->fullName()) + )); + } + public function addWebHook( string $name, array $config, diff --git a/src/Resource/Async/Repository/EmptyMilestone.php b/src/Resource/Async/Repository/EmptyMilestone.php new file mode 100644 index 0000000000..983ce89a5c --- /dev/null +++ b/src/Resource/Async/Repository/EmptyMilestone.php @@ -0,0 +1,9 @@ +handleCommand(new RefreshCommand($this)); + } +} diff --git a/src/Resource/Repository/EmptyMilestone.php b/src/Resource/Repository/EmptyMilestone.php new file mode 100644 index 0000000000..4a63c3bcc9 --- /dev/null +++ b/src/Resource/Repository/EmptyMilestone.php @@ -0,0 +1,80 @@ +id; + } + + /** + * @return int + */ + public function number(): int + { + return $this->number; + } + + /** + * @return string + */ + public function state(): string + { + return $this->state; + } + + /** + * @return string + */ + public function title(): string + { + return $this->title; + } + + /** + * @return string + */ + public function description(): string + { + return $this->description; + } + + /** + * @return User + */ + public function creator(): User + { + return $this->creator; + } + + /** + * @return int + */ + public function openIssues(): int + { + return $this->open_issues; + } + + /** + * @return int + */ + public function closedIssues(): int + { + return $this->closed_issues; + } + + /** + * @return string + */ + public function url(): string + { + return $this->url; + } +} diff --git a/src/Resource/Repository/MilestoneInterface.php b/src/Resource/Repository/MilestoneInterface.php new file mode 100644 index 0000000000..cef2a8f022 --- /dev/null +++ b/src/Resource/Repository/MilestoneInterface.php @@ -0,0 +1,50 @@ +wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (MilestoneInterface $milestone) { + return $milestone->refresh(); + })); + } +} diff --git a/yaml/repository-milestone.yml b/yaml/repository-milestone.yml new file mode 100644 index 0000000000..499c579c78 --- /dev/null +++ b/yaml/repository-milestone.yml @@ -0,0 +1,14 @@ +class: Repository\Milestone +properties: + id: int + number: int + state: string + title: string + description: string + creator: + type: User + annotations: + nested: User + open_issues: int + closed_issues: int + url: string