2019-01-29 23:01:10 +01:00
/// <reference lib="esnext.asynciterable" />
2019-07-01 20:10:43 +02:00
/// <reference lib="es2015.promise" />
2019-01-29 23:01:10 +01:00
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
2020-02-21 18:49:02 +01:00
import { Octokit } from "@octokit/rest" ;
2020-07-17 15:43:50 +02:00
const { runSequence } = require ( "./run-sequence" ) ;
2018-05-11 00:02:35 +02:00
2020-07-17 15:43:50 +02:00
const userName = process . env . GH_USERNAME || "typescript-bot" ;
2019-05-31 00:20:41 +02:00
const reviewers = process . env . REQUESTING_USER ? [ process . env . REQUESTING_USER ] : [ "weswigham" , "sandersn" , "RyanCavanaugh" ] ;
2018-05-11 00:02:35 +02:00
const now = new Date ( ) ;
2020-03-11 22:38:59 +01:00
const masterBranchname = ` user-baseline-updates ` ;
2020-03-11 23:19:39 +01:00
const targetBranch = process . env . TARGET_BRANCH || "master" ;
2020-07-17 15:43:50 +02:00
const branchName = process . env . TARGET_FORK ? . toLowerCase ( ) === "microsoft" && ( targetBranch === "master" || targetBranch === "refs/heads/master" )
2020-03-11 22:38:59 +01:00
? masterBranchname
2020-03-11 23:19:39 +01:00
: ` user-update- ${ process . env . TARGET_FORK } - ${ process . env . TARGET_BRANCH ? "-" + process . env . TARGET_BRANCH : "" } ` ;
2018-05-14 19:27:13 +02:00
const remoteUrl = ` https:// ${ process . argv [ 2 ] } @github.com/ ${ userName } /TypeScript.git ` ;
2020-03-11 22:38:59 +01:00
const baseRef = branchName === masterBranchname ? "master" : masterBranchname ;
2018-05-11 00:02:35 +02:00
runSequence ( [
2020-03-11 22:38:59 +01:00
[ "git" , [ "remote" , "add" , "fork" , remoteUrl ] ] , // Add the remote fork
2018-05-11 00:02:35 +02:00
[ "git" , [ "checkout" , "." ] ] , // reset any changes
2020-03-11 22:38:59 +01:00
[ "git" , [ "fetch" , baseRef === "master" ? "origin" : "fork" , baseRef ] ] , // fetch target ref in case it's not present locally
[ "git" , [ "checkout" , baseRef ] ] , // move head to target
2019-02-21 00:32:15 +01:00
[ "node" , [ "./node_modules/gulp/bin/gulp.js" , "baseline-accept" ] ] , // accept baselines
2018-05-11 00:02:35 +02:00
[ "git" , [ "checkout" , "-b" , branchName ] ] , // create a branch
[ "git" , [ "add" , "." ] ] , // Add all changes
2020-08-18 22:28:33 +02:00
[ "git" , [ "commit" , "-m" , ` "Update user baselines ${ + process . env . SOURCE_ISSUE === 33716 ? " +cc @sandersn" : "" } " ` ] ] , // Commit all changes (ping nathan if we would post to CI thread)
2018-05-16 21:44:03 +02:00
[ "git" , [ "push" , "--set-upstream" , "fork" , branchName , "-f" ] ] // push the branch
2018-05-11 00:02:35 +02:00
] ) ;
2020-02-21 18:49:02 +01:00
const gh = new Octokit ( {
auth : process.argv [ 2 ]
2018-05-11 00:02:35 +02:00
} ) ;
2020-03-11 22:38:59 +01:00
const prOwner = branchName === masterBranchname ? "microsoft" : userName ;
2019-01-29 23:01:10 +01:00
gh . pulls . create ( {
2020-03-11 22:38:59 +01:00
owner : prOwner ,
2018-05-11 00:02:35 +02:00
repo : "TypeScript" ,
maintainer_can_modify : true ,
2019-04-06 02:52:24 +02:00
title : ` 🤖 User test baselines have changed ` + ( process . env . TARGET_BRANCH ? ` for ${ process . env . TARGET_BRANCH } ` : "" ) ,
2018-05-11 00:02:35 +02:00
head : ` ${ userName } : ${ branchName } ` ,
2020-03-11 22:38:59 +01:00
base : branchName === masterBranchname ? "master" : masterBranchname ,
2018-05-11 00:02:35 +02:00
body :
2019-05-31 00:20:41 +02:00
` ${ 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.
2018-05-16 22:12:17 +02:00
You can view the build log [ here ] ( https : //typescript.visualstudio.com/TypeScript/_build/index?buildId=${process.env.BUILD_BUILDID}&_a=summary).
2018-05-11 00:02:35 +02:00
cc $ { reviewers . map ( r = > "@" + r ) . join ( " " ) } ` ,
2019-04-06 02:52:24 +02:00
} ) . then ( async r = > {
2018-05-11 00:02:35 +02:00
const num = r . data . number ;
console . log ( ` Pull request ${ num } created. ` ) ;
2019-05-31 00:20:41 +02:00
if ( ! process . env . SOURCE_ISSUE ) {
2020-07-17 15:43:50 +02:00
await gh . pulls . requestReviewers ( {
2020-03-11 22:38:59 +01:00
owner : prOwner ,
2019-04-06 03:29:30 +02:00
repo : "TypeScript" ,
2019-07-01 20:10:43 +02:00
pull_number : num ,
2019-04-06 03:29:30 +02:00
reviewers ,
} ) ;
}
else {
2019-04-06 02:52:24 +02:00
await gh . issues . createComment ( {
2020-02-21 18:49:02 +01:00
issue_number : + process . env . SOURCE_ISSUE ,
2020-03-11 22:38:59 +01:00
owner : "microsoft" ,
2019-04-06 02:52:24 +02:00
repo : "TypeScript" ,
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 } ). `
} ) ;
}
2018-05-11 00:02:35 +02:00
} ) . then ( ( ) = > {
console . log ( ` Reviewers requested, done. ` ) ;
} ) . catch ( e = > {
console . error ( e ) ;
process . exit ( 1 ) ;
} ) ;