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) {
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 = [
"Close",
......@@ -131,3 +131,18 @@ describe("getPRsFromCommitMessage", () => {
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 { getMilestones } from "./github";
import { getLinkedIssues, getPRsFromCommitMessage } from "./linked-issues";
import { getLinkedIssues, getPRsFromCommitMessage, getBackportSourcePRNumber } from "./linked-issues";
import type { Issue, GithubProps, Milestone } from "./types";
import {
getMajorVersion,
......@@ -54,13 +54,17 @@ async function getOriginalPR({
pull_number: pullRequestNumber,
});
if (pull?.data && isBackport(pull.data)) {
return getOriginalPR({
github,
repo,
owner,
pullRequestNumber: pull.data.number
});
if (pull?.data && isBackport(pull.data) && pull.data.body) {
const sourcePRNumber = getBackportSourcePRNumber(pull.data.body);
if (sourcePRNumber && sourcePRNumber !== pullRequestNumber) {
console.log('found backport PR', pull.data.number, 'source PR', sourcePRNumber);
return getOriginalPR({
github,
repo,
owner,
pullRequestNumber: sourcePRNumber,
});
}
}
const linkedIssues = await getLinkedIssues(pull.data.body ?? '');
......@@ -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 });
}
}
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