ad236925ffbcde60278c96dce3eed549e7b9e06f
[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;
7
8 $cli = new http\Client("curl", "seekat");
9 $cli->configure([
10 "max_host_connections" => 10,
11 "max_total_connections" => 50,
12 ]);
13
14 $log = new Monolog\Logger("seekat");
15 $log->pushHandler((new Monolog\Handler\StreamHandler(STDERR))->setLevel(Monolog\Logger::WARNING));
16
17 $api = new API([
18 "Authorization" => "token ".getenv("GITHUB_TOKEN")
19 ], 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 = $repos->next();
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 });