Skip to content

Commit f97c370

Browse files
committed
Fetch git refs
1 parent c17ad1a commit f97c370

File tree

24 files changed

+673
-0
lines changed

24 files changed

+673
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\RefsHandler")
9+
*/
10+
final class RefsCommand
11+
{
12+
/** @var string */
13+
private $fullName;
14+
15+
/** @var string|null */
16+
private $namespace;
17+
18+
/**
19+
* @param string $fullName
20+
* @param string|null $namespace
21+
*/
22+
public function __construct(string $fullName, ?string $namespace)
23+
{
24+
$this->fullName = $fullName;
25+
$this->namespace = $namespace;
26+
}
27+
28+
/**
29+
* @return string
30+
*/
31+
public function getFullName(): string
32+
{
33+
return $this->fullName;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getNamespace(): ?string
40+
{
41+
return $this->namespace;
42+
}
43+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Handler\Repository;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand;
6+
use ApiClients\Client\Github\Resource\Git\RefInterface;
7+
use ApiClients\Client\Github\Service\IteratePagesService;
8+
use ApiClients\Foundation\Hydrator\Hydrator;
9+
use function ApiClients\Tools\Rx\observableFromArray;
10+
use React\Promise\PromiseInterface;
11+
use function React\Promise\resolve;
12+
13+
final class RefsHandler
14+
{
15+
/**
16+
* @var IteratePagesService
17+
*/
18+
private $iteratePagesService;
19+
20+
/**
21+
* @var Hydrator
22+
*/
23+
private $hydrator;
24+
25+
/**
26+
* @param IteratePagesService $iteratePagesService
27+
* @param Hydrator $hydrator
28+
*/
29+
public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
30+
{
31+
$this->iteratePagesService = $iteratePagesService;
32+
$this->hydrator = $hydrator;
33+
}
34+
35+
/**
36+
* @param RefsCommand $command
37+
* @return PromiseInterface
38+
*/
39+
public function handle(RefsCommand $command): PromiseInterface
40+
{
41+
$namespace = !empty($command->getNamespace()) ? '/' . $command->getNamespace() : '';
42+
43+
return resolve(
44+
$this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/git/refs' . $namespace)
45+
->flatMap(function ($commits) {
46+
return observableFromArray($commits);
47+
})->map(function ($commit) {
48+
return $this->hydrator->hydrate(RefInterface::HYDRATE_CLASS, $commit);
49+
})
50+
);
51+
}
52+
}

src/Resource/Async/Git/EmptyRef.php

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\Git;
4+
5+
use ApiClients\Client\Github\Resource\Git\EmptyRef as BaseEmptyRef;
6+
7+
class EmptyRef extends BaseEmptyRef
8+
{
9+
}

src/Resource/Async/Git/Ref.php

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\Git;
4+
5+
use ApiClients\Client\Github\Resource\Git\Ref as BaseRef;
6+
7+
class Ref extends BaseRef
8+
{
9+
public function refresh(): Ref
10+
{
11+
throw new \Exception('TODO: create refresh method!');
12+
}
13+
}

src/Resource/Async/Repository.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@
66
use ApiClients\Client\Github\CommandBus\Command\Repository\AddLabelCommand;
77
use ApiClients\Client\Github\CommandBus\Command\Repository\AddWebHookCommand;
88
use ApiClients\Client\Github\CommandBus\Command\Repository\AppVeyorCommand;
9+
use ApiClients\Client\Github\CommandBus\Command\Repository\BlobCommand;
910
use ApiClients\Client\Github\CommandBus\Command\Repository\BranchesCommand;
11+
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitCommand;
1012
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitsCommand;
1113
use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand;
1214
use ApiClients\Client\Github\CommandBus\Command\Repository\Contents\FileUploadCommand;
1315
use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand;
1416
use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand;
1517
use ApiClients\Client\Github\CommandBus\Command\Repository\LanguagesCommand;
18+
use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand;
1619
use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand;
1720
use ApiClients\Client\Github\CommandBus\Command\Repository\ReplaceTopicsCommand;
1821
use ApiClients\Client\Github\CommandBus\Command\Repository\ScrutinizerCommand;
1922
use ApiClients\Client\Github\CommandBus\Command\Repository\SubscribeCommand;
2023
use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand;
2124
use ApiClients\Client\Github\CommandBus\Command\Repository\TravisCommand;
25+
use ApiClients\Client\Github\CommandBus\Command\Repository\TreeCommand;
2226
use ApiClients\Client\Github\CommandBus\Command\Repository\UnSubscribeCommand;
2327
use ApiClients\Client\Github\CommandBus\Command\Repository\UpdateSettingsCommand;
2428
use ApiClients\Client\Github\CommandBus\Command\WebHooksCommand;
29+
use ApiClients\Client\Github\Resource\Git\TreeInterface;
2530
use ApiClients\Client\Github\Resource\Repository as BaseRepository;
31+
use ApiClients\Client\Github\VO\NamedBlob;
2632
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
2733
use React\Promise\PromiseInterface;
2834
use React\Stream\ReadableStreamInterface;
@@ -191,4 +197,26 @@ public function updateSettings(array $settings): PromiseInterface
191197

192198
return $this->handleCommand(new UpdateSettingsCommand($this->fullName(), $settings));
193199
}
200+
201+
public function blob(ReadableStreamInterface $contents): PromiseInterface
202+
{
203+
return $this->handleCommand(new BlobCommand($this->fullName(), $contents));
204+
}
205+
206+
public function tree(?string $baseTree, NamedBlob ...$blobs): PromiseInterface
207+
{
208+
return $this->handleCommand(new TreeCommand($this->fullName(), $baseTree, ...$blobs));
209+
}
210+
211+
public function commit(string $message, TreeInterface $tree, ?string ...$baseCommits): PromiseInterface
212+
{
213+
return $this->handleCommand(new CommitCommand($this->fullName(), $message, $tree->sha(), ...$baseCommits));
214+
}
215+
216+
public function refs(?string $namespace = null): ObservableInterface
217+
{
218+
return unwrapObservableFromPromise($this->handleCommand(
219+
new RefsCommand($this->fullName(), $namespace)
220+
));
221+
}
194222
}

src/Resource/Git/EmptyRef.php

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\Resource\Git;
4+
5+
use ApiClients\Foundation\Resource\EmptyResourceInterface;
6+
7+
abstract class EmptyRef implements RefInterface, EmptyResourceInterface
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function ref(): string
13+
{
14+
return null;
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function url(): string
21+
{
22+
return null;
23+
}
24+
25+
/**
26+
* @return Git\Ref\Object_
27+
*/
28+
public function author(): Git\Ref\Object_
29+
{
30+
return null;
31+
}
32+
}

src/Resource/Git/Ref.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Git;
4+
5+
use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
6+
use ApiClients\Foundation\Hydrator\Annotation\Nested;
7+
use ApiClients\Foundation\Resource\AbstractResource;
8+
9+
/**
10+
* @Nested(
11+
* author="Git\Ref\Object_"
12+
* )
13+
* @EmptyResource("Git\EmptyRef")
14+
*/
15+
abstract class Ref extends AbstractResource implements RefInterface
16+
{
17+
/**
18+
* @var string
19+
*/
20+
protected $ref;
21+
22+
/**
23+
* @var string
24+
*/
25+
protected $url;
26+
27+
/**
28+
* @var Git\Ref\Object_
29+
*/
30+
protected $author;
31+
32+
/**
33+
* @return string
34+
*/
35+
public function ref(): string
36+
{
37+
return $this->ref;
38+
}
39+
40+
/**
41+
* @return string
42+
*/
43+
public function url(): string
44+
{
45+
return $this->url;
46+
}
47+
48+
/**
49+
* @return Git\Ref\Object_
50+
*/
51+
public function author(): Git\Ref\Object_
52+
{
53+
return $this->author;
54+
}
55+
}

src/Resource/Git/Ref/EmptyObject_.php

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\Resource\Git\Ref;
4+
5+
use ApiClients\Foundation\Resource\EmptyResourceInterface;
6+
7+
abstract class EmptyObject_ implements Object_Interface, EmptyResourceInterface
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function type(): string
13+
{
14+
return null;
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function sha(): string
21+
{
22+
return null;
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function url(): string
29+
{
30+
return null;
31+
}
32+
}

src/Resource/Git/Ref/Object_.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Git\Ref;
4+
5+
use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
6+
use ApiClients\Foundation\Resource\AbstractResource;
7+
8+
/**
9+
* @EmptyResource("Git\Ref\EmptyObject_")
10+
*/
11+
abstract class Object_ extends AbstractResource implements Object_Interface
12+
{
13+
/**
14+
* @var string
15+
*/
16+
protected $type;
17+
18+
/**
19+
* @var string
20+
*/
21+
protected $sha;
22+
23+
/**
24+
* @var string
25+
*/
26+
protected $url;
27+
28+
/**
29+
* @return string
30+
*/
31+
public function type(): string
32+
{
33+
return $this->type;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function sha(): string
40+
{
41+
return $this->sha;
42+
}
43+
44+
/**
45+
* @return string
46+
*/
47+
public function url(): string
48+
{
49+
return $this->url;
50+
}
51+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Git\Ref;
4+
5+
use ApiClients\Foundation\Resource\ResourceInterface;
6+
7+
interface Object_Interface extends ResourceInterface
8+
{
9+
const HYDRATE_CLASS = 'Git\\Ref\\Object_';
10+
11+
/**
12+
* @return string
13+
*/
14+
public function type(): string;
15+
16+
/**
17+
* @return string
18+
*/
19+
public function sha(): string;
20+
21+
/**
22+
* @return string
23+
*/
24+
public function url(): string;
25+
}

0 commit comments

Comments
 (0)