Files
tea-sdlc/scripts/pr-comments.js
T
jiantw83andClaude Opus 5 42f5b86299 merge(pr-留言): 把議題支援套到 pr-threads 的共用結構上
#48 把留言讀取抽成 pr-threads 給 pr-watch 與 pr-comments 共用,本分支則在修「純議題讀不了」
與「已處理的判定有兩份」。兩邊動到同一塊,但要的其實是同一件事——#48 的檔頭就寫著
「規則寫兩份遲早會各自演化,一邊認自己打的 +1、另一邊認任何人的」,而那正是本分支在
lib 與 pr-comments 之間發現的那個 bug。

合併的方向是保留 pr-threads 的結構,把修正套進去:

- readGeneral 改名 readGeneralComments 並導出,pr-comments 判斷出是純議題時只叫它。
  先讀 /issues/{index} 再決定要不要翻 review——每個 PR 都是議題,反過來不成立。
- pr-threads 自己那份 markedByMe 拿掉,改用 lib 的 mergedByMe。抽取契約數未整併則數
  用的是同一條規則,現在三處共用一份,#48 擔心的分歧不會再發生。
- pr-comments 的試跑改印 commonRequests:它收得下兩種輸入,而試跑階段還沒讀過議題、
  不知道是哪一種。與其假設是 PR 而列出五個(對純議題有三個根本不會發),不如只列一定
  會發的,其餘交給 note。pr-watch 的輸入一定是 PR,繼續用 plannedRequests。

lib.js 與 sdlc-feat.md 兩邊改的是不同區域,三方合併無衝突。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 09:16:34 +00:00

78 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* 讀 PR 或議題上的留言。
*
* PR 有三類:一般留言、review 總評、行內留言,分散在三個端點——漏掉任何一類就會有
* reviewer 的意見沒被處理,而那正是 `/sdlc-fix` 存在的理由。
* 純議題只有一般留言,`/sdlc-sync` 要的就是那一份。
*
* **每個 PR 都是議題,但議題不一定是 PR。** 所以先讀 `/issues/{index}`(兩種都有),
* 看它有沒有 `pull_request` 才決定要不要去翻 review;反過來先打 `/pulls/{index}`,
* 對純議題會 404,整個流程在讀到第一則留言之前就斷了。
*
* 讀取本身與「已處理」的判定在 `pr-threads.js`——`pr-watch` 要數同一件事,
* 規則寫兩份遲早會各自演化。
*
* 用法:
* node scripts/pr-comments.js --repo owner/name --index 45 [--host <網址>] [--dry-run]
*/
import {
fetchIssue,
main,
parseFlags,
parseIndex,
parseRepo,
preflight,
resolveLogin,
} from './lib.js';
import {
ISSUE_OR_PULL_NOTE,
commonRequests,
readGeneralComments,
readPullComments,
unhandledCount,
} from './pr-threads.js';
main(async () => {
const flags = parseFlags(process.argv.slice(2), {
required: ['repo', 'index'],
optional: ['host'],
booleans: ['dry-run'],
});
const repo = parseRepo(flags.repo);
const index = parseIndex(flags.index);
if (flags['dry-run']) {
return {
dryRun: true,
repo,
index,
requests: commonRequests(repo, index),
note: ISSUE_OR_PULL_NOTE,
};
}
const login = resolveLogin({ host: flags.host });
const { user } = await preflight(login, repo);
const me = user.login;
// 先讀議題: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: issue.number,
類型: isPull ? 'PR' : '議題',
title: issue.title,
url: issue.html_url,
state: issue.state,
留言,
未處理數: unhandledCount(留言),
};
});