pr-watch 要數「還有幾則沒處理」,數的是與 pr-comments 完全同一件事:三類留言分散在 三個端點,一般留言與總評看自己打的 +1、行內留言看有沒有被 resolve,而總評的 reaction 掛在它的 issue comment id 上。這套規則寫兩份,遲早會一邊認自己的 +1、另一邊認任何人的 ——而那個差異要等到有留言被靜靜跳過才會被發現。 pr-comments 只留輸入輸出,行為不變。 議題 #41 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
72 lines
2.1 KiB
JavaScript
72 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 讀 PR 上的三類留言:一般留言、review 總評、行內留言。
|
|
*
|
|
* 三類分散在三個端點,漏掉任何一類就會有 reviewer 的意見沒被處理——而那正是
|
|
* `/sdlc-fix` 存在的理由。這一支只讀不寫,分類(必改/建議)由讀到內容的人判斷。
|
|
*
|
|
* 讀取本身與「已處理」的判定在 `pr-threads.js`——`pr-watch` 要數同一件事,
|
|
* 規則寫兩份遲早會各自演化。
|
|
*
|
|
* 用法:
|
|
* node scripts/pr-comments.js --repo owner/name --index 45 [--host <網址>] [--dry-run]
|
|
*/
|
|
import {
|
|
expectOk,
|
|
giteaRequest,
|
|
main,
|
|
parseFlags,
|
|
parseIndex,
|
|
parseRepo,
|
|
preflight,
|
|
resolveLogin,
|
|
} from './lib.js';
|
|
import { fetchPull, 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);
|
|
const pullPath = `/repos/${repo}/pulls/${index}`;
|
|
|
|
if (flags['dry-run']) {
|
|
return {
|
|
dryRun: true,
|
|
repo,
|
|
index,
|
|
requests: [
|
|
{ method: 'GET', path: '/user' },
|
|
{ method: 'GET', path: pullPath },
|
|
{ method: 'GET', path: `/repos/${repo}/issues/${index}/comments` },
|
|
{ method: 'GET', path: `${pullPath}/reviews` },
|
|
{ method: 'GET', path: `/repos/${repo}/issues/${index}/timeline` },
|
|
],
|
|
note:
|
|
'每則一般留言還會各查一次 reaction、每個 review 還會各查一次它的行內留言;' +
|
|
'次數取決於留言數,事前無法列舉。',
|
|
};
|
|
}
|
|
|
|
const login = resolveLogin({ host: flags.host });
|
|
await preflight(login, repo);
|
|
|
|
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);
|
|
|
|
return {
|
|
repo,
|
|
index: pull.number,
|
|
title: pull.title,
|
|
url: pull.html_url,
|
|
state: pull.state,
|
|
留言,
|
|
未處理數: unhandledCount(留言),
|
|
};
|
|
});
|
|
|