Skip to content

Commit

Permalink
Fetch git refs
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Feb 13, 2019
1 parent c17ad1a commit f97c370
Show file tree
Hide file tree
Showing 24 changed files with 673 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/CommandBus/Command/Repository/RefsCommand.php
@@ -0,0 +1,43 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Command\Repository;

use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;

/**
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Repository\RefsHandler")
*/
final class RefsCommand
{
/** @var string */
private $fullName;

/** @var string|null */
private $namespace;

/**
* @param string $fullName
* @param string|null $namespace
*/
public function __construct(string $fullName, ?string $namespace)
{
$this->fullName = $fullName;
$this->namespace = $namespace;
}

/**
* @return string
*/
public function getFullName(): string
{
return $this->fullName;
}

/**
* @return string
*/
public function getNamespace(): ?string
{
return $this->namespace;
}
}
52 changes: 52 additions & 0 deletions src/CommandBus/Handler/Repository/RefsHandler.php
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\CommandBus\Handler\Repository;

use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand;
use ApiClients\Client\Github\Resource\Git\RefInterface;
use ApiClients\Client\Github\Service\IteratePagesService;
use ApiClients\Foundation\Hydrator\Hydrator;
use function ApiClients\Tools\Rx\observableFromArray;
use React\Promise\PromiseInterface;
use function React\Promise\resolve;

final class RefsHandler
{
/**
* @var IteratePagesService
*/
private $iteratePagesService;

/**
* @var Hydrator
*/
private $hydrator;

/**
* @param IteratePagesService $iteratePagesService
* @param Hydrator $hydrator
*/
public function __construct(IteratePagesService $iteratePagesService, Hydrator $hydrator)
{
$this->iteratePagesService = $iteratePagesService;
$this->hydrator = $hydrator;
}

/**
* @param RefsCommand $command
* @return PromiseInterface
*/
public function handle(RefsCommand $command): PromiseInterface
{
$namespace = !empty($command->getNamespace()) ? '/' . $command->getNamespace() : '';

return resolve(
$this->iteratePagesService->iterate('repos/' . $command->getFullName() . '/git/refs' . $namespace)
->flatMap(function ($commits) {
return observableFromArray($commits);
})->map(function ($commit) {
return $this->hydrator->hydrate(RefInterface::HYDRATE_CLASS, $commit);
})
);
}
}
9 changes: 9 additions & 0 deletions src/Resource/Async/Git/EmptyRef.php
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Async\Git;

use ApiClients\Client\Github\Resource\Git\EmptyRef as BaseEmptyRef;

class EmptyRef extends BaseEmptyRef
{
}
13 changes: 13 additions & 0 deletions src/Resource/Async/Git/Ref.php
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Async\Git;

use ApiClients\Client\Github\Resource\Git\Ref as BaseRef;

class Ref extends BaseRef
{
public function refresh(): Ref
{
throw new \Exception('TODO: create refresh method!');
}
}
28 changes: 28 additions & 0 deletions src/Resource/Async/Repository.php
Expand Up @@ -6,23 +6,29 @@
use ApiClients\Client\Github\CommandBus\Command\Repository\AddLabelCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\AddWebHookCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\AppVeyorCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\BlobCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\BranchesCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\CommitsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\CommunityHealthCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\Contents\FileUploadCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\ContentsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\LabelsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\LanguagesCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\RefsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\ReleasesCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\ReplaceTopicsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\ScrutinizerCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\SubscribeCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\TagsCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\TravisCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\TreeCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\UnSubscribeCommand;
use ApiClients\Client\Github\CommandBus\Command\Repository\UpdateSettingsCommand;
use ApiClients\Client\Github\CommandBus\Command\WebHooksCommand;
use ApiClients\Client\Github\Resource\Git\TreeInterface;
use ApiClients\Client\Github\Resource\Repository as BaseRepository;
use ApiClients\Client\Github\VO\NamedBlob;
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
use React\Promise\PromiseInterface;
use React\Stream\ReadableStreamInterface;
Expand Down Expand Up @@ -191,4 +197,26 @@ public function updateSettings(array $settings): PromiseInterface

return $this->handleCommand(new UpdateSettingsCommand($this->fullName(), $settings));
}

public function blob(ReadableStreamInterface $contents): PromiseInterface
{
return $this->handleCommand(new BlobCommand($this->fullName(), $contents));
}

public function tree(?string $baseTree, NamedBlob ...$blobs): PromiseInterface
{
return $this->handleCommand(new TreeCommand($this->fullName(), $baseTree, ...$blobs));
}

public function commit(string $message, TreeInterface $tree, ?string ...$baseCommits): PromiseInterface
{
return $this->handleCommand(new CommitCommand($this->fullName(), $message, $tree->sha(), ...$baseCommits));
}

public function refs(?string $namespace = null): ObservableInterface
{
return unwrapObservableFromPromise($this->handleCommand(
new RefsCommand($this->fullName(), $namespace)
));
}
}
32 changes: 32 additions & 0 deletions src/Resource/Git/EmptyRef.php
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Git;

use ApiClients\Foundation\Resource\EmptyResourceInterface;

abstract class EmptyRef implements RefInterface, EmptyResourceInterface
{
/**
* @return string
*/
public function ref(): string
{
return null;
}

/**
* @return string
*/
public function url(): string
{
return null;
}

/**
* @return Git\Ref\Object_
*/
public function author(): Git\Ref\Object_
{
return null;
}
}
55 changes: 55 additions & 0 deletions src/Resource/Git/Ref.php
@@ -0,0 +1,55 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Git;

use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
use ApiClients\Foundation\Hydrator\Annotation\Nested;
use ApiClients\Foundation\Resource\AbstractResource;

/**
* @Nested(
* author="Git\Ref\Object_"
* )
* @EmptyResource("Git\EmptyRef")
*/
abstract class Ref extends AbstractResource implements RefInterface
{
/**
* @var string
*/
protected $ref;

/**
* @var string
*/
protected $url;

/**
* @var Git\Ref\Object_
*/
protected $author;

/**
* @return string
*/
public function ref(): string
{
return $this->ref;
}

/**
* @return string
*/
public function url(): string
{
return $this->url;
}

/**
* @return Git\Ref\Object_
*/
public function author(): Git\Ref\Object_
{
return $this->author;
}
}
32 changes: 32 additions & 0 deletions src/Resource/Git/Ref/EmptyObject_.php
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Git\Ref;

use ApiClients\Foundation\Resource\EmptyResourceInterface;

abstract class EmptyObject_ implements Object_Interface, EmptyResourceInterface
{
/**
* @return string
*/
public function type(): string
{
return null;
}

/**
* @return string
*/
public function sha(): string
{
return null;
}

/**
* @return string
*/
public function url(): string
{
return null;
}
}
51 changes: 51 additions & 0 deletions src/Resource/Git/Ref/Object_.php
@@ -0,0 +1,51 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Git\Ref;

use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
use ApiClients\Foundation\Resource\AbstractResource;

/**
* @EmptyResource("Git\Ref\EmptyObject_")
*/
abstract class Object_ extends AbstractResource implements Object_Interface
{
/**
* @var string
*/
protected $type;

/**
* @var string
*/
protected $sha;

/**
* @var string
*/
protected $url;

/**
* @return string
*/
public function type(): string
{
return $this->type;
}

/**
* @return string
*/
public function sha(): string
{
return $this->sha;
}

/**
* @return string
*/
public function url(): string
{
return $this->url;
}
}
25 changes: 25 additions & 0 deletions src/Resource/Git/Ref/Object_Interface.php
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Resource\Git\Ref;

use ApiClients\Foundation\Resource\ResourceInterface;

interface Object_Interface extends ResourceInterface
{
const HYDRATE_CLASS = 'Git\\Ref\\Object_';

/**
* @return string
*/
public function type(): string;

/**
* @return string
*/
public function sha(): string;

/**
* @return string
*/
public function url(): string;
}

0 comments on commit f97c370

Please sign in to comment.