Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions ng-dev/caretaker/handoff/update-github-team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ export async function updateCaretakerTeamViaPrompt() {

/** The list of current members in the group. */
const current = new Set(await getGroupMembers(caretakerGroup));
/** The list of members able to be added to the group as defined by a separate roster group. */
const roster = (await getGroupMembers(`${caretakerGroup}-roster`)).map((member) => ({
value: member,
checked: current.has(member),
}));
const [roster, emeaRoster] = await Promise.all([
getGroupMembers(`${caretakerGroup}-roster`),
getGroupMembers(`${caretakerGroup}-roster-emea`),
]);

/** The list of users selected to be members of the caretaker group. */
const selected = await Prompt.checkbox({
choices: roster,
message: 'Select 2 caretakers for the upcoming rotation:',
const selectedPrimaryAndSecondary = await Prompt.checkbox<string>({
choices: roster.map((member) => ({
value: member,
checked: current.has(member),
})),
message: 'Select 2 caretakers for the upcoming rotation (primary and secondary):',
validate: (value) => {
if (value.length !== 2) {
return 'Please select exactly 2 caretakers for the upcoming rotation.';
Expand All @@ -42,6 +44,19 @@ export async function updateCaretakerTeamViaPrompt() {
},
});

const emeaOptions = emeaRoster
// Do not show members that are already selected as primary/secondary.
.filter((m) => !selectedPrimaryAndSecondary.includes(m))
.map((member) => ({
value: member,
name: `${member} (EMEA)`,
checked: current.has(member),
}));
const selectedEmea = await Prompt.select<string>({
choices: emeaOptions,
message: 'Select EMEA caretaker',
});

/** Whether the user positively confirmed the selected made. */
const confirmation = await Prompt.confirm({
default: true,
Expand All @@ -53,13 +68,16 @@ export async function updateCaretakerTeamViaPrompt() {
return;
}

if (JSON.stringify(selected) === JSON.stringify(current)) {
const selectedSorted = [...selectedPrimaryAndSecondary, selectedEmea].sort();
const currentSorted = Array.from(current).sort();

if (JSON.stringify(selectedSorted) === JSON.stringify(currentSorted)) {
Log.info(green(' ✔ Caretaker group already up to date.'));
return;
}

try {
await setCaretakerGroup(caretakerGroup, selected);
await setCaretakerGroup(caretakerGroup, selectedSorted);
} catch {
Log.error(' ✘ Failed to update caretaker group.');
return;
Expand Down