-
Notifications
You must be signed in to change notification settings - Fork 35
feat: add validation check for manual bp release notes #285
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
base: main
Are you sure you want to change the base?
Changes from all commits
e7dea25
441ab20
26811f0
4fb7f24
06b5caa
f143e82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { | |||||||||||
| backportImpl, | ||||||||||||
| getPRNumbersFromPRBody, | ||||||||||||
| isAuthorizedUser, | ||||||||||||
| isValidManualBackportReleaseNotes, | ||||||||||||
| labelClosedPR, | ||||||||||||
| } from './utils'; | ||||||||||||
| import { | ||||||||||||
|
|
@@ -249,8 +250,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { | |||||||||||
| ]; | ||||||||||||
| const FASTTRACK_LABELS: string[] = ['fast-track 🚅']; | ||||||||||||
|
|
||||||||||||
| const failureMap = new Map(); | ||||||||||||
|
|
||||||||||||
| // There are several types of PRs which might not target main yet which are | ||||||||||||
| // inherently valid; e.g roller-bot PRs. Check for and allow those here. | ||||||||||||
| if (oldPRNumbers.length === 0) { | ||||||||||||
|
|
@@ -286,7 +285,9 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { | |||||||||||
| robot.log( | ||||||||||||
| `#${pr.number} has backport numbers - checking their validity now`, | ||||||||||||
| ); | ||||||||||||
| const failureMap = new Map(); | ||||||||||||
| const supported = await getSupportedBranches(context); | ||||||||||||
| const oldPRs = []; | ||||||||||||
|
|
||||||||||||
| for (const oldPRNumber of oldPRNumbers) { | ||||||||||||
| robot.log(`Checking validity of #${oldPRNumber}`); | ||||||||||||
|
|
@@ -296,6 +297,8 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { | |||||||||||
| }), | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| oldPRs.push(oldPR); | ||||||||||||
|
|
||||||||||||
| // The current PR is only valid if the PR it is backporting | ||||||||||||
| // was merged to main or to a supported release branch. | ||||||||||||
| if ( | ||||||||||||
|
|
@@ -312,29 +315,48 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { | |||||||||||
| failureMap.set(oldPRNumber, cause); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| for (const oldPRNumber of oldPRNumbers) { | ||||||||||||
| if (failureMap.has(oldPRNumber)) { | ||||||||||||
| robot.log( | ||||||||||||
| `#${pr.number} is targeting a branch that is not ${ | ||||||||||||
| pr.base.repo.default_branch | ||||||||||||
| } - ${failureMap.get(oldPRNumber)}`, | ||||||||||||
| for (const oldPRNumber of oldPRNumbers) { | ||||||||||||
| if (failureMap.has(oldPRNumber)) { | ||||||||||||
| robot.log( | ||||||||||||
| `#${pr.number} is targeting a branch that is not ${ | ||||||||||||
| pr.base.repo.default_branch | ||||||||||||
| } - ${failureMap.get(oldPRNumber)}`, | ||||||||||||
| ); | ||||||||||||
| await updateBackportValidityCheck(context, checkRun, { | ||||||||||||
| title: 'Invalid Backport', | ||||||||||||
| summary: `This PR is targeting a branch that is not ${ | ||||||||||||
| pr.base.repo.default_branch | ||||||||||||
| } but ${failureMap.get(oldPRNumber)}`, | ||||||||||||
| conclusion: CheckRunStatus.FAILURE, | ||||||||||||
| }); | ||||||||||||
| } else { | ||||||||||||
| robot.log(`#${pr.number} is a valid backport of #${oldPRNumber}`); | ||||||||||||
| await updateBackportValidityCheck(context, checkRun, { | ||||||||||||
| title: 'Valid Backport', | ||||||||||||
| summary: `This PR is declared as backporting "#${oldPRNumber}" which is a valid PR that has been merged into ${pr.base.repo.default_branch}`, | ||||||||||||
| conclusion: CheckRunStatus.SUCCESS, | ||||||||||||
| }); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (['opened', 'edited'].includes(action)) { | ||||||||||||
| robot.log(`Checking validity of release notes`); | ||||||||||||
| // Check to make sure backport PR has the same release notes as at least one of the old prs | ||||||||||||
| const isValidReleaseNotes = await isValidManualBackportReleaseNotes( | ||||||||||||
| context, | ||||||||||||
| oldPRs as WebHookPR[], | ||||||||||||
| ); | ||||||||||||
| await updateBackportValidityCheck(context, checkRun, { | ||||||||||||
| title: 'Invalid Backport', | ||||||||||||
| summary: `This PR is targeting a branch that is not ${ | ||||||||||||
| pr.base.repo.default_branch | ||||||||||||
| } but ${failureMap.get(oldPRNumber)}`, | ||||||||||||
| conclusion: CheckRunStatus.FAILURE, | ||||||||||||
| }); | ||||||||||||
| } else { | ||||||||||||
| robot.log(`#${pr.number} is a valid backport of #${oldPRNumber}`); | ||||||||||||
| await updateBackportValidityCheck(context, checkRun, { | ||||||||||||
| title: 'Valid Backport', | ||||||||||||
| summary: `This PR is declared as backporting "#${oldPRNumber}" which is a valid PR that has been merged into ${pr.base.repo.default_branch}`, | ||||||||||||
| conclusion: CheckRunStatus.SUCCESS, | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| if (!isValidReleaseNotes) { | ||||||||||||
| await updateBackportValidityCheck(context, checkRun, { | ||||||||||||
| title: 'Invalid Backport', | ||||||||||||
| summary: `The release notes of the backport PR do not match those of ${oldPRNumbers | ||||||||||||
| .map((pr) => `#${pr}`) | ||||||||||||
| .join(', ')}.`, | ||||||||||||
| conclusion: CheckRunStatus.FAILURE, | ||||||||||||
| }); | ||||||||||||
|
Comment on lines
+352
to
+358
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is going to get clobbered by the update a bit further down in this file: Lines 358 to 362 in 47f78d4
Might take some more refactoring to ensure the clobbering doesn't happen. However, I'm a bit worried about a regression since we don't have good test coverage here. Could you look at expanding test coverage in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the pointers!
|
||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } else { | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.