diff --git a/examples/user-repositories-branches-async.php b/examples/user-repositories-branches-async.php index e9cbcd2af5..e14a20f691 100644 --- a/examples/user-repositories-branches-async.php +++ b/examples/user-repositories-branches-async.php @@ -4,6 +4,7 @@ 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'; @@ -21,6 +22,18 @@ resource_pretty_print($branch, 2, true); $branch->detailedCommit()->then(function (Repository\Commit $commit) { resource_pretty_print($commit); + + $promises = []; + foreach ($commit->parents() as $parent) { + $promises[] = $parent->detailedCommit(); + } + + return all($promises); + })->then(function ($commits) { + /** @var Repository\Commit $commit */ + foreach ($commits as $commit) { + resource_pretty_print($commit); + } })->done(null, 'display_throwable'); }, function ($error) { echo (string)$error; diff --git a/src/Resource/Async/Tree.php b/src/Resource/Async/Tree.php index 8a4430989a..8ba1aca831 100644 --- a/src/Resource/Async/Tree.php +++ b/src/Resource/Async/Tree.php @@ -2,7 +2,9 @@ namespace ApiClients\Client\Github\Resource\Async; +use ApiClients\Client\Github\CommandBus\Command\Repository\DetailedCommitCommand; use ApiClients\Client\Github\Resource\Tree as BaseTree; +use React\Promise\PromiseInterface; class Tree extends BaseTree { @@ -10,4 +12,12 @@ public function refresh(): Tree { throw new \Exception('TODO: create refresh method!'); } + + public function detailedCommit(): PromiseInterface + { + return $this->handleCommand(new DetailedCommitCommand( + \str_replace('/commits/' . $this->sha, '', \explode('/repos/', $this->url)[1]), + $this->sha + )); + } } diff --git a/src/Resource/Repository/Commit.php b/src/Resource/Repository/Commit.php index 5c41b5a1da..28d93d9c88 100644 --- a/src/Resource/Repository/Commit.php +++ b/src/Resource/Repository/Commit.php @@ -9,6 +9,8 @@ use ApiClients\Foundation\Hydrator\Annotation\EmptyResource; use ApiClients\Foundation\Hydrator\Annotation\Nested; use ApiClients\Foundation\Resource\AbstractResource; +use Rx\Observable; +use function ApiClients\Tools\Rx\observableFromArray; /** * @Collection( @@ -107,9 +109,9 @@ public function comitter(): UserInterface } /** - * @return TreeInterface + * @return TreeInterface[] */ - public function parents(): TreeInterface + public function parents(): array { return $this->parents; } diff --git a/src/Resource/Repository/CommitInterface.php b/src/Resource/Repository/CommitInterface.php index 76d7c85925..b9556503ea 100644 --- a/src/Resource/Repository/CommitInterface.php +++ b/src/Resource/Repository/CommitInterface.php @@ -42,7 +42,7 @@ public function author(): UserInterface; public function comitter(): UserInterface; /** - * @return TreeInterface + * @return TreeInterface[] */ - public function parents(): TreeInterface; + public function parents(): array; }