| 1 |
import { DateTime, Duration } from "luxon"; |
| 2 |
import { Octokit } from "octokit"; |
| 3 |
|
| 4 |
const token = process.env.GITHUB_TOKEN; |
| 5 |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/"); |
| 6 |
const { rest, paginate } = new Octokit({ auth: token }); |
| 7 |
|
| 8 |
const now = DateTime.now(); |
| 9 |
|
| 10 |
(async () => { |
| 11 |
for await (const { data: issues } of paginate.iterator( |
| 12 |
rest.issues.listForRepo, |
| 13 |
{ owner, repo } |
| 14 |
)) { |
| 15 |
issues.forEach((issue) => { |
| 16 |
const { number, created_at, title, pull_request, html_url } = issue; |
| 17 |
const assignee = issue.assignee?.login; |
| 18 |
|
| 19 |
const age = now |
| 20 |
.diff(DateTime.fromISO(created_at)) |
| 21 |
.shiftTo("years", "months", "days") |
| 22 |
.toHuman({ maximumFractionDigits: 0 }); |
| 23 |
|
| 24 |
const labels = issue.labels.map(({ name }) => name); |
| 25 |
const version = labels.find((name) => /\d+\.[\dx]+\.[\dx]+/.test(name)); |
| 26 |
|
| 27 |
const triage = labels.includes("triage"); |
| 28 |
const help = labels.includes("help wanted"); |
| 29 |
|
| 30 |
const question = labels.includes("question"); |
| 31 |
const unanswered = labels.includes("unanswered"); |
| 32 |
|
| 33 |
const directions = labels.filter((i) => |
| 34 |
["bug", "enhancement", "question"].includes(i) |
| 35 |
); |
| 36 |
|
| 37 |
const problems = []; |
| 38 |
|
| 39 |
if (version) { |
| 40 |
if (assignee && help) { |
| 41 |
problems.push( |
| 42 |
'Should not have both an assignee and a "help wanted" label' |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
if (!assignee && !help) { |
| 47 |
problems.push('Missing an assignee or a "help wanted" label'); |
| 48 |
} |
| 49 |
} else { |
| 50 |
if (assignee || help) { |
| 51 |
problems.push("Missing a version label"); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if (pull_request) { |
| 56 |
if (triage && version) { |
| 57 |
problems.push('Should not have both a "triage" and version label'); |
| 58 |
} |
| 59 |
|
| 60 |
if (!triage && !version) { |
| 61 |
problems.push('Missing a "triage" or version label'); |
| 62 |
} |
| 63 |
} else { |
| 64 |
if ([triage, question, version].filter((i) => i).length > 1) { |
| 65 |
problems.push('Too many "triage", "question" and version labels'); |
| 66 |
} |
| 67 |
|
| 68 |
if ([triage, question, version].every((i) => !i)) { |
| 69 |
problems.push('Missing a "triage", "question" or version label'); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
if (!triage) { |
| 74 |
if (directions.length === 0) { |
| 75 |
problems.push('Missing a "bug", "enhancement" or "question" label'); |
| 76 |
} |
| 77 |
|
| 78 |
if (directions.length > 1) { |
| 79 |
problems.push('Too many "bug", "enhancement" and "question" labels'); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if (problems.length > 0) { |
| 84 |
console.log({ |
| 85 |
age, |
| 86 |
source: { |
| 87 |
id: number, |
| 88 |
title, |
| 89 |
url: html_url, |
| 90 |
}, |
| 91 |
problems, |
| 92 |
context: { |
| 93 |
labels, |
| 94 |
assignee, |
| 95 |
version, |
| 96 |
help_wanted: help, |
| 97 |
triage, |
| 98 |
question, |
| 99 |
unanswered, |
| 100 |
directions, |
| 101 |
}, |
| 102 |
}); |
| 103 |
} |
| 104 |
}); |
| 105 |
} |
| 106 |
})(); |