forked from minicli/action-contributors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minicli
executable file
·56 lines (44 loc) · 1.59 KB
/
minicli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/php
<?php
if(php_sapi_name() !== 'cli') {
exit;
}
require __DIR__ . '/vendor/autoload.php';
use Minicli\App;
use Minicli\Curly\Client;
$app = new App([
'app_path' => __DIR__ . '/app/Command',
'repository' => getenv('CONTRIB_REPOSITORY') ?: 'minicli/minicli',
'output_file' => getenv('CONTRIB_OUTPUT_FILE') ?: 'CONTRIBUTORS.md',
'ignore_users' => [ 'github-actions[bot]' ]
]);
$app->registerCommand('update-contributors', function () use ($app) {
$app->getPrinter()->info('Fetching top contributors...');
$client = new Client();
$response = $client->get(
"https://api.github.com/repos/" . $app->config->repository. "/contributors",
['Accept: application/vnd.github.v3+json', 'User-Agent: Curly']
);
if ($response['code'] != 200) {
$app->getPrinter()->error("an error occurred: " . $response['code']);
return 1;
}
$content = "# Contributors\n\n";
$content .= "Shout out to our top contributors!\n\n";
foreach (json_decode($response['body']) as $item) {
if (!in_array($item->login, $app->config->ignore_users)) {
$content .= "- [$item->login]($item->html_url)\n";
}
}
try {
$contrib_file = fopen($app->config->output_file, 'w+');
fwrite($contrib_file, $content);
fclose($contrib_file);
} catch (Exception $exception) {
$app->getPrinter()->error("An error occurred while trying to save the contrib file.");
return 1;
}
$app->getPrinter()->success("Finished updating contrib file.");
return 0;
});
$app->runCommand($argv);