@pecot/workflow-mcp 8.0.1-dev.58 → 8.0.1-dev.60
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/base-reading.d.ts +1 -1
- package/cli/dist/commands/base-reading.js +1 -1
- package/cli/dist/commands/board-sync.js +1 -1
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +12 -4
- package/cli/dist/commands/issue-comment.js +3 -2
- package/cli/dist/commands/issue-show.js +3 -2
- package/cli/dist/commands/names.js +1 -0
- package/cli/dist/commands/output.d.ts +4 -0
- package/cli/dist/commands/output.js +1 -0
- package/cli/dist/commands/pr-merge.js +3 -2
- package/cli/dist/commands/pr-restack.js +16 -9
- package/cli/dist/commands/pr.js +18 -18
- package/cli/dist/commands/project.js +5 -3
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +8 -8
- package/cli/dist/commands/restack-reading.d.ts +4 -0
- package/cli/dist/commands/restack-reading.js +1 -1
- package/cli/dist/commands/review-finish.d.ts +3 -0
- package/cli/dist/commands/review-finish.js +276 -0
- package/cli/dist/commands/session-finish.js +18 -8
- package/cli/dist/commands/session.js +1 -1
- package/cli/dist/commands/tracker-sync-dependabot.js +1 -1
- package/cli/dist/commands/tracker-sync-security.js +1 -1
- package/cli/dist/commands/worktree.js +4 -3
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/release.d.ts +10 -1
- package/cli/dist/domain/release.js +10 -6
- package/cli/dist/domain/review-finish.d.ts +102 -0
- package/cli/dist/domain/review-finish.js +169 -0
- package/cli/dist/infra/git.d.ts +20 -16
- package/cli/dist/infra/git.js +40 -96
- package/cli/dist/infra/github/client.d.ts +12 -1
- package/cli/dist/infra/github/client.js +49 -16
- 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/dist/infra/nx-scope.d.ts +5 -1
- package/cli/dist/infra/nx-scope.js +20 -13
- package/cli/dist/infra/process-run.d.ts +57 -0
- package/cli/dist/infra/process-run.js +168 -0
- package/cli/dist/infra/worktree-setup.d.ts +3 -6
- package/cli/dist/infra/worktree-setup.js +8 -26
- package/cli/dist/infra/worktree.d.ts +5 -1
- package/cli/dist/infra/worktree.js +4 -4
- package/cli/dist/mcp/result.d.ts +3 -3
- package/cli/dist/mcp/result.js +4 -3
- package/cli/dist/mcp/serve.d.ts +12 -0
- package/cli/dist/mcp/serve.js +30 -2
- package/cli/dist/mcp/server.d.ts +4 -0
- package/cli/dist/mcp/server.js +14 -6
- 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
|
@@ -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
|
|
@@ -11,7 +11,7 @@ import { createIssueReference } from '../domain/reference-parser.js';
|
|
|
11
11
|
import { RESTACK_PATH } from '../domain/restack.js';
|
|
12
12
|
import { isSameRepository } from '../domain/repository-resolver.js';
|
|
13
13
|
import { FLAG_PECOT_BASE, FLAG_PECOT_SESSION_TITLE } from '../domain/state.js';
|
|
14
|
-
import { gitCurrentBranch, GitCommandError, runGit } from '../infra/git.js';
|
|
14
|
+
import { GIT_TIMED_OUT, gitCurrentBranch, GitCommandError, NON_INTERACTIVE_GIT, REMOTE_TIMEOUT_MILLISECONDS, runGit, runGitAsync } from '../infra/git.js';
|
|
15
15
|
import { GitHubAPIError, GitHubNotFoundError, isClosedByAnotherRequest, isMissingReferenceError } from '../infra/github/errors.js';
|
|
16
16
|
import { isFileNotFound } from '../infra/os-error.js';
|
|
17
17
|
import { removeFlag } from '../infra/state-store.js';
|
|
@@ -271,13 +271,23 @@ function resolveCheckoutTarget(cwd, config, location, out) {
|
|
|
271
271
|
return undefined;
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
-
|
|
274
|
+
// isRemote の git(pull)は、認証の入力を待たず、取り消しと時間切れで止める
|
|
275
|
+
async function didRunLocalStep(context, operation, cwd, arguments_, failure, isRemote = false) {
|
|
275
276
|
const { out, isDryRun } = context;
|
|
276
277
|
out.planned(operation);
|
|
277
278
|
if (isDryRun)
|
|
278
279
|
return true;
|
|
279
280
|
try {
|
|
280
|
-
|
|
281
|
+
if (isRemote) {
|
|
282
|
+
const result = await runGitAsync(arguments_, { cwd, check: true, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS, signal: out.signal });
|
|
283
|
+
if (result.exitCode === GIT_TIMED_OUT) {
|
|
284
|
+
out.warning(`${failure} failed: timed out after ${String(REMOTE_TIMEOUT_MILLISECONDS / 1000)} seconds`);
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
runGit(arguments_, { cwd, check: true });
|
|
290
|
+
}
|
|
281
291
|
}
|
|
282
292
|
catch (error) {
|
|
283
293
|
if (!(error instanceof GitCommandError) && !isFileNotFound(error))
|
|
@@ -288,7 +298,7 @@ function didRunLocalStep(context, operation, cwd, arguments_, failure) {
|
|
|
288
298
|
out.done(operation);
|
|
289
299
|
return true;
|
|
290
300
|
}
|
|
291
|
-
function localCleanupAfterMerge(context, headBranch, config, location) {
|
|
301
|
+
async function localCleanupAfterMerge(context, headBranch, config, location) {
|
|
292
302
|
const { out } = context;
|
|
293
303
|
const cwd = process.cwd();
|
|
294
304
|
const remote = sameRepositoryRemote(cwd, location, out);
|
|
@@ -306,18 +316,18 @@ function localCleanupAfterMerge(context, headBranch, config, location) {
|
|
|
306
316
|
if (currentBranch === checkoutTarget) {
|
|
307
317
|
settle(out, { verb: 'unchanged', target: `current branch ${checkoutTarget}` });
|
|
308
318
|
}
|
|
309
|
-
else if (!didRunLocalStep(context, { verb: 'set', target: `current branch to ${checkoutTarget}` }, cwd, ['checkout', checkoutTarget], `checking out ${checkoutTarget}`)) {
|
|
319
|
+
else if (!await didRunLocalStep(context, { verb: 'set', target: `current branch to ${checkoutTarget}` }, cwd, ['checkout', checkoutTarget], `checking out ${checkoutTarget}`)) {
|
|
310
320
|
// checkout が失敗したら、pull と branch -D は別のブランチに当たるので止める
|
|
311
321
|
if (currentBranch !== undefined)
|
|
312
322
|
context.record.currentBranch = currentBranch;
|
|
313
323
|
return;
|
|
314
324
|
}
|
|
315
325
|
context.record.currentBranch = checkoutTarget;
|
|
316
|
-
didRunLocalStep(context, { verb: 'update', target: `${checkoutTarget} from ${remote}/${developBranch}` }, cwd, ['pull', remote, developBranch], `pulling ${developBranch}
|
|
326
|
+
await didRunLocalStep(context, { verb: 'update', target: `${checkoutTarget} from ${remote}/${developBranch}` }, cwd, ['pull', remote, developBranch], `pulling ${developBranch}`, true);
|
|
317
327
|
if (headBranch === checkoutTarget) {
|
|
318
328
|
settle(out, { verb: 'skip', target: `deleting local branch ${headBranch} (it is the checkout target)` });
|
|
319
329
|
}
|
|
320
|
-
else if (didRunLocalStep(context, { verb: 'delete', target: `local branch ${headBranch}` }, cwd, ['branch', '-D', headBranch], `deleting local branch ${headBranch}`)) {
|
|
330
|
+
else if (await didRunLocalStep(context, { verb: 'delete', target: `local branch ${headBranch}` }, cwd, ['branch', '-D', headBranch], `deleting local branch ${headBranch}`)) {
|
|
321
331
|
context.record.deletedBranches.push({ branch: headBranch, location: 'local' });
|
|
322
332
|
}
|
|
323
333
|
}
|
|
@@ -366,7 +376,7 @@ async function finish(input, context) {
|
|
|
366
376
|
await deleteMergedBranch(context, client, location, pr.head_ref);
|
|
367
377
|
if (input.skip_local_cleanup)
|
|
368
378
|
return;
|
|
369
|
-
localCleanupAfterMerge(context, pr.head_ref, config, location);
|
|
379
|
+
await localCleanupAfterMerge(context, pr.head_ref, config, location);
|
|
370
380
|
if (input.dry_run) {
|
|
371
381
|
return;
|
|
372
382
|
}
|
|
@@ -92,7 +92,7 @@ async function stackSection(active, origin, directory, output) {
|
|
|
92
92
|
// ブランチは作業ディレクトリのリポにあるので、PR もそこで探す(pr restack と同じ)
|
|
93
93
|
const { owner, repository } = origin ?? stackedOn.repository;
|
|
94
94
|
// 載せ直す先は、fetch せずに、下の段の remote の先頭を尋ねて記録と比べる
|
|
95
|
-
const read = await readRestackDecision({ client: () => active.client, owner, repository, cwd: directory, remote: primaryRemoteName(directory), reading, developBranch: getDevelopBranch(active.config, owner, repository) ?? '' });
|
|
95
|
+
const read = await readRestackDecision({ client: () => active.client, owner, repository, cwd: directory, remote: primaryRemoteName(directory), reading, developBranch: getDevelopBranch(active.config, owner, repository) ?? '', signal: output.signal });
|
|
96
96
|
if (read.kind === 'pull-request-unreadable')
|
|
97
97
|
output.warning(`cannot read the PR of the base branch: ${read.error.message}`);
|
|
98
98
|
const pullRequest = read.kind === 'pull-request-unreadable' ? 'unknown' : read.lowerPullRequest;
|
|
@@ -117,7 +117,7 @@ tracker sync の source dependabot の本体。Tracker の Dependabot PRs waitin
|
|
|
117
117
|
export async function runDependabotSync(input, io) {
|
|
118
118
|
const out = createOutput(input.dry_run, io);
|
|
119
119
|
const { config, owner, repository } = loadTarget(out, input.repo, input.project);
|
|
120
|
-
const client = makeClient(out, config);
|
|
120
|
+
const client = await makeClient(out, config);
|
|
121
121
|
let pullRequests;
|
|
122
122
|
let issues;
|
|
123
123
|
try {
|
|
@@ -126,7 +126,7 @@ tracker sync の source security の本体。Tracker の open security alerts
|
|
|
126
126
|
export async function runSecuritySync(input, io) {
|
|
127
127
|
const out = createOutput(input.dry_run, io);
|
|
128
128
|
const { config, owner, repository } = loadTarget(out, input.repo, input.project);
|
|
129
|
-
const client = makeClient(out, config);
|
|
129
|
+
const client = await makeClient(out, config);
|
|
130
130
|
const sources = { scan: createScanAlertSource(client), dependabot: createDependabotSource(client) };
|
|
131
131
|
const { alerts, failed, disabled } = await fetchOpenAlerts(out, sources, config.host, owner, repository);
|
|
132
132
|
let issues;
|
|
@@ -84,14 +84,14 @@ const worktreeAddCommand = defineCommand({
|
|
|
84
84
|
shortFlags: { directory: '-D' },
|
|
85
85
|
aliases: { allow_existing_branch: '--force' },
|
|
86
86
|
interactive: false,
|
|
87
|
-
run: (input, io) =>
|
|
87
|
+
run: async (input, io) => await runAdd(input, io),
|
|
88
88
|
});
|
|
89
|
-
function runAdd(input, io) {
|
|
89
|
+
async function runAdd(input, io) {
|
|
90
90
|
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
91
91
|
const out = createOutput(input.dry_run, io);
|
|
92
92
|
try {
|
|
93
93
|
ensureDevcontainerEnvironment();
|
|
94
|
-
const result = createWorktree(input.directory, out, {
|
|
94
|
+
const result = await createWorktree(input.directory, out, {
|
|
95
95
|
baseBranch: input.base,
|
|
96
96
|
path: input.path,
|
|
97
97
|
shouldCopy: !input.no_copy,
|
|
@@ -100,6 +100,7 @@ function runAdd(input, io) {
|
|
|
100
100
|
isDryRun: input.dry_run,
|
|
101
101
|
isExistingBranchAllowed: input.allow_existing_branch,
|
|
102
102
|
project: input.project,
|
|
103
|
+
signal: out.signal,
|
|
103
104
|
});
|
|
104
105
|
const operation = { verb: 'create', target: `worktree ${result.name} at ${result.path} (branch ${result.branch} from ${result.baseBranch})` };
|
|
105
106
|
out.planned(operation);
|
|
@@ -7,6 +7,11 @@ export declare class BaseError extends Error {
|
|
|
7
7
|
export declare class PecotError extends BaseError {
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
+
MCP の要求が取り消され、待っていた子プロセスや要求を止めた。message は取り消しの理由
|
|
11
|
+
*/
|
|
12
|
+
export declare class CancelledError extends BaseError {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
10
15
|
プロジェクトルートが見つからない
|
|
11
16
|
*/
|
|
12
17
|
export declare class ProjectRootNotFoundError extends PecotError {
|
|
@@ -19,6 +19,11 @@ export class BaseError extends Error {
|
|
|
19
19
|
export class PecotError extends BaseError {
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
+
MCP の要求が取り消され、待っていた子プロセスや要求を止めた。message は取り消しの理由
|
|
23
|
+
*/
|
|
24
|
+
export class CancelledError extends BaseError {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
22
27
|
プロジェクトルートが見つからない
|
|
23
28
|
*/
|
|
24
29
|
export class ProjectRootNotFoundError extends PecotError {
|
|
@@ -45,9 +45,18 @@ base より head が進んでいる commit の数。GitHub の compare で数え
|
|
|
45
45
|
*/
|
|
46
46
|
export type CountCommitsAhead = (base: string, head: string) => Promise<number>;
|
|
47
47
|
/**
|
|
48
|
+
remote のタグの有無。尋ねられなければ failure に git の stderr
|
|
49
|
+
*/
|
|
50
|
+
export type RemoteTagLookup = {
|
|
51
|
+
readonly isFound: boolean;
|
|
52
|
+
} | {
|
|
53
|
+
readonly failure: string;
|
|
54
|
+
};
|
|
55
|
+
export type LookUpRemoteTag = (remote: string, tagName: string) => Promise<RemoteTagLookup>;
|
|
56
|
+
/**
|
|
48
57
|
リリース前チェックを実行する。
|
|
49
58
|
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
50
59
|
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
51
60
|
*/
|
|
52
|
-
export declare function runPreflight(options: PreflightOptions, git: GitRunner, countAhead: CountCommitsAhead): Promise<PreflightResult>;
|
|
61
|
+
export declare function runPreflight(options: PreflightOptions, git: GitRunner, lookUpRemoteTag: LookUpRemoteTag, countAhead: CountCommitsAhead): Promise<PreflightResult>;
|
|
53
62
|
//# sourceMappingURL=release.d.ts.map
|
|
@@ -9,11 +9,13 @@ git を実行して標準出力を返す。非 0 終了は ReleaseError
|
|
|
9
9
|
*/
|
|
10
10
|
function runGit(git, arguments_) {
|
|
11
11
|
const result = git(arguments_);
|
|
12
|
-
if (result.exitCode !== 0)
|
|
13
|
-
throw
|
|
14
|
-
}
|
|
12
|
+
if (result.exitCode !== 0)
|
|
13
|
+
throw gitFailed(arguments_, result.stderr);
|
|
15
14
|
return pythonStrip(result.stdout);
|
|
16
15
|
}
|
|
16
|
+
function gitFailed(arguments_, stderr) {
|
|
17
|
+
return new ReleaseError(`git command failed: git ${arguments_.join(' ')}\n${pythonStrip(stderr)}`);
|
|
18
|
+
}
|
|
17
19
|
function determineVersion(options, changelogContent) {
|
|
18
20
|
if (options.version === undefined) {
|
|
19
21
|
try {
|
|
@@ -33,7 +35,7 @@ function determineVersion(options, changelogContent) {
|
|
|
33
35
|
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
34
36
|
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
35
37
|
*/
|
|
36
|
-
export async function runPreflight(options, git, countAhead) {
|
|
38
|
+
export async function runPreflight(options, git, lookUpRemoteTag, countAhead) {
|
|
37
39
|
const { changelogContent, developBranch, releaseBranch } = options;
|
|
38
40
|
if (changelogContent === undefined)
|
|
39
41
|
throw new ReleaseError(changelogNotFoundMessage(options.changelogPath));
|
|
@@ -43,8 +45,10 @@ export async function runPreflight(options, git, countAhead) {
|
|
|
43
45
|
const localTags = runGit(git, ['tag', '-l', tagName]);
|
|
44
46
|
if (localTags.split('\n').includes(tagName))
|
|
45
47
|
throw new ReleaseError(`tag already exists locally: ${tagName}`);
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
+
const remoteTag = await lookUpRemoteTag(remote, tagName);
|
|
49
|
+
if ('failure' in remoteTag)
|
|
50
|
+
throw gitFailed(['ls-remote', '--tags', remote, `refs/tags/${tagName}`], remoteTag.failure);
|
|
51
|
+
if (remoteTag.isFound)
|
|
48
52
|
throw new ReleaseError(`tag already exists on the remote: ${tagName}`);
|
|
49
53
|
const diffCount = await countAhead(releaseBranch, developBranch);
|
|
50
54
|
if (diffCount === 0) {
|
|
@@ -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
|