|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +use ApiClients\Client\Github\AsyncClient; |
| 4 | +use ApiClients\Client\Github\Resource\Async\Label; |
| 5 | +use ApiClients\Client\Github\Resource\Async\Repository; |
| 6 | +use ApiClients\Client\Github\Resource\Async\User; |
| 7 | +use React\EventLoop\Factory; |
| 8 | +use function ApiClients\Tools\Rx\unwrapObservableFromPromise; |
| 9 | +use function React\Promise\resolve; |
| 10 | + |
| 11 | +require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php'; |
| 12 | + |
| 13 | +$loop = Factory::create(); |
| 14 | +$client = AsyncClient::create($loop, require 'resolve_token.php'); |
| 15 | + |
| 16 | +unwrapObservableFromPromise($client->user($argv[1])->then(function (User $user) { |
| 17 | + return resolve($user->repositories()); |
| 18 | +}))->filter(function (Repository $repository) { |
| 19 | + return $repository->fork() === false; |
| 20 | +})->subscribe(function (Repository $repository) { |
| 21 | + $hasHacktoberfestLabel = false; |
| 22 | + $repository->labels()->filter(function (Label $label) { |
| 23 | + return strtolower($label->name()) === 'hacktoberfest'; |
| 24 | + })->subscribe(function () use (&$hasHacktoberfestLabel) { |
| 25 | + $hasHacktoberfestLabel = true; |
| 26 | + }, function ($error) { |
| 27 | + echo (string)$error; |
| 28 | + }, function () use ($repository, &$hasHacktoberfestLabel) { |
| 29 | + if ($hasHacktoberfestLabel === true) { |
| 30 | + echo $repository->fullName(), ' ✗', PHP_EOL; |
| 31 | + |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + $repository->addLabel('hacktoberfest', '3241a6')->done(function () use ($repository) { |
| 36 | + echo $repository->fullName(), ' ✓', PHP_EOL; |
| 37 | + }); |
| 38 | + }); |
| 39 | +}, function ($error) { |
| 40 | + echo (string)$error; |
| 41 | +}); |
| 42 | + |
| 43 | +$loop->run(); |
| 44 | + |
| 45 | +displayState($client->getRateLimitState()); |
0 commit comments