Skip to content

Commit

Permalink
Also edit the cherry-pick script to handle non-master base branches w…
Browse files Browse the repository at this point in the history
…hile we are here
  • Loading branch information
weswigham committed Feb 5, 2020
1 parent 212edf8 commit 68cbe9e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions scripts/open-cherry-pick-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,34 @@ async function main() {
const currentAuthor = runSequence([
["git", ["log", "-1", `--pretty="%aN <%aE>"`]]
]);

const gh = new Octokit();
gh.authenticate({
type: "token",
token: process.argv[2]
});

const inputPR = (await gh.pulls.get({ pull_number: +process.env.SOURCE_ISSUE, owner: "microsoft", repo: "TypeScript" })).data;
let remoteName = "origin";
if (inputPR.base.repo.git_url !== `git:github.com/microsoft/TypeScript`) {
runSequence([
["git", ["remote", "add", "nonlocal", inputPR.base.repo.git_url]]
]);
remoteName = "nonlocal";
}
const baseBranchName = inputPR.base.ref;
runSequence([
["git", ["fetch", "origin", "master"]]
["git", ["fetch", remoteName, baseBranchName]]
]);
let logText = runSequence([
["git", ["log", `origin/master..${currentSha.trim()}`, `--pretty="%h %s%n%b"`, "--reverse"]]
["git", ["log", `${remoteName}/${baseBranchName}..${currentSha.trim()}`, `--pretty="%h %s%n%b"`, "--reverse"]]
]);
logText = `Cherry-pick PR #${process.env.SOURCE_ISSUE} into ${process.env.TARGET_BRANCH}
Component commits:
${logText.trim()}`;
const logpath = path.join(__dirname, "../", "logmessage.txt");
const mergebase = runSequence([["git", ["merge-base", "origin/master", currentSha]]]).trim();
const mergebase = runSequence([["git", ["merge-base", `${remoteName}/${baseBranchName}`, currentSha]]]).trim();
runSequence([
["git", ["checkout", "-b", "temp-branch"]],
["git", ["reset", mergebase, "--soft"]]
Expand Down Expand Up @@ -67,11 +83,6 @@ ${logText.trim()}`;
["git", ["push", "--set-upstream", "fork", branchName, "-f"]] // push the branch
]);

const gh = new Octokit();
gh.authenticate({
type: "token",
token: process.argv[2]
});
const r = await gh.pulls.create({
owner: "Microsoft",
repo: "TypeScript",
Expand Down

0 comments on commit 68cbe9e

Please sign in to comment.