• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/// <reference lib="esnext.asynciterable" />
2/// <reference lib="es2015.promise" />
3// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
4import { Octokit } from "@octokit/rest";
5const {runSequence} = require("./run-sequence");
6
7const userName = process.env.GH_USERNAME || "typescript-bot";
8const reviewers = process.env.REQUESTING_USER ? [process.env.REQUESTING_USER] : ["weswigham", "sandersn", "RyanCavanaugh"];
9const now = new Date();
10const masterBranchname = `user-baseline-updates`;
11const targetBranch = process.env.TARGET_BRANCH || "master";
12const 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 : ""}`;
15const remoteUrl = `https://${process.argv[2]}@github.com/${userName}/TypeScript.git`;
16const baseRef = branchName === masterBranchname ? "master" : masterBranchname;
17runSequence([
18    ["git", ["remote", "add", "fork", remoteUrl]], // Add the remote fork
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
22    ["node", ["./node_modules/gulp/bin/gulp.js", "baseline-accept"]], // accept baselines
23    ["git", ["checkout", "-b", branchName]], // create a branch
24    ["git", ["add", "."]], // Add all changes
25    ["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)
26    ["git", ["push", "--set-upstream", "fork", branchName, "-f"]] // push the branch
27]);
28
29const gh = new Octokit({
30    auth: process.argv[2]
31});
32const prOwner = branchName === masterBranchname ? "microsoft" : userName;
33gh.pulls.create({
34    owner: prOwner,
35    repo: "TypeScript",
36    maintainer_can_modify: true,
37    title: `�� User test baselines have changed` + (process.env.TARGET_BRANCH ? ` for ${process.env.TARGET_BRANCH}` : ""),
38    head: `${userName}:${branchName}`,
39    base: branchName === masterBranchname ? "master" : masterBranchname,
40    body:
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.
42You can view the build log [here](https://typescript.visualstudio.com/TypeScript/_build/index?buildId=${process.env.BUILD_BUILDID}&_a=summary).
43
44cc ${reviewers.map(r => "@" + r).join(" ")}`,
45}).then(async r => {
46    const num = r.data.number;
47    console.log(`Pull request ${num} created.`);
48    if (!process.env.SOURCE_ISSUE) {
49        await gh.pulls.requestReviewers({
50            owner: prOwner,
51            repo: "TypeScript",
52            pull_number: num,
53            reviewers,
54        });
55    }
56    else {
57        await gh.issues.createComment({
58            issue_number: +process.env.SOURCE_ISSUE,
59            owner: "microsoft",
60            repo: "TypeScript",
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}).`
62        });
63    }
64}).then(() => {
65    console.log(`Reviewers requested, done.`);
66}).catch(e => {
67    console.error(e);
68    process.exit(1);
69});
70