@pecot/workflow-mcp 8.0.1-dev.58 → 8.0.1-dev.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/cli/dist/commands/names.js +1 -0
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/review-finish.d.ts +3 -0
- package/cli/dist/commands/review-finish.js +276 -0
- package/cli/dist/domain/review-finish.d.ts +102 -0
- package/cli/dist/domain/review-finish.js +169 -0
- package/cli/dist/infra/github/issues.d.ts +4 -0
- package/cli/dist/infra/github/issues.js +6 -0
- package/cli/dist/infra/github/pulls.d.ts +9 -0
- package/cli/dist/infra/github/pulls.js +14 -0
- package/cli/dist/infra/github/repos.d.ts +4 -0
- package/cli/dist/infra/github/repos.js +8 -1
- package/cli/templates/comment/review-stopped.md +28 -0
- package/cli/templates/workflow/pecot-review.yml +11 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,6 +111,7 @@ Claude Code では、Claude Code がサーバを起動するディレクトリ
|
|
|
111
111
|
| `pr_check` | PR を作る前に確かめる情報をまとめて表示する |
|
|
112
112
|
| `pr_merge` | PR をマージする(スタックの中の PR は最下段だけ) |
|
|
113
113
|
| `pr_restack` | 積んだブランチを、base にしたブランチの新しい位置へ載せ直す |
|
|
114
|
+
| `review_finish` | 自動レビューを終える(止まったときだけ、止まったことを知らせるコメントを PR に書く) |
|
|
114
115
|
| `release_check` | リリース前の確認をする |
|
|
115
116
|
| `release_create` | GitHub のリリースとタグを作る(ノートは CHANGELOG から取る) |
|
|
116
117
|
| `release_merge` | リリースの PR を通常のマージで取り込む |
|
|
@@ -22,6 +22,7 @@ export const COMMAND_GROUPS = [
|
|
|
22
22
|
{ name: 'issue', meaning: 'Issue そのもの', help: 'Work with Issues' },
|
|
23
23
|
{ name: 'session', meaning: '1 つの Issue の作業の始まりから終わりまで', help: 'Start, show and finish the work on an Issue' },
|
|
24
24
|
{ name: 'pr', meaning: 'PR そのもの', help: 'Work with PRs' },
|
|
25
|
+
{ name: 'review', meaning: 'PR の自動レビューの実行', help: 'Work with automated reviews of PRs' },
|
|
25
26
|
{ name: 'release', meaning: 'リリース', help: 'Work with releases' },
|
|
26
27
|
{ name: 'tracker', meaning: 'Tracker の Issue の書き直し', help: 'Rewrite the list in a Tracker Issue' },
|
|
27
28
|
{ name: 'worktree', meaning: 'worktree', help: 'Work with worktrees' },
|
|
@@ -5,6 +5,7 @@ import { BRANCH_COMMANDS } from './branch.js';
|
|
|
5
5
|
import { registerCommandHints } from './command-hint.js';
|
|
6
6
|
import { ISSUE_COMMANDS } from './issue.js';
|
|
7
7
|
import { PR_RESTACK_COMMANDS } from './pr-restack.js';
|
|
8
|
+
import { REVIEW_COMMANDS } from './review-finish.js';
|
|
8
9
|
import { PR_COMMANDS } from './pr.js';
|
|
9
10
|
import { PROJECT_COMMANDS } from './project.js';
|
|
10
11
|
import { RELEASE_COMMANDS } from './release.js';
|
|
@@ -20,6 +21,7 @@ export const COMMANDS = [
|
|
|
20
21
|
...SESSION_COMMANDS,
|
|
21
22
|
...PR_COMMANDS,
|
|
22
23
|
...PR_RESTACK_COMMANDS,
|
|
24
|
+
...REVIEW_COMMANDS,
|
|
23
25
|
...RELEASE_COMMANDS,
|
|
24
26
|
...TRACKER_COMMANDS,
|
|
25
27
|
...WORKTREE_COMMANDS,
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は内部の状態を持つ */
|
|
2
|
+
// review finish。自動レビューが止まったときだけ、止まったことを知らせるコメントを PR に 1 つ書く。
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { isJsonObject, jsonField } from '../domain/json.js';
|
|
5
|
+
import { stripFrontmatter, stripLeadingHtmlComment } from '../domain/frontmatter.js';
|
|
6
|
+
import { decideReviewFinish, hasStoppedMarker, readExecution, renderReviewStopped, stopLocationOf } from '../domain/review-finish.js';
|
|
7
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
8
|
+
import { isFileNotFound } from '../infra/os-error.js';
|
|
9
|
+
import { templateFile } from '../infra/template-store.js';
|
|
10
|
+
import { readTextFile } from '../infra/text-file.js';
|
|
11
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
12
|
+
import { hinted, inputNameHint } from './command-hint.js';
|
|
13
|
+
import { stopWith } from './command-stop.js';
|
|
14
|
+
import { kindOfFailure } from './failure.js';
|
|
15
|
+
import { createGitHubClient } from './github-client.js';
|
|
16
|
+
import { COMMENT_VALIDATION_EXIT_CODE, hasReportedTemplateViolations } from './issue-shared.js';
|
|
17
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
18
|
+
import { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
|
|
19
|
+
const PATH = ['review', 'finish'];
|
|
20
|
+
const DEFAULT_TRIGGER_PHRASE = '@pecotbot review';
|
|
21
|
+
// action の checkWritePermissions と同じ。collaborators の permission で maintain は write になる
|
|
22
|
+
const WRITE_PERMISSIONS = new Set(['admin', 'write']);
|
|
23
|
+
const SKIP_REASON_SCHEMA = z.enum(['reviewed', 'job-succeeded', 'workflow-mismatch', 'closed', 'already-written', 'actor-without-write']);
|
|
24
|
+
function skipText(reason) {
|
|
25
|
+
switch (reason) {
|
|
26
|
+
case 'reviewed': {
|
|
27
|
+
return 'the review finished';
|
|
28
|
+
}
|
|
29
|
+
case 'job-succeeded': {
|
|
30
|
+
return 'the job succeeded';
|
|
31
|
+
}
|
|
32
|
+
case 'workflow-mismatch': {
|
|
33
|
+
return 'the workflow file differs from the default branch, so the action skipped the review; a review started by a comment does not run on this PR either';
|
|
34
|
+
}
|
|
35
|
+
case 'closed': {
|
|
36
|
+
return 'the PR is closed';
|
|
37
|
+
}
|
|
38
|
+
case 'already-written': {
|
|
39
|
+
return 'this run already posted one';
|
|
40
|
+
}
|
|
41
|
+
case 'actor-without-write': {
|
|
42
|
+
return 'the actor has no write permission';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const InputSchema = z.object({
|
|
47
|
+
pr_ref: z.string().describe(PR_REFERENCE_DESCRIPTION),
|
|
48
|
+
result: z.enum(['reviewed', 'failed', 'limit', 'setup-missing']).optional().describe('Result of the review, passed by the skill (reviewed/failed/limit/setup-missing)'),
|
|
49
|
+
detail: z.string().optional().describe('Name of the missing setting (only with result setup-missing)'),
|
|
50
|
+
ensure: z.boolean().default(false).describe('Called from the cleanup step of the workflow: decide the result from the job and write only if this run has not'),
|
|
51
|
+
job_status: z.enum(['success', 'failure', 'cancelled']).optional().describe('Status of the job (required with ensure)'),
|
|
52
|
+
execution_file: z.string().optional().describe('Path of the execution_file output of claude-code-action (only with ensure)'),
|
|
53
|
+
since: z.string().optional().describe('Start time of the run in ISO 8601, to find the inline comments it posted (only with ensure)'),
|
|
54
|
+
review_outcome: z.enum(['success', 'failure', 'cancelled', 'skipped']).optional().describe('Outcome of the automated review step (required with ensure)'),
|
|
55
|
+
review_conclusion: z.string().optional().describe('The conclusion output of claude-code-action; empty when Claude Code did not run (required with ensure, may be empty)'),
|
|
56
|
+
review_has_token: z.enum(['true', 'false']).optional().describe('Whether claude-code-action output a github_token (required with ensure; never the token itself)'),
|
|
57
|
+
dry_run: z.boolean().default(false).describe('Read the PR and show the comment that would be posted without posting it'),
|
|
58
|
+
});
|
|
59
|
+
const OUTPUT = z.strictObject({
|
|
60
|
+
pullRequest: z.string().describe('PR (owner/repo/N)'),
|
|
61
|
+
result: z.enum(['failed', 'limit', 'setup-missing']).optional().describe('Result written in the comment (absent when skipped)'),
|
|
62
|
+
location: z.enum(['before-findings', 'after-inline', 'unknown']).optional().describe('Where the review stopped (absent when skipped)'),
|
|
63
|
+
skipped: SKIP_REASON_SCHEMA.optional().describe('Why no comment was written (absent when written)'),
|
|
64
|
+
commentUrl: z.string().optional().describe('URL of the comment written (absent when skipped or on dry_run)'),
|
|
65
|
+
dryRun: DRY_RUN_FIELD,
|
|
66
|
+
});
|
|
67
|
+
function displayOf(target) {
|
|
68
|
+
return `PR ${target.owner}/${target.repository}#${String(target.number)}`;
|
|
69
|
+
}
|
|
70
|
+
function nonEmpty(value) {
|
|
71
|
+
return value === undefined || value.trim() === '' ? undefined : value.trim();
|
|
72
|
+
}
|
|
73
|
+
function stopInvalid(out, message) {
|
|
74
|
+
return stopWith(out, message, 'invalid-input');
|
|
75
|
+
}
|
|
76
|
+
// --result と --ensure のどちらか 1 つ。ensure の補助の引数は ensure と、detail は setup-missing と組む
|
|
77
|
+
function validateCombination(out, input) {
|
|
78
|
+
const result = inputNameHint(PATH, 'result');
|
|
79
|
+
const ensure = inputNameHint(PATH, 'ensure');
|
|
80
|
+
if (input.ensure === (input.result !== undefined))
|
|
81
|
+
stopInvalid(out, hinted `specify exactly one of ${result} and ${ensure}`);
|
|
82
|
+
if (input.detail !== undefined && input.result !== 'setup-missing')
|
|
83
|
+
stopInvalid(out, hinted `${inputNameHint(PATH, 'detail')} is only for ${result} setup-missing`);
|
|
84
|
+
if (!input.ensure) {
|
|
85
|
+
const given = { job_status: input.job_status, review_outcome: input.review_outcome, review_conclusion: input.review_conclusion, review_has_token: input.review_has_token, execution_file: input.execution_file, since: input.since };
|
|
86
|
+
const ensureOnly = Object.entries(given).find(([, value]) => value !== undefined)?.[0];
|
|
87
|
+
if (ensureOnly !== undefined)
|
|
88
|
+
stopInvalid(out, hinted `${inputNameHint(PATH, ensureOnly)} is only for ${ensure}`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const required = { job_status: input.job_status, review_outcome: input.review_outcome, review_conclusion: input.review_conclusion, review_has_token: input.review_has_token };
|
|
92
|
+
const missing = Object.entries(required).find(([, value]) => value === undefined)?.[0];
|
|
93
|
+
if (missing !== undefined)
|
|
94
|
+
stopInvalid(out, hinted `${inputNameHint(PATH, missing)} is required with ${ensure}`);
|
|
95
|
+
}
|
|
96
|
+
function parseSince(out, since) {
|
|
97
|
+
// 雛形の出力が空のときも、止まった場所が分からないとして書く
|
|
98
|
+
const value = nonEmpty(since);
|
|
99
|
+
if (value === undefined)
|
|
100
|
+
return undefined;
|
|
101
|
+
const time = Date.parse(value);
|
|
102
|
+
if (Number.isNaN(time))
|
|
103
|
+
stopInvalid(out, hinted `${inputNameHint(PATH, 'since')} is not an ISO 8601 time: ${value}`);
|
|
104
|
+
return new Date(time);
|
|
105
|
+
}
|
|
106
|
+
function readExecutionFile(path) {
|
|
107
|
+
const file = nonEmpty(path);
|
|
108
|
+
if (file === undefined)
|
|
109
|
+
return { kind: 'absent' };
|
|
110
|
+
try {
|
|
111
|
+
return readExecution(readTextFile(file));
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return isFileNotFound(error) ? { kind: 'absent' } : { kind: 'unreadable' };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function finishInputOf(input) {
|
|
118
|
+
if (input.result !== undefined)
|
|
119
|
+
return { kind: 'result', result: input.result };
|
|
120
|
+
const jobStatus = input.job_status ?? 'failure';
|
|
121
|
+
const absent = { kind: 'absent' };
|
|
122
|
+
const execution = jobStatus === 'failure' ? readExecutionFile(input.execution_file) : absent;
|
|
123
|
+
return {
|
|
124
|
+
kind: 'ensure',
|
|
125
|
+
jobStatus,
|
|
126
|
+
reviewOutcome: input.review_outcome ?? 'skipped',
|
|
127
|
+
reviewConclusion: input.review_conclusion?.trim() ?? '',
|
|
128
|
+
hasToken: input.review_has_token === 'true',
|
|
129
|
+
execution,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function runIdentity() {
|
|
133
|
+
const runId = nonEmpty(process.env['GITHUB_RUN_ID']);
|
|
134
|
+
return runId === undefined ? undefined : { runId, attempt: nonEmpty(process.env['GITHUB_RUN_ATTEMPT']) ?? '1' };
|
|
135
|
+
}
|
|
136
|
+
function skip(out, target, reason) {
|
|
137
|
+
out.result({ pullRequest: `${target.owner}/${target.repository}/${String(target.number)}`, skipped: reason });
|
|
138
|
+
const line = { verb: 'skip', target: `stopped-review comment on ${displayOf(target)} (${skipText(reason)})` };
|
|
139
|
+
out.planned(line);
|
|
140
|
+
out.done(line);
|
|
141
|
+
}
|
|
142
|
+
async function readOrStop(out, what, read) {
|
|
143
|
+
try {
|
|
144
|
+
return await read();
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (!(error instanceof GitHubAPIError))
|
|
148
|
+
throw error;
|
|
149
|
+
return stopWith(out, `could not read ${what}: ${error.message}`, kindOfFailure(error));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// 読めないときは書く側に倒す。止まったことが PR に残らないほうが困る
|
|
153
|
+
async function canActorWrite(out, client, target) {
|
|
154
|
+
const actor = nonEmpty(process.env['GITHUB_ACTOR']);
|
|
155
|
+
// action の checkWritePermissions と同じく、名前が [bot] で終わる起動者は API を読まずに書ける側とみなす
|
|
156
|
+
if (actor === undefined || actor.endsWith('[bot]'))
|
|
157
|
+
return true;
|
|
158
|
+
try {
|
|
159
|
+
return WRITE_PERMISSIONS.has(await client.getCollaboratorPermission(target.owner, target.repository, actor));
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (!(error instanceof GitHubAPIError))
|
|
163
|
+
throw error;
|
|
164
|
+
out.warning(`could not read the permission of ${actor}: ${error.message}`);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function issueCommentOf(value) {
|
|
169
|
+
const body = jsonField(value, 'body');
|
|
170
|
+
const userType = jsonField(jsonField(value, 'user'), 'type');
|
|
171
|
+
return { body: typeof body === 'string' ? body : '', userType: typeof userType === 'string' ? userType : '' };
|
|
172
|
+
}
|
|
173
|
+
function reviewCommentOf(value) {
|
|
174
|
+
const body = jsonField(value, 'body');
|
|
175
|
+
const createdAt = jsonField(value, 'created_at');
|
|
176
|
+
return { body: typeof body === 'string' ? body : '', createdAt: typeof createdAt === 'string' ? createdAt : '' };
|
|
177
|
+
}
|
|
178
|
+
async function stopLocation(out, client, target, since) {
|
|
179
|
+
if (since === undefined)
|
|
180
|
+
return 'unknown';
|
|
181
|
+
const comments = await readOrStop(out, `the review comments of ${displayOf(target)}`, async () => await client.listPullRequestReviewComments(target.owner, target.repository, target.number));
|
|
182
|
+
return stopLocationOf(comments.filter(comment => isJsonObject(comment)).map(comment => reviewCommentOf(comment)), since);
|
|
183
|
+
}
|
|
184
|
+
function renderBody(out, decision, location, input, run) {
|
|
185
|
+
const file = templateFile('comment', 'review-stopped');
|
|
186
|
+
const templateBody = stripLeadingHtmlComment(stripFrontmatter(readTextFile(file)));
|
|
187
|
+
const body = renderReviewStopped(templateBody, {
|
|
188
|
+
result: decision.result,
|
|
189
|
+
next: decision.next,
|
|
190
|
+
location,
|
|
191
|
+
triggerPhrase: nonEmpty(process.env['PECOT_REVIEW_TRIGGER_PHRASE']) ?? DEFAULT_TRIGGER_PHRASE,
|
|
192
|
+
...input.detail !== undefined && { detail: input.detail },
|
|
193
|
+
...run !== undefined && { run },
|
|
194
|
+
});
|
|
195
|
+
if (hasReportedTemplateViolations(out, body, file))
|
|
196
|
+
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
|
|
197
|
+
return body;
|
|
198
|
+
}
|
|
199
|
+
// プロジェクトの設定を読まない。ホストは既定の github.com
|
|
200
|
+
function makeDefaultClient(out) {
|
|
201
|
+
try {
|
|
202
|
+
return createGitHubClient(out, undefined);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (!(error instanceof GitHubAPIError))
|
|
206
|
+
throw error;
|
|
207
|
+
return stopWith(out, error.message, kindOfFailure(error));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function finish(out, input, globalRepository) {
|
|
211
|
+
validateCombination(out, input);
|
|
212
|
+
const since = parseSince(out, input.since);
|
|
213
|
+
const target = parseReference(input.pr_ref, globalRepository, out);
|
|
214
|
+
const decision = decideReviewFinish(finishInputOf(input));
|
|
215
|
+
if (decision.action === 'skip') {
|
|
216
|
+
skip(out, target, decision.reason);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const client = makeDefaultClient(out);
|
|
220
|
+
const state = await readOrStop(out, displayOf(target), async () => await client.getPullRequestState(target.owner, target.repository, target.number));
|
|
221
|
+
if (state !== 'open') {
|
|
222
|
+
skip(out, target, 'closed');
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (decision.shouldCheckActor && !await canActorWrite(out, client, target)) {
|
|
226
|
+
skip(out, target, 'actor-without-write');
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const run = runIdentity();
|
|
230
|
+
if (run !== undefined) {
|
|
231
|
+
const comments = await readOrStop(out, `the comments of ${displayOf(target)}`, async () => await client.listIssueComments(target.owner, target.repository, target.number));
|
|
232
|
+
if (hasStoppedMarker(comments.filter(comment => isJsonObject(comment)).map(comment => issueCommentOf(comment)), run)) {
|
|
233
|
+
skip(out, target, 'already-written');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const location = await stopLocation(out, client, target, since);
|
|
238
|
+
const body = renderBody(out, decision, location, input, run);
|
|
239
|
+
const pullRequest = `${target.owner}/${target.repository}/${String(target.number)}`;
|
|
240
|
+
const created = { verb: 'create', target: `stopped-review comment (${decision.result}) on ${displayOf(target)}` };
|
|
241
|
+
if (input.dry_run) {
|
|
242
|
+
out.result({ pullRequest, result: decision.result, location });
|
|
243
|
+
out.planned(created);
|
|
244
|
+
out.data(body);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let comment;
|
|
248
|
+
try {
|
|
249
|
+
comment = await client.addIssueComment(target.owner, target.repository, target.number, body);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (!(error instanceof GitHubAPIError))
|
|
253
|
+
throw error;
|
|
254
|
+
return stopWith(out, `could not create a comment on ${displayOf(target)}: ${error.message}`, kindOfFailure(error));
|
|
255
|
+
}
|
|
256
|
+
const url = jsonField(comment, 'html_url');
|
|
257
|
+
out.result({ pullRequest, result: decision.result, location, ...typeof url === 'string' && { commentUrl: url } });
|
|
258
|
+
out.done(created);
|
|
259
|
+
if (typeof url === 'string')
|
|
260
|
+
out.data(url);
|
|
261
|
+
}
|
|
262
|
+
const REVIEW_FINISH = defineCommand({
|
|
263
|
+
path: PATH,
|
|
264
|
+
description: 'Finish an automated review: post a comment on the PR only when the review stopped (failed, limit or setup-missing)',
|
|
265
|
+
input: InputSchema,
|
|
266
|
+
output: OUTPUT,
|
|
267
|
+
positional: ['pr_ref'],
|
|
268
|
+
interactive: false,
|
|
269
|
+
run: async (input, io) => {
|
|
270
|
+
const out = createOutput(input.dry_run, io);
|
|
271
|
+
await finish(out, input, input.repo);
|
|
272
|
+
return 0;
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
export const REVIEW_COMMANDS = [REVIEW_FINISH];
|
|
276
|
+
//# sourceMappingURL=review-finish.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export type ReviewResult = 'reviewed' | 'failed' | 'limit' | 'setup-missing';
|
|
2
|
+
export type StoppedResult = Exclude<ReviewResult, 'reviewed'>;
|
|
3
|
+
export type JobStatus = 'success' | 'failure' | 'cancelled';
|
|
4
|
+
/**
|
|
5
|
+
execution_file の最後の `type: result` の行。claude-code-action の base-action が SDK のメッセージの配列で書く
|
|
6
|
+
*/
|
|
7
|
+
export interface ExecutionResult {
|
|
8
|
+
readonly subtype: string | undefined;
|
|
9
|
+
readonly isError: boolean;
|
|
10
|
+
readonly terminalReason: string | undefined;
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly errors: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
execution_file の読み方。無い(absent)、JSON の配列として読めない(unreadable)、読めた(read。result の行が無ければ last は undefined)
|
|
16
|
+
*/
|
|
17
|
+
export type ExecutionReading = {
|
|
18
|
+
readonly kind: 'absent';
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'unreadable';
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'read';
|
|
23
|
+
readonly last: ExecutionResult | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
自動レビューの step の `outcome`
|
|
27
|
+
*/
|
|
28
|
+
export type ReviewOutcome = 'success' | 'failure' | 'cancelled' | 'skipped';
|
|
29
|
+
/**
|
|
30
|
+
後始末の step が渡す値。`reviewConclusion` は action の出力 `conclusion` で、Claude Code を動かさなかった run では空
|
|
31
|
+
*/
|
|
32
|
+
export interface EnsureInput {
|
|
33
|
+
readonly kind: 'ensure';
|
|
34
|
+
readonly jobStatus: JobStatus;
|
|
35
|
+
readonly reviewOutcome: ReviewOutcome;
|
|
36
|
+
readonly reviewConclusion: string;
|
|
37
|
+
readonly hasToken: boolean;
|
|
38
|
+
readonly execution: ExecutionReading;
|
|
39
|
+
}
|
|
40
|
+
export type FinishInput = EnsureInput | {
|
|
41
|
+
readonly kind: 'result';
|
|
42
|
+
readonly result: ReviewResult;
|
|
43
|
+
};
|
|
44
|
+
export type NextStep = 'retry' | 'auth' | 'app-token' | 'limit' | 'setup-detail';
|
|
45
|
+
export type SkipReason = 'reviewed' | 'job-succeeded' | 'workflow-mismatch';
|
|
46
|
+
export type FinishDecision = {
|
|
47
|
+
readonly action: 'skip';
|
|
48
|
+
readonly reason: SkipReason;
|
|
49
|
+
} | {
|
|
50
|
+
readonly action: 'write';
|
|
51
|
+
readonly result: StoppedResult;
|
|
52
|
+
readonly next: NextStep;
|
|
53
|
+
readonly shouldCheckActor: boolean;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
execution_file の本文を読む。JSON の配列でなければ unreadable、result の行が無ければ last は undefined
|
|
57
|
+
*/
|
|
58
|
+
export declare function readExecution(text: string): ExecutionReading;
|
|
59
|
+
/**
|
|
60
|
+
結果を決める。順は spec 027 の contracts/cli-commands.md の表のとおりで、最初に当たった行で決める
|
|
61
|
+
*/
|
|
62
|
+
export declare function decideReviewFinish(input: Readonly<FinishInput>): FinishDecision;
|
|
63
|
+
export type StopLocation = 'before-findings' | 'after-inline' | 'unknown';
|
|
64
|
+
export interface ReviewCommentReading {
|
|
65
|
+
readonly body: string;
|
|
66
|
+
readonly createdAt: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
止まった場所。since より後に作られた指摘のインラインコメントがあれば after-inline。since が無ければ unknown
|
|
70
|
+
*/
|
|
71
|
+
export declare function stopLocationOf(comments: readonly Readonly<ReviewCommentReading>[], since: Readonly<Date> | undefined): StopLocation;
|
|
72
|
+
export interface RunIdentity {
|
|
73
|
+
readonly runId: string;
|
|
74
|
+
readonly attempt: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
同じ実行で 2 度書かないための、画面に出ない目印の行。re-run では run の ID が変わらないので、試行の番号も入れる
|
|
78
|
+
*/
|
|
79
|
+
export declare function stoppedMarker(run: Readonly<RunIdentity>): string;
|
|
80
|
+
export interface IssueCommentReading {
|
|
81
|
+
readonly body: string;
|
|
82
|
+
readonly userType: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
同じ実行の目印を持つコメントがあるか。人が目印を書き込んで記録を消せないよう、Bot のコメントだけを見る
|
|
86
|
+
*/
|
|
87
|
+
export declare function hasStoppedMarker(comments: readonly Readonly<IssueCommentReading>[], run: Readonly<RunIdentity>): boolean;
|
|
88
|
+
export declare const REVIEW_STOPPED_PLACEHOLDERS: Readonly<Record<'summary' | 'result' | 'location' | 'next', string>>;
|
|
89
|
+
export interface ReviewStoppedValues {
|
|
90
|
+
readonly result: StoppedResult;
|
|
91
|
+
readonly next: NextStep;
|
|
92
|
+
readonly location: StopLocation;
|
|
93
|
+
readonly triggerPhrase: string;
|
|
94
|
+
readonly detail?: string;
|
|
95
|
+
readonly run?: RunIdentity;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
テンプレートの本文(フロントマターと冒頭のコメントを外したもの)のプレースホルダを埋める。
|
|
99
|
+
run があれば、末尾に目印の行を足す
|
|
100
|
+
*/
|
|
101
|
+
export declare function renderReviewStopped(templateBody: string, values: Readonly<ReviewStoppedValues>): string;
|
|
102
|
+
//# sourceMappingURL=review-finish.d.ts.map
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// review finish の結果の決め方と、止まったことを知らせるコメントの本文。決まりは spec 027 の contracts/cli-commands.md。
|
|
2
|
+
// GitHub を読む・書くのは commands/review-finish.ts が受け持つ。
|
|
3
|
+
import { isJsonObject, jsonField, tryParseJsonText } from './json.js';
|
|
4
|
+
import { isJsonArray } from './python-format.js';
|
|
5
|
+
function stringField(object, key) {
|
|
6
|
+
const value = jsonField(object, key);
|
|
7
|
+
return typeof value === 'string' ? value : undefined;
|
|
8
|
+
}
|
|
9
|
+
function readResultLine(line) {
|
|
10
|
+
const errors = jsonField(line, 'errors');
|
|
11
|
+
return {
|
|
12
|
+
subtype: stringField(line, 'subtype'),
|
|
13
|
+
isError: jsonField(line, 'is_error') === true,
|
|
14
|
+
terminalReason: stringField(line, 'terminal_reason'),
|
|
15
|
+
text: stringField(line, 'result') ?? '',
|
|
16
|
+
errors: isJsonArray(errors) ? errors.filter(entry => typeof entry === 'string') : [],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
execution_file の本文を読む。JSON の配列でなければ unreadable、result の行が無ければ last は undefined
|
|
21
|
+
*/
|
|
22
|
+
export function readExecution(text) {
|
|
23
|
+
const parsed = tryParseJsonText(text);
|
|
24
|
+
if (!isJsonArray(parsed))
|
|
25
|
+
return { kind: 'unreadable' };
|
|
26
|
+
const last = parsed.findLast(line => isJsonObject(line) && jsonField(line, 'type') === 'result');
|
|
27
|
+
return { kind: 'read', last: last === undefined ? undefined : readResultLine(last) };
|
|
28
|
+
}
|
|
29
|
+
const AUTHENTICATION_ERROR = 'authentication_error';
|
|
30
|
+
function isAuthenticationFailure(last) {
|
|
31
|
+
return last.text.includes(AUTHENTICATION_ERROR) || last.errors.some(entry => entry.includes(AUTHENTICATION_ERROR));
|
|
32
|
+
}
|
|
33
|
+
function write(result, next, shouldCheckActor = false) {
|
|
34
|
+
return { action: 'write', result, next, shouldCheckActor };
|
|
35
|
+
}
|
|
36
|
+
function decideFailure(input) {
|
|
37
|
+
const last = input.execution.kind === 'read' ? input.execution.last : undefined;
|
|
38
|
+
if (last?.isError === true && last.terminalReason === 'api_error')
|
|
39
|
+
return write('failed', isAuthenticationFailure(last) ? 'auth' : 'retry');
|
|
40
|
+
if (last?.subtype === 'error_max_turns')
|
|
41
|
+
return write('limit', 'limit');
|
|
42
|
+
// action は、Claude の App のトークンを受け取れずに止めたときも、空の github_token を出力する
|
|
43
|
+
if (input.reviewOutcome === 'failure' && !input.hasToken)
|
|
44
|
+
return write('setup-missing', 'app-token');
|
|
45
|
+
// Claude Code が動かずに step が落ちた run には、action が書いた人の権限で止めた場合が入る
|
|
46
|
+
return write('failed', 'retry', input.reviewOutcome === 'failure' && input.reviewConclusion === '');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
結果を決める。順は spec 027 の contracts/cli-commands.md の表のとおりで、最初に当たった行で決める
|
|
50
|
+
*/
|
|
51
|
+
export function decideReviewFinish(input) {
|
|
52
|
+
if (input.kind === 'result') {
|
|
53
|
+
switch (input.result) {
|
|
54
|
+
case 'reviewed': {
|
|
55
|
+
return { action: 'skip', reason: 'reviewed' };
|
|
56
|
+
}
|
|
57
|
+
case 'failed': {
|
|
58
|
+
return write('failed', 'retry');
|
|
59
|
+
}
|
|
60
|
+
case 'limit': {
|
|
61
|
+
return write('limit', 'limit');
|
|
62
|
+
}
|
|
63
|
+
case 'setup-missing': {
|
|
64
|
+
return write('setup-missing', 'setup-detail');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// PR のブランチで雛形を変えた run は、Claude の App がトークンを出さず、action がレビューを飛ばして step を成功で終える
|
|
69
|
+
if (input.reviewOutcome === 'success' && input.reviewConclusion === '')
|
|
70
|
+
return { action: 'skip', reason: 'workflow-mismatch' };
|
|
71
|
+
switch (input.jobStatus) {
|
|
72
|
+
case 'success': {
|
|
73
|
+
return { action: 'skip', reason: 'job-succeeded' };
|
|
74
|
+
}
|
|
75
|
+
// 時間の上限と、人が run を取り消したときは同じ cancelled で、見分けない(research の R9)
|
|
76
|
+
case 'cancelled': {
|
|
77
|
+
return write('limit', 'limit');
|
|
78
|
+
}
|
|
79
|
+
case 'failure': {
|
|
80
|
+
return decideFailure(input);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// w-revise の指摘のインラインコメントの先頭。`**F-NN**` か、2 巡目以降の `**R<巡>/F-NN**`
|
|
85
|
+
const FINDING_HEAD = /^\*\*(?:R\d+\/F|F)-\d+\*\*/u;
|
|
86
|
+
/**
|
|
87
|
+
止まった場所。since より後に作られた指摘のインラインコメントがあれば after-inline。since が無ければ unknown
|
|
88
|
+
*/
|
|
89
|
+
export function stopLocationOf(comments, since) {
|
|
90
|
+
if (since === undefined)
|
|
91
|
+
return 'unknown';
|
|
92
|
+
const sinceTime = since.getTime();
|
|
93
|
+
const hasPosted = comments.some(comment => FINDING_HEAD.test(comment.body) && Date.parse(comment.createdAt) >= sinceTime);
|
|
94
|
+
return hasPosted ? 'after-inline' : 'before-findings';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
同じ実行で 2 度書かないための、画面に出ない目印の行。re-run では run の ID が変わらないので、試行の番号も入れる
|
|
98
|
+
*/
|
|
99
|
+
export function stoppedMarker(run) {
|
|
100
|
+
return `<!-- pecot-review-stopped run=${run.runId} attempt=${run.attempt} -->`;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
同じ実行の目印を持つコメントがあるか。人が目印を書き込んで記録を消せないよう、Bot のコメントだけを見る
|
|
104
|
+
*/
|
|
105
|
+
export function hasStoppedMarker(comments, run) {
|
|
106
|
+
const marker = stoppedMarker(run);
|
|
107
|
+
return comments.some(comment => comment.userType === 'Bot' && comment.body.includes(marker));
|
|
108
|
+
}
|
|
109
|
+
// テンプレートのプレースホルダ。cli/templates/comment/review-stopped.md の本文と同じ文字列
|
|
110
|
+
export const REVIEW_STOPPED_PLACEHOLDERS = {
|
|
111
|
+
summary: '<止まった理由を1行で>',
|
|
112
|
+
result: '<結果>',
|
|
113
|
+
location: '<止まった場所>',
|
|
114
|
+
next: '<次にすること>',
|
|
115
|
+
};
|
|
116
|
+
const SUMMARIES = {
|
|
117
|
+
'failed': '自動レビューが途中で失敗して止まった',
|
|
118
|
+
'limit': '自動レビューがターンか時間の上限で止まった',
|
|
119
|
+
'setup-missing': '自動レビューに要る設定が足りずに止まった',
|
|
120
|
+
};
|
|
121
|
+
const RESULT_LINES = {
|
|
122
|
+
'failed': '`failed`(途中で失敗した)',
|
|
123
|
+
'limit': '`limit`(ターンか時間の上限で止まった)',
|
|
124
|
+
'setup-missing': '`setup-missing`(要る権限か設定が足りない)',
|
|
125
|
+
};
|
|
126
|
+
const LOCATION_LINES = {
|
|
127
|
+
'before-findings': '指摘を投稿する前',
|
|
128
|
+
'after-inline': 'インラインコメントを投稿した後(指摘の一覧はまだ無い)',
|
|
129
|
+
'unknown': '分からない',
|
|
130
|
+
};
|
|
131
|
+
// 利用者の値をコードの書き方の中に入れる。改行とバッククォートで書き方が崩れないよう、空白と引用符に替える
|
|
132
|
+
function code(text) {
|
|
133
|
+
return `\`${text.replaceAll(/\s+/gu, ' ').replaceAll('`', '\'')}\``;
|
|
134
|
+
}
|
|
135
|
+
function nextLine(next, triggerPhrase, detail) {
|
|
136
|
+
const retry = `PR に ${code(triggerPhrase)} とコメントして起動し直すか、端末で ${code('/pecot-w:w-revise')} を回す`;
|
|
137
|
+
switch (next) {
|
|
138
|
+
case 'retry': {
|
|
139
|
+
return `実行の記録で原因を確かめてから、${retry}`;
|
|
140
|
+
}
|
|
141
|
+
case 'auth': {
|
|
142
|
+
return `モデルの認証に失敗した。${code('claude setup-token')} でトークンを作り直し、secret ${code('CLAUDE_CODE_OAUTH_TOKEN')} に登録し直す。その後、${retry}`;
|
|
143
|
+
}
|
|
144
|
+
case 'app-token': {
|
|
145
|
+
return `リポに Claude の GitHub App を入れてから、${retry}`;
|
|
146
|
+
}
|
|
147
|
+
case 'limit': {
|
|
148
|
+
return `大きな PR は、端末で ${code('/pecot-w:w-revise')} を回す。自動で回すなら、変数 ${code('PECOT_REVIEW_MAX_TURNS')}・${code('PECOT_REVIEW_TIMEOUT_MINUTES')} で上限を上げる。その後、PR に ${code(triggerPhrase)} とコメントして起動し直す`;
|
|
149
|
+
}
|
|
150
|
+
case 'setup-detail': {
|
|
151
|
+
const missing = detail === undefined || detail.trim() === '' ? '' : `足りない設定は ${code(detail.trim())} だ。`;
|
|
152
|
+
return `${missing}設定を整えてから、${retry}`;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
テンプレートの本文(フロントマターと冒頭のコメントを外したもの)のプレースホルダを埋める。
|
|
158
|
+
run があれば、末尾に目印の行を足す
|
|
159
|
+
*/
|
|
160
|
+
export function renderReviewStopped(templateBody, values) {
|
|
161
|
+
const filled = templateBody
|
|
162
|
+
.replace(REVIEW_STOPPED_PLACEHOLDERS.summary, () => SUMMARIES[values.result])
|
|
163
|
+
.replace(REVIEW_STOPPED_PLACEHOLDERS.result, () => RESULT_LINES[values.result])
|
|
164
|
+
.replace(REVIEW_STOPPED_PLACEHOLDERS.location, () => LOCATION_LINES[values.location])
|
|
165
|
+
.replace(REVIEW_STOPPED_PLACEHOLDERS.next, () => nextLine(values.next, values.triggerPhrase, values.detail))
|
|
166
|
+
.trim();
|
|
167
|
+
return values.run === undefined ? `${filled}\n` : `${filled}\n\n${stoppedMarker(values.run)}\n`;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=review-finish.js.map
|
|
@@ -84,6 +84,10 @@ export declare class IssuesApi extends ProjectsApi {
|
|
|
84
84
|
*/
|
|
85
85
|
addIssueComment(owner: string, repository: string, number: number, body: string): Promise<JsonObject>;
|
|
86
86
|
/**
|
|
87
|
+
Issue・PR のコメントを全件取る(REST)
|
|
88
|
+
*/
|
|
89
|
+
listIssueComments(owner: string, repository: string, number: number): Promise<readonly JsonValue[]>;
|
|
90
|
+
/**
|
|
87
91
|
Issue 番号から GraphQL Node ID を取る。見つからなければ GitHubNotFoundError
|
|
88
92
|
*/
|
|
89
93
|
getIssueNodeId(owner: string, repository: string, number: number): Promise<string>;
|
|
@@ -190,6 +190,12 @@ export class IssuesApi extends ProjectsApi {
|
|
|
190
190
|
return this.restObject('POST', `${repositoryPath(owner, repository)}/issues/${String(number)}/comments`, { json: { body } });
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
|
+
Issue・PR のコメントを全件取る(REST)
|
|
194
|
+
*/
|
|
195
|
+
async listIssueComments(owner, repository, number) {
|
|
196
|
+
return this.listAll(`${repositoryPath(owner, repository)}/issues/${String(number)}/comments`, { per_page: ISSUES_PER_PAGE });
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
193
199
|
Issue 番号から GraphQL Node ID を取る。見つからなければ GitHubNotFoundError
|
|
194
200
|
*/
|
|
195
201
|
async getIssueNodeId(owner, repository, number) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { JsonObject } from '../../domain/json.js';
|
|
2
2
|
import type { PullRequestsByHeadReadout } from '../../domain/issue-readout.js';
|
|
3
|
+
import type { JsonValue } from '../../domain/python-format.js';
|
|
3
4
|
import { IssuesApi } from './issues.js';
|
|
4
5
|
/**
|
|
5
6
|
base のブランチ名で引いた、同じリポの開いている PR
|
|
@@ -197,6 +198,14 @@ export declare class PullsApi extends IssuesApi {
|
|
|
197
198
|
*/
|
|
198
199
|
addToStack(owner: string, repository: string, stackNumber: number, pullRequestNumbers: readonly number[]): Promise<PullRequestStack>;
|
|
199
200
|
/**
|
|
201
|
+
PR の state(REST の `open`・`closed`)
|
|
202
|
+
*/
|
|
203
|
+
getPullRequestState(owner: string, repository: string, number: number): Promise<string>;
|
|
204
|
+
/**
|
|
205
|
+
PR のレビューのコメント(行に付いたインラインコメント)を全件取る(REST)
|
|
206
|
+
*/
|
|
207
|
+
listPullRequestReviewComments(owner: string, repository: string, number: number): Promise<readonly JsonValue[]>;
|
|
208
|
+
/**
|
|
200
209
|
open の dependabot の PR を全件取る(GraphQL)。pullRequests に author の引数が無いので、全ページを辿ってから絞る。
|
|
201
210
|
GraphQL のノードをそのまま返す
|
|
202
211
|
*/
|
|
@@ -10,6 +10,7 @@ import { asObject, isTruthy, numberOrNull, requireNumber, requireString, require
|
|
|
10
10
|
import { QUERY_GET_PULL_REQUEST_FOR_FINISH, QUERY_GET_PULL_REQUEST_FOR_MERGE, QUERY_GET_PULL_REQUEST_FOR_MERGE_WITHOUT_QUEUE, QUERY_GET_PULL_REQUEST_SLIM, QUERY_GET_PULL_REQUEST_WITH_REVIEWS, QUERY_LIST_OPEN_PULL_REQUESTS, QUERY_LIST_PULL_REQUESTS_BY_BASE, QUERY_LIST_PULL_REQUESTS_BY_HEAD } from './queries.js';
|
|
11
11
|
import { readPullRequests } from './readout.js';
|
|
12
12
|
import { repositoryPath } from './rest-path.js';
|
|
13
|
+
const REVIEW_COMMENTS_PER_PAGE = 100;
|
|
13
14
|
/**
|
|
14
15
|
Stacks API が求める X-GitHub-Api-Version(https://docs.github.com/en/rest/pulls/stacks)
|
|
15
16
|
*/
|
|
@@ -321,6 +322,19 @@ export class PullsApi extends IssuesApi {
|
|
|
321
322
|
}));
|
|
322
323
|
}
|
|
323
324
|
/**
|
|
325
|
+
PR の state(REST の `open`・`closed`)
|
|
326
|
+
*/
|
|
327
|
+
async getPullRequestState(owner, repository, number) {
|
|
328
|
+
const pullRequest = await this.restObject('GET', `${repositoryPath(owner, repository)}/pulls/${String(number)}`);
|
|
329
|
+
return requireString(pullRequest['state'], 'state');
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
PR のレビューのコメント(行に付いたインラインコメント)を全件取る(REST)
|
|
333
|
+
*/
|
|
334
|
+
async listPullRequestReviewComments(owner, repository, number) {
|
|
335
|
+
return this.listAll(`${repositoryPath(owner, repository)}/pulls/${String(number)}/comments`, { per_page: REVIEW_COMMENTS_PER_PAGE });
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
324
338
|
open の dependabot の PR を全件取る(GraphQL)。pullRequests に author の引数が無いので、全ページを辿ってから絞る。
|
|
325
339
|
GraphQL のノードをそのまま返す
|
|
326
340
|
*/
|
|
@@ -32,6 +32,10 @@ export declare class ReposApi extends GitHubClientBase {
|
|
|
32
32
|
*/
|
|
33
33
|
getRepositoryId(owner: string, name: string): Promise<string>;
|
|
34
34
|
/**
|
|
35
|
+
利用者のリポへの権限(REST の collaborators の permission)。maintain は write、triage は read で返る
|
|
36
|
+
*/
|
|
37
|
+
getCollaboratorPermission(owner: string, repository: string, user: string): Promise<string>;
|
|
38
|
+
/**
|
|
35
39
|
ブランチの最新 commit の SHA(REST)。見つからなければ GitHubNotFoundError
|
|
36
40
|
*/
|
|
37
41
|
getBranchSha(owner: string, repository: string, branch: string): Promise<string>;
|
|
@@ -4,7 +4,7 @@ import { GitHubClientBase } from './client.js';
|
|
|
4
4
|
import { GitHubAPIError, GitHubNotFoundError } from './errors.js';
|
|
5
5
|
import { asArray, isTruthy, requireString } from './payload.js';
|
|
6
6
|
import { MUTATION_CREATE_LINKED_BRANCH, QUERY_GET_REPOSITORY_ID } from './queries.js';
|
|
7
|
-
import { encodePath, repositoryPath } from './rest-path.js';
|
|
7
|
+
import { encodePath, encodePathSegment, repositoryPath } from './rest-path.js';
|
|
8
8
|
const ALERTS_PER_PAGE = 100;
|
|
9
9
|
const NO_CONTENT = 204;
|
|
10
10
|
const NOT_FOUND = 404;
|
|
@@ -59,6 +59,13 @@ export class ReposApi extends GitHubClientBase {
|
|
|
59
59
|
return requireString(jsonField(repository, 'id'), 'repository.id');
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
+
利用者のリポへの権限(REST の collaborators の permission)。maintain は write、triage は read で返る
|
|
63
|
+
*/
|
|
64
|
+
async getCollaboratorPermission(owner, repository, user) {
|
|
65
|
+
const result = await this.restObject('GET', `${repositoryPath(owner, repository)}/collaborators/${encodePathSegment(user)}/permission`);
|
|
66
|
+
return requireString(jsonField(result, 'permission'), 'permission');
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
62
69
|
ブランチの最新 commit の SHA(REST)。見つからなければ GitHubNotFoundError
|
|
63
70
|
*/
|
|
64
71
|
async getBranchSha(owner, repository, branch) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
template: review-stopped
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<!--
|
|
6
|
+
読者: 自動レビューが止まった PR の作者。止まった理由と、続きを進める手順を読む。末尾の「例:」の形になる。
|
|
7
|
+
|
|
8
|
+
書き方:
|
|
9
|
+
- この本文は `pecot review finish` が埋めて PR に投稿する。エージェントも人も、手で書かない
|
|
10
|
+
- 結果は `failed`・`limit`・`setup-missing` のどれかにする。レビューを終えたとき(`reviewed`)は投稿しない
|
|
11
|
+
- 止まった場所は「指摘を投稿する前」「インラインコメントを投稿した後」「分からない」のどれかにする
|
|
12
|
+
- トークンの値と secret の値を書かない
|
|
13
|
+
- 末尾に、同じ実行で 2 度投稿しないための目印のコメントの行が付く
|
|
14
|
+
|
|
15
|
+
例:
|
|
16
|
+
|
|
17
|
+
## Review stopped — 自動レビューがターンか時間の上限で止まった
|
|
18
|
+
|
|
19
|
+
- 結果 — `limit`(ターンか時間の上限で止まった)
|
|
20
|
+
- 止まった場所 — インラインコメントを投稿した後(指摘の一覧はまだ無い)
|
|
21
|
+
- 次にすること — 大きな PR は、端末で `/pecot-w:w-revise` を回す。自動で回すなら、変数 `PECOT_REVIEW_MAX_TURNS`・`PECOT_REVIEW_TIMEOUT_MINUTES` で上限を上げる。その後、PR に `@pecotbot review` とコメントして起動し直す
|
|
22
|
+
-->
|
|
23
|
+
|
|
24
|
+
## Review stopped — <止まった理由を1行で>
|
|
25
|
+
|
|
26
|
+
- 結果 — <結果>
|
|
27
|
+
- 止まった場所 — <止まった場所>
|
|
28
|
+
- 次にすること — <次にすること>
|
|
@@ -90,6 +90,11 @@ jobs:
|
|
|
90
90
|
PECOT_REVIEW_EXTRA_ALLOWED_TOOLS: ""
|
|
91
91
|
# pecot-review:allowed-tools:end
|
|
92
92
|
steps:
|
|
93
|
+
# The finish step names where the review stopped from the inline comments posted after this time.
|
|
94
|
+
- name: Record the start time
|
|
95
|
+
id: start
|
|
96
|
+
run: echo "time=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
|
|
97
|
+
|
|
93
98
|
- name: Generate GitHub App token
|
|
94
99
|
id: token
|
|
95
100
|
if: ${{ vars.PECOT_AGENT_APP_CLIENT_ID != '' }}
|
|
@@ -174,7 +179,7 @@ jobs:
|
|
|
174
179
|
claude_args: >-
|
|
175
180
|
--permission-mode default
|
|
176
181
|
--max-turns ${{ vars.PECOT_REVIEW_MAX_TURNS || '60' }}
|
|
177
|
-
--allowedTools "Read,Glob,Grep,mcp__plugin_pecot-w_pecot-workflow__pr_show,mcp__plugin_pecot-w_pecot-workflow__issue_show,mcp__plugin_pecot-w_pecot-workflow__pr_restack,mcp__plugin_pecot-w_pecot-workflow__issue_comment,mcp__plugin_pecot-w_pecot-
|
|
182
|
+
--allowedTools "Read,Glob,Grep,mcp__plugin_pecot-w_pecot-workflow__pr_show,mcp__plugin_pecot-w_pecot-workflow__issue_show,mcp__plugin_pecot-w_pecot-workflow__pr_restack,mcp__plugin_pecot-w_pecot-workflow__issue_comment,mcp__plugin_pecot-w_pecot-workflow__review_finish,mcp__github_inline_comment__create_inline_comment${{ env.PECOT_REVIEW_EXTRA_ALLOWED_TOOLS != '' && format(',{0}', env.PECOT_REVIEW_EXTRA_ALLOWED_TOOLS) || '' }}"
|
|
178
183
|
--disallowedTools "Bash,Edit,Write,NotebookEdit,AskUserQuestion,Agent,WebFetch,WebSearch"
|
|
179
184
|
|
|
180
185
|
# The dist-tag after the package name decides the version. @latest is the newest release,
|
|
@@ -189,8 +194,12 @@ jobs:
|
|
|
189
194
|
REVIEW_CONCLUSION: ${{ steps.claude.outputs.conclusion }}
|
|
190
195
|
# Pass only whether the action got a token, never the token itself.
|
|
191
196
|
REVIEW_HAS_TOKEN: ${{ steps.claude.outputs.github_token != '' }}
|
|
197
|
+
EXECUTION_FILE: ${{ steps.claude.outputs.execution_file }}
|
|
198
|
+
REVIEW_STARTED_AT: ${{ steps.start.outputs.time }}
|
|
199
|
+
PECOT_REVIEW_TRIGGER_PHRASE: ${{ vars.PECOT_REVIEW_TRIGGER_PHRASE }}
|
|
192
200
|
PECOT_GITHUB_COM_TOKEN: ${{ steps.token.outputs.token || github.token }}
|
|
193
201
|
run: >-
|
|
194
|
-
npx -y --prefix=/ @pecot/workflow-mcp@latest
|
|
202
|
+
npx -y --prefix=/ @pecot/workflow-mcp@latest review finish "$GITHUB_REPOSITORY/$PR" --ensure
|
|
195
203
|
--job-status "$JOB_STATUS" --review-outcome "$REVIEW_OUTCOME"
|
|
196
204
|
--review-conclusion "$REVIEW_CONCLUSION" --review-has-token "$REVIEW_HAS_TOKEN"
|
|
205
|
+
--execution-file "$EXECUTION_FILE" --since "$REVIEW_STARTED_AT"
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pecot/workflow-mcp",
|
|
3
|
-
"version": "8.0.1-dev.
|
|
3
|
+
"version": "8.0.1-dev.59",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@pecot/workflow-mcp",
|
|
9
|
-
"version": "8.0.1-dev.
|
|
9
|
+
"version": "8.0.1-dev.59",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/server": "^2.4.0",
|