fix(r3): add 10s AbortSignal timeout and per-issue tracker persistence
This commit is contained in:
parent
19e612241c
commit
eb0317b533
|
|
@ -617,7 +617,7 @@ async function main(): Promise<void> {
|
|||
existsSync(uploadedTrackerPath) ? (JSON.parse(readFileSync(uploadedTrackerPath, 'utf8')) as number[]) : [],
|
||||
)
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
@ -662,9 +662,9 @@ async function main(): Promise<void> {
|
|||
await postGiteaIssueComment(entry.issueNumber, commentMd)
|
||||
await closeGiteaIssue(entry.issueNumber)
|
||||
commentedIssues.add(entry.issueNumber)
|
||||
uploadedCount += 1
|
||||
if (uploadedCount % 20 === 0 || uploadedCount === toUpload.length) {
|
||||
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`)
|
||||
}
|
||||
}
|
||||
|
|
@ -674,13 +674,17 @@ async function main(): Promise<void> {
|
|||
writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2))
|
||||
|
||||
// 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}` },
|
||||
signal: AbortSignal.timeout(10000),
|
||||
})
|
||||
const openList = (await openRes.json()) as { number: number }[]
|
||||
if (openList.length === 0) break
|
||||
for (const iss of openList) {
|
||||
await closeGiteaIssue(iss.number)
|
||||
}
|
||||
}
|
||||
|
||||
// Final check on Milestone #9 open/closed count
|
||||
const msRes = await fetch(`${GITEA_BASE_URL}/milestones/9`, {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ export async function uploadPngToGiteaIssue(
|
|||
const bytes = readFileSync(pngPath)
|
||||
const fileName = basename(pngPath)
|
||||
for (let attempt = 1; attempt <= 6; attempt += 1) {
|
||||
try {
|
||||
const form = new FormData()
|
||||
form.append('attachment', new Blob([bytes], { type: 'image/png' }), 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}`,
|
||||
},
|
||||
body: form,
|
||||
signal: AbortSignal.timeout(10000),
|
||||
})
|
||||
if (res.ok) {
|
||||
return (await res.json()) as GiteaAssetUploadResult
|
||||
|
|
@ -42,6 +44,9 @@ export async function uploadPngToGiteaIssue(
|
|||
if (attempt === 6) {
|
||||
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)
|
||||
}
|
||||
throw new Error('Unreachable')
|
||||
|
|
@ -52,6 +57,7 @@ export async function postGiteaIssueComment(
|
|||
markdownBody: string,
|
||||
): Promise<{ id: number; body: string }> {
|
||||
for (let attempt = 1; attempt <= 6; attempt += 1) {
|
||||
try {
|
||||
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/comments`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
@ -59,6 +65,7 @@ export async function postGiteaIssueComment(
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ body: markdownBody }),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
})
|
||||
if (res.ok) {
|
||||
return (await res.json()) as { id: number; body: string }
|
||||
|
|
@ -66,6 +73,9 @@ export async function postGiteaIssueComment(
|
|||
if (attempt === 6) {
|
||||
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)
|
||||
}
|
||||
throw new Error('Unreachable')
|
||||
|
|
@ -73,6 +83,7 @@ export async function postGiteaIssueComment(
|
|||
|
||||
export async function closeGiteaIssue(issueNumber: number): Promise<void> {
|
||||
for (let attempt = 1; attempt <= 6; attempt += 1) {
|
||||
try {
|
||||
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
|
|
@ -80,11 +91,15 @@ export async function closeGiteaIssue(issueNumber: number): Promise<void> {
|
|||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ state: 'closed' }),
|
||||
signal: AbortSignal.timeout(10000),
|
||||
})
|
||||
if (res.ok) return
|
||||
if (attempt === 6) {
|
||||
throw new Error(`Failed to close issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
|
||||
}
|
||||
} catch (err) {
|
||||
if (attempt === 6) throw err
|
||||
}
|
||||
await sleep(250 * attempt)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue