python3Packages.scikit-survival: fix and update (#359183)
[NixPkgs.git] / maintainers / scripts / fix-maintainers.pl
blobc953cff5cc4878edbe732c4afdb623c9a8a9dcb5
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i perl -p perl -p perlPackages.LWP -p perlPackages.LWPProtocolHttps -p perlPackages.LWPUserAgent -p perlPackages.JSON -p perlPackages.PathTiny
3 use LWP::UserAgent;
4 use JSON;
5 use Path::Tiny;
6 use strict;
7 use warnings;
9 my $maintainers_list_nix = "../maintainer-list.nix";
10 my $maintainers_json = from_json(`nix-instantiate --json --eval --expr 'builtins.fromJSON (builtins.toJSON (import $maintainers_list_nix))'`);
12 STDOUT->autoflush(1);
14 my $ua = LWP::UserAgent->new();
16 if (!defined $ENV{GH_TOKEN}) {
17 die "Set GH_TOKEN before running this script";
20 keys %$maintainers_json; # reset the internal iterator so a prior each() doesn't affect the loop
21 while(my($k, $v) = each %$maintainers_json) {
22 my $current_user = %$v{'github'};
23 if (!defined $current_user) {
24 print "$k has no github handle\n";
26 my $github_id = %$v{'githubId'};
27 if (!defined $github_id) {
28 print "$k has no githubId\n";
29 next;
31 my $url = 'https://api.github.com/user/' . $github_id;
32 my $resp = $ua->get(
33 $url,
34 "Authorization" => "Token $ENV{GH_TOKEN}"
37 if ($resp->header("X-RateLimit-Remaining") == 0) {
38 my $ratelimit_reset = $resp->header("X-RateLimit-Reset");
39 print "Request limit exceeded, waiting until " . scalar localtime $ratelimit_reset . "\n";
40 sleep($ratelimit_reset - time() + 5);
42 if ($resp->code != 200) {
43 print "$k likely deleted their github account\n";
44 next;
46 my $resp_json = from_json($resp->content);
47 my $api_user = %$resp_json{"login"};
48 if (!defined $current_user) {
49 print "$k is known on github as $api_user.\n";
51 elsif (lc($current_user) ne lc($api_user)) {
52 print "$k is now known on github as $api_user. Editing maintainer-list.nix…\n";
53 my $file = path($maintainers_list_nix);
54 my $data = $file->slurp_utf8;
55 $data =~ s/github = "$current_user";$/github = "$api_user";/m;
56 $file->spew_utf8($data);