2019-01-29 23:01:10 +01:00
/// <reference lib="esnext.asynciterable" />
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
2018-05-11 00:02:35 +02:00
import Octokit = require ( "@octokit/rest" ) ;
2019-04-23 22:52:23 +02:00
import { runSequence } from "./run-sequence" ;
2018-05-11 00:02:35 +02:00
function padNum ( number : number ) {
const str = "" + number ;
return str . length >= 2 ? str : "0" + str ;
}
const userName = process . env . GH_USERNAME ;
2019-04-06 03:29:30 +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 ( ) ;
2019-04-06 01:28:25 +02:00
const branchName = ` user-update- ${ process . env . TARGET_FORK } - ${ now . getFullYear ( ) } ${ padNum ( now . getMonth ( ) ) } ${ padNum ( now . getDay ( ) ) } ${ 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 ` ;
2018-05-11 00:02:35 +02:00
runSequence ( [
[ "git" , [ "checkout" , "." ] ] , // reset any changes
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
[ "git" , [ "commit" , "-m" , ` "Update user baselines" ` ] ] , // Commit all changes
[ "git" , [ "remote" , "add" , "fork" , remoteUrl ] ] , // Add the remote fork
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
] ) ;
const gh = new Octokit ( ) ;
gh . authenticate ( {
type : "token" ,
2018-05-11 00:37:44 +02:00
token : process.argv [ 2 ]
2018-05-11 00:02:35 +02:00
} ) ;
2019-01-29 23:01:10 +01:00
gh . pulls . create ( {
2018-05-11 00:02:35 +02:00
owner : process.env.TARGET_FORK ,
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 } ` ,
2019-04-06 01:28:25 +02:00
base : process.env.TARGET_BRANCH || "master" ,
2018-05-11 00:02:35 +02:00
body :
2019-04-06 02:52:24 +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-04-06 03:29:30 +02:00
if ( ! process . env . source_issue ) {
await gh . pulls . createReviewRequest ( {
owner : process.env.TARGET_FORK ,
repo : "TypeScript" ,
number : num ,
reviewers ,
} ) ;
}
else {
2019-04-06 02:52:24 +02:00
await gh . issues . createComment ( {
number : + process . env . source_issue ,
owner : "Microsoft" ,
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 ) ;
} ) ;