• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { Octokit } from "@octokit/rest";
2import { runSequence } from "./run-sequence.mjs";
3
4const userName = process.env.GH_USERNAME || "typescript-bot";
5const reviewers = process.env.REQUESTING_USER ? [process.env.REQUESTING_USER] : ["weswigham", "sandersn", "RyanCavanaugh"];
6const masterBranchname = `user-baseline-updates`;
7const targetBranch = process.env.TARGET_BRANCH || "main";
8const branchName = process.env.TARGET_FORK?.toLowerCase() === "microsoft" && (targetBranch === "main" || targetBranch === "refs/heads/main")
9    ? masterBranchname
10    : `user-update-${process.env.TARGET_FORK}-${process.env.TARGET_BRANCH ? "-" + process.env.TARGET_BRANCH : ""}`;
11const remoteUrl = `https://${process.argv[2]}@github.com/${userName}/TypeScript.git`;
12const baseRef = branchName === masterBranchname ? "main" : masterBranchname;
13runSequence([
14    ["git", ["remote", "add", "fork", remoteUrl]], // Add the remote fork
15    ["git", ["checkout", "."]], // reset any changes
16    ["git", ["fetch", baseRef === "main" ? "origin" : "fork", baseRef]], // fetch target ref in case it's not present locally
17    ["git", ["checkout", baseRef]], // move head to target
18    ["node", ["./node_modules/gulp/bin/gulp.js", "baseline-accept"]], // accept baselines
19    ["git", ["checkout", "-b", branchName]], // create a branch
20    ["git", ["add", "."]], // Add all changes
21    ["git", ["commit", "-m", `"Update user baselines${+(process.env.SOURCE_ISSUE ?? 0) === 33716 ? " +cc @sandersn" : ""}"`]], // Commit all changes (ping nathan if we would post to CI thread)
22    ["git", ["push", "--set-upstream", "fork", branchName, "-f"]] // push the branch
23]);
24
25const gh = new Octokit({
26    auth: process.argv[2]
27});
28const prOwner = branchName === masterBranchname ? "microsoft" : userName;
29gh.pulls.create({
30    owner: prOwner,
31    repo: "TypeScript",
32    maintainer_can_modify: true,
33    title: `�� User test baselines have changed` + (process.env.TARGET_BRANCH ? ` for ${process.env.TARGET_BRANCH}` : ""),
34    head: `${userName}:${branchName}`,
35    base: branchName === masterBranchname ? "main" : masterBranchname,
36    body:
37`${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.
38You can view the build log [here](https://typescript.visualstudio.com/TypeScript/_build/index?buildId=${process.env.BUILD_BUILDID}&_a=summary).
39
40cc ${reviewers.map(r => "@" + r).join(" ")}`,
41}).then(async r => {
42    const num = r.data.number;
43    console.log(`Pull request ${num} created.`);
44    if (!process.env.SOURCE_ISSUE) {
45        await gh.pulls.requestReviewers({
46            owner: prOwner,
47            repo: "TypeScript",
48            pull_number: num,
49            reviewers,
50        });
51    }
52    else {
53        await gh.issues.createComment({
54            issue_number: +process.env.SOURCE_ISSUE,
55            owner: "microsoft",
56            repo: "TypeScript",
57            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}).`
58        });
59    }
60}).then(() => {
61    console.log(`Reviewers requested, done.`);
62}).catch(e => {
63    console.error(e);
64    process.exit(1);
65});
66