Skip to content
/ beam Public
forked from apache/beam

Commit

Permalink
Use fallback reviewers for bot (apache#33155)
Browse files Browse the repository at this point in the history
  • Loading branch information
damccorm authored Nov 18, 2024
1 parent a568bb8 commit 0871f93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion scripts/ci/pr-bot/findPrsNeedingAttention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,16 @@ async function assignToNewReviewers(
reviewersToExclude.push(pull.user.login);
const reviewersForLabels: { [key: string]: string[] } =
reviewerConfig.getReviewersForLabels(labelObjects, reviewersToExclude);
const fallbackReviewers =
reviewerConfig.getFallbackReviewers();
for (const labelObject of labelObjects) {
const label = labelObject.name;
let availableReviewers = reviewersForLabels[label];
if (availableReviewers && availableReviewers.length > 0) {
let reviewersState = await stateClient.getReviewersForLabelState(label);
let chosenReviewer = await reviewersState.assignNextCommitter(
availableReviewers
availableReviewers,
fallbackReviewers
);
reviewerStateToUpdate[label] = reviewersState;
prState.reviewersAssignedForLabels[label] = chosenReviewer;
Expand Down
5 changes: 4 additions & 1 deletion scripts/ci/pr-bot/processNewPrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ async function processPull(
);
const availableReviewers =
reviewerConfig.getReviewersForLabel(labelOfReviewer);
const fallbackReviewers =
reviewerConfig.getFallbackReviewers();
const chosenCommitter = await reviewersState.assignNextCommitter(
availableReviewers
availableReviewers,
fallbackReviewers
);
prState.reviewersAssignedForLabels[labelOfReviewer] = chosenCommitter;
prState.committerAssigned = true;
Expand Down
9 changes: 7 additions & 2 deletions scripts/ci/pr-bot/shared/reviewersForLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class ReviewersForLabel {
// Given the up to date list of available reviewers (excluding the author),
// returns the next reviewer up based on who has reviewed least recently.
// Updates this object to reflect their assignment.
async assignNextCommitter(availableReviewers: string[]): Promise<string> {
async assignNextCommitter(
availableReviewers: string[],
fallbackReviewers: string[]
): Promise<string> {
let earliestDate = Date.now();
let earliestCommitter: string = "";

Expand All @@ -94,7 +97,9 @@ export class ReviewersForLabel {
}

if (!earliestCommitter) {
throw new Error(`No committers available for label ${this.label}`);
console.log(`No committers available for label ${this.label}`);
console.log(`Using fallbackReviewers label instead of ${this.label}`);
return this.assignNextCommitter(fallbackReviewers, fallbackReviewers);
}
this.dateOfLastReviewAssignment[earliestCommitter] = Date.now();
return earliestCommitter;
Expand Down

0 comments on commit 0871f93

Please sign in to comment.