4
4
import { Octokit } from "@octokit/rest" ;
5
5
import { runSequence } from "./run-sequence" ;
6
6
7
- function padNum ( num : number ) {
8
- const str = "" + num ;
9
- return str . length >= 2 ? str : "0" + str ;
10
- }
11
-
12
7
const userName = process . env . GH_USERNAME ;
13
8
const reviewers = process . env . REQUESTING_USER ? [ process . env . REQUESTING_USER ] : [ "weswigham" , "sandersn" , "RyanCavanaugh" ] ;
14
9
const 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 : "" } ` ;
16
15
const remoteUrl = `https://${ process . argv [ 2 ] } @github.com/${ userName } /TypeScript.git` ;
16
+ const baseRef = branchName === masterBranchname ? "master" : masterBranchname ;
17
17
runSequence ( [
18
+ [ "git" , [ "remote" , "add" , "fork" , remoteUrl ] ] , // Add the remote fork
18
19
[ "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
19
22
[ "node" , [ "./node_modules/gulp/bin/gulp.js" , "baseline-accept" ] ] , // accept baselines
20
23
[ "git" , [ "checkout" , "-b" , branchName ] ] , // create a branch
21
24
[ "git" , [ "add" , "." ] ] , // Add all changes
22
25
[ "git" , [ "commit" , "-m" , `"Update user baselines"` ] ] , // Commit all changes
23
- [ "git" , [ "remote" , "add" , "fork" , remoteUrl ] ] , // Add the remote fork
24
26
[ "git" , [ "push" , "--set-upstream" , "fork" , branchName , "-f" ] ] // push the branch
25
27
] ) ;
26
28
27
29
const gh = new Octokit ( {
28
30
auth : process . argv [ 2 ]
29
31
} ) ;
32
+ const prOwner = branchName === masterBranchname ? "microsoft" : userName ;
30
33
gh . pulls . create ( {
31
- owner : process . env . TARGET_FORK ! ,
34
+ owner : prOwner ,
32
35
repo : "TypeScript" ,
33
36
maintainer_can_modify : true ,
34
37
title : `🤖 User test baselines have changed` + ( process . env . TARGET_BRANCH ? ` for ${ process . env . TARGET_BRANCH } ` : "" ) ,
35
38
head : `${ userName } :${ branchName } ` ,
36
- base : process . env . TARGET_BRANCH || "master" ,
39
+ base : branchName === masterBranchname ? "master" : masterBranchname ,
37
40
body :
38
41
`${ 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.
39
42
You 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(" ")}`,
44
47
console . log ( `Pull request ${ num } created.` ) ;
45
48
if ( ! process . env . SOURCE_ISSUE ) {
46
49
await gh . pulls . createReviewRequest ( {
47
- owner : process . env . TARGET_FORK ! ,
50
+ owner : prOwner ,
48
51
repo : "TypeScript" ,
49
52
pull_number : num ,
50
53
reviewers,
@@ -53,7 +56,7 @@ cc ${reviewers.map(r => "@" + r).join(" ")}`,
53
56
else {
54
57
await gh . issues . createComment ( {
55
58
issue_number : + process . env . SOURCE_ISSUE ,
56
- owner : "Microsoft " ,
59
+ owner : "microsoft " ,
57
60
repo : "TypeScript" ,
58
61
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 } ).`
59
62
} ) ;
0 commit comments