-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow-issues.js
343 lines (302 loc) · 13.8 KB
/
show-issues.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
const fs = require('fs');
const staff = ["costinberty", "D4ryl00", "dependabot[bot]", "dework-integration[bot]",
"gfanton", "iuricmp", "jefft0", "moul", "berty-assistant"];
const gnoDevs = ['aeddi', 'ajnavarro', 'albttx', 'alexiscolin', 'carlopezzuto', 'deelawn', 'gfanton', 'ilgooz',
'jaekwon', 'jeronimoalbi', 'Kouteki', 'kristovatlas', 'ltzmaxwell', 'mazzy89', 'michelleellen', 'moul', 'mvertes',
'n2p5', 'petar-dambovaliev', 'piux2', 'salmad3', 'sw360cab', 'thehowl', 'x1unix', 'zivkovicmilos'];
const triageReviewers = ['jefft0', 'leohhhn', 'n0izn0iz', 'notJoon', 'omarsy', 'wyhaines'];
function main() {
const headers = ["NEEDS QA ATTENTION", "MORE INFO NEEDED", "HAS DEV FOCUS", "BACKLOG OR DRAFT"]
const repos = ["berty", "weshnet", "weshnet-expo", "weshnet-expo-examples", "go-orbit-db", "go-ipfs-log",
"gnonative", "gnokey-mobile", "dsocial", "www.berty.tech", "www.wesh.network", "gomobile-ipfs"];
for (const header of headers) {
let total = 0;
let oldest = new Date();
for (const repo of repos) {
result = showIssues(repo, header);
total += result.total;
if (result.oldest < oldest)
oldest = result.oldest;
}
if (total == 0)
console.log("\n" + header + ":")
console.log("\n Total: " + total);
console.log(" Oldest: " + oldest.toISOString().substring(0, 10));
}
result = showGnoPRs();
console.log("\n Total: " + result.total);
console.log("Oldest: " + result.oldest.toISOString().substring(0, 10));
}
/**
* Read the JSON files for the repo and show all the issues for the header.
* @returns An object with total and oldest for the shown issues.
*/
function showIssues(repo, header) {
let showBacklogOrDraft = false;
let showMoreInfoNeeded = false;
let showHasDevFocus = false;
if (header == "BACKLOG OR DRAFT")
showBacklogOrDraft = true;
else if (header == "MORE INFO NEEDED")
showMoreInfoNeeded = true;
else if (header == "HAS DEV FOCUS")
showHasDevFocus = true;
else {
if (header != "NEEDS QA ATTENTION") {
console.log("ERROR: Unrecognised header: " + header);
return;
}
}
const issues = readJsonFile(repo + ".issues.json");
const pulls = readJsonFile(repo + ".pulls.json");
let total = 0;
let now = new Date();
let oldest = now;
let showedHeader = false;
for (const issue of issues) {
const isBacklog = hasLabel(issue, "backlog");
const isPullRequest = (issue.pull_request !== undefined);
const isBug = hasLabel(issue, "bug");
const isFeatureRequest = hasLabel(issue, ":rocket: feature-request");
const isQuestion = hasLabel(issue, "question");
const isApproved = hasLabel(issue, "✅ Approved");
const isVerified = hasLabel(issue, "verified");
const isMoreInfoNeeded = hasLabel(issue, "more info needed");
const url = "https://github.com/" +
(repo == "gomobile-ipfs" ? "ipfs-shipyard" : (repo == "gnonative" || repo == "gnokey-mobile" ? "gnolang" : (repo == "dsocial" ? "gnoverse" : "berty"))) +
"/" + repo + (isPullRequest ? "/pull/" : "/issues/") + issue.number;
const user = issue.user.login;
const createdAt = new Date(issue.created_at);
const updatedAt = new Date(issue.updated_at);
let daysSinceUpdate = (now - updatedAt) / (1000 * 3600 * 24);
const assignee = (issue.assignee ? issue.assignee.login : null);
let pull = null;
let hasReviewer = false;
let isDraft = false;
if (isPullRequest) {
pull = getPull(pulls, issue.number);
if (pull == null)
// (We don't expect this.)
console.log(" WARNING: Can't find pull request detail: " + url);
else {
hasReviewer = (pull.requested_reviewers.length > 0);
isDraft = pull.draft;
}
}
const isBacklogOrDraft = (isBacklog || isDraft);
const hasDevFocus = (isPullRequest ? hasReviewer : !!assignee);
if (isBacklogOrDraft != showBacklogOrDraft)
continue;
if (!isBacklogOrDraft) {
if (isMoreInfoNeeded != showMoreInfoNeeded)
continue;
if (!isMoreInfoNeeded) {
if (hasDevFocus != showHasDevFocus)
continue;
}
}
let category = " ";
if (isPullRequest)
category = "pull";
else if (isBug)
category = isVerified ? "vbug" : "bug ";
else if (isFeatureRequest)
category = isApproved ? "appf" : "feat";
else if (isQuestion)
category = "ques";
if (category == " " && (hasLabel(issue, "Feature") ||
hasLabel(issue, "chore") ||
hasLabel(issue, "🔬 R&D Study") ||
hasLabel(issue, "Toolkit")))
// Don't show GitHub Project tracking issues.
continue;
++total;
if (!showedHeader) {
console.log("\n" + header + ": " + repo);
showedHeader = true;
}
if (createdAt < oldest)
oldest = createdAt;
// Wait until 21 days pass for a response.
const daysRemaining = (isMoreInfoNeeded ? String(Math.max(0, Math.ceil(21 - daysSinceUpdate))).padStart(2, '0') + "d " : "")
console.log(daysRemaining + category + " " + url + " ".repeat(4 - ("" + issue.number).length) +
(isPullRequest ? " " : " ") + createdAt.toISOString().substring(0, 10) + ", " +
String(Math.ceil(daysSinceUpdate)).padStart(2, '0') + "d idle, " +
issue.comments + " cmts, " + user + ", " + issue.title);
if (assignee && !staff.includes(assignee))
console.log(" WARNING: #" + issue.number + " is assigned to non staff member " + assignee);
if (showBacklogOrDraft) {
if (isBacklogOrDraft && isMoreInfoNeeded)
console.log(" WARNING: #" + issue.number + " has both backlog (or draft) and more-info-needed");
if (isBacklogOrDraft && hasDevFocus && isPullRequest) {
if (isDraft)
console.log(" WARNING: draft PR #" + issue.number + " has a reviewer");
else
console.log(" WARNING: backlog PR #" + issue.number + " has a reviewer");
}
}
if (isVerified && !isBug)
console.log(" WARNING: non-bug #" + issue.number + " has the 'verified' label");
if (isApproved && !isFeatureRequest)
console.log(" WARNING: non-feature request #" + issue.number + " has the 'approved' label");
if (showHasDevFocus && !isPullRequest && issue.assignees.length > 1)
console.log(" WARNING: #" + issue.number + " is assigned to multiple devs: " + issue.assignees.length);
if (isPullRequest && pull.requested_reviewers.length > 1)
console.log(" WARNING: PR #" + issue.number + " has multiple reviewers: " + pull.requested_reviewers.length);
if (isPullRequest && pull.requested_teams.length > 0)
console.log(" WARNING: PR #" + issue.number + " has a team as a reviewer");
if (isPullRequest && isBacklog)
console.log(" WARNING: PR #" + issue.number + " has the 'backlog' label");
if (isPullRequest && isBug)
console.log(" WARNING: PR #" + issue.number + " has the 'bug' label");
if (category == " ")
console.log(" WARNING: issue/PR #" + issue.number + " doesn't have a label for 'bug', 'question', etc.");
}
return { total: total, oldest: oldest}
}
function showGnoPRs() {
const repo = "gno";
console.log("\n" + repo);
const issues = readJsonFile(repo + ".issues.json");
const pulls = readJsonFile(repo + ".pulls.json");
let total = 0;
let now = new Date();
let oldest = now;
let fetchMessages = "";
for (const issue of issues) {
const isReviewTriagePending = hasLabel(issue, "review/triage-pending");
const isStale = hasLabel(issue, "Stale");
const isPullRequest = (issue.pull_request !== undefined);
if (!isPullRequest)
continue;
const url = "https://github.com/" + "gnolang" + "/" + repo + (isPullRequest ? "/pull/" : "/issues/") + issue.number;
const user = issue.user.login;
const createdAt = new Date(issue.created_at);
const updatedAt = new Date(issue.updated_at);
let daysSinceUpdate = (now - updatedAt) / (1000 * 3600 * 24);
const message = url + " ".repeat(4 - ("" + issue.number).length) +
(isPullRequest ? " " : " ") + createdAt.toISOString().substring(0, 10) + ", " +
(isStale ? "STALE " : "") + String(Math.ceil(daysSinceUpdate)).padStart(2, '0') + "d idle, " +
issue.comments + " cmts, " + user + ", " + issue.title;
let isDraft = false;
if (isPullRequest) {
const pull = getPull(pulls, issue.number);
if (pull == null) {
// (We don't expect this.)
console.log(message + "\n WARNING: Can't find pull request detail: " + url);
continue;
}
else {
isDraft = pull.draft;
}
}
if (isDraft) {
if (isReviewTriagePending)
console.log(message + "\n WARNING: #" + issue.number + " is draft but has the 'review/triage-pending' label");
continue;
}
if (gnoDevs.includes(user)) {
if (isReviewTriagePending)
console.log(message + "\n WARNING: #" + issue.number + " was created by a Gno dev but has the 'review/triage-pending' label");
continue;
}
let hasGnoDevIssueComment = false;
{
const comments = readJsonFile(repo + ".issue-comments/" + issue.number + ".json");
for (const comment of comments) {
if (gnoDevs.includes(comment.user.login)) {
hasGnoDevIssueComment = true;
break;
}
}
}
let hasGnoDevPullComment = false;
{
const comments = readJsonFile(repo + ".pull-comments/" + issue.number + ".json");
for (const comment of comments) {
if (gnoDevs.includes(comment.user.login)) {
hasGnoDevPullComment = true;
break;
}
}
}
let hasGnoDevPullReview = false;
{
const comments = readJsonFile(repo + ".pull-reviews/" + issue.number + ".json");
for (const comment of comments) {
if (gnoDevs.includes(comment.user.login)) {
hasGnoDevPullReview = true;
break;
}
}
}
let hasTriageReviewerApproval = false;
{
const comments = readJsonFile(repo + ".pull-reviews/" + issue.number + ".json");
for (const comment of comments) {
if (comment.state == "APPROVED" && triageReviewers.includes(comment.user.login)) {
hasTriageReviewerApproval = true;
break;
}
}
}
if (hasTriageReviewerApproval) {
if (isReviewTriagePending)
console.log(message + "\n WARNING: #" + issue.number + " was approved by a triage reviewer but has the 'review/triage-pending' label");
continue;
}
else if (hasGnoDevIssueComment || hasGnoDevPullComment || hasGnoDevPullReview) {
if (isReviewTriagePending)
console.log(message + "\n WARNING: #" + issue.number + " was " + (hasGnoDevPullReview ? "reviewed" : "commented") + " by a Gno dev but has the 'review/triage-pending' label");
continue;
}
else {
if (!isReviewTriagePending) {
// Need to know if a new review is an approval or new comment is from a Gno dev.
fetchMessages += '\ncurl "https://api.github.com/repos/gnolang/' + repo + '/issues/' + issue.number + '/comments" > ' + repo + '.issue-comments/' + issue.number + '.json';
fetchMessages += '\ncurl "https://api.github.com/repos/gnolang/' + repo + '/pulls/' + issue.number + '/comments" > ' + repo + '.pull-comments/' + issue.number + '.json';
fetchMessages += '\ncurl "https://api.github.com/repos/gnolang/' + repo + '/pulls/' + issue.number + '/reviews" > ' + repo + '.pull-reviews/' + issue.number + '.json';
}
}
++total;
if (createdAt < oldest)
oldest = createdAt;
console.log(message);
if (!isReviewTriagePending)
console.log(" WARNING: #" + issue.number + " doesn't have the 'review/triage-pending' label");
}
console.log(fetchMessages);
return { total: total, oldest: oldest}
}
function readJsonFile(filePath) {
let text = "";
try {
text = fs.readFileSync(filePath, 'utf8');
} catch (e) {
return [];
}
const blankResult = "[\n\n]\n";
if (text.endsWith(blankResult))
// The second fetched "page" of issues is blank.
text = text.substring(0, text.length - blankResult.length);
// Replace the boundary between two pages of results.
text = text.replaceAll('\n]\n[\n', ',\n');
if (text == "")
text = "[]";
return JSON.parse(text);
}
function getPull(pulls, number) {
for (const pull of pulls) {
if (pull.number == number)
return pull;
}
return null;
}
function hasLabel(issue, labelName) {
for (const label of issue.labels) {
if (label.name == labelName)
return true;
}
return false;
}
main();