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

feat: Support picking rebased PRs for patch releases #7750

Merged
merged 1 commit into from
May 26, 2023
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
42 changes: 41 additions & 1 deletion packages/release-tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,53 @@ function formatChangelog(previousReleasedVersion: string, prs: ExtendedGithubPrD
].join("\n");
}

async function getCommitsOfPr(pr: ExtendedGithubPrData) {
const commits: components["schemas"]["commit"][] = [];

for (let page = 1; ; page += 1) {
const pageResult = await octokit.request("GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", {
owner: "lensapp",
repo: "lens",
pull_number: pr.number,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
},
per_page: 100,
page,
});

commits.push(...pageResult.data);
jim-docker marked this conversation as resolved.
Show resolved Hide resolved

if (pageResult.data.length < 100) {
break;
}
}

return commits;
}

async function computeIfPrWasSquashed(pr: ExtendedGithubPrData, commits: components["schemas"]["commit"][]): Promise<boolean> {
const { stdout: mergeCommitSubject } = await execFile("git", ["log", "-1", "--format=%s", pr.mergeCommitSha]);

return commits.every(commit => commit.commit.message !== mergeCommitSubject);
}

async function cherryPickCommits(prs: ExtendedGithubPrData[]): Promise<void> {
const rl = createInterface(process.stdin);
const cherryPickCommit = cherryPickCommitWith(rl);

for (const pr of prs) {
if (pr.shouldAttemptCherryPick) {
await cherryPickCommit(pr.mergeCommitSha);
const commits = await getCommitsOfPr(pr);
const wasSquashed = await computeIfPrWasSquashed(pr, commits);

if (wasSquashed) {
await cherryPickCommit(pr.mergeCommitSha);
} else {
for (const commit of commits) {
await cherryPickCommit(commit.sha);
jim-docker marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
console.log(`Skipping cherry picking of #${pr.number} - ${pr.title}`);
}
Expand Down