More conditional linkage in user PR responses when manually triggered

This commit is contained in:
Wesley Wigham 2019-04-05 17:52:24 -07:00
parent 0ddd847e03
commit 73616c9725
No known key found for this signature in database
GPG Key ID: D59F87F60C5400C9

View File

@ -18,7 +18,10 @@ function padNum(number: number) {
}
const userName = process.env.GH_USERNAME;
const reviewers = ["weswigham", "sandersn", "RyanCavanaugh"]
const reviewers = ["weswigham", "sandersn", "RyanCavanaugh"];
if (process.env.requesting_user && reviewers.indexOf(process.env.requesting_user) === -1) {
reviewers.push(process.env.requesting_user);
}
const now = new Date();
const branchName = `user-update-${process.env.TARGET_FORK}-${now.getFullYear()}${padNum(now.getMonth())}${padNum(now.getDay())}${process.env.TARGET_BRANCH ? "-" + process.env.TARGET_BRANCH : ""}`;
const remoteUrl = `https://${process.argv[2]}@github.com/${userName}/TypeScript.git`;
@ -41,23 +44,31 @@ gh.pulls.create({
owner: process.env.TARGET_FORK,
repo: "TypeScript",
maintainer_can_modify: true,
title: `🤖 User test baselines have changed`,
title: `🤖 User test baselines have changed` + (process.env.TARGET_BRANCH ? ` for ${process.env.TARGET_BRANCH}` : ""),
head: `${userName}:${branchName}`,
base: process.env.TARGET_BRANCH || "master",
body:
`Please review the diff and merge if no changes are unexpected.
`${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.
You can view the build log [here](https://typescript.visualstudio.com/TypeScript/_build/index?buildId=${process.env.BUILD_BUILDID}&_a=summary).
cc ${reviewers.map(r => "@" + r).join(" ")}`,
}).then(r => {
}).then(async r => {
const num = r.data.number;
console.log(`Pull request ${num} created.`);
return gh.pulls.createReviewRequest({
await gh.pulls.createReviewRequest({
owner: process.env.TARGET_FORK,
repo: "TypeScript",
number: num,
reviewers,
});
if (process.env.source_issue) {
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}).`
});
}
}).then(() => {
console.log(`Reviewers requested, done.`);
}).catch(e => {