Add script for pack response postback (#31748)

This commit is contained in:
Wesley Wigham 2019-06-03 15:24:35 -07:00 committed by GitHub
parent 790c6ee199
commit 49c44f650a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View file

@ -48,11 +48,13 @@
"@types/mocha": "latest",
"@types/ms": "latest",
"@types/node": "8.5.5",
"@types/node-fetch": "^2.3.4",
"@types/q": "latest",
"@types/source-map-support": "latest",
"@types/through2": "latest",
"@types/travis-fold": "latest",
"@types/xml2js": "^0.4.0",
"azure-devops-node-api": "^8.0.0",
"browser-resolve": "^1.11.2",
"browserify": "latest",
"chai": "latest",
@ -74,6 +76,7 @@
"mocha": "latest",
"mocha-fivemat-progress-reporter": "latest",
"ms": "latest",
"node-fetch": "^2.6.0",
"plugin-error": "latest",
"pretty-hrtime": "^1.0.3",
"prex": "^0.4.3",

View file

@ -0,0 +1,64 @@
// @ts-check
/// <reference lib="esnext.asynciterable" />
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
const Octokit = require("@octokit/rest");
const ado = require("azure-devops-node-api");
const { default: fetch } = require("node-fetch");
async function main() {
if (!process.env.SOURCE_ISSUE) {
throw new Error("No source issue specified");
}
if (!process.env.BUILD_BUILDID) {
throw new Error("No build ID specified");
}
// The pipelines API does _not_ make getting the direct URL to a specific file _within_ an artifact trivial
const cli = new ado.WebApi("https://typescript.visualstudio.com/defaultcollection", ado.getHandlerFromToken("")); // Empty token, anon auth
const build = await cli.getBuildApi();
const artifact = await build.getArtifact("typescript", +process.env.BUILD_BUILDID, "tgz");
const updatedUrl = new URL(artifact.resource.url);
updatedUrl.search = `artifactName=tgz&fileId=${artifact.resource.data}&fileName=manifest`;
const resp = await (await fetch(`${updatedUrl}`)).json();
const file = resp.items[0];
const tgzUrl = new URL(artifact.resource.url);
tgzUrl.search = `artifactName=tgz&fileId=${file.blob.id}&fileName=${file.path}`;
const link = "" + tgzUrl;
const gh = new Octokit();
gh.authenticate({
type: "token",
token: process.argv[2]
});
await gh.issues.createComment({
number: +process.env.SOURCE_ISSUE,
owner: "Microsoft",
repo: "TypeScript",
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:
\`\`\`
{
"devDependencies": {
"typescript": "${link}"
}
}
\`\`\`
and then running \`npm install\`.
`
});
}
main().catch(async e => {
console.error(e);
process.exitCode = 1;
if (process.env.SOURCE_ISSUE) {
const gh = new Octokit();
gh.authenticate({
type: "token",
token: process.argv[2]
});
await gh.issues.createComment({
number: +process.env.SOURCE_ISSUE,
owner: "Microsoft",
repo: "TypeScript",
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)).`
});
}
});