Skip to content

Commit c70291b

Browse files
[infra] Request review from approving reviewers as well (#241)
1 parent 2ba827e commit c70291b

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

.github/workflows/scripts/prs/detectTargetBranch.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,41 @@ module.exports = async ({ core, context, github }) => {
3030
(label) => label !== 'needs cherry-pick' && !vBranchRegex.test(label),
3131
);
3232

33+
if (vBranchRegex.test(pr.head_ref)) {
34+
// the branch this is coming from is a version branch, so one of the targets should be master
35+
core.info('>>> Head Ref is a version branch. Adding `master` as target');
36+
targetLabels.push('master');
37+
}
38+
3339
if (targetLabels.length === 0) {
3440
// there was no target branch present
3541
core.info('>>> No target label found');
3642

37-
if (vBranchRegex.test(pr.head_ref)) {
38-
// the branch this is coming from is a version branch, so the cherry-pick target should be master
39-
core.info('>>> Head Ref is a version branch, setting `master` as target');
40-
core.setOutput('TARGET_BRANCHES', ['master']);
41-
return;
42-
}
43-
4443
// the PR is not coming from a version branch
4544
core.setOutput('TARGET_BRANCHES', '');
4645
return;
4746
}
4847

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

51-
// get a list of the original reviewers
52-
const reviewers = pr.requested_reviewers.map((reviewer) => reviewer.login);
50+
// get a list of the originally requested reviewers
51+
const reuestedReviewers = pr.requested_reviewers.map((reviewer) => reviewer.login);
52+
53+
// get a list of the reviews done for the PR
54+
const reviews = github.rest.pulls.listReviews({
55+
owner,
56+
repo,
57+
pull_number: pullNumber,
58+
});
59+
60+
// extract the reviewers who approved the PR from the reviews
61+
const approvingReviewers = reviews
62+
.filter((review) => review.state === 'APPROVED')
63+
.map((review) => review.user.login);
64+
65+
// merge the 2 arrays into a single array of unique reviewers
66+
const reviewers = [...new Set([...reuestedReviewers, ...approvingReviewers])];
67+
5368
core.info(`>>> Reviewers from original PR: ${reviewers.join(', ')}`);
5469

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

0 commit comments

Comments
 (0)