-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathensure-labels.php
66 lines (50 loc) · 1.87 KB
/
ensure-labels.php
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
57
58
59
60
61
62
63
64
65
66
<?php
require_once __DIR__ . '/vendor/autoload.php';
if (empty($argv[1]) || empty($argv[2])) {
echo 'Usage: php ensure-labels.php <repository> <your_github token>';
exit(0);
}
$package = $argv[1];
$token = $argv[2];
$labelsConfig = require 'config/labels.php';
$labelsRenameConfig = require 'config/labels-rename.php';
$client = new \Github\Client();
$client->authenticate($token, null, Github\Client::AUTH_HTTP_TOKEN);
ensureLabels($client, $package, $labelsConfig, $labelsRenameConfig);
function ensureLabels(\Github\Client $client, string $package, array $labelsConfig, array $labelsRenameConfig)
{
echo "Processing $package.\n";
[$vendor, $packageName] = explode('/', $package);
$repoLabels = new \yiisoft\RepoLabels($client, $vendor, $packageName);
echo '[Renaming Labels] ';
try {
[$skipped, $renamed] = $repoLabels->rename($labelsRenameConfig);
} catch (\Github\Exception\RuntimeException $e) {
echo '[' . $e->getCode() . '] ' . $e->getMessage() . ":\n" . $e->getTraceAsString() . "\n";
exit(1);
}
if ($skipped !== []) {
echo 'Skipped: ' . implode(', ', $skipped) . ' ';
}
if ($renamed !== []) {
echo 'Renamed: ' . implode(', ', $renamed) . ' ';
}
echo "\n";
echo '[Ensuring Labels] ';
try {
[$added, $updated, $deleted] = $repoLabels->ensure($labelsConfig, ['common', 'pr', 'status', 'type', 'severity'], false);
} catch (\Github\Exception\RuntimeException $e) {
echo '[' . $e->getCode() . '] ' . $e->getMessage() . ":\n" . $e->getTraceAsString() . "\n";
exit(1);
}
if ($added !== []) {
echo 'Added: ' . implode(', ', $added) . ' ';
}
if ($updated !== []) {
echo 'Updated: ' . implode(', ', $updated) . ' ';
}
if ($deleted !== []) {
echo 'Deleted: ' . implode(', ', $deleted) . ' ';
}
echo "\n";
}