Skip to content
Snippets Groups Projects
Unverified Commit 452382bc authored by Ryan Laurie's avatar Ryan Laurie Committed by GitHub
Browse files

Fix infinite backport PR recursion in milestone setter (#44593)

* fix infinite backport PR recursion

* dedupe issue numbers
parent ea69066d
No related branches found
No related tags found
No related merge requests found
...@@ -22,3 +22,9 @@ export function getPRsFromCommitMessage(message: string) { ...@@ -22,3 +22,9 @@ export function getPRsFromCommitMessage(message: string) {
return result.map(r => Number(r[1])); return result.map(r => Number(r[1]));
} }
// backport PRs just have a pr number in the body without a keyword
export function getBackportSourcePRNumber(body: string) {
const matches = body.match(/#(\d+)/);
return matches ? Number(matches[1]) : null;
}
import { getLinkedIssues, getPRsFromCommitMessage } from "./linked-issues"; import { getLinkedIssues, getPRsFromCommitMessage, getBackportSourcePRNumber } from "./linked-issues";
const closingKeywords = [ const closingKeywords = [
"Close", "Close",
...@@ -131,3 +131,18 @@ describe("getPRsFromCommitMessage", () => { ...@@ -131,3 +131,18 @@ describe("getPRsFromCommitMessage", () => {
expect(getPRsFromCommitMessage("Backport (#1234) and (#4567)")).toEqual([1234, 4567]); expect(getPRsFromCommitMessage("Backport (#1234) and (#4567)")).toEqual([1234, 4567]);
}); });
}); });
describe("getBackportSourcePRNumber", () => {
it("should return `null` when no PR is found", () => {
expect(getBackportSourcePRNumber("")).toBeNull();
expect(getBackportSourcePRNumber("Lorem ipsum dolor sit amet.")).toBeNull();
expect(getBackportSourcePRNumber("#yolo")).toBeNull();
});
it("should return the pr number when it is found", () => {
expect(getBackportSourcePRNumber("#4567")).toBe(4567);
expect(getBackportSourcePRNumber(" #4567 ")).toBe(4567);
expect(getBackportSourcePRNumber("backports #4567 and #6789")).toBe(4567);
});
});
import _ from "underscore"; import _ from "underscore";
import { getMilestones } from "./github"; import { getMilestones } from "./github";
import { getLinkedIssues, getPRsFromCommitMessage } from "./linked-issues"; import { getLinkedIssues, getPRsFromCommitMessage, getBackportSourcePRNumber } from "./linked-issues";
import type { Issue, GithubProps, Milestone } from "./types"; import type { Issue, GithubProps, Milestone } from "./types";
import { import {
getMajorVersion, getMajorVersion,
...@@ -54,13 +54,17 @@ async function getOriginalPR({ ...@@ -54,13 +54,17 @@ async function getOriginalPR({
pull_number: pullRequestNumber, pull_number: pullRequestNumber,
}); });
if (pull?.data && isBackport(pull.data)) { if (pull?.data && isBackport(pull.data) && pull.data.body) {
return getOriginalPR({ const sourcePRNumber = getBackportSourcePRNumber(pull.data.body);
github, if (sourcePRNumber && sourcePRNumber !== pullRequestNumber) {
repo, console.log('found backport PR', pull.data.number, 'source PR', sourcePRNumber);
owner, return getOriginalPR({
pullRequestNumber: pull.data.number github,
}); repo,
owner,
pullRequestNumber: sourcePRNumber,
});
}
} }
const linkedIssues = await getLinkedIssues(pull.data.body ?? ''); const linkedIssues = await getLinkedIssues(pull.data.body ?? '');
...@@ -182,9 +186,11 @@ export async function setMilestoneForCommits({ ...@@ -182,9 +186,11 @@ export async function setMilestoneForCommits({
}))); })));
} }
console.log(`Tagging ${issuesToTag.length} issues with milestone ${nextMilestone.title}`) const uniqueIssuesToTag = _.uniq(issuesToTag);
console.log(`Tagging ${uniqueIssuesToTag.length} issues with milestone ${nextMilestone.title}`)
for (const issueNumber of issuesToTag) { // for loop to avoid rate limiting for (const issueNumber of uniqueIssuesToTag) { // for loop to avoid rate limiting
await setMilestone({ github, owner, repo, issueNumber, milestone: nextMilestone }); await setMilestone({ github, owner, repo, issueNumber, milestone: nextMilestone });
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment