10BC0 Parents on commit should return array of Trees not Tree by WyriHaximus · Pull Request #61 · php-api-clients/github · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/user-repositories-branches-async.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/Resource/Async/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

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
{
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
));
}
}
6 changes: 4 additions & 2 deletions src/Resource/Repository/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -107,9 +109,9 @@ public function comitter(): UserInterface
}

/**
* @return TreeInterface
* @return TreeInterface[]
*/
public function parents(): TreeInterface
public function parents(): array
{
return $this->parents;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Resource/Repository/CommitInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function author(): UserInterface;
public function comitter(): UserInterface;

/**
* @return TreeInterface
* @return TreeInterface[]
*/
public function parents(): TreeInterface;
public function parents(): array;
}
0