Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[infra] Request review from approving reviewers as well #241

Merged
merged 2 commits into from
Nov 13, 2024
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
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
Loading