From 6125c2b6e05fc9920068fab224b36a668eb6fe2e Mon Sep 17 00:00:00 2001 From: Jeffery Date: Thu, 17 Sep 2026 05:00:28 +0000 Subject: [PATCH] =?UTF-8?q?fix(issue-extract):=20=E7=95=99=E8=A8=80?= =?UTF-8?q?=E9=80=90=E9=A0=81=E8=AE=80=E5=AE=8C=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=8F=AA=E6=95=B8=E7=AC=AC=E4=B8=80=E9=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原本只打一次留言端點就收工,留言超過一頁時未整併的則數會少算——而少算的後果 是下游以為描述是最新的,照著過期的描述做事。改用 lib.pages 走完所有頁,讀不完 就以 COMMENT_LIMIT 報錯,不無聲回傳半份。 Co-Authored-By: Claude Opus 5 (1M context) --- scripts/issue-extract.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/issue-extract.js b/scripts/issue-extract.js index 874037a..d9a5423 100644 --- a/scripts/issue-extract.js +++ b/scripts/issue-extract.js @@ -14,6 +14,7 @@ import { expectOk, giteaRequest, main, + pages, parseFlags, parseRepo, preflight, @@ -92,16 +93,20 @@ async function fetchIssue(login, repo, index, path) { * * 已整併的留言會被打上 `+1` reaction(由 sdlc-sync 負責標記),而 Gitea 的留言物件 * 不含 reaction,所以只能逐則再查一次。留言多時請求數會跟著長,但這個數字要準 - * ——它決定下游會不會拿著過期的描述做事。 + * ——它決定下游會不會拿著過期的描述做事,所以留言也要逐頁讀完,讀不完寧可報錯。 */ async function countUnmergedComments(login, repo, commentsPath) { - const comments = expectOk(await giteaRequest(login, 'GET', commentsPath), `GET ${commentsPath}`) ?? []; - let unmerged = 0; - for (const comment of comments) { - const path = `/repos/${repo}/issues/comments/${comment.id}/reactions`; - const reactions = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? []; - if (!reactions.some((reaction) => reaction.content === '+1')) unmerged += 1; + + for await (const comments of pages(login, commentsPath, { + limitCode: 'COMMENT_LIMIT', + limitHint: `${commentsPath} 的留言太多,數不完未整併的則數`, + })) { + for (const comment of comments) { + const path = `/repos/${repo}/issues/comments/${comment.id}/reactions`; + const reactions = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? []; + if (!reactions.some((reaction) => reaction.content === '+1')) unmerged += 1; + } } return unmerged; }