Skip to content

Commit ec426ee

Browse files
authored
Add script to work around GH issue with suggested reviewers (#37422)
1 parent 9120497 commit ec426ee

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ scripts/processDiagnosticMessages.js
5353
scripts/produceLKG.js
5454
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
5555
scripts/generateLocalizedDiagnosticMessages.js
56+
scripts/request-pr-review.js
5657
scripts/*.js.map
5758
scripts/typings/
5859
coverage/

Diff for: Gulpfile.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const copyright = "CopyrightNotice.txt";
2222
const cleanTasks = [];
2323

2424
const buildScripts = () => buildProject("scripts");
25+
task("scripts", buildScripts);
26+
task("scripts").description = "Builds files in the 'scripts' folder.";
27+
2528
const cleanScripts = () => cleanProject("scripts");
2629
cleanTasks.push(cleanScripts);
2730

Diff for: scripts/request-pr-review.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/// <reference lib="esnext.asynciterable" />
2+
/// <reference lib="es2015.promise" />
3+
import octokit = require("@octokit/rest");
4+
import Octokit = octokit.Octokit;
5+
import minimist = require("minimist");
6+
7+
const options = minimist(process.argv.slice(2), {
8+
boolean: ["help"],
9+
string: ["token", "pull", "reviewer", "owner", "repo"],
10+
alias: {
11+
pr: "pull",
12+
h: "help",
13+
["?"]: "help"
14+
},
15+
default: {
16+
token: process.env.GH_TOKEN,
17+
pull: process.env.GH_PULL_NUMBER,
18+
reviewer: process.env.REQUESTED_REVIEWER,
19+
owner: "microsoft",
20+
repo: "TypeScript"
21+
}
22+
});
23+
24+
if (options.help) {
25+
printHelpAndExit(0);
26+
}
27+
28+
if (!options.token || !options.pull || !options.reviewer || !options.owner || !options.repo) {
29+
console.error("Invalid arguments");
30+
printHelpAndExit(-1);
31+
}
32+
33+
const pull_number = +options.pull;
34+
if (!isFinite(pull_number)) {
35+
console.error("Invalid arguments");
36+
printHelpAndExit(-2);
37+
}
38+
39+
const reviewers = Array.isArray(options.reviewer) ? options.reviewer : [options.reviewer];
40+
41+
main().catch(console.error);
42+
43+
async function main() {
44+
const gh = new Octokit({ auth: options.token });
45+
const response = await gh.pulls.createReviewRequest({
46+
owner: options.owner,
47+
repo: options.repo,
48+
pull_number,
49+
reviewers,
50+
});
51+
if (response.status === 201) {
52+
console.log(`Added ${reviewers.join(", ")} to ${response.data.url}`);
53+
}
54+
else {
55+
console.log(`Failed to add ${reviewers.join(", ")} to the pull request.`);
56+
}
57+
}
58+
59+
function printHelpAndExit(exitCode: number) {
60+
console.log(`
61+
usage: request-pr-review.js [options]
62+
63+
options:
64+
--token <token> Your GitHub auth token. Uses %GH_TOKEN% if present.
65+
--owner <owner> The GH user or organization for the repo (default: 'microsoft').
66+
--repo <repo> The GH repo for the pull request (default: 'TypeScript').
67+
--pull <pr_number> The pull request number. Uses %GH_PULL_NUMBER% if present.
68+
--reviewer <reviewer> The GH username of reviewer to add. May be specified multiple times.
69+
Uses %REQUESTED_REVIEWER% if present.
70+
-h --help Prints this help message.
71+
`);
72+
return process.exit(exitCode);
73+
}

Diff for: scripts/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"configurePrerelease.ts",
1818
"buildProtocol.ts",
1919
"produceLKG.ts",
20-
"word2md.ts"
20+
"word2md.ts",
21+
"request-pr-review.ts"
2122
]
2223
}

0 commit comments

Comments
 (0)