Skip to content

Commit 68cbe9e

Browse files
committed
Also edit the cherry-pick script to handle non-master base branches while we are here
1 parent 212edf8 commit 68cbe9e

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

scripts/open-cherry-pick-pr.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,34 @@ async function main() {
2626
const currentAuthor = runSequence([
2727
["git", ["log", "-1", `--pretty="%aN <%aE>"`]]
2828
]);
29+
30+
const gh = new Octokit();
31+
gh.authenticate({
32+
type: "token",
33+
token: process.argv[2]
34+
});
35+
36+
const inputPR = (await gh.pulls.get({ pull_number: +process.env.SOURCE_ISSUE, owner: "microsoft", repo: "TypeScript" })).data;
37+
let remoteName = "origin";
38+
if (inputPR.base.repo.git_url !== `git:github.com/microsoft/TypeScript`) {
39+
runSequence([
40+
["git", ["remote", "add", "nonlocal", inputPR.base.repo.git_url]]
41+
]);
42+
remoteName = "nonlocal";
43+
}
44+
const baseBranchName = inputPR.base.ref;
2945
runSequence([
30-
["git", ["fetch", "origin", "master"]]
46+
["git", ["fetch", remoteName, baseBranchName]]
3147
]);
3248
let logText = runSequence([
33-
["git", ["log", `origin/master..${currentSha.trim()}`, `--pretty="%h %s%n%b"`, "--reverse"]]
49+
["git", ["log", `${remoteName}/${baseBranchName}..${currentSha.trim()}`, `--pretty="%h %s%n%b"`, "--reverse"]]
3450
]);
3551
logText = `Cherry-pick PR #${process.env.SOURCE_ISSUE} into ${process.env.TARGET_BRANCH}
3652
3753
Component commits:
3854
${logText.trim()}`;
3955
const logpath = path.join(__dirname, "../", "logmessage.txt");
40-
const mergebase = runSequence([["git", ["merge-base", "origin/master", currentSha]]]).trim();
56+
const mergebase = runSequence([["git", ["merge-base", `${remoteName}/${baseBranchName}`, currentSha]]]).trim();
4157
runSequence([
4258
["git", ["checkout", "-b", "temp-branch"]],
4359
["git", ["reset", mergebase, "--soft"]]
@@ -67,11 +83,6 @@ ${logText.trim()}`;
6783
["git", ["push", "--set-upstream", "fork", branchName, "-f"]] // push the branch
6884
]);
6985

70-
const gh = new Octokit();
71-
gh.authenticate({
72-
type: "token",
73-
token: process.argv[2]
74-
});
7586
const r = await gh.pulls.create({
7687
owner: "Microsoft",
7788
repo: "TypeScript",

0 commit comments

Comments
 (0)