fix(r3): add 10s AbortSignal timeout and per-issue tracker persistence

This commit is contained in:
troytt 2026-09-22 03:57:00 +00:00
parent 19e612241c
commit eb0317b533
2 changed files with 66 additions and 47 deletions

View File

@ -617,7 +617,7 @@ async function main(): Promise<void> {
existsSync(uploadedTrackerPath) ? (JSON.parse(readFileSync(uploadedTrackerPath, 'utf8')) as number[]) : [], existsSync(uploadedTrackerPath) ? (JSON.parse(readFileSync(uploadedTrackerPath, 'utf8')) as number[]) : [],
) )
// Mark the first 35 issues that already had comments posted during Phase 1 // Mark the first 35 issues that already had comments posted during Phase 1
for (let i = 0; i < entries.length - remaining.length; i += 1) { for (let i = 0; i < 35; i += 1) {
commentedIssues.add(entries[i]!.issueNumber) commentedIssues.add(entries[i]!.issueNumber)
} }
@ -662,9 +662,9 @@ async function main(): Promise<void> {
await postGiteaIssueComment(entry.issueNumber, commentMd) await postGiteaIssueComment(entry.issueNumber, commentMd)
await closeGiteaIssue(entry.issueNumber) await closeGiteaIssue(entry.issueNumber)
commentedIssues.add(entry.issueNumber) commentedIssues.add(entry.issueNumber)
uploadedCount += 1
if (uploadedCount % 20 === 0 || uploadedCount === toUpload.length) {
writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2)) writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2))
uploadedCount += 1
if (uploadedCount % 10 === 0 || uploadedCount === toUpload.length) {
console.log(` [Gitea Upload+Comment+Close] ${String(uploadedCount)}/${String(toUpload.length)} completed`) console.log(` [Gitea Upload+Comment+Close] ${String(uploadedCount)}/${String(toUpload.length)} completed`)
} }
} }
@ -674,13 +674,17 @@ async function main(): Promise<void> {
writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2)) writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2))
// Ensure any remaining open issues in Milestone #9 are closed // Ensure any remaining open issues in Milestone #9 are closed
const openRes = await fetch(`${GITEA_BASE_URL}/issues?state=open&type=issues&milestones=9&limit=50`, { for (let page = 1; page <= 5; page += 1) {
const openRes = await fetch(`${GITEA_BASE_URL}/issues?state=open&type=issues&milestones=9&limit=50&page=1`, {
headers: { Authorization: `token ${GITEA_TOKEN}` }, headers: { Authorization: `token ${GITEA_TOKEN}` },
signal: AbortSignal.timeout(10000),
}) })
const openList = (await openRes.json()) as { number: number }[] const openList = (await openRes.json()) as { number: number }[]
if (openList.length === 0) break
for (const iss of openList) { for (const iss of openList) {
await closeGiteaIssue(iss.number) await closeGiteaIssue(iss.number)
} }
}
// Final check on Milestone #9 open/closed count // Final check on Milestone #9 open/closed count
const msRes = await fetch(`${GITEA_BASE_URL}/milestones/9`, { const msRes = await fetch(`${GITEA_BASE_URL}/milestones/9`, {

View File

@ -27,6 +27,7 @@ export async function uploadPngToGiteaIssue(
const bytes = readFileSync(pngPath) const bytes = readFileSync(pngPath)
const fileName = basename(pngPath) const fileName = basename(pngPath)
for (let attempt = 1; attempt <= 6; attempt += 1) { for (let attempt = 1; attempt <= 6; attempt += 1) {
try {
const form = new FormData() const form = new FormData()
form.append('attachment', new Blob([bytes], { type: 'image/png' }), fileName) form.append('attachment', new Blob([bytes], { type: 'image/png' }), fileName)
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/assets?name=${encodeURIComponent(fileName)}`, { const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/assets?name=${encodeURIComponent(fileName)}`, {
@ -35,6 +36,7 @@ export async function uploadPngToGiteaIssue(
Authorization: `token ${GITEA_TOKEN}`, Authorization: `token ${GITEA_TOKEN}`,
}, },
body: form, body: form,
signal: AbortSignal.timeout(10000),
}) })
if (res.ok) { if (res.ok) {
return (await res.json()) as GiteaAssetUploadResult return (await res.json()) as GiteaAssetUploadResult
@ -42,6 +44,9 @@ export async function uploadPngToGiteaIssue(
if (attempt === 6) { if (attempt === 6) {
throw new Error(`Failed to upload PNG to issue #${String(issueNumber)}: HTTP ${String(res.status)}`) throw new Error(`Failed to upload PNG to issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
} }
} catch (err) {
if (attempt === 6) throw err
}
await sleep(250 * attempt) await sleep(250 * attempt)
} }
throw new Error('Unreachable') throw new Error('Unreachable')
@ -52,6 +57,7 @@ export async function postGiteaIssueComment(
markdownBody: string, markdownBody: string,
): Promise<{ id: number; body: string }> { ): Promise<{ id: number; body: string }> {
for (let attempt = 1; attempt <= 6; attempt += 1) { for (let attempt = 1; attempt <= 6; attempt += 1) {
try {
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/comments`, { const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/comments`, {
method: 'POST', method: 'POST',
headers: { headers: {
@ -59,6 +65,7 @@ export async function postGiteaIssueComment(
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ body: markdownBody }), body: JSON.stringify({ body: markdownBody }),
signal: AbortSignal.timeout(10000),
}) })
if (res.ok) { if (res.ok) {
return (await res.json()) as { id: number; body: string } return (await res.json()) as { id: number; body: string }
@ -66,6 +73,9 @@ export async function postGiteaIssueComment(
if (attempt === 6) { if (attempt === 6) {
throw new Error(`Failed to post comment on issue #${String(issueNumber)}: HTTP ${String(res.status)}`) throw new Error(`Failed to post comment on issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
} }
} catch (err) {
if (attempt === 6) throw err
}
await sleep(250 * attempt) await sleep(250 * attempt)
} }
throw new Error('Unreachable') throw new Error('Unreachable')
@ -73,6 +83,7 @@ export async function postGiteaIssueComment(
export async function closeGiteaIssue(issueNumber: number): Promise<void> { export async function closeGiteaIssue(issueNumber: number): Promise<void> {
for (let attempt = 1; attempt <= 6; attempt += 1) { for (let attempt = 1; attempt <= 6; attempt += 1) {
try {
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}`, { const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}`, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
@ -80,11 +91,15 @@ export async function closeGiteaIssue(issueNumber: number): Promise<void> {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ state: 'closed' }), body: JSON.stringify({ state: 'closed' }),
signal: AbortSignal.timeout(10000),
}) })
if (res.ok) return if (res.ok) return
if (attempt === 6) { if (attempt === 6) {
throw new Error(`Failed to close issue #${String(issueNumber)}: HTTP ${String(res.status)}`) throw new Error(`Failed to close issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
} }
} catch (err) {
if (attempt === 6) throw err
}
await sleep(250 * attempt) await sleep(250 * attempt)
} }
} }