@pecot/workflow-mcp 6.0.0 → 7.0.0
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 +4 -57
- package/cli/dist/commands/board-add.js +11 -1
- package/cli/dist/commands/board-judgment.d.ts +12 -3
- package/cli/dist/commands/board-judgment.js +12 -6
- package/cli/dist/commands/board-move.js +9 -1
- package/cli/dist/commands/board-readiness.d.ts +3 -3
- package/cli/dist/commands/board-show.js +5 -2
- package/cli/dist/commands/board-sync.js +14 -5
- package/cli/dist/commands/board-view.d.ts +94 -5
- package/cli/dist/commands/board-view.js +119 -17
- package/cli/dist/commands/branch.js +12 -1
- package/cli/dist/commands/command-definition.d.ts +19 -2
- package/cli/dist/commands/command-definition.js +9 -0
- package/cli/dist/commands/failure-kind.d.ts +1 -1
- package/cli/dist/commands/failure-kind.js +1 -0
- package/cli/dist/commands/issue-board.d.ts +31 -3
- package/cli/dist/commands/issue-board.js +28 -4
- package/cli/dist/commands/issue-comment.js +19 -2
- package/cli/dist/commands/issue-create.js +90 -7
- package/cli/dist/commands/issue-dependency.js +32 -4
- package/cli/dist/commands/issue-readiness.d.ts +30 -2
- package/cli/dist/commands/issue-readiness.js +35 -0
- package/cli/dist/commands/issue-reopen.js +18 -3
- package/cli/dist/commands/issue-shared.d.ts +3 -3
- package/cli/dist/commands/issue-shared.js +3 -2
- package/cli/dist/commands/issue-show.js +78 -8
- package/cli/dist/commands/names.js +1 -0
- package/cli/dist/commands/output.d.ts +18 -2
- package/cli/dist/commands/output.js +16 -3
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +230 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +233 -0
- package/cli/dist/commands/pr-waiting.d.ts +41 -2
- package/cli/dist/commands/pr-waiting.js +74 -37
- package/cli/dist/commands/pr.d.ts +10 -6
- package/cli/dist/commands/pr.js +160 -67
- package/cli/dist/commands/project-sync.d.ts +10 -2
- package/cli/dist/commands/project-sync.js +7 -6
- package/cli/dist/commands/project.js +173 -16
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +67 -18
- package/cli/dist/commands/repository-match.js +7 -2
- package/cli/dist/commands/session-finish.js +128 -12
- package/cli/dist/commands/session-start.js +22 -6
- package/cli/dist/commands/session.js +121 -20
- package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
- package/cli/dist/commands/tracker-sync-security.js +22 -4
- package/cli/dist/commands/tracker-sync.d.ts +30 -0
- package/cli/dist/commands/tracker-sync.js +15 -0
- package/cli/dist/commands/tracker.js +2 -0
- package/cli/dist/commands/work-target.d.ts +10 -2
- package/cli/dist/commands/work-target.js +6 -4
- package/cli/dist/commands/worktree.js +71 -5
- package/cli/dist/domain/issue-readout.d.ts +0 -4
- package/cli/dist/domain/pull-request.d.ts +1 -1
- package/cli/dist/domain/readiness.d.ts +17 -0
- package/cli/dist/domain/readiness.js +39 -2
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/state.d.ts +39 -0
- package/cli/dist/domain/state.js +28 -1
- package/cli/dist/domain/work-start.d.ts +0 -4
- package/cli/dist/domain/work-start.js +0 -7
- package/cli/dist/infra/git.d.ts +64 -0
- package/cli/dist/infra/git.js +110 -0
- package/cli/dist/infra/github/pulls.d.ts +81 -2
- package/cli/dist/infra/github/pulls.js +116 -5
- package/cli/dist/infra/github/queries.d.ts +4 -1
- package/cli/dist/infra/github/queries.js +47 -32
- package/cli/dist/infra/github/readout.js +0 -33
- package/cli/dist/mcp/result.d.ts +63 -16
- package/cli/dist/mcp/result.js +106 -30
- package/cli/dist/mcp/server.js +37 -4
- package/cli/templates/comment/plan.md +2 -2
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/cli/dist/commands/pr.js
CHANGED
|
@@ -15,12 +15,11 @@ import { isEpicIssue } from '../domain/issue-kind.js';
|
|
|
15
15
|
import { jsonField } from '../domain/json.js';
|
|
16
16
|
import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBase, describeBaseStop, describePushStatus, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, pickLowerPullRequest, validatePullRequestContent } from '../domain/pull-request.js';
|
|
17
17
|
import { parsePythonInteger, pythonStrip } from '../domain/python-format.js';
|
|
18
|
-
import {
|
|
19
|
-
import { AmbiguousRepositoryError, resolveRepository, splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
18
|
+
import { splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
20
19
|
import { FLAG_PECOT_ACTIVE, FLAG_PR_CREATE_SLASH_PENDING } from '../domain/state.js';
|
|
21
20
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
22
21
|
import { parsePullRequestFile } from '../infra/frontmatter-file.js';
|
|
23
|
-
import { gitCurrentBranch, gitRemoteUrl,
|
|
22
|
+
import { gitCurrentBranch, gitRemoteUrl, gitStdout, gitToplevel, primaryRemoteName, remoteBranchHead, runGit } from '../infra/git.js';
|
|
24
23
|
import { TransportFailure } from '../infra/github/client.js';
|
|
25
24
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
26
25
|
import { changedFiles, expectedScope, nxProjects, parseTitleScope } from '../infra/nx-scope.js';
|
|
@@ -32,20 +31,20 @@ import { readTextFile } from '../infra/text-file.js';
|
|
|
32
31
|
import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
|
|
33
32
|
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
34
33
|
import { kindOfFailure } from './failure.js';
|
|
35
|
-
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
36
34
|
import { directorySchema } from './directory-option.js';
|
|
37
35
|
import { createGitHubClient } from './github-client.js';
|
|
38
|
-
import { createOutput } from './output.js';
|
|
36
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
39
37
|
import { CommandExit, defineCommand } from './command-definition.js';
|
|
38
|
+
import { BOARD_MOVE_JSON, moveJson } from './issue-board.js';
|
|
39
|
+
import { PR_MERGE_COMMAND } from './pr-merge.js';
|
|
40
|
+
import { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
|
|
40
41
|
import { moveWaitingIssues } from './pr-waiting.js';
|
|
41
|
-
export
|
|
42
|
+
export { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
|
|
42
43
|
// 本文の検証の失敗。1(通信・設定・引数)と 2(preflight)と区別する
|
|
43
44
|
const VALIDATION_EXIT_CODE = 3;
|
|
44
45
|
const PREFLIGHT_EXIT_CODE = 2;
|
|
45
46
|
// 下の段の PR が開いておらず、マージもされていない
|
|
46
47
|
const NO_OPEN_BASE_EXIT_CODE = 2;
|
|
47
|
-
// git ls-remote --exit-code が、一致する参照が無いときに返す
|
|
48
|
-
const LS_REMOTE_NOT_FOUND = 2;
|
|
49
48
|
// Python の `{e}` に当たる、例外の文
|
|
50
49
|
export function reasonOf(error) {
|
|
51
50
|
return error instanceof Error ? error.message : String(error);
|
|
@@ -125,13 +124,30 @@ function titleScopeErrors(query, out) {
|
|
|
125
124
|
return [`PR title scope must be ${expected.join(',')} (given: ${shown}; computed from the tags of the changed nx projects)`];
|
|
126
125
|
}
|
|
127
126
|
// pr create
|
|
127
|
+
const PR_CREATE_OUTPUT = z.strictObject({
|
|
128
|
+
url: z.string().optional().describe('URL of the created PR (omitted on dry_run and prepare)'),
|
|
129
|
+
number: z.int().optional().describe('Number of the created PR (omitted on dry_run and prepare, or when the response has none)'),
|
|
130
|
+
head: z.string().optional().describe('Head branch of the PR (omitted on prepare)'),
|
|
131
|
+
base: z.string().optional().describe('Base branch of the PR. On prepare, the base filled into the draft (omitted when it was not filled)'),
|
|
132
|
+
title: z.string().optional().describe('Title of the PR (omitted on prepare)'),
|
|
133
|
+
inReview: z.int().optional().describe('Issue number whose status was set to In Review (omitted when not set)'),
|
|
134
|
+
stack: z.strictObject({
|
|
135
|
+
lower: z.int().describe('PR number of the lower stage the new PR is stacked on'),
|
|
136
|
+
registered: z.boolean().optional().describe('Whether the new PR was registered to the stack (omitted on dry_run)'),
|
|
137
|
+
number: z.int().optional().describe('Stack number (omitted when not registered)'),
|
|
138
|
+
}).optional().describe('Stack of the PR (omitted when the PR is not stacked)'),
|
|
139
|
+
moves: z.array(BOARD_MOVE_JSON).optional().describe('Issues waiting for this PR whose column or Status was written (omitted on dry_run and prepare)'),
|
|
140
|
+
file: z.string().optional().describe('Absolute path of the draft file written on prepare'),
|
|
141
|
+
dryRun: DRY_RUN_FIELD,
|
|
142
|
+
});
|
|
128
143
|
function inReviewOperation(issueNumber) {
|
|
129
144
|
return { verb: 'set', target: `Issue #${String(issueNumber)} status to In Review` };
|
|
130
145
|
}
|
|
146
|
+
// Status を In Review にした Issue の番号を返す。書かなかったら undefined
|
|
131
147
|
async function updateIssueStatusToInReview(config, client, location, headBranch, out) {
|
|
132
148
|
const issueNumber = extractIssueNumberFromBranch(headBranch);
|
|
133
149
|
if (issueNumber === undefined)
|
|
134
|
-
return;
|
|
150
|
+
return undefined;
|
|
135
151
|
const label = `Issue #${String(issueNumber)}`;
|
|
136
152
|
let itemId;
|
|
137
153
|
try {
|
|
@@ -163,6 +179,7 @@ async function updateIssueStatusToInReview(config, client, location, headBranch,
|
|
|
163
179
|
return;
|
|
164
180
|
}
|
|
165
181
|
out.done(inReviewOperation(issueNumber));
|
|
182
|
+
return issueNumber;
|
|
166
183
|
}
|
|
167
184
|
const LINK_PATH = ['project', 'link'];
|
|
168
185
|
const PR_CREATE_PATH = ['pr', 'create'];
|
|
@@ -238,7 +255,7 @@ function getPushStatus(branch, cwd, remote) {
|
|
|
238
255
|
return aheadCount === undefined || behindCount === undefined ? failed : describePushStatus(remote, branch, aheadCount, behindCount);
|
|
239
256
|
}
|
|
240
257
|
// pr create の早い確認と pr check が共有する前提。満たさなければ終了コード 1
|
|
241
|
-
function validatePullRequestContext(directory, out) {
|
|
258
|
+
export function validatePullRequestContext(directory, out) {
|
|
242
259
|
if (gitToplevel({ cwd: directory }) === undefined)
|
|
243
260
|
stopWith(out, 'not a git repository', 'git-unresolved');
|
|
244
261
|
const found = primaryRemote(directory);
|
|
@@ -278,9 +295,10 @@ function lazyClient(config, out) {
|
|
|
278
295
|
}
|
|
279
296
|
// 下の段の PR が入っているスタックに足す。無ければ下の段と新しい PR で作る。失敗は warning にとどめる
|
|
280
297
|
async function registerStack(client, location, lower, created, out) {
|
|
298
|
+
const unregistered = { lower, registered: false };
|
|
281
299
|
if (created === undefined) {
|
|
282
300
|
out.warning('could not register stack: the PR creation response has no PR number');
|
|
283
|
-
return;
|
|
301
|
+
return unregistered;
|
|
284
302
|
}
|
|
285
303
|
try {
|
|
286
304
|
const stack = await client.getStackOfPullRequest(location.owner, location.repository, lower);
|
|
@@ -288,22 +306,25 @@ async function registerStack(client, location, lower, created, out) {
|
|
|
288
306
|
// GitHub は一番上にしか足せないので、同じ下の段に 2 つ目を積んだときは 422 を待たずに知らせる
|
|
289
307
|
if (stack !== undefined && top !== lower) {
|
|
290
308
|
out.warning(`could not register stack: PR #${String(lower)} is not the top of stack #${String(stack.number)} (top: PR #${String(top)}); PR #${String(created)} was not added`);
|
|
291
|
-
return;
|
|
309
|
+
return unregistered;
|
|
292
310
|
}
|
|
293
311
|
const registered = stack === undefined
|
|
294
312
|
? await client.createStack(location.owner, location.repository, [lower, created])
|
|
295
313
|
: await client.addToStack(location.owner, location.repository, stack.number, [created]);
|
|
296
314
|
out.done({ verb: 'add', target: `PR #${String(created)} to stack #${String(registered.number)}` });
|
|
315
|
+
return { lower, registered: true, number: registered.number };
|
|
297
316
|
}
|
|
298
317
|
catch (error) {
|
|
299
318
|
if (!isRequestFailure(error))
|
|
300
319
|
throw error;
|
|
301
320
|
out.warning(`could not register stack: ${describeRequestFailure(error)}`);
|
|
321
|
+
return unregistered;
|
|
302
322
|
}
|
|
303
323
|
}
|
|
304
|
-
|
|
324
|
+
// moves に、書けた列と札を足していく。例外で止まっても、それまでの分が残る
|
|
325
|
+
async function moveWaitingIssuesSafely(client, config, location, issueNumber, pullRequest, out, moves) {
|
|
305
326
|
try {
|
|
306
|
-
await moveWaitingIssues(out, client, config, { repository: location, issueNumber, pullRequest });
|
|
327
|
+
await moveWaitingIssues(out, client, config, { repository: location, issueNumber, pullRequest }, moves);
|
|
307
328
|
}
|
|
308
329
|
catch (error) {
|
|
309
330
|
if (!isRequestFailure(error))
|
|
@@ -325,20 +346,29 @@ async function submitPullRequest(config, client, directory, draft, stackOn, out)
|
|
|
325
346
|
out.done(createOperation(draft));
|
|
326
347
|
const createdNumber = jsonField(created, 'number');
|
|
327
348
|
const pullRequest = typeof createdNumber === 'number' ? createdNumber : undefined;
|
|
328
|
-
|
|
329
|
-
|
|
349
|
+
const url = jsonField(created, 'html_url');
|
|
350
|
+
// url は先に渡す。後の処理が例外で止まっても、作った PR を結果から読める
|
|
351
|
+
out.result({ head: draft.head, base: draft.base, title: draft.title, ...pullRequest !== undefined && { number: pullRequest }, ...typeof url === 'string' && { url } });
|
|
352
|
+
const inReview = draft.isRelease ? undefined : await updateIssueStatusToInReview(config, client(), draft.location, draft.head, out);
|
|
353
|
+
if (inReview !== undefined)
|
|
354
|
+
out.result({ inReview });
|
|
330
355
|
if (stackOn !== undefined)
|
|
331
|
-
await registerStack(client(), draft.location, stackOn, pullRequest, out);
|
|
356
|
+
out.result({ stack: await registerStack(client(), draft.location, stackOn, pullRequest, out) });
|
|
332
357
|
const issueNumber = extractIssueNumberFromBranch(draft.head);
|
|
333
|
-
|
|
334
|
-
|
|
358
|
+
const moves = [];
|
|
359
|
+
try {
|
|
360
|
+
if (!draft.isRelease && isPositive(issueNumber))
|
|
361
|
+
await moveWaitingIssuesSafely(client(), config, draft.location, issueNumber, pullRequest, out, moves);
|
|
362
|
+
}
|
|
363
|
+
finally {
|
|
364
|
+
out.result({ moves: moves.map(move => moveJson(move)) });
|
|
365
|
+
}
|
|
335
366
|
consumeFlag(FLAG_PR_CREATE_SLASH_PENDING);
|
|
336
|
-
const url = jsonField(created, 'html_url');
|
|
337
367
|
if (typeof url !== 'string')
|
|
338
368
|
return stopWith(out, 'PR was created, but the response has no html_url; find it on GitHub', 'other');
|
|
339
369
|
out.data(url);
|
|
340
370
|
}
|
|
341
|
-
function stopOnMalformedRecord(reading, out) {
|
|
371
|
+
export function stopOnMalformedRecord(reading, out) {
|
|
342
372
|
if (reading.kind === 'malformed')
|
|
343
373
|
stopWith(out, describeBaseStop({ kind: 'stop', reason: 'malformed', content: reading.content }).join('\n'), 'content-invalid');
|
|
344
374
|
}
|
|
@@ -436,6 +466,7 @@ async function validateAndSubmit(input, out) {
|
|
|
436
466
|
out.planned(inReviewOperation(issueNumber));
|
|
437
467
|
if (use?.stackOn !== undefined)
|
|
438
468
|
out.planned({ verb: 'add', target: `the new PR to the stack of PR #${String(use.stackOn)}` });
|
|
469
|
+
out.result({ head, base, title, ...use?.stackOn !== undefined && { stack: { lower: use.stackOn } } });
|
|
439
470
|
}
|
|
440
471
|
function requireRepository(value, out) {
|
|
441
472
|
return splitOwnerRepository(value) ?? stopWith(out, `invalid repository format: ${value} (expected: owner/repo)`, 'invalid-input');
|
|
@@ -585,6 +616,7 @@ async function prepareTemplate(directory, out, template) {
|
|
|
585
616
|
const base = record?.branch ?? developBranch;
|
|
586
617
|
content = content.replace(/^base:\s*"[^"]*"/mu, () => `base: "${base}"`);
|
|
587
618
|
out.done({ verb: 'set', target: `base to ${base}` });
|
|
619
|
+
out.result({ base });
|
|
588
620
|
content = addScopeHint(content, config, { owner: location.owner, repository: location.repository }, base, directory, record === undefined ? undefined : { sha: record.sha }, out);
|
|
589
621
|
}
|
|
590
622
|
}
|
|
@@ -594,6 +626,7 @@ async function prepareTemplate(directory, out, template) {
|
|
|
594
626
|
try {
|
|
595
627
|
withReservedOutputPath(outputDirectory(), timestamp => `${prefix}-${timestamp}.md`, (reserved) => {
|
|
596
628
|
writeFileSync(reserved, content, 'utf8');
|
|
629
|
+
out.result({ file: path.resolve(reserved) });
|
|
597
630
|
out.data(reserved);
|
|
598
631
|
});
|
|
599
632
|
}
|
|
@@ -651,33 +684,68 @@ async function runCreate(input, io) {
|
|
|
651
684
|
}
|
|
652
685
|
}
|
|
653
686
|
// pr show
|
|
654
|
-
// グローバルの --repo か、いまの git の repository。決められなければ undefined
|
|
655
|
-
function resolveBaseRepository(globalRepository) {
|
|
656
|
-
try {
|
|
657
|
-
return resolveRepository(globalRepository, gitRunnerFor(process.cwd())).repository;
|
|
658
|
-
}
|
|
659
|
-
catch (error) {
|
|
660
|
-
if (error instanceof AmbiguousRepositoryError)
|
|
661
|
-
return undefined;
|
|
662
|
-
throw error;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
export function parseReference(reference, globalRepository, out) {
|
|
666
|
-
try {
|
|
667
|
-
const parsed = parsePullRequestReference(reference, resolveBaseRepository(globalRepository), { repositoryFlag: true });
|
|
668
|
-
return { owner: parsed.repository.owner, repository: parsed.repository.repository, number: parsed.number };
|
|
669
|
-
}
|
|
670
|
-
catch (error) {
|
|
671
|
-
if (error instanceof ReferenceParseError)
|
|
672
|
-
return stopWith(out, error.hintedText ?? error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
673
|
-
throw error;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
687
|
const ShowInputSchema = z.strictObject({
|
|
677
688
|
pr_ref: z.string().describe(PR_REFERENCE_DESCRIPTION),
|
|
678
689
|
json: z.boolean().default(false).describe('Output as JSON'),
|
|
679
690
|
reviews: z.boolean().default(false).describe('Include review details (bodies and line comments)'),
|
|
680
691
|
});
|
|
692
|
+
const ISSUE_LINK_JSON = z.strictObject({
|
|
693
|
+
number: z.int().describe('Issue number'),
|
|
694
|
+
title: z.string().describe('Title of the Issue (empty for referenced_issues)'),
|
|
695
|
+
});
|
|
696
|
+
const REVIEW_JSON = z.strictObject({
|
|
697
|
+
state: z.string().describe('State of the review'),
|
|
698
|
+
author: z.string().nullable().describe('Login of the reviewer (null when deleted)'),
|
|
699
|
+
body: z.string().optional().describe('Body of the review (only with reviews)'),
|
|
700
|
+
submitted_at: z.string().nullable().optional().describe('Submission time (only with reviews)'),
|
|
701
|
+
});
|
|
702
|
+
const REVIEW_COMMENT_JSON = z.strictObject({
|
|
703
|
+
author: z.string().nullable().describe('Login of the author (null when deleted)'),
|
|
704
|
+
body: z.string().describe('Body of the comment'),
|
|
705
|
+
created_at: z.string().nullable().describe('Creation time'),
|
|
706
|
+
});
|
|
707
|
+
const REVIEW_THREAD_JSON = z.strictObject({
|
|
708
|
+
is_resolved: z.boolean().describe('Whether the thread is resolved'),
|
|
709
|
+
path: z.string().nullable().describe('File path of the thread'),
|
|
710
|
+
line: z.int().nullable().describe('Line of the thread'),
|
|
711
|
+
comments: z.array(REVIEW_COMMENT_JSON).describe('Comments in the thread'),
|
|
712
|
+
});
|
|
713
|
+
const PR_SHOW_OUTPUT = z.strictObject({
|
|
714
|
+
number: z.int().describe('PR number'),
|
|
715
|
+
state: z.string().describe('State of the PR (OPEN, CLOSED or MERGED)'),
|
|
716
|
+
title: z.string().describe('Title of the PR'),
|
|
717
|
+
body: z.string().describe('Body of the PR'),
|
|
718
|
+
head_ref: z.string().describe('Head branch'),
|
|
719
|
+
base_ref: z.string().describe('Base branch'),
|
|
720
|
+
is_draft: z.boolean().describe('Whether the PR is a draft'),
|
|
721
|
+
mergeable: z.string().describe('Mergeability (MERGEABLE, CONFLICTING or UNKNOWN)'),
|
|
722
|
+
comments: z.int().describe('Number of comments'),
|
|
723
|
+
closing_issues: z.array(ISSUE_LINK_JSON).describe('Issues the PR closes'),
|
|
724
|
+
referenced_issues: z.array(ISSUE_LINK_JSON).describe('Issues referenced by Refs in the body and not in closing_issues'),
|
|
725
|
+
reviews: z.array(REVIEW_JSON).describe('Reviews'),
|
|
726
|
+
review_threads: z.array(REVIEW_THREAD_JSON).optional().describe('Line comment threads (only with reviews)'),
|
|
727
|
+
});
|
|
728
|
+
/**
|
|
729
|
+
--json の標準出力と MCP の data の中身。キーを並べた順が --json の出力の順になる
|
|
730
|
+
*/
|
|
731
|
+
function pullRequestJson(pr) {
|
|
732
|
+
// 項目を手で並べるので、satisfies で PR の型の項目の過不足を tsc に止めさせる
|
|
733
|
+
const base = {
|
|
734
|
+
number: pr.number,
|
|
735
|
+
state: pr.state,
|
|
736
|
+
title: pr.title,
|
|
737
|
+
body: pr.body,
|
|
738
|
+
head_ref: pr.head_ref,
|
|
739
|
+
base_ref: pr.base_ref,
|
|
740
|
+
is_draft: pr.is_draft,
|
|
741
|
+
mergeable: pr.mergeable,
|
|
742
|
+
comments: pr.comments,
|
|
743
|
+
closing_issues: pr.closing_issues.map(issue => ({ ...issue })),
|
|
744
|
+
referenced_issues: pr.referenced_issues.map(issue => ({ ...issue })),
|
|
745
|
+
reviews: pr.reviews.map(review => ({ ...review })),
|
|
746
|
+
};
|
|
747
|
+
return 'review_threads' in pr ? { ...base, review_threads: pr.review_threads.map(thread => ({ ...thread, comments: thread.comments.map(comment => ({ ...comment })) })) } : base;
|
|
748
|
+
}
|
|
681
749
|
async function runShow(input, io) {
|
|
682
750
|
const out = createOutput(false, io);
|
|
683
751
|
const config = requireActiveConfigPlain(out);
|
|
@@ -686,11 +754,15 @@ async function runShow(input, io) {
|
|
|
686
754
|
const client = createGitHubClient(out, config.host);
|
|
687
755
|
if (input.reviews) {
|
|
688
756
|
const pr = await client.getPullRequestWithReviews(owner, repository, number);
|
|
689
|
-
|
|
757
|
+
const json = pullRequestJson(pr);
|
|
758
|
+
out.result(json);
|
|
759
|
+
out.data(`${input.json ? JSON.stringify(json, undefined, 2) : formatPullRequestWithReviewsMarkdown(pr, owner, repository)}\n`);
|
|
690
760
|
}
|
|
691
761
|
else {
|
|
692
762
|
const pr = await client.getPullRequestSlim(owner, repository, number);
|
|
693
|
-
|
|
763
|
+
const json = pullRequestJson(pr);
|
|
764
|
+
out.result(json);
|
|
765
|
+
out.data(`${input.json ? JSON.stringify(json, undefined, 2) : formatPullRequestMarkdown(pr)}\n`);
|
|
694
766
|
}
|
|
695
767
|
}
|
|
696
768
|
catch (error) {
|
|
@@ -703,18 +775,14 @@ async function runShow(input, io) {
|
|
|
703
775
|
function hasBranch(branch, cwd) {
|
|
704
776
|
return runGit(['rev-parse', '--verify', branch], { cwd }).exitCode === 0;
|
|
705
777
|
}
|
|
706
|
-
// pr check の ls-remote は、認証の入力を待たずに、この時間で諦める
|
|
707
|
-
const LS_REMOTE_TIMEOUT_MILLISECONDS = 10_000;
|
|
708
|
-
// 端末で尋ねさせない。ssh は GIT_SSH_COMMAND で BatchMode にすると利用者の GIT_SSH と core.sshCommand を上書きするので、askpass を失敗させる
|
|
709
|
-
const NON_INTERACTIVE_GIT = { GIT_TERMINAL_PROMPT: '0', SSH_ASKPASS: 'false', SSH_ASKPASS_REQUIRE: 'force' };
|
|
710
778
|
// 下の段のブランチがマージで消えた後は、開発ブランチと比べる。追跡参照は fetch --prune まで残るので、
|
|
711
|
-
// remote
|
|
779
|
+
// remote に尋ね、無いと答えたときだけ消えたとみなす。届かないか時間切れなら追跡参照で決める
|
|
712
780
|
function isOnRemote(branch, cwd, remote, out) {
|
|
713
|
-
const
|
|
714
|
-
if (
|
|
781
|
+
const head = remoteBranchHead(cwd, remote, branch);
|
|
782
|
+
if (head.isReachable && head.sha === undefined)
|
|
715
783
|
return false;
|
|
716
784
|
const isTracked = hasBranch(`${remote}/${branch}`, cwd);
|
|
717
|
-
if (!isTracked &&
|
|
785
|
+
if (!isTracked && head.isReachable)
|
|
718
786
|
out.warning(`base branch ${branch} is on ${remote}, but ${remote}/${branch} is not fetched; compared with the develop branch\nrun: git fetch ${remote} ${branch}`);
|
|
719
787
|
return isTracked;
|
|
720
788
|
}
|
|
@@ -759,19 +827,36 @@ function readGitExclude(cwd) {
|
|
|
759
827
|
return '(read error)';
|
|
760
828
|
}
|
|
761
829
|
}
|
|
762
|
-
|
|
830
|
+
const PR_CHECK_OUTPUT = z.strictObject({
|
|
831
|
+
remoteUrl: z.string().describe('URL of the primary git remote'),
|
|
832
|
+
currentBranch: z.string().describe('Current branch'),
|
|
833
|
+
pushed: z.boolean().describe('Whether the current branch is pushed and even with its remote branch'),
|
|
834
|
+
pushStatus: z.string().describe('Push status as shown in the Push Status section'),
|
|
835
|
+
baseBranch: z.string().describe('Remote branch compared against (remote/branch): the lower stage when stacked, else the develop branch'),
|
|
836
|
+
gitStatus: z.string().describe('Output of git status'),
|
|
837
|
+
commits: z.string().describe('Commits since the base branch, as shown in the Commits section'),
|
|
838
|
+
diffSummary: z.string().describe('Diff stat against the base branch, as shown in the Diff Summary section'),
|
|
839
|
+
worktree: z.strictObject({
|
|
840
|
+
list: z.string().describe('Output of git worktree list'),
|
|
841
|
+
directoryName: z.string().describe('Name of the current directory'),
|
|
842
|
+
isWorktree: z.boolean().optional().describe('Whether the directory is a linked worktree (omitted when it could not be determined)'),
|
|
843
|
+
}).describe('Worktree information'),
|
|
844
|
+
stashList: z.string().describe('Stash list, as shown in the Stash List section'),
|
|
845
|
+
});
|
|
846
|
+
function readWorktreeInfo(cwd) {
|
|
763
847
|
const listed = gitStdout(['worktree', 'list'], { cwd });
|
|
764
|
-
const
|
|
848
|
+
const list = listed === undefined ? '(git worktree list failed)' : pythonStrip(listed);
|
|
849
|
+
const directoryName = path.basename(cwd);
|
|
765
850
|
const gitDirectory = gitStdout(['rev-parse', '--git-dir'], { cwd });
|
|
766
851
|
const commonDirectory = gitDirectory === undefined ? undefined : gitStdout(['rev-parse', '--git-common-dir'], { cwd });
|
|
767
|
-
if (gitDirectory === undefined || commonDirectory === undefined)
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
return
|
|
852
|
+
if (gitDirectory === undefined || commonDirectory === undefined)
|
|
853
|
+
return { list, directoryName };
|
|
854
|
+
const isWorktree = resolveRealPath(path.resolve(cwd, pythonStrip(gitDirectory))) !== resolveRealPath(path.resolve(cwd, pythonStrip(commonDirectory)));
|
|
855
|
+
return { list, directoryName, isWorktree };
|
|
856
|
+
}
|
|
857
|
+
function formatWorktreeInfo(info) {
|
|
858
|
+
const worktreeText = info.isWorktree === undefined ? '(unknown)' : String(info.isWorktree);
|
|
859
|
+
return [info.list, '', `Current directory name: ${info.directoryName}`, `Is worktree environment: ${worktreeText}`].join('\n');
|
|
775
860
|
}
|
|
776
861
|
const CheckInputSchema = z.strictObject({
|
|
777
862
|
directory: directorySchema,
|
|
@@ -786,6 +871,11 @@ function runCheck(input, io) {
|
|
|
786
871
|
const diffSummary = gitStdout(['diff', '--stat', `${baseBranch}...HEAD`], { cwd: directory });
|
|
787
872
|
const push = getPushStatus(context.currentBranch, directory, context.remoteName);
|
|
788
873
|
const stashList = getStashList(directory);
|
|
874
|
+
const commitsText = commits === undefined ? '(git log failed)' : pythonStrip(commits) || '(no commits)';
|
|
875
|
+
const diffText = diffSummary === undefined ? '(git diff failed)' : pythonStrip(diffSummary) || '(no diff)';
|
|
876
|
+
const worktree = readWorktreeInfo(directory);
|
|
877
|
+
// preflight の warning で失敗に終わっても、集めた値を data に残す
|
|
878
|
+
out.result({ remoteUrl: context.remoteUrl, currentBranch: context.currentBranch, pushed: push.isPushed, pushStatus: push.message, baseBranch, gitStatus, commits: commitsText, diffSummary: diffText, worktree, stashList });
|
|
789
879
|
const sections = [
|
|
790
880
|
['=== Git Remote ===', context.remoteUrl],
|
|
791
881
|
['=== Current Branch ===', context.currentBranch],
|
|
@@ -794,9 +884,9 @@ function runCheck(input, io) {
|
|
|
794
884
|
['=== Git Status ===', gitStatus],
|
|
795
885
|
['=== .gitignore ===', readGitignore(directory)],
|
|
796
886
|
['=== Git Exclude ===', readGitExclude(directory)],
|
|
797
|
-
[`=== Commits (vs ${baseBranch}) ===`,
|
|
798
|
-
[`=== Diff Summary (vs ${baseBranch}) ===`,
|
|
799
|
-
['=== Worktree Info ===',
|
|
887
|
+
[`=== Commits (vs ${baseBranch}) ===`, commitsText],
|
|
888
|
+
[`=== Diff Summary (vs ${baseBranch}) ===`, diffText],
|
|
889
|
+
['=== Worktree Info ===', formatWorktreeInfo(worktree)],
|
|
800
890
|
['=== Stash List ===', stashList],
|
|
801
891
|
];
|
|
802
892
|
for (const [index, [heading, content]] of sections.entries()) {
|
|
@@ -815,6 +905,7 @@ const prCreate = defineCommand({
|
|
|
815
905
|
path: PR_CREATE_PATH,
|
|
816
906
|
description: 'Create a PR (pull request)',
|
|
817
907
|
input: CreateInputSchema,
|
|
908
|
+
output: PR_CREATE_OUTPUT,
|
|
818
909
|
positional: ['file'],
|
|
819
910
|
shortFlags: { message: '-m', title: '-t', base: '-b', draft: '-d', prepare: '-p', dry_run: '-n', repo: '-r' },
|
|
820
911
|
hasOwnRepo: true,
|
|
@@ -828,6 +919,7 @@ const prShow = defineCommand({
|
|
|
828
919
|
path: ['pr', 'show'],
|
|
829
920
|
description: 'Get PR details efficiently (GraphQL, only the needed fields)',
|
|
830
921
|
input: ShowInputSchema,
|
|
922
|
+
output: PR_SHOW_OUTPUT,
|
|
831
923
|
positional: ['pr_ref'],
|
|
832
924
|
shortFlags: { json: '-j', reviews: '-r' },
|
|
833
925
|
interactive: false,
|
|
@@ -840,6 +932,7 @@ const prCheck = defineCommand({
|
|
|
840
932
|
path: ['pr', 'check'],
|
|
841
933
|
description: 'Show all the information to check before creating a PR',
|
|
842
934
|
input: CheckInputSchema,
|
|
935
|
+
output: PR_CHECK_OUTPUT,
|
|
843
936
|
positional: [],
|
|
844
937
|
shortFlags: { directory: '-D' },
|
|
845
938
|
interactive: false,
|
|
@@ -848,5 +941,5 @@ const prCheck = defineCommand({
|
|
|
848
941
|
return Promise.resolve(0);
|
|
849
942
|
},
|
|
850
943
|
});
|
|
851
|
-
export const PR_COMMANDS = [prCreate, prShow, prCheck];
|
|
944
|
+
export const PR_COMMANDS = [prCreate, prShow, prCheck, PR_MERGE_COMMAND];
|
|
852
945
|
//# sourceMappingURL=pr.js.map
|
|
@@ -77,7 +77,15 @@ export interface RepositoryParts {
|
|
|
77
77
|
*/
|
|
78
78
|
export declare function buildRepository(parts: Readonly<RepositoryParts>): Repository;
|
|
79
79
|
/**
|
|
80
|
-
|
|
80
|
+
syncProjectConfig の結果。行に出した値と同じ。change は設定ファイルの扱い、activeProject はアクティブにした(dry-run では、する)設定の名前で、unchanged なら undefined
|
|
81
|
+
*/
|
|
82
|
+
export interface SyncedProjectConfig {
|
|
83
|
+
readonly configPath: string;
|
|
84
|
+
readonly change: 'create' | 'update' | 'unchanged';
|
|
85
|
+
readonly activeProject: string | undefined;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
GitHub Projects V2 の情報から設定ファイルを作るか更新し、アクティブにする。設定ファイルのパスと、行に出した扱いを返す。
|
|
81
89
|
pecot-workflow に合うプロジェクトだけを扱う。suffix はその名前の workflow フィールドを使う。
|
|
82
90
|
skipIfUnchanged は、設定ファイルの内容が同じなら何も書かない。isDryRun は読むだけで、書く操作を planned で出す
|
|
83
91
|
*/
|
|
@@ -88,5 +96,5 @@ export declare function syncProjectConfig(out: Readonly<Output>, client: Readonl
|
|
|
88
96
|
suffix?: string | undefined;
|
|
89
97
|
skipIfUnchanged?: boolean | undefined;
|
|
90
98
|
isDryRun?: boolean | undefined;
|
|
91
|
-
}>): Promise<
|
|
99
|
+
}>): Promise<SyncedProjectConfig>;
|
|
92
100
|
//# sourceMappingURL=project-sync.d.ts.map
|
|
@@ -227,7 +227,7 @@ function loadExistingConfig(configPath) {
|
|
|
227
227
|
return existsSync(configPath) ? loadConfig(configPath) : undefined;
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
|
-
GitHub Projects V2
|
|
230
|
+
GitHub Projects V2 の情報から設定ファイルを作るか更新し、アクティブにする。設定ファイルのパスと、行に出した扱いを返す。
|
|
231
231
|
pecot-workflow に合うプロジェクトだけを扱う。suffix はその名前の workflow フィールドを使う。
|
|
232
232
|
skipIfUnchanged は、設定ファイルの内容が同じなら何も書かない。isDryRun は読むだけで、書く操作を planned で出す
|
|
233
233
|
*/
|
|
@@ -265,18 +265,19 @@ export async function syncProjectConfig(out, client, target) {
|
|
|
265
265
|
const normalized = parseProjectConfig(parseJsonText(serializeProjectConfig(config)));
|
|
266
266
|
if (skipIfUnchanged && existing !== undefined && serializeProjectConfig(existing) === serializeProjectConfig(normalized)) {
|
|
267
267
|
out.planned({ verb: 'unchanged', target: `config file ${configPath}` });
|
|
268
|
-
return configPath;
|
|
268
|
+
return { configPath, change: 'unchanged', activeProject: undefined };
|
|
269
269
|
}
|
|
270
270
|
const verb = existing === undefined ? 'create' : 'update';
|
|
271
|
+
const activeProject = path.parse(configPath).name;
|
|
271
272
|
if (target.isDryRun === true) {
|
|
272
273
|
out.planned({ verb, target: `config file ${configPath}` });
|
|
273
|
-
out.planned({ verb: 'set', target: `active project to ${
|
|
274
|
-
return configPath;
|
|
274
|
+
out.planned({ verb: 'set', target: `active project to ${activeProject}` });
|
|
275
|
+
return { configPath, change: verb, activeProject };
|
|
275
276
|
}
|
|
276
277
|
saveConfig(config, configPath);
|
|
277
278
|
out.done({ verb, target: `config file ${configPath}` });
|
|
278
279
|
setActiveConfig(configPath);
|
|
279
|
-
out.done({ verb: 'set', target: `active project to ${
|
|
280
|
-
return configPath;
|
|
280
|
+
out.done({ verb: 'set', target: `active project to ${activeProject}` });
|
|
281
|
+
return { configPath, change: verb, activeProject };
|
|
281
282
|
}
|
|
282
283
|
//# sourceMappingURL=project-sync.js.map
|