flush
[m6w6/seekat] / examples / hooks.php
1 #!/usr/bin/env php
2 <?php
3
4 require_once __DIR__."/../vendor/autoload.php";
5
6 use seekat\{API, API\Future, API\Links};
7 use Monolog\{Logger, Handler};
8
9 $cli = new http\Client("curl", "seekat");
10 $cli->configure([
11 "max_host_connections" => 10,
12 "max_total_connections" => 50,
13 "use_eventloop" => true,
14 ]);
15
16 $log = new Logger("seekat");
17 $log->pushHandler(new Handler\StreamHandler(STDERR, Logger::NOTICE));
18
19 $api = new API(Future\react(), API\auth("token", getenv("GITHUB_TOKEN")), null, $cli, $log);
20
21 $api(function() use($api) {
22 $repos = yield $api->users->m6w6->repos([
23 "visibility" => "public",
24 "affiliation" => "owner"
25 ]);
26 while ($repos) {
27 $next = Links\next($repos);
28
29 $batch = [];
30 foreach ($repos as $repo) {
31 $batch[] = $repo->hooks();
32 }
33 foreach (yield $batch as $key => $hooks) {
34 if (!count($hooks)) {
35 continue;
36 }
37 printf("%s:\n", $repos->{$key}->name);
38 foreach ($hooks as $hook) {
39 if ($hook->name == "web") {
40 printf("\t%s\n", $hook->config->url);
41 } else {
42 printf("\t%s\n", $hook->name);
43 }
44 }
45 }
46
47 $repos = yield $next;
48 }
49 });