1 #!/usr/bin/env nix-shell
2 #!nix-shell -i perl -p perl -p perlPackages.JSON perlPackages.LWPUserAgent perlPackages.LWPProtocolHttps perlPackages.TermReadKey
4 # This script generates a list of teams to ping for the Feature Freeze announcement on Discourse.
5 # It's intended to be used by Release Managers before creating such posts.
7 # The script interactively reads a GitHub username and a corresponding GitHub Personal Access token.
8 # This is required to access the GitHub Teams API so the token needs at least the read:org privilege.
10 ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::ProhibitBacktickOperators)
16 use JSON
qw(decode_json);
18 use Term
::ReadKey
qw(ReadLine ReadMode);
20 sub github_team_members
{
21 my ($team_name, $username, $token) = @_;
24 my $req = HTTP
::Request
->new('GET', "https://api.github.com/orgs/NixOS/teams/$team_name/members", [ 'Accept' => 'application/vnd.github.v3+json' ]);
25 $req->authorization_basic($username, $token);
26 my $response = LWP
::UserAgent
->new->request($req);
28 if ($response->is_success) {
29 my $content = decode_json
($response->decoded_content);
30 foreach (@
{$content}) {
31 push @ret, $_->{'login'};
34 print {*STDERR
} "!! Requesting members of GitHub Team '$team_name' failed: " . $response->status_line;
40 # Read GitHub credentials
41 print {*STDERR
} 'GitHub username: ';
42 my $github_user = ReadLine
(0);
44 print {*STDERR
} 'GitHub personal access token (no echo): ';
45 my $github_token = ReadLine
(0);
52 my $nix_version = `nix --version`;
54 my $lib_path = abs_path
(dirname
(__FILE__
)) . '../../../lib';
55 if ($nix_version =~ m/2[.]3[.]/msx) {
56 $out = `nix eval --json '(import $lib_path).teams'` || croak
'nix eval failed';
58 $out = `nix --extra-experimental-features nix-command eval --json --impure --expr '(import $lib_path).teams'` || croak
('nix eval failed');
60 my $data = decode_json
($out);
64 while (my ($team_nix_key, $team_config) = each %{$data}) {
65 # Ignore teams that don't want to be or can't be pinged
66 if (not defined $team_config->{enableFeatureFreezePing
} or not $team_config->{enableFeatureFreezePing
}) {
69 if (not defined $team_config->{shortName
}) {
70 print {*STDERR
} "!! The team with the nix key '$team_nix_key' has no shortName set - ignoring";
74 print {*STDERR
} "$team_config->{shortName}:";
77 if (defined $team_config->{githubTeams
}) {
78 foreach (@
{$team_config->{githubTeams
}}) {
79 print {*STDERR
} " \@NixOS/${_}";
80 push @github_members, @
{github_team_members
($_, $github_user, $github_token)};
83 my %github_members = map { $_ => 1 } @github_members;
85 if (defined $team_config->{members
}) {
86 foreach (@
{$team_config->{members
}}) {
88 my $github_handle = $user{'github'};
89 # Ensure we don't ping team members twice (as team member and directly)
90 if (defined $github_members{$github_handle}) {
93 print {*STDERR
} " \@$github_handle";