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
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))'`);
14 my $ua = LWP
::UserAgent
->new();
16 keys %$maintainers_json; # reset the internal iterator so a prior each() doesn't affect the loop
17 while(my($k, $v) = each %$maintainers_json) {
18 my $current_user = %$v{'github'};
19 if (!defined $current_user) {
20 print "$k has no github handle\n";
23 my $github_id = %$v{'githubId'};
24 if (!defined $github_id) {
25 print "$k has no githubId\n";
28 my $url = 'https://api.github.com/user/' . $github_id;
31 "Authorization" => "Token $ENV{GH_TOKEN}"
34 if ($resp->header("X-RateLimit-Remaining") == 0) {
35 my $ratelimit_reset = $resp->header("X-RateLimit-Reset");
36 print "Request limit exceeded, waiting until " . scalar localtime $ratelimit_reset . "\n";
37 sleep($ratelimit_reset - time() + 5);
39 if ($resp->code != 200) {
40 print $current_user . " likely deleted their github account\n";
43 my $resp_json = from_json
($resp->content);
44 my $api_user = %$resp_json{"login"};
45 if (lc($current_user) ne lc($api_user)) {
46 print $current_user . " is now known on github as " . $api_user . ". Editing maintainer-list.nix…\n";
47 my $file = path
($maintainers_list_nix);
48 my $data = $file->slurp_utf8;
49 $data =~ s/github = "$current_user";$/github = "$api_user";/m;
50 $file->spew_utf8($data);