From a9441411096052571a0f577b31808ba9ca876190 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Tue, 22 Sep 2026 14:37:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=95=99=E8=A8=80=E5=88=86=E9=A0=81):=20?= =?UTF-8?q?=E6=94=B9=E7=94=A8=20timeline=20=E5=88=86=E9=A0=81=E8=AE=80?= =?UTF-8?q?=E5=8F=96=E7=95=99=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitea 議題留言端點無法可靠處理分頁;改由 timeline 逐頁篩選 comment 事件並去重,讓抽取、整併與 PR 留言流程取得完整集合。 --- scripts/issue-extract.js | 5 ++--- scripts/lib.js | 16 +++++++++++----- scripts/pr-reply.js | 11 +++-------- scripts/pr-threads.js | 4 ++-- scripts/wp-extract.js | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/issue-extract.js b/scripts/issue-extract.js index 89e5bc5..c9cb113 100644 --- a/scripts/issue-extract.js +++ b/scripts/issue-extract.js @@ -31,16 +31,15 @@ main(async () => { const repo = parseRepo(flags.repo); const index = parseIndex(flags.index); const issuePath = `/repos/${repo}/issues/${index}`; - const commentsPath = `${issuePath}/comments`; + const timelinePath = `${issuePath}/timeline`; if (flags['dry-run']) { return { dryRun: true, repo, - index, requests: [ { method: 'GET', path: issuePath }, - { method: 'GET', path: commentsPath }, + { method: 'GET', path: timelinePath }, ], note: UNMERGED_COMMENT_NOTE, }; diff --git a/scripts/lib.js b/scripts/lib.js index 3cf593b..df55762 100644 --- a/scripts/lib.js +++ b/scripts/lib.js @@ -974,16 +974,22 @@ export async function countUnmergedComments(login, repo, index, me) { /** * 逐頁走過一顆議題(或 PR)的一般留言。 * 三支腳本都要做這件事:數未整併的則數、列出留言內容、核對 --merged 的 id。 + * Gitea 的 comments 端點固定只回第一批,完整清單改從 timeline 取得。 * @returns {AsyncGenerator} 一則一則交出去 */ export async function* listIssueComments(login, repo, index) { - const path = `/repos/${repo}/issues/${index}/comments`; + const path = `/repos/${repo}/issues/${index}/timeline`; + const seen = new Set(); - for await (const comments of pages(login, path, { - limitCode: 'COMMENT_LIMIT', - limitHint: `${path} 的留言太多,讀不完整份清單`, + for await (const entries of pages(login, path, { + limitCode: 'TIMELINE_LIMIT', + limitHint: `${path} 的 timeline 太多,讀不完整份留言清單`, })) { - for (const comment of comments) yield comment; + for (const entry of entries) { + if (entry.type !== 'comment' || seen.has(entry.id)) continue; + seen.add(entry.id); + yield entry; + } } } diff --git a/scripts/pr-reply.js b/scripts/pr-reply.js index 941906d..41d7432 100644 --- a/scripts/pr-reply.js +++ b/scripts/pr-reply.js @@ -24,6 +24,7 @@ import { ScriptError, expectOk, giteaRequest, + listIssueComments, main, pages, parseFlags, @@ -205,14 +206,8 @@ async function findInline(login, repo, index, commentId) { } async function findGeneral(login, repo, index, commentId) { - const path = `/repos/${repo}/issues/${index}/comments`; - - for await (const comments of pages(login, path, { - limitCode: 'COMMENT_LIMIT', - limitHint: `${path} 的留言太多,找不完`, - })) { - const hit = comments.find((comment) => comment.id === commentId); - if (hit) return hit; + for await (const comment of listIssueComments(login, repo, index)) { + if (comment.id === commentId) return comment; } throw notFound(index, '一般留言', commentId); } diff --git a/scripts/pr-threads.js b/scripts/pr-threads.js index 2120d80..ba7e98f 100644 --- a/scripts/pr-threads.js +++ b/scripts/pr-threads.js @@ -49,7 +49,7 @@ export function plannedRequests(repo, index) { return [ { method: 'GET', path: '/user' }, { method: 'GET', path: pullPath }, - { method: 'GET', path: `/repos/${repo}/issues/${index}/comments` }, + { method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` }, { method: 'GET', path: `${pullPath}/reviews` }, { method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` }, ]; @@ -65,7 +65,7 @@ export function plannedRequests(repo, index) { export function commonRequests(repo, index) { return [ { method: 'GET', path: `/repos/${repo}/issues/${index}` }, - { method: 'GET', path: `/repos/${repo}/issues/${index}/comments` }, + { method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` }, ]; } diff --git a/scripts/wp-extract.js b/scripts/wp-extract.js index ae6f25c..de0d320 100644 --- a/scripts/wp-extract.js +++ b/scripts/wp-extract.js @@ -54,7 +54,7 @@ main(async () => { { method: 'GET', path: issuePath }, { method: 'GET', path: `${issuePath}/dependencies` }, { method: 'GET', path: `${issuePath}/blocks` }, - { method: 'GET', path: `${issuePath}/comments` }, + { method: 'GET', path: `${issuePath}/timeline` }, ], note: UNMERGED_COMMENT_NOTE, };