|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +use ApiClients\Client\Github\AsyncClient; |
| 4 | +use ApiClients\Client\Github\Resource\Async\Git\Commit; |
| 5 | +use ApiClients\Client\Github\Resource\Async\Git\Ref; |
| 6 | +use ApiClients\Client\Github\Resource\Async\Repository; |
| 7 | +use ApiClients\Client\Github\Resource\Git\RefInterface; |
| 8 | +use ApiClients\Client\Github\Resource\TreeInterface; |
| 9 | +use ApiClients\Client\Github\Resource\UserInterface; |
| 10 | +use ApiClients\Client\Github\VO\NamedBlob; |
| 11 | +use function ApiClients\Foundation\resource_pretty_print; |
| 12 | +use React\EventLoop\Factory; |
| 13 | +use React\Stream\ThroughStream; |
| 14 | +use Rx\React\Promise; |
| 15 | + |
| 16 | +require \dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'vendor/autoload.php'; |
| 17 | + |
| 18 | +$loop = Factory::create(); |
| 19 | +$client = AsyncClient::create($loop, require 'resolve_token.php'); |
| 20 | + |
| 21 | +$client->user($argv[1] ?? 'WyriHaximus')->then(function (UserInterface $user) use ($argv) { |
| 22 | + resource_pretty_print($user); |
| 23 | + |
| 24 | + return $user->repository($argv[2] ?? 'php-api-clients-github-client-playground-expert-octo-spork'); |
| 25 | +})->then(function (Repository $repository) use ($argv, $loop) { |
| 26 | + resource_pretty_print($repository); |
| 27 | + |
| 28 | + $stream = new ThroughStream(); |
| 29 | + |
| 30 | + $loop->addTimer(1, function () use ($stream) { |
| 31 | + $stream->end(\bin2hex(\random_bytes(2048))); |
| 32 | + }); |
| 33 | + |
| 34 | + return $repository->blob($stream)->then(function (TreeInterface $tree) use ($repository) { |
| 35 | + resource_pretty_print($tree); |
| 36 | + |
| 37 | + return Promise::fromObservable($repository->commits()->take(1))->then(function (Repository\Commit $commit) use ($tree, $repository) { |
| 38 | + return $repository->tree( |
| 39 | + $commit->commit()->tree()->sha(), |
| 40 | + new NamedBlob( |
| 41 | + \bin2hex(\random_bytes(13)), |
| 42 | + '100644', |
| 43 | + 'blob', |
| 44 | + $tree->sha(), |
| 45 | + null |
| 46 | + ) |
| 47 | + )->then(function (\ApiClients\Client\Github\Resource\Git\TreeInterface $tree) use ($repository, $commit) { |
| 48 | + return $repository->commit( |
| 49 | + 'Commit message: ' . \bin2hex(\random_bytes(13)), |
| 50 | + $tree, |
| 51 | + $commit->sha() |
| 52 | + ); |
| 53 | + }); |
| 54 | + }); |
| 55 | + })->then(function (Commit $commit) use ($repository) { |
| 56 | + return Promise::fromObservable($repository->refs()->filter(function (RefInterface $ref) { |
| 57 | + return $ref->ref() === 'refs/heads/master'; |
| 58 | + }))->then(function (?Ref $ref) use ($repository, $commit) { |
| 59 | + if ($ref === null) { |
| 60 | + die('whoops'); |
| 61 | + |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + return $repository->ref($ref, $commit); |
| 66 | + }); |
| 67 | + }); |
| 68 | +})->done(function ($resource) { |
| 69 | + resource_pretty_print($resource); |
| 70 | +}, 'display_throwable'); |
| 71 | + |
| 72 | +$loop->run(); |
| 73 | + |
| 74 | +displayState($client->getRateLimitState()); |
0 commit comments