|
1 | 1 | <?php declare(strict_types=1);
|
2 | 2 |
|
3 | 3 | /**
|
4 |
| - * This example enables travis for all repositories |
5 |
| - * with a .travis.yml that aren't forks and aren't enabled yet. |
| 4 | + * This example enables travis, appveyor, and scrutinizer for all |
| 5 | + * repositories with .travis.yml, appveyor.yml, and .scrutinizer.yml |
| 6 | + * files that aren't forks and aren't enabled yet. |
6 | 7 | */
|
7 | 8 |
|
8 | 9 | use ApiClients\Client\AppVeyor\AsyncClient as AsyncAppVeyorClient;
|
|
11 | 12 | use ApiClients\Client\Github\Resource\Async\Repository;
|
12 | 13 | use ApiClients\Client\Github\Resource\Contents\FileInterface;
|
13 | 14 | use ApiClients\Client\Github\Resource\UserInterface;
|
| 15 | +use ApiClients\Client\Scrutinizer\AsyncClient as AsyncScrutinizerClient; |
| 16 | +use ApiClients\Client\Scrutinizer\AsyncClientInterface as AsyncScrutinizerClientInterface; |
14 | 17 | use ApiClients\Client\Travis\AsyncClient as AsyncTravisClient;
|
15 | 18 | use ApiClients\Client\Travis\AsyncClientInterface as AsyncTravisClientInterface;
|
16 | 19 | use ApiClients\Client\Travis\Resource\Async\Repository as TravisRepository;
|
|
19 | 22 | use ApiClients\Middleware\Delay\DelayMiddleware;
|
20 | 23 | use ApiClients\Middleware\Pool\PoolMiddleware;
|
21 | 24 | use React\EventLoop\Factory;
|
| 25 | +use function React\Promise\resolve; |
22 | 26 | use ResourcePool\Pool;
|
23 | 27 | use Rx\Observable;
|
24 | 28 | use function ApiClients\Foundation\resource_pretty_print;
|
|
52 | 56 | $travisClient = AsyncTravisClient::create($loop, require 'resolve_travis-key.php', [
|
53 | 57 | Options::TRANSPORT_OPTIONS => $transportOptions,
|
54 | 58 | ]);
|
| 59 | +$scrutinizerClient = AsyncScrutinizerClient::create($loop, require 'resolve_scrutinizer-token.php', [ |
| 60 | + Options::TRANSPORT_OPTIONS => $transportOptions, |
| 61 | +]); |
55 | 62 | $githubClient = AsyncClient::create($loop, require 'resolve_token.php', [
|
56 | 63 | Options::TRANSPORT_OPTIONS => $transportOptions,
|
57 | 64 | // Pass the AppVeyor and Travis client into the Github client internal container
|
58 | 65 | Options::CONTAINER_DEFINITIONS => [
|
59 | 66 | AsyncAppVeyorClient::class => $appVeyorClient,
|
60 | 67 | AsyncTravisClientInterface::class => $travisClient,
|
| 68 | + AsyncScrutinizerClientInterface::class => $scrutinizerClient, |
61 | 69 | ],
|
62 | 70 | ]);
|
63 | 71 |
|
|
81 | 89 | // Only check repositories that start with reactphp-http
|
82 | 90 | // This is optional and you can remove this to check all repositories
|
83 | 91 | // BUT that takes a lot of calls to check and time due to throttling
|
84 |
| - return strpos($repository->name(), 'php-super') === 0; |
| 92 | + return strpos($repository->name(), 'reactphp-') === 0; |
85 | 93 | })->flatMap(function (Repository $repository) {
|
86 | 94 | // Check if the repository contains a .travis.yml
|
87 | 95 | return Observable::fromPromise(new React\Promise\Promise(function ($resolve, $reject) use ($repository) {
|
88 | 96 | $hasCi = [
|
89 | 97 | 'repo' => $repository,
|
90 | 98 | 'travis' => false,
|
91 | 99 | 'appveyor' => false,
|
| 100 | + 'scrutinizer' => false, |
92 | 101 | ];
|
93 | 102 | $repository->contents()->filter(function ($node) {
|
94 | 103 | // Only let through files
|
|
102 | 111 | if ($file->name() === 'appveyor.yml') {
|
103 | 112 | $hasCi['appveyor'] = true;
|
104 | 113 |
|
| 114 | + return; |
| 115 | + } |
| 116 | + if ($file->name() === '.scrutinizer.yml') { |
| 117 | + $hasCi['scrutinizer'] = true; |
| 118 | + |
105 | 119 | return;
|
106 | 120 | }
|
107 | 121 | }, function ($error) use ($reject) {
|
|
134 | 148 | // Activate repository on Travis
|
135 | 149 | $repository->enable()->done(function (TravisRepository $repository) {
|
136 | 150 | resource_pretty_print($repository);
|
137 |
| - }, 'display_throwable'); |
138 |
| -}, 'display_throwable'); |
| 151 | + }, function ($e) { |
| 152 | + echo 'Travis', PHP_EOL; |
| 153 | + echo (string)$e; |
| 154 | + }); |
| 155 | +}, function ($e) { |
| 156 | + echo 'Travis', PHP_EOL; |
| 157 | + echo (string)$e; |
| 158 | +}); |
139 | 159 |
|
140 | 160 | /**
|
141 | 161 | * Stream handling the AppVeyor side of things.
|
|
153 | 173 | return $appVeyorClient->addProject('gitHub', $repository->fullName());
|
154 | 174 | })->done(function ($repository) {
|
155 | 175 | resource_pretty_print($repository);
|
156 |
| - }, 'display_throwable'); |
157 |
| -}, 'display_throwable'); |
| 176 | + }, function ($e) { |
| 177 | + if ($e === null) { |
| 178 | + return; |
| 179 | + } |
| 180 | + |
| 181 | + echo 'AppVeyor', PHP_EOL; |
| 182 | + echo (string)$e; |
| 183 | + }); |
| 184 | +}, function ($e) { |
| 185 | + echo 'AppVeyor', PHP_EOL; |
| 186 | + echo (string)$e; |
| 187 | +}); |
| 188 | + |
| 189 | +/** |
| 190 | + * Stream handling the Scrutinizer side of things. |
| 191 | + */ |
| 192 | +$baseStream->filter(function (array $d) { |
| 193 | + return $d['scrutinizer']; |
| 194 | +})->map(function (array $d) { |
| 195 | + return $d['repo']; |
| 196 | +})->subscribe(function (Repository $repository) use ($scrutinizerClient) { |
| 197 | + $repository->scrutinizerRepository()->then(function ($scrutinizer) use ($scrutinizerClient, $repository) { |
| 198 | + if ($scrutinizer !== false) { |
| 199 | + return reject(); |
| 200 | + } |
| 201 | + |
| 202 | + return $scrutinizerClient->github()->addRepository($repository->fullName()); |
| 203 | + })->done(function ($repository) { |
| 204 | + resource_pretty_print($repository); |
| 205 | + }, function ($e) { |
| 206 | + if ($e === null) { |
| 207 | + return; |
| 208 | + } |
| 209 | + |
| 210 | + echo 'Scrutinizer', PHP_EOL; |
| 211 | + echo (string)$e; |
| 212 | + }); |
| 213 | +}, function ($e) { |
| 214 | + echo 'Scrutinizer', PHP_EOL; |
| 215 | + echo (string)$e; |
| 216 | +}); |
158 | 217 |
|
159 | 218 | $loop->run();
|
160 | 219 |
|
|
0 commit comments