8000 Merge pull request #61 from php-api-clients/parents-should-return-obs… · php-api-clients/github@4e43e9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e43e9f

Browse files
authored
Merge pull request #61 from php-api-clients/parents-should-return-observable-not-tree-interface
Parents on commit should return array of Trees not Tree
2 parents 178cacd + bd9a1fd commit 4e43e9f

File tree

4 files changed

+29
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use ApiClients\Client\Github\Resource\Async\User;
55
use function ApiClients\Foundation\resource_pretty_print;
66
use React\EventLoop\Factory;
7+
use function React\Promise\all;
78

89
require \dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'vendor/autoload.php';
910

@@ -21,6 +22,18 @@
2122
resource_pretty_print($branch, 2, true);
2223
$branch->detailedCommit()->then(function (Repository\Commit $commit) {
2324
resource_pretty_print($commit);
25+
26+
$promises = [];
27+
foreach ($commit->parents() as $parent) {
28+
$promises[] = $parent->detailedCommit();
29+
}
30+
31+
return all($promises);
32+
})->then(function ($commits) {
33+
/** @var Repository\Commit $commit */
34+
foreach ($commits as $commit) {
35+
resource_pretty_print($commit);
36+
}
2437
})->done(null, 'display_throwable');
2538
}, function ($error) {
2639
echo (string)$error;
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
namespace ApiClients\Client\Github\Resource\Async;
44

5+
use ApiClients\Client\Github\CommandBus\Command\Repository\DetailedCommitCommand;
56
use ApiClients\Client\Github\Resource\Tree as BaseTree;
7+
use React\Promise\PromiseInterface;
68

79
class Tree extends BaseTree
810
{
911
public function refresh(): Tree
1012
{
1113
throw new \Exception('TODO: create refresh method!');
1214
}
15+
16+
public function detailedCommit(): PromiseInterface
17+
{
18+
return $this->handleCommand(new DetailedCommitCommand(
19+
\str_replace('/commits/' . $this->sha, '', \explode('/repos/', $this->url)[1]),
20+
$this->sha
21+
));
22+
}
1323
}
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
1010
use ApiClients\Foundation\Hydrator\Annotation\Nested;
1111
use ApiClients\Foundation\Resource\AbstractResource;
12+
use Rx\Observable;
13+
use function ApiClients\Tools\Rx\observableFromArray;
1214

1315
/**
1416
* @Collection(
@@ -107,9 +109,9 @@ public function comitter(): UserInterface
107109
}
108110

109111
/**
110-
* @return TreeInterface
112+
* @return TreeInterface[]
111113
*/
112-
public function parents(): TreeInterface
114+
public function parents(): array
113115
{
114116
return $this->parents;
115117
}
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function author(): UserInterface;
4242
public function comitter(): UserInterface;
4343

4444
/**
45-
* @return TreeInterface
45+
* @return TreeInterface[]
4646
*/
47-
public function parents(): TreeInterface;
47+
public function parents(): array;
4848
}