Skip to content

Commit

Permalink
[infra] Request review from approving reviewers as well (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
michelengelen authored Nov 13, 2024
1 parent 2ba827e commit c70291b
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions .github/workflows/scripts/prs/detectTargetBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,41 @@ module.exports = async ({ core, context, github }) => {
(label) => label !== 'needs cherry-pick' && !vBranchRegex.test(label),
);

if (vBranchRegex.test(pr.head_ref)) {
// the branch this is coming from is a version branch, so one of the targets should be master
core.info('>>> Head Ref is a version branch. Adding `master` as target');
targetLabels.push('master');
}

if (targetLabels.length === 0) {
// there was no target branch present
core.info('>>> No target label found');

if (vBranchRegex.test(pr.head_ref)) {
// the branch this is coming from is a version branch, so the cherry-pick target should be master
core.info('>>> Head Ref is a version branch, setting `master` as target');
core.setOutput('TARGET_BRANCHES', ['master']);
return;
}

// the PR is not coming from a version branch
core.setOutput('TARGET_BRANCHES', '');
return;
}

core.info(`>>> Target labels found: ${targetLabels.join(', ')}`);

// get a list of the original reviewers
const reviewers = pr.requested_reviewers.map((reviewer) => reviewer.login);
// get a list of the originally requested reviewers
const reuestedReviewers = pr.requested_reviewers.map((reviewer) => reviewer.login);

// get a list of the reviews done for the PR
const reviews = github.rest.pulls.listReviews({
owner,
repo,
pull_number: pullNumber,
});

// extract the reviewers who approved the PR from the reviews
const approvingReviewers = reviews
.filter((review) => review.state === 'APPROVED')
.map((review) => review.user.login);

// merge the 2 arrays into a single array of unique reviewers
const reviewers = [...new Set([...reuestedReviewers, ...approvingReviewers])];

core.info(`>>> Reviewers from original PR: ${reviewers.join(', ')}`);

core.info(`>>> Creating explanatory comment on PR`);
Expand Down

0 comments on commit c70291b

Please sign in to comment.