fix(pr-comments): 議題也讀得了,不再先打 PR 端點

每個 PR 都是議題,議題不一定是 PR——原本的註解把這句話講反了,程式也照著反過來寫:
先打 /pulls/{index},對純議題回 404,於是 /sdlc-sync 在讀到第一則留言之前就斷了。

改成先讀 /issues/{index}(兩種都有),看它有沒有 pull_request 才決定要不要去翻 review。
輸出加上「類型」讓下游知道拿到的是議題還是 PR。

讀取的共用結構沿用 pr-threads(#48 為了讓 pr-watch 數同一件事而抽出來的):readGeneral
改名 readGeneralComments 並導出,純議題只叫它;pr-threads 自己那份 markedByMe 拿掉,
改用 lib 的 mergedByMe。#48 的檔頭擔心「規則寫兩份遲早會各自演化」,現在三處共用一份。

試跑改印 commonRequests:pr-comments 收得下兩種輸入,而試跑階段還沒讀過議題、不知道是
哪一種。與其假設是 PR 而列出五個(對純議題有三個根本不會發),不如只列一定會發的。
pr-watch 的輸入一定是 PR,繼續用 plannedRequests。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 09:19:06 +00:00
co-authored by Claude Opus 5
parent b263915afc
commit 051fe0ded4
2 changed files with 65 additions and 52 deletions
+27 -18
View File
@@ -1,9 +1,14 @@
#!/usr/bin/env node
/**
* 讀 PR 上的三類留言:一般留言、review 總評、行內留言。
* 讀 PR 或議題上的留言。
*
* 三類分散在三個端點,漏掉任何一類就會有 reviewer 的意見沒被處理——而那正是
* `/sdlc-fix` 存在的理由。這一支只讀不寫,分類(必改/建議)由讀到內容的人判斷。
* PR 有三類:一般留言、review 總評、行內留言,分散在三個端點——漏掉任何一類就會有
* reviewer 的意見沒被處理,而那正是 `/sdlc-fix` 存在的理由。
* 純議題只有一般留言,`/sdlc-sync` 要的就是那一份。
*
* **每個 PR 都是議題,但議題不一定是 PR。** 所以先讀 `/issues/{index}`(兩種都有),
* 看它有沒有 `pull_request` 才決定要不要去翻 review;反過來先打 `/pulls/{index}`,
* 對純議題會 404,整個流程在讀到第一則留言之前就斷了。
*
* 讀取本身與「已處理」的判定在 `pr-threads.js`——`pr-watch` 要數同一件事,
* 規則寫兩份遲早會各自演化。
@@ -12,8 +17,7 @@
* node scripts/pr-comments.js --repo owner/name --index 45 [--host <網址>] [--dry-run]
*/
import {
expectOk,
giteaRequest,
fetchIssue,
main,
parseFlags,
parseIndex,
@@ -22,9 +26,9 @@ import {
resolveLogin,
} from './lib.js';
import {
COMMENT_REQUEST_NOTE,
fetchPull,
plannedRequests,
ISSUE_OR_PULL_NOTE,
commonRequests,
readGeneralComments,
readPullComments,
unhandledCount,
} from './pr-threads.js';
@@ -43,24 +47,29 @@ main(async () => {
dryRun: true,
repo,
index,
requests: plannedRequests(repo, index),
note: COMMENT_REQUEST_NOTE,
requests: commonRequests(repo, index),
note: ISSUE_OR_PULL_NOTE,
};
}
const login = resolveLogin({ host: flags.host });
await preflight(login, repo);
const { user } = await preflight(login, repo);
const me = user.login;
const me = expectOk(await giteaRequest(login, 'GET', '/user'), 'GET /user').login;
const pull = await fetchPull(login, repo, index);
const 留言 = await readPullComments(login, repo, index, me);
// 先讀議題:PR 也是議題,反過來不成立。這一步同時決定要不要去翻 review
const issue = await fetchIssue(login, repo, index);
const isPull = issue.pull_request != null;
const 留言 = isPull
? await readPullComments(login, repo, index, me)
: await readGeneralComments(login, repo, index, me);
return {
repo,
index: pull.number,
title: pull.title,
url: pull.html_url,
state: pull.state,
index: issue.number,
類型: isPull ? 'PR' : '議題',
title: issue.title,
url: issue.html_url,
state: issue.state,
留言,
未處理數: unhandledCount(留言),
};