Unverified Commit 05d13d45 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Drain the maintainer auto-close queue in one run (#100733)

> [!TIP]
> Best reviewed by hide whitespace:
[files?w=1](https://github.com/vercel/next.js/pull/100733/files?w=1).

Previously, were checking to close issue 1 per hour. Now that check
closes all availables at once. Currently maxed to 5 from agent side.
parent 68406a4c
async function deliverOneVerifiedClose({ core, github }) { async function deliverVerifiedCloses({ core, github }) {
const queue = const queue =
'https://next-maintainer-agent.vercel.tools/eve/agents/close-verifier/eve/v1/auto-close' 'https://next-maintainer-agent.vercel.tools/eve/agents/close-verifier/eve/v1/auto-close'
const repository = 'vercel/next.js' const repository = 'vercel/next.js'
...@@ -58,98 +58,109 @@ async function deliverOneVerifiedClose({ core, github }) { ...@@ -58,98 +58,109 @@ async function deliverOneVerifiedClose({ core, github }) {
} }
} }
const claimed = await queueRequest('/claim') async function deliver(claim) {
if (claimed === null) return const marker = `<!-- next-maintainer-auto-close:${claim.approvalId} -->`
const claim = claimed
const marker = `<!-- next-maintainer-auto-close:${claim.approvalId} -->`
try { try {
const issue = await readIssue(claim.issueNumber) const issue = await readIssue(claim.issueNumber)
if (issue === null) { if (issue === null) {
await reportStale(claim, 'Issue no longer exists in this repository.') await reportStale(claim, 'Issue no longer exists in this repository.')
return return
}
if (issue.pull_request !== undefined) {
await reportStale(claim, 'Target is a pull request.')
return
}
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: claim.issueNumber,
per_page: 100,
})
const markerComment = comments.find((comment) =>
(comment.body ?? '').includes(marker)
)
if (issue.state === 'closed') {
if (markerComment === undefined) {
await reportStale(claim, 'Issue was closed independently.')
} else {
await report(claim, 'closed')
} }
return if (issue.pull_request !== undefined) {
} await reportStale(claim, 'Target is a pull request.')
if (markerComment !== undefined) { return
// This is either a partial prior run or a human reopen. Leave it open. }
await reportStale(claim, 'Issue is open after a prior delivery comment.')
return const comments = await github.paginate(github.rest.issues.listComments, {
} owner,
repo,
issue_number: claim.issueNumber,
per_page: 100,
})
const markerComment = comments.find((comment) =>
(comment.body ?? '').includes(marker)
)
let duplicateIssueId if (issue.state === 'closed') {
if (claim.stateReason === 'duplicate') { if (markerComment === undefined) {
if (claim.duplicateIssueNumber === claim.issueNumber) { await reportStale(claim, 'Issue was closed independently.')
await reportStale(claim, 'Issue cannot be a duplicate of itself.') } else {
await report(claim, 'closed')
}
return return
} }
const canonical = await readIssue(claim.duplicateIssueNumber) if (markerComment !== undefined) {
if (canonical === null || canonical.pull_request !== undefined) { // This is either a partial prior run or a human reopen. Leave it open.
await reportStale( await reportStale(
claim, claim,
'Duplicate target is not an issue in this repository.' 'Issue is open after a prior delivery comment.'
) )
return return
} }
duplicateIssueId = canonical.id
}
await github.rest.issues.createComment({ let duplicateIssueId
owner, if (claim.stateReason === 'duplicate') {
repo, if (claim.duplicateIssueNumber === claim.issueNumber) {
issue_number: claim.issueNumber, await reportStale(claim, 'Issue cannot be a duplicate of itself.')
body: `${claim.closeComment}\n\n${marker}`, return
}) }
const canonical = await readIssue(claim.duplicateIssueNumber)
if (canonical === null || canonical.pull_request !== undefined) {
await reportStale(
claim,
'Duplicate target is not an issue in this repository.'
)
return
}
duplicateIssueId = canonical.id
}
const updated = ( await github.rest.issues.createComment({
await github.rest.issues.update({
owner, owner,
repo, repo,
issue_number: claim.issueNumber, issue_number: claim.issueNumber,
state: 'closed', body: `${claim.closeComment}\n\n${marker}`,
state_reason: claim.stateReason,
...(duplicateIssueId === undefined
? {}
: { duplicate_issue_id: duplicateIssueId }),
}) })
).data
if ( const updated = (
updated.state !== 'closed' || await github.rest.issues.update({
updated.state_reason !== claim.stateReason owner,
) { repo,
throw new Error('GitHub did not apply the requested close reason.') issue_number: claim.issueNumber,
} state: 'closed',
await report(claim, 'closed') state_reason: claim.stateReason,
} catch (error) { ...(duplicateIssueId === undefined
const message = error instanceof Error ? error.message : String(error) ? {}
try { : { duplicate_issue_id: duplicateIssueId }),
await report(claim, 'retry', message) })
} catch (callbackError) { ).data
core.warning(`Could not report retry: ${callbackError}`) if (
updated.state !== 'closed' ||
updated.state_reason !== claim.stateReason
) {
throw new Error('GitHub did not apply the requested close reason.')
}
await report(claim, 'closed')
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
try {
await report(claim, 'retry', message)
} catch (callbackError) {
core.warning(`Could not report retry: ${callbackError}`)
}
throw error
} }
throw error }
// The queue releases each cycle's verified closes together and enforces the
// daily limit, so take claims until it has nothing left. A failed close
// stops the run after reporting a retry.
for (;;) {
const claim = await queueRequest('/claim')
if (claim === null) return
await deliver(claim)
} }
} }
module.exports = { deliverOneVerifiedClose } module.exports = { deliverVerifiedCloses }
...@@ -29,10 +29,10 @@ jobs: ...@@ -29,10 +29,10 @@ jobs:
sparse-checkout: .github/scripts/next-maintainer-auto-close.js sparse-checkout: .github/scripts/next-maintainer-auto-close.js
sparse-checkout-cone-mode: false sparse-checkout-cone-mode: false
- name: Pull and deliver one verified close - name: Pull and deliver every released close
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
script: | script: |
const { deliverOneVerifiedClose } = require('./.github/scripts/next-maintainer-auto-close.js') const { deliverVerifiedCloses } = require('./.github/scripts/next-maintainer-auto-close.js')
await deliverOneVerifiedClose({ core, github }) await deliverVerifiedCloses({ core, github })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment