@@ -26,18 +26,34 @@ async function main() {
26
26
const currentAuthor = runSequence ( [
27
27
[ "git" , [ "log" , "-1" , `--pretty="%aN <%aE>"` ] ]
28
28
] ) ;
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 ;
29
45
runSequence ( [
30
- [ "git" , [ "fetch" , "origin" , "master" ] ]
46
+ [ "git" , [ "fetch" , remoteName , baseBranchName ] ]
31
47
] ) ;
32
48
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" ] ]
34
50
] ) ;
35
51
logText = `Cherry-pick PR #${ process . env . SOURCE_ISSUE } into ${ process . env . TARGET_BRANCH }
36
52
37
53
Component commits:
38
54
${ logText . trim ( ) } `;
39
55
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 ( ) ;
41
57
runSequence ( [
42
58
[ "git" , [ "checkout" , "-b" , "temp-branch" ] ] ,
43
59
[ "git" , [ "reset" , mergebase , "--soft" ] ]
@@ -67,11 +83,6 @@ ${logText.trim()}`;
67
83
[ "git" , [ "push" , "--set-upstream" , "fork" , branchName , "-f" ] ] // push the branch
68
84
] ) ;
69
85
70
- const gh = new Octokit ( ) ;
71
- gh . authenticate ( {
72
- type : "token" ,
73
- token : process . argv [ 2 ]
74
- } ) ;
75
86
const r = await gh . pulls . create ( {
76
87
owner : "Microsoft" ,
77
88
repo : "TypeScript" ,
0 commit comments