44import { Octokit } from "@octokit/rest" ;
55import { runSequence } from "./run-sequence" ;
66
7- function padNum ( num : number ) {
8- const str = "" + num ;
9- return str . length >= 2 ? str : "0" + str ;
10- }
11-
127const userName = process . env . GH_USERNAME ;
138const reviewers = process . env . REQUESTING_USER ? [ process . env . REQUESTING_USER ] : [ "weswigham" , "sandersn" , "RyanCavanaugh" ] ;
149const now = new Date ( ) ;
15- const branchName = `user-update-${ process . env . TARGET_FORK } -${ now . getFullYear ( ) } ${ padNum ( now . getMonth ( ) + 1 ) } ${ padNum ( now . getDate ( ) ) } ${ process . env . TARGET_BRANCH ? "-" + process . env . TARGET_BRANCH : "" } ` ;
10+ const masterBranchname = `user-baseline-updates` ;
11+ const targetBranch = process . env . TARGET_BRANCH || "master" ;
12+ const branchName = process . env . TARGET_FORK . toLowerCase ( ) === "microsoft" && ( targetBranch === "master" || targetBranch === "refs/heads/master" )
13+ ? masterBranchname
14+ : `user-update-${ process . env . TARGET_FORK } -${ process . env . TARGET_BRANCH ? "-" + process . env . TARGET_BRANCH : "" } ` ;
1615const remoteUrl = `https://${ process . argv [ 2 ] } @github.com/${ userName } /TypeScript.git` ;
16+ const baseRef = branchName === masterBranchname ? "master" : masterBranchname ;
1717runSequence ( [
18+ [ "git" , [ "remote" , "add" , "fork" , remoteUrl ] ] , // Add the remote fork
1819 [ "git" , [ "checkout" , "." ] ] , // reset any changes
20+ [ "git" , [ "fetch" , baseRef === "master" ? "origin" : "fork" , baseRef ] ] , // fetch target ref in case it's not present locally
21+ [ "git" , [ "checkout" , baseRef ] ] , // move head to target
1922 [ "node" , [ "./node_modules/gulp/bin/gulp.js" , "baseline-accept" ] ] , // accept baselines
2023 [ "git" , [ "checkout" , "-b" , branchName ] ] , // create a branch
2124 [ "git" , [ "add" , "." ] ] , // Add all changes
2225 [ "git" , [ "commit" , "-m" , `"Update user baselines"` ] ] , // Commit all changes
23- [ "git" , [ "remote" , "add" , "fork" , remoteUrl ] ] , // Add the remote fork
2426 [ "git" , [ "push" , "--set-upstream" , "fork" , branchName , "-f" ] ] // push the branch
2527] ) ;
2628
2729const gh = new Octokit ( {
2830 auth : process . argv [ 2 ]
2931} ) ;
32+ const prOwner = branchName === masterBranchname ? "microsoft" : userName ;
3033gh . pulls . create ( {
31- owner : process . env . TARGET_FORK ! ,
34+ owner : prOwner ,
3235 repo : "TypeScript" ,
3336 maintainer_can_modify : true ,
3437 title : `🤖 User test baselines have changed` + ( process . env . TARGET_BRANCH ? ` for ${ process . env . TARGET_BRANCH } ` : "" ) ,
3538 head : `${ userName } :${ branchName } ` ,
36- base : process . env . TARGET_BRANCH || "master" ,
39+ base : branchName === masterBranchname ? "master" : masterBranchname ,
3740 body :
3841`${ process . env . SOURCE_ISSUE ? `This test run was triggerd by a request on https://github.com/Microsoft/TypeScript/pull/${ process . env . SOURCE_ISSUE } ` + "\n" : "" } Please review the diff and merge if no changes are unexpected.
3942You can view the build log [here](https://typescript.visualstudio.com/TypeScript/_build/index?buildId=${ process . env . BUILD_BUILDID } &_a=summary).
@@ -44,7 +47,7 @@ cc ${reviewers.map(r => "@" + r).join(" ")}`,
4447 console . log ( `Pull request ${ num } created.` ) ;
4548 if ( ! process . env . SOURCE_ISSUE ) {
4649 await gh . pulls . createReviewRequest ( {
47- owner : process . env . TARGET_FORK ! ,
50+ owner : prOwner ,
4851 repo : "TypeScript" ,
4952 pull_number : num ,
5053 reviewers,
@@ -53,7 +56,7 @@ cc ${reviewers.map(r => "@" + r).join(" ")}`,
5356 else {
5457 await gh . issues . createComment ( {
5558 issue_number : + process . env . SOURCE_ISSUE ,
56- owner : "Microsoft " ,
59+ owner : "microsoft " ,
5760 repo : "TypeScript" ,
5861 body : `The user suite test run you requested has finished and _failed_. I've opened a [PR with the baseline diff from master](${ r . data . html_url } ).`
5962 } ) ;
0 commit comments