nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1#!/usr/bin/env nix-shell
2#!nix-shell -i perl -p perl -p perlPackages.JSON github-cli
3
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.
6#
7# The script uses the credentials from the GitHub CLI (gh)
8# This is required to access the GitHub Teams API so it needs at least the read:org privilege.
9
10## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::ProhibitBacktickOperators)
11use strict;
12use warnings;
13use Carp;
14use Cwd 'abs_path';
15use File::Basename;
16use JSON qw(decode_json);
17
18sub github_team_members {
19 my ($team_name) = @_;
20 my @ret;
21
22 my $content = decode_json(`gh api orgs/NixOS/teams/$team_name/members`);
23 foreach (@{$content}) {
24 push @ret, $_->{'login'};
25 }
26
27 return \@ret;
28}
29
30`gh auth status` or die "`gh` comes from `pkgs.github-cli`, or in one command:
31nix-shell -p github-cli --run 'gh auth login'\n";
32
33# Read nix output
34my $nix_version = `nix --version`;
35my $out;
36my $lib_path = abs_path(dirname(__FILE__)) . '../../../lib';
37if ($nix_version =~ m/2[.]3[.]/msx) {
38 $out = `nix eval --json '(import $lib_path).teams'` || croak 'nix eval failed';
39} else {
40 $out = `nix --extra-experimental-features nix-command eval --json --impure --expr '(import $lib_path).teams'` || croak('nix eval failed');
41}
42my $data = decode_json($out);
43
44# Process teams
45while (my ($team_nix_key, $team_config) = each %{$data}) {
46 # Ignore teams that don't want to be or can't be pinged
47 if (not defined $team_config->{enableFeatureFreezePing} or not $team_config->{enableFeatureFreezePing}) {
48 next;
49 }
50 if (not defined $team_config->{shortName}) {
51 print {*STDERR} "!! The team with the nix key '$team_nix_key' has no shortName set - ignoring";
52 next;
53 }
54 # Team name
55 print {*STDOUT} "$team_config->{shortName}:";
56 # GitHub Teams
57 my @github_members;
58 if (defined $team_config->{github}) {
59 print {*STDOUT} " \@NixOS/$team_config->{github}";
60 push @github_members, @{github_team_members($team_config->{github})};
61 }
62 my %github_members = map { $_ => 1 } @github_members;
63 # Members
64 if (defined $team_config->{members}) {
65 foreach (@{$team_config->{members}}) {
66 my %user = %{$_};
67 my $github_handle = $user{'github'};
68 # Ensure we don't ping team members twice (as team member and directly)
69 if (defined $github_members{$github_handle}) {
70 next;
71 }
72 print {*STDOUT} " \@$github_handle";
73 }
74 }
75
76 print {*STDOUT} "\n";
77}
78
79print {*STDOUT} "Everyone else: \@NixOS/nixpkgs-committers\n";