Skip to content

Commit e20b87f

Browse files
authored
Add script for posting perf results back to GH (microsoft#30526)
* Add script for posting perf results back to GH * Slightly more logging, use html url, not api url, lol * Log even more, nonzero exit code on error
1 parent 0f6f3b7 commit e20b87f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

scripts/perf-result-post.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @ts-check
2+
/// <reference lib="esnext.asynciterable" />
3+
// Must reference esnext.asynciterable lib, since octokit uses AsyncIterable internally
4+
const Octokit = require("@octokit/rest");
5+
const fs = require("fs");
6+
7+
const requester = process.env.requesting_user;
8+
const source = process.env.source_issue;
9+
const postedComment = process.env.status_comment;
10+
console.log(`Loading fragment from ${process.argv[3]}...`);
11+
const outputTableText = fs.readFileSync(process.argv[3], { encoding: "utf8" });
12+
console.log(`Fragment contents:
13+
${outputTableText}`);
14+
15+
const gh = new Octokit();
16+
gh.authenticate({
17+
type: "token",
18+
token: process.argv[2]
19+
});
20+
gh.issues.createComment({
21+
number: +source,
22+
owner: "Microsoft",
23+
repo: "TypeScript",
24+
body: `@${requester}
25+
The results of the perf run you requested are in! Here they are:
26+
27+
${outputTableText}`
28+
}).then(async data => {
29+
console.log(`Results posted!`);
30+
const newCommentUrl = data.data.html_url;
31+
const comment = await gh.issues.getComment({
32+
owner: "Microsoft",
33+
repo: "TypeScript",
34+
comment_id: +postedComment
35+
});
36+
const newBody = `${comment.data.body}
37+
38+
Update: [The results are in!](${newCommentUrl})`;
39+
return await gh.issues.updateComment({
40+
owner: "Microsoft",
41+
repo: "TypeScript",
42+
comment_id: +postedComment,
43+
body: newBody
44+
});
45+
}).catch(e => {
46+
console.error(e);
47+
process.exit(1);
48+
});

0 commit comments

Comments
 (0)