()
| 140 | Thanks again for taking the time to contribute.` |
| 141 | |
| 142 | async function main() { |
| 143 | console.log(`${values.execute ? "EXECUTE" : "DRY RUN"}: PR cleanup for ${repo.owner}/${repo.name}`) |
| 144 | console.log(`Cutoff: ${cutoff.toISOString()}`) |
| 145 | console.log(`Threshold: fewer than ${threshold} positive reactions`) |
| 146 | |
| 147 | const prs = await fetchOpenPullRequests() |
| 148 | const recentCount = prs.filter((pr) => new Date(pr.createdAt) >= cutoff).length |
| 149 | const matching = prs |
| 150 | .map((pr) => ({ ...pr, positiveReactions: positiveReactionCount(pr) })) |
| 151 | .filter((pr) => new Date(pr.createdAt) < cutoff && pr.positiveReactions < threshold) |
| 152 | const candidates = matching.filter((pr) => !hasPriorCleanup(pr)) |
| 153 | const selected = maxClose === undefined ? candidates : candidates.slice(0, maxClose) |
| 154 | |
| 155 | console.log(`Fetched ${prs.length} open PRs`) |
| 156 | console.log(`Matching cleanup criteria: ${matching.length}`) |
| 157 | console.log(`Skipped previously cleaned PRs: ${matching.length - candidates.length}`) |
| 158 | console.log(`Recent PRs untouched: ${recentCount}`) |
| 159 | console.log( |
| 160 | `Older PRs with at least ${threshold} positive reactions untouched: ${prs.length - matching.length - recentCount}`, |
| 161 | ) |
| 162 | |
| 163 | if (selected.length === 0) return |
| 164 | |
| 165 | if (!values.execute) { |
| 166 | console.log(`\nDry-run only. Re-run with --execute to comment and close matching PRs.`) |
| 167 | console.log(`Showing ${Math.min(printLimit, selected.length)} of ${selected.length} matching PRs:\n`) |
| 168 | for (const pr of selected.slice(0, printLimit)) { |
| 169 | console.log(`#${pr.number} ${pr.createdAt} positive=${pr.positiveReactions} ${pr.url}`) |
| 170 | } |
| 171 | if (selected.length > printLimit) console.log(`... ${selected.length - printLimit} more not shown`) |
| 172 | return |
| 173 | } |
| 174 | |
| 175 | await ensureCleanupLabel() |
| 176 | |
| 177 | console.log(`\nCommenting and closing ${selected.length} PRs...`) |
| 178 | for (const pr of selected) { |
| 179 | await closePullRequest(pr) |
| 180 | if (sleepMs > 0) await sleep(sleepMs) |
| 181 | } |
| 182 | console.log(`Closed ${selected.length} PRs`) |
| 183 | } |
| 184 | |
| 185 | async function fetchOpenPullRequests() { |
| 186 | const prs: PullRequest[] = [] |
no test coverage detected