MCPcopy Index your code
hub / github.com/anomalyco/opencode / main

Function main

script/github/close-prs.ts:142–183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140Thanks again for taking the time to contribute.`
141
142async 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
185async function fetchOpenPullRequests() {
186 const prs: PullRequest[] = []

Callers 1

close-prs.tsFile · 0.70

Calls 7

fetchOpenPullRequestsFunction · 0.85
positiveReactionCountFunction · 0.85
hasPriorCleanupFunction · 0.85
ensureCleanupLabelFunction · 0.85
closePullRequestFunction · 0.85
sleepFunction · 0.70
logMethod · 0.45

Tested by

no test coverage detected