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
29 changes: 27 additions & 2 deletions scripts/update-topgear-reviewers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ interface ChallengeContext {
name: string;
typeId: string | null;
trackId: string | null;
type?: {
name: string | null;
} | null;
track?: {
name: string | null;
} | null;
phases: ChallengePhaseInfo[];
}

Expand Down Expand Up @@ -132,6 +138,16 @@ async function backfillChallengeReviewers() {
name: true,
typeId: true,
trackId: true,
type: {
select: {
name: true,
},
},
track: {
select: {
name: true,
},
},
phases: {
select: {
id: true,
Expand All @@ -150,6 +166,13 @@ async function backfillChallengeReviewers() {
let challengesUpdated = 0;

for (const challenge of challenges) {
const typeName = challenge.type?.name ?? 'Unknown type';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The use of ?? 'Unknown type' and ?? 'Unknown track' for default values could lead to misleading log messages if the type or track is null but typeId or trackId is present. Consider checking for typeId and trackId before assigning default values to ensure accurate logging.

const trackName = challenge.track?.name ?? 'Unknown track';

console.log(
`Processing challenge ${challenge.id} (${challenge.name}) – Type: ${typeName}, Track: ${trackName}`,
);

if (!challenge.typeId || !challenge.trackId) {
console.warn(
`Skipping challenge ${challenge.id} (${challenge.name}) because typeId or trackId is missing.`,
Expand All @@ -159,7 +182,7 @@ async function backfillChallengeReviewers() {

if (taskTypeIds.has(challenge.typeId)) {
console.log(
`Skipping challenge ${challenge.id} (${challenge.name}) because it is a Task type.`,
`Skipping challenge ${challenge.id} (${challenge.name}) because it is a Task type (Type: ${typeName}, Track: ${trackName}).`,
);
continue;
}
Expand Down Expand Up @@ -204,7 +227,9 @@ async function backfillChallengeReviewers() {

if (!matchingPhases || !matchingPhases.length) {
console.warn(
`Challenge ${challenge.id} (${challenge.name}) does not have a phase matching "${defaultReviewer.phaseName}".`,
`Challenge ${challenge.id} (${challenge.name}) does not have a phase matching "${defaultReviewer.phaseName}". Available phases: ${challenge.phases
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The console.warn statement concatenates phase names without checking if challenge.phases is empty, which could lead to an empty string being logged. Consider adding a check to ensure challenge.phases has elements before calling .map().

.map((phase) => phase.name)
.join(', ')}`,
);
continue;
}
Expand Down