1// @ts-check 2/// <reference lib="esnext.asynciterable" /> 3// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally 4const { Octokit } = require("@octokit/rest"); 5const ado = require("azure-devops-node-api"); 6const { default: fetch } = require("node-fetch"); 7 8async function main() { 9 if (!process.env.SOURCE_ISSUE) { 10 throw new Error("No source issue specified"); 11 } 12 if (!process.env.BUILD_BUILDID) { 13 throw new Error("No build ID specified"); 14 } 15 // The pipelines API does _not_ make getting the direct URL to a specific file _within_ an artifact trivial 16 const cli = new ado.WebApi("https://typescript.visualstudio.com/defaultcollection", ado.getHandlerFromToken("")); // Empty token, anon auth 17 const build = await cli.getBuildApi(); 18 const artifact = await build.getArtifact("typescript", +process.env.BUILD_BUILDID, "tgz"); 19 const updatedUrl = new URL(artifact.resource.url); 20 updatedUrl.search = `artifactName=tgz&fileId=${artifact.resource.data}&fileName=manifest`; 21 const resp = await (await fetch(`${updatedUrl}`)).json(); 22 const file = resp.items[0]; 23 const tgzUrl = new URL(artifact.resource.url); 24 tgzUrl.search = `artifactName=tgz&fileId=${file.blob.id}&fileName=${file.path}`; 25 const link = "" + tgzUrl; 26 const gh = new Octokit({ 27 auth: process.argv[2] 28 }); 29 30 // Please keep the strings "an installable tgz" and "packed" in this message, as well as the devDependencies section, 31 // so that the playgrounds deployment process can find these comments. 32 33 await gh.issues.createComment({ 34 issue_number: +process.env.SOURCE_ISSUE, 35 owner: "Microsoft", 36 repo: "TypeScript", 37 body: `Hey @${process.env.REQUESTING_USER}, I've packed this into [an installable tgz](${link}). You can install it for testing by referencing it in your \`package.json\` like so: 38\`\`\` 39{ 40 "devDependencies": { 41 "typescript": "${link}" 42 } 43} 44\`\`\` 45and then running \`npm install\`. 46` 47 }); 48 49 // Temporarily disable until we get access controls set up right 50 // Send a ping to https://github.com/microsoft/typescript-make-monaco-builds#pull-request-builds 51 await gh.request("POST /repos/microsoft/typescript-make-monaco-builds/dispatches", { event_type: process.env.SOURCE_ISSUE, headers: { Accept: "application/vnd.github.everest-preview+json" }}); 52} 53 54main().catch(async e => { 55 console.error(e); 56 process.exitCode = 1; 57 if (process.env.SOURCE_ISSUE) { 58 const gh = new Octokit({ 59 auth: process.argv[2] 60 }); 61 await gh.issues.createComment({ 62 issue_number: +process.env.SOURCE_ISSUE, 63 owner: "Microsoft", 64 repo: "TypeScript", 65 body: `Hey @${process.env.REQUESTING_USER}, something went wrong when looking for the build artifact. ([You can check the log here](https://typescript.visualstudio.com/TypeScript/_build/index?buildId=${process.env.BUILD_BUILDID}&_a=summary)).` 66 }); 67 } 68}); 69