Skip to content

Commit bba9de1

Browse files
refactor: move release notes check after failureMap
1 parent 40e9766 commit bba9de1

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

spec/utils.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('utils', () => {
109109
).toBe(true);
110110
});
111111

112-
it('should update backport PR if release notes do not match original PR for single PR', async () => {
112+
it('should return not valid if release notes do not match original PR for single PR', async () => {
113113
const context = { ...backportPRMissingReleaseNotes };
114114
expect(
115115
await isValidManualBackportReleaseNotes(context, [
@@ -118,7 +118,7 @@ describe('utils', () => {
118118
).toBe(false);
119119
});
120120

121-
it('should update backport PR if release notes do not match original PR for multiple PR', async () => {
121+
it('should return not valid if release notes do not match original PR for multiple PR', async () => {
122122
const context = { ...backportPRMissingReleaseNotes };
123123
expect(
124124
await isValidManualBackportReleaseNotes(context, [

src/index.ts

+28-27
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
272272
];
273273
const FASTTRACK_LABELS: string[] = ['fast-track 🚅'];
274274

275-
const failureMap = new Map();
276-
277275
// There are several types of PRs which might not target main yet which are
278276
// inherently valid; e.g roller-bot PRs. Check for and allow those here.
279277
if (oldPRNumbers.length === 0) {
@@ -309,6 +307,7 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
309307
robot.log(
310308
`#${pr.number} has backport numbers - checking their validity now`,
311309
);
310+
const failureMap = new Map();
312311
const supported = await getSupportedBranches(context);
313312
const oldPRs = [];
314313

@@ -319,7 +318,9 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
319318
pull_number: oldPRNumber,
320319
}),
321320
);
321+
322322
oldPRs.push(oldPR);
323+
323324
// The current PR is only valid if the PR it is backporting
324325
// was merged to main or to a supported release branch.
325326
if (
@@ -337,9 +338,33 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
337338
}
338339
}
339340

341+
for (const oldPRNumber of oldPRNumbers) {
342+
if (failureMap.has(oldPRNumber)) {
343+
robot.log(
344+
`#${pr.number} is targeting a branch that is not ${
345+
pr.base.repo.default_branch
346+
} - ${failureMap.get(oldPRNumber)}`,
347+
);
348+
await updateBackportValidityCheck(context, checkRun, {
349+
title: 'Invalid Backport',
350+
summary: `This PR is targeting a branch that is not ${
351+
pr.base.repo.default_branch
352+
} but ${failureMap.get(oldPRNumber)}`,
353+
conclusion: CheckRunStatus.FAILURE,
354+
});
355+
} else {
356+
robot.log(`#${pr.number} is a valid backport of #${oldPRNumber}`);
357+
await updateBackportValidityCheck(context, checkRun, {
358+
title: 'Valid Backport',
359+
summary: `This PR is declared as backporting "#${oldPRNumber}" which is a valid PR that has been merged into ${pr.base.repo.default_branch}`,
360+
conclusion: CheckRunStatus.SUCCESS,
361+
});
362+
}
363+
}
364+
340365
if (['opened', 'edited'].includes(action)) {
341366
robot.log(`Checking validity of release notes`);
342-
// Check to make sure backport PR has the same release notes as at least on of the old prs
367+
// Check to make sure backport PR has the same release notes as at least one of the old prs
343368
const isValidReleaseNotes = await isValidManualBackportReleaseNotes(
344369
context,
345370
oldPRs as WebHookPR[],
@@ -356,30 +381,6 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
356381
}
357382
}
358383
}
359-
360-
for (const oldPRNumber of oldPRNumbers) {
361-
if (failureMap.has(oldPRNumber)) {
362-
robot.log(
363-
`#${pr.number} is targeting a branch that is not ${
364-
pr.base.repo.default_branch
365-
} - ${failureMap.get(oldPRNumber)}`,
366-
);
367-
await updateBackportValidityCheck(context, checkRun, {
368-
title: 'Invalid Backport',
369-
summary: `This PR is targeting a branch that is not ${
370-
pr.base.repo.default_branch
371-
} but ${failureMap.get(oldPRNumber)}`,
372-
conclusion: CheckRunStatus.FAILURE,
373-
});
374-
} else {
375-
robot.log(`#${pr.number} is a valid backport of #${oldPRNumber}`);
376-
await updateBackportValidityCheck(context, checkRun, {
377-
title: 'Valid Backport',
378-
summary: `This PR is declared as backporting "#${oldPRNumber}" which is a valid PR that has been merged into ${pr.base.repo.default_branch}`,
379-
conclusion: CheckRunStatus.SUCCESS,
380-
});
381-
}
382-
}
383384
} else {
384385
// If we're somehow targeting main and have a check run,
385386
// we mark this check as cancelled.

0 commit comments

Comments
 (0)