8000 Fetch pull requests · php-api-clients/github@1edb99c · GitHub
[go: up one dir, main page]

Skip to content

Commit 1edb99c

Browse files
committed
Fetch pull requests
1 parent 5a937fd commit 1edb99c

36 files changed

+1803
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
use ApiClients\Client\Github\AsyncClient;
3+
use ApiClients\Client\Github\Resource\Async\Repository;
4+
use ApiClients\Client\Github\Resource\Async\User;
5+
use function ApiClients\Foundation\resource_pretty_print;
6+
use React\EventLoop\Factory;
7+
8+
require \dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'vendor/autoload.php';
9+
10+
$loop = Factory::create();
11+
12+
$client = AsyncClient::create($loop, require 'resolve_token.php');
13+
14+
$client->user($argv[1] ?? 'php-api-clients')->then(function (User $user) use ($argv) {
15+
resource_pretty_print($user);
16+
17+
return $user->repository($argv[2] ?? 'github');
18+
})->then(function (Repository $repository) {
19+
resource_pretty_print($repository, 1, true);
20+
$repository->pullRequests()->subscribe(function (Repository\PullRequest $pullRequest) {
21+
resource_pretty_print($pullRequest);
22+
$pullRequest->refresh()->then(function (Repository\PullRequest $pullRequest) {
23+
resource_pretty_print($pullRequest);
24+
});
25+
}, function ($error) {
26+
echo (string)$error;
27+
});
28+
})->done(null, 'display_throwable');
29+
30+
$loop->run();
31+
32+
displayState($client->getRateLimitState());
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Command\Repository;
4+
5+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
6+
7+
/**
8+
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\PullRequestsHandler")
9+
*/
10+
final class PullRequestsCommand
11+
{
12+
/**
13+
* @var string
14+
*/
15+
private $fullName;
16+
17+
/**
18+
* @param string $fullName
19+
*/
20+
public function __construct(string $fullName)
21+
{
22+
$this->fullName = $fullName;
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getFullName(): string
29+
{
30+
return $this->fullName;
31+
}
32+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Handler\Repository;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\Repository\BranchesCommand;
6+
use ApiClients\Client\Github\CommandBus\Command\Repository\MilestonesCommand;
7+
use ApiClients\Client\Github\CommandBus\Command\Repository\PullRequestsCommand;
8+
use ApiClients\Client\Github\Resource\Repository\BranchInterface;
9+
use ApiClients\Client\Github\Resource\Repository\MilestoneInterface;
10+
use ApiClients\Client\Github\Resource\Repository\PullRequestInterface;
11+
use ApiClients\Client\Github\Service\IteratePagesService;
12+
use ApiClients\Foundation\Hydrator\Hydrator;
13+
use function ApiClients\Tools\Rx\observableFromArray;
14+
use React\Promise\PromiseInterface;
15+
use function React\Promise\resolve;
16+
17+
final class PullRequestsHandler
18+
{
19+
/**
20+
* @var IteratePagesService
21+
*/
22+
private $iteratePagesService;
23+
24+
/**
25+
* @var Hydrator
26+
*/
27+
private $hydrator;
28+
29+
/**
30+
* @param IteratePagesService $iteratePagesService
31+
* @param Hydrator $hydrator
32+
*/
33+
public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
34+
{
35+
$this->iteratePagesService = $iteratePagesService;
36+
$this->hydrator = $hydrator;
37+
}
38+
39+
/**
40+
* @param PullRequestsCommand $command
41+
* @return PromiseInterface
42+
*/
43+
public function handle(PullRequestsCommand $command): PromiseInterface
44+
{
45+
return resolve(
46+
$this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/pulls')
47+
->flatMap(function ($milestones) {
48+
return observableFromArray($milestones);
49+
})->map(function ($milestone) {
50+
return $this->hydrator->hydrate(PullRequestInterface::HYDRATE_CLASS, $milestone);
51+
})
52+
);
53+
}
54+
}

src/Resource/Async/Repository.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand;
1818
use ApiClients\Client\Github\CommandBus\Command\Repository\LanguagesCommand;
1919
use ApiClients\Client\Github\CommandBus\Command\Repository\MilestonesCommand;
20+
use ApiClients\Client\Github\CommandBus\Command\Repository\PullRequestsCommand;
2021
use ApiClients\Client\Github\CommandBus\Command\Repository\RefCommand;
2122
use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand;
2223
use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand;
@@ -138,6 +139,13 @@ public function milestones(): ObservableInterface
138139
));
139140
}
140141

142+
public function pullRequests(): ObservableInterface
143+
{
144+
return unwrapObservableFromPromise($this->handleCommand(
145+
new PullRequestsCommand($this->fullName())
146+
));
147+
}
148+
141149
public function addWebHook(
142150
string $name,
143151
array $config,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async\Repository;
4+
5+
use ApiClients\Client\Github\Resource\Repository\EmptyPullRequest as BaseEmptyPullRequest;
6+
7+
class EmptyPullRequest extends BaseEmptyPullRequest
8+
{
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async\Repository;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\RefreshCommand;
6+
use ApiClients\Client\Github\Resource\Repository\PullRequest as BasePullRequest;
7+
use React\Promise\PromiseInterface;
8+
9+
class PullRequest extends BasePullRequest
10+
{
11+
public function refresh(): PromiseInterface
12+
{
13+
return $this->handleCommand(new RefreshCommand($this));
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async\Repository\PullRequest;
4+
5+
use ApiClients\Client\Github\Resource\Repository\PullRequest\EmptyRb as BaseEmptyRb;
6+
7+
class EmptyRb extends BaseEmptyRb
8+
{
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async\Repository\PullRequest;
4+
5+
use ApiClients\Client\Github\Resource\Repository\PullRequest\Rb as BaseRb;
6+
7+
class Rb extends BaseRb
8+
{
9+
public function refresh(): Rb
10+
{
11+
throw new \Exception('TODO: create refresh method!');
12+
}
13+
}

0 commit comments

Comments
 (0)
0