#!/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(留言), }; });