in ng-dev/caretaker/handoff/update-github-team.ts [17:77]
export async function updateCaretakerTeamViaPrompt() {
/** Caretaker specific configuration. */
const config = getConfig();
assertValidCaretakerConfig(config);
const {caretakerGroup} = config.caretaker;
if (caretakerGroup === undefined) {
throw Error('`caretakerGroup` is not defined in the `caretaker` config');
}
/** The list of current members in the group. */
const current = 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`);
const {
/** The list of users selected to be members of the caretaker group. */
selected,
/** Whether the user positively confirmed the selected made. */
confirm,
} = await prompt([
{
type: 'checkbox',
choices: roster,
message: 'Select 2 caretakers for the upcoming rotation:',
default: current,
name: 'selected',
prefix: '',
validate: (selected: string[]) => {
if (selected.length !== 2) {
return 'Please select exactly 2 caretakers for the upcoming rotation.';
}
return true;
},
},
{
type: 'confirm',
default: true,
prefix: '',
message: 'Are you sure?',
name: 'confirm',
},
]);
if (confirm === false) {
info(yellow(' ⚠ Skipping caretaker group update.'));
return;
}
if (JSON.stringify(selected) === JSON.stringify(current)) {
info(green(' √ Caretaker group already up to date.'));
return;
}
try {
await setCaretakerGroup(caretakerGroup, selected);
} catch {
info(red(' ✘ Failed to update caretaker group.'));
return;
}
info(green(' √ Successfully updated caretaker group'));
}