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[]) : [],
|
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)
|
||||||
|
writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2))
|
||||||
uploadedCount += 1
|
uploadedCount += 1
|
||||||
if (uploadedCount % 20 === 0 || uploadedCount === toUpload.length) {
|
if (uploadedCount % 10 === 0 || uploadedCount === toUpload.length) {
|
||||||
writeFileSync(uploadedTrackerPath, JSON.stringify(Array.from(commentedIssues), null, 2))
|
|
||||||
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,12 +674,16 @@ 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) {
|
||||||
headers: { Authorization: `token ${GITEA_TOKEN}` },
|
const openRes = await fetch(`${GITEA_BASE_URL}/issues?state=open&type=issues&milestones=9&limit=50&page=1`, {
|
||||||
})
|
headers: { Authorization: `token ${GITEA_TOKEN}` },
|
||||||
const openList = (await openRes.json()) as { number: number }[]
|
signal: AbortSignal.timeout(10000),
|
||||||
for (const iss of openList) {
|
})
|
||||||
await closeGiteaIssue(iss.number)
|
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
|
// Final check on Milestone #9 open/closed count
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,25 @@ 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) {
|
||||||
const form = new FormData()
|
try {
|
||||||
form.append('attachment', new Blob([bytes], { type: 'image/png' }), fileName)
|
const form = new FormData()
|
||||||
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/assets?name=${encodeURIComponent(fileName)}`, {
|
form.append('attachment', new Blob([bytes], { type: 'image/png' }), fileName)
|
||||||
method: 'POST',
|
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/assets?name=${encodeURIComponent(fileName)}`, {
|
||||||
headers: {
|
method: 'POST',
|
||||||
Authorization: `token ${GITEA_TOKEN}`,
|
headers: {
|
||||||
},
|
Authorization: `token ${GITEA_TOKEN}`,
|
||||||
body: form,
|
},
|
||||||
})
|
body: form,
|
||||||
if (res.ok) {
|
signal: AbortSignal.timeout(10000),
|
||||||
return (await res.json()) as GiteaAssetUploadResult
|
})
|
||||||
}
|
if (res.ok) {
|
||||||
if (attempt === 6) {
|
return (await res.json()) as GiteaAssetUploadResult
|
||||||
throw new Error(`Failed to upload PNG to issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
|
}
|
||||||
|
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)
|
await sleep(250 * attempt)
|
||||||
}
|
}
|
||||||
|
|
@ -52,19 +57,24 @@ 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) {
|
||||||
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/comments`, {
|
try {
|
||||||
method: 'POST',
|
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}/comments`, {
|
||||||
headers: {
|
method: 'POST',
|
||||||
Authorization: `token ${GITEA_TOKEN}`,
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
Authorization: `token ${GITEA_TOKEN}`,
|
||||||
},
|
'Content-Type': 'application/json',
|
||||||
body: JSON.stringify({ body: markdownBody }),
|
},
|
||||||
})
|
body: JSON.stringify({ body: markdownBody }),
|
||||||
if (res.ok) {
|
signal: AbortSignal.timeout(10000),
|
||||||
return (await res.json()) as { id: number; body: string }
|
})
|
||||||
}
|
if (res.ok) {
|
||||||
if (attempt === 6) {
|
return (await res.json()) as { id: number; body: string }
|
||||||
throw new Error(`Failed to post comment on issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
|
}
|
||||||
|
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)
|
await sleep(250 * attempt)
|
||||||
}
|
}
|
||||||
|
|
@ -73,17 +83,22 @@ 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) {
|
||||||
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}`, {
|
try {
|
||||||
method: 'PATCH',
|
const res = await fetch(`${GITEA_BASE_URL}/issues/${String(issueNumber)}`, {
|
||||||
headers: {
|
method: 'PATCH',
|
||||||
Authorization: `token ${GITEA_TOKEN}`,
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
Authorization: `token ${GITEA_TOKEN}`,
|
||||||
},
|
'Content-Type': 'application/json',
|
||||||
body: JSON.stringify({ state: 'closed' }),
|
},
|
||||||
})
|
body: JSON.stringify({ state: 'closed' }),
|
||||||
if (res.ok) return
|
signal: AbortSignal.timeout(10000),
|
||||||
if (attempt === 6) {
|
})
|
||||||
throw new Error(`Failed to close issue #${String(issueNumber)}: HTTP ${String(res.status)}`)
|
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)
|
await sleep(250 * attempt)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue