()
| 60 | } |
| 61 | |
| 62 | async function main() { |
| 63 | let page = 1 |
| 64 | let closed = 0 |
| 65 | |
| 66 | while (true) { |
| 67 | const res = await fetch( |
| 68 | `https://api.github.com/repos/${repo}/issues?state=open&sort=updated&direction=asc&per_page=100&page=${page}`, |
| 69 | { headers }, |
| 70 | ) |
| 71 | if (!res.ok) throw new Error(res.statusText) |
| 72 | |
| 73 | const all = (await res.json()) as Issue[] |
| 74 | if (all.length === 0) break |
| 75 | console.log(`Fetched page ${page} ${all.length} issues`) |
| 76 | |
| 77 | const stale: number[] = [] |
| 78 | for (const i of all) { |
| 79 | const updated = new Date(i.updated_at) |
| 80 | if (updated < cutoff) { |
| 81 | if (shouldSkip(i)) { |
| 82 | console.log(`Skipping stale issue #${i.number}; author ${i.user?.login ?? "unknown"} is exempt`) |
| 83 | continue |
| 84 | } |
| 85 | stale.push(i.number) |
| 86 | } else { |
| 87 | console.log(`\nFound fresh issue #${i.number}, stopping`) |
| 88 | if (stale.length > 0) { |
| 89 | for (const num of stale) { |
| 90 | await close(num) |
| 91 | closed++ |
| 92 | } |
| 93 | } |
| 94 | console.log(`Closed ${closed} issues total`) |
| 95 | return |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (stale.length > 0) { |
| 100 | for (const num of stale) { |
| 101 | await close(num) |
| 102 | closed++ |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | page++ |
| 107 | } |
| 108 | |
| 109 | console.log(`Closed ${closed} issues total`) |
| 110 | } |
| 111 | |
| 112 | main().catch((err) => { |
| 113 | console.error("Error:", err) |
no test coverage detected