lib.teams: Collect all errors for missing lib.maintainers entries

In https://github.com/NixOS/nixpkgs/pull/471116#pullrequestreview-3580366406
we had two users without maintainer entries, while CI only showed one
This commit is contained in:
Silvan Mosberger 2025-12-15 23:27:12 +01:00
parent b5bb9861d6
commit e53ca90334

View file

@ -12,48 +12,65 @@ let
]; ];
maintainerSetToList = maintainerSetToList =
githubTeam: githubTeam: users:
lib.mapAttrsToList (
login: id:
maintainersById.${toString id}
or (throw "lib.teams: No maintainer entry for GitHub user @${login} who's part of the @NixOS/${githubTeam} team")
);
in
# TODO: Consider automatically exposing all GitHub teams under `lib.teams`,
# so that no manual PRs are necessary to add such teams anymore
lib.mapAttrs (
name: attrs:
if attrs ? github then
let let
githubTeam = missingUsers = lib.filter (login: !maintainersById ? ${toString users.${login}}) (
githubTeams.${attrs.github} lib.attrNames users
or (throw "lib.teams.${name}: Corresponding GitHub team ${attrs.github} not known yet, make sure to create it and wait for the regular team sync"); );
in in
# TODO: Consider specifying `githubId` in team-list.nix and inferring `github` from it (or even dropping it) if missingUsers == [ ] then
# This would make renames easier because no additional place needs to keep track of them. lib.mapAttrsToList (login: id: maintainersById.${toString id}) users
# Though in a future where all Nixpkgs GitHub teams are automatically exposed under `lib.teams`, else
# this would also not be an issue anymore. {
assert lib.assertMsg (!attrs ? githubId) errors = map (
"lib.teams.${name}: Both `githubId` and `github` is set, but the former is synced from the latter"; login:
assert lib.assertMsg (!attrs ? shortName) "\n- No maintainer entry for GitHub user @${login} who's part of the @NixOS/${githubTeam} team"
"lib.teams.${name}: Both `shortName` and `github` is set, but the former is synced from the latter"; ) missingUsers;
assert lib.assertMsg ( };
!attrs ? scope
) "lib.teams.${name}: Both `scope` and `github` is set, but the former is synced from the latter"; # TODO: Consider automatically exposing all GitHub teams under `lib.teams`,
assert lib.assertMsg ( # so that no manual PRs are necessary to add such teams anymore
!attrs ? members result = lib.mapAttrs (
) "lib.teams.${name}: Both `members` and `github` is set, but the former is synced from the latter"; name: attrs:
attrs if attrs ? github then
// { let
githubId = githubTeam.id; githubTeam =
shortName = githubTeam.name; githubTeams.${attrs.github}
scope = githubTeam.description; or (throw "lib.teams.${name}: Corresponding GitHub team ${attrs.github} not known yet, make sure to create it and wait for the regular team sync");
members = maintainers = maintainerSetToList attrs.github githubTeam.maintainers;
maintainerSetToList attrs.github githubTeam.maintainers nonMaintainers = maintainerSetToList attrs.github githubTeam.members;
++ maintainerSetToList attrs.github githubTeam.members; in
githubMaintainers = maintainerSetToList attrs.github githubTeam.maintainers; # TODO: Consider specifying `githubId` in team-list.nix and inferring `github` from it (or even dropping it)
} # This would make renames easier because no additional place needs to keep track of them.
else # Though in a future where all Nixpkgs GitHub teams are automatically exposed under `lib.teams`,
attrs # this would also not be an issue anymore.
) teams assert lib.assertMsg (!attrs ? githubId)
"lib.teams.${name}: Both `githubId` and `github` is set, but the former is synced from the latter";
assert lib.assertMsg (!attrs ? shortName)
"lib.teams.${name}: Both `shortName` and `github` is set, but the former is synced from the latter";
assert lib.assertMsg (
!attrs ? scope
) "lib.teams.${name}: Both `scope` and `github` is set, but the former is synced from the latter";
assert lib.assertMsg (
!attrs ? members
) "lib.teams.${name}: Both `members` and `github` is set, but the former is synced from the latter";
if !maintainers ? errors && !nonMaintainers ? errors then
attrs
// {
githubId = githubTeam.id;
shortName = githubTeam.name;
scope = githubTeam.description;
members = maintainers ++ nonMaintainers;
githubMaintainers = maintainers;
}
else
maintainers.errors or [ ] ++ nonMaintainers.errors or [ ]
else
attrs
) teams;
errors = lib.concatLists (
lib.mapAttrsToList (name: value: value) (lib.filterAttrs (name: lib.isList) result)
);
in
if errors == [ ] then result else throw ("lib.teams:" + lib.concatStrings errors)