-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgithub-issue-labels
executable file
·119 lines (101 loc) · 2.77 KB
/
github-issue-labels
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!perl
use v5.30.0;
use warnings;
use Getopt::Long::Descriptive;
use JSON::MaybeXS;
use Path::Tiny;
use Pithub;
my ($opt, $usage) = describe_options(
'%c %o',
[ 'labels-file|f=s', 'from which to read labels', ],
[ 'really', 'actually make changes; otherwise, do a dry run' ],
[ 'delete', 'delete unexpected labels' ],
);
my $pithub = Pithub->new(
user => $ENV{USER},
token => $ENV{PITHUB_TOKEN},
auto_pagination => 1,
);
my %want;
if ($opt->labels_file) {
my $file = path($opt->labels_file);
my $json = $file->slurp_utf8;
my $data = decode_json($json);
%want = %$data;
} else {
%want = (
'Abandoned?' => '000000',
'Already Fixed?' => 'ffffff',
'Critical' => 'ff0000',
'Docs' => 'cc00cc',
# 'Hacktoberfest' => 'ff7619',
'Needs Champion' => 'e11d21',
'Needs Rebase' => 'ffb8d4',
'Needs Rework' => '00c0c0',
'Release Soon' => '009800',
'Should Be Fixed' => '736C0F',
'Test' => 'ff8833',
'Wishlist' => 'ffff00',
);
}
REPO: for my $repo (@ARGV) {
my ($user, $repo) = split m{/}, $repo, 2;
die "bogus input" unless $user && $repo;
my $row = $pithub->repos->get(user => $user, repo => $repo)->first;
my $labels = $pithub->issues->labels;
warn "<considering $row->{name}>\n";
# next unless $row->{owner}{login} eq $pithub->user;
next if $row->{fork};
# next unless $row->{open_issues_count};
unless ($row->{has_issues}) {
print "[error] $row->{name} does not use Issues\n";
next REPO;
}
printf "%s\n", $row->{name};
my $label_list = $labels->list(
repo => $row->{name},
user => $user,
)->content;
my %has = map {; $_->{name} => $_->{color} } @$label_list;
LABEL: for my $key (sort keys %want) {
if (my $existing = delete $has{$key}) {
next LABEL if lc $existing eq lc $want{$key};
print "Updating [$key] from $existing to $want{$key}\n";
next LABEL unless $opt->really;
$labels->update(
user => $user,
repo => $row->{name},
label => $key,
data => {
name => $key,
color => $want{$key},
},
);
} else {
print "creating $key on $row->{name}...\n";
next LABEL unless $opt->really;
my $result = $pithub->issues->labels->create(
user => $user,
repo => $row->{name},
data => {
color => $want{$key},
name => $key,
},
);
}
}
for my $unexpected (sort keys %has) {
if ($opt->delete) {
print "deleting label $unexpected\n";
if ($opt->really) {
$labels->delete(
repo => $repo,
user => $user,
label => $unexpected,
);
}
} else {
print "unexpected label $unexpected\n";
}
}
}