@pecot/workflow-mcp 7.0.0 → 7.0.1-dev.20
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 -1
- package/cli/dist/commands/branch.js +3 -20
- package/cli/dist/commands/issue-board.d.ts +1 -1
- package/cli/dist/commands/issue-board.js +1 -1
- package/cli/dist/commands/issue-create.js +7 -11
- package/cli/dist/commands/issue-dependency.js +21 -12
- package/cli/dist/commands/issue-shared.d.ts +8 -2
- package/cli/dist/commands/issue-shared.js +22 -4
- package/cli/dist/commands/names.d.ts +1 -1
- package/cli/dist/commands/names.js +2 -3
- package/cli/dist/commands/pr-merge.js +9 -14
- package/cli/dist/commands/pr-restack.js +47 -22
- package/cli/dist/commands/pr.js +84 -56
- package/cli/dist/commands/project.js +2 -2
- package/cli/dist/commands/renamed-commands.js +0 -1
- package/cli/dist/commands/repository-match.d.ts +6 -0
- package/cli/dist/commands/repository-match.js +20 -6
- package/cli/dist/commands/restack-reading.d.ts +45 -0
- package/cli/dist/commands/restack-reading.js +43 -0
- package/cli/dist/commands/session-finish.js +6 -18
- package/cli/dist/commands/session-start.js +10 -55
- package/cli/dist/commands/session.js +52 -169
- package/cli/dist/commands/work-target.d.ts +5 -8
- package/cli/dist/commands/work-target.js +17 -19
- package/cli/dist/domain/branch-name.d.ts +7 -0
- package/cli/dist/domain/branch-name.js +23 -1
- package/cli/dist/domain/command-hint.d.ts +1 -1
- package/cli/dist/domain/pull-request.d.ts +20 -2
- package/cli/dist/domain/pull-request.js +26 -9
- package/cli/dist/domain/repository-policy.d.ts +4 -0
- package/cli/dist/domain/repository-policy.js +5 -1
- package/cli/dist/domain/restack.d.ts +11 -0
- package/cli/dist/domain/restack.js +6 -1
- package/cli/dist/domain/state.d.ts +2 -12
- package/cli/dist/domain/state.js +3 -14
- package/cli/dist/infra/git.d.ts +13 -0
- package/cli/dist/infra/git.js +19 -0
- package/cli/dist/infra/paths.d.ts +1 -3
- package/cli/dist/infra/paths.js +2 -45
- package/cli/dist/infra/state-store.d.ts +3 -8
- package/cli/dist/infra/state-store.js +6 -24
- package/cli/templates/workflow/pecot-board-sync.yml +3 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/cli/dist/commands/pr.js
CHANGED
|
@@ -6,29 +6,29 @@ import { existsSync, statSync, writeFileSync } from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
import { describeApiError } from '../domain/api-error-detail.js';
|
|
9
|
-
import { extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
9
|
+
import { activeIssueFromBranch, extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
10
10
|
import { effectiveReleaseType, findRepository, getDevelopBranch, getFieldId, getOptionId, getReleaseBranch } from '../domain/config.js';
|
|
11
11
|
import { InvalidValueError } from '../domain/errors.js';
|
|
12
12
|
import { FrontmatterError } from '../domain/frontmatter.js';
|
|
13
13
|
import { parseRemoteUrl } from '../domain/git-url.js';
|
|
14
14
|
import { isEpicIssue } from '../domain/issue-kind.js';
|
|
15
15
|
import { jsonField } from '../domain/json.js';
|
|
16
|
-
import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBase, describeBaseStop, describePushStatus, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, pickLowerPullRequest, validatePullRequestContent } from '../domain/pull-request.js';
|
|
16
|
+
import { appendIssueCloseIfNeeded, collectPreflightWarnings, decidePullRequestBase, describeBaseStop, describePushStatus, DIVERGED_FIX_HINT, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, pickLowerPullRequest, pushFixHintOf, validatePullRequestContent } from '../domain/pull-request.js';
|
|
17
17
|
import { parsePythonInteger, pythonStrip } from '../domain/python-format.js';
|
|
18
18
|
import { splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
19
|
-
import {
|
|
19
|
+
import { RESTACK_PATH } from '../domain/restack.js';
|
|
20
20
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
21
21
|
import { parsePullRequestFile } from '../infra/frontmatter-file.js';
|
|
22
|
-
import { gitCurrentBranch, gitRemoteUrl, gitStdout, gitToplevel, primaryRemoteName, remoteBranchHead, runGit } from '../infra/git.js';
|
|
22
|
+
import { gitCurrentBranch, gitRemoteUrl, gitStdout, gitToplevel, isAncestor, primaryRemoteName, remoteBranchHead, resolveCommit, runGit } from '../infra/git.js';
|
|
23
23
|
import { TransportFailure } from '../infra/github/client.js';
|
|
24
24
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
25
25
|
import { changedFiles, expectedScope, nxProjects, parseTitleScope } from '../infra/nx-scope.js';
|
|
26
26
|
import { isFileNotFound } from '../infra/os-error.js';
|
|
27
27
|
import { outputDirectory, OutputPathReservationError, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
|
|
28
|
-
import {
|
|
28
|
+
import { readBaseRecord } from '../infra/state-store.js';
|
|
29
29
|
import { readTemplateSections, templateFile } from '../infra/template-store.js';
|
|
30
30
|
import { readTextFile } from '../infra/text-file.js';
|
|
31
|
-
import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
|
|
31
|
+
import { commandHint, hinted, inputHint, inputNameHint, joinHinted, placeholder } from './command-hint.js';
|
|
32
32
|
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
33
33
|
import { kindOfFailure } from './failure.js';
|
|
34
34
|
import { directorySchema } from './directory-option.js';
|
|
@@ -38,6 +38,7 @@ import { CommandExit, defineCommand } from './command-definition.js';
|
|
|
38
38
|
import { BOARD_MOVE_JSON, moveJson } from './issue-board.js';
|
|
39
39
|
import { PR_MERGE_COMMAND } from './pr-merge.js';
|
|
40
40
|
import { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
|
|
41
|
+
import { readRestackDecision } from './restack-reading.js';
|
|
41
42
|
import { moveWaitingIssues } from './pr-waiting.js';
|
|
42
43
|
export { parseReference, PR_REFERENCE_DESCRIPTION } from './pr-reference.js';
|
|
43
44
|
// 本文の検証の失敗。1(通信・設定・引数)と 2(preflight)と区別する
|
|
@@ -237,15 +238,15 @@ function getStashList(cwd) {
|
|
|
237
238
|
return stdout === undefined ? '(git stash list failed)' : pythonStrip(stdout) || '(no stash)';
|
|
238
239
|
}
|
|
239
240
|
function getPushStatus(branch, cwd, remote) {
|
|
240
|
-
const failed = { isPushed: false, message: '(git rev-list failed)' };
|
|
241
|
+
const failed = { isPushed: false, message: '(git rev-list failed)', isDiverged: false };
|
|
241
242
|
try {
|
|
242
243
|
if (runGit(['rev-parse', '--verify', `${remote}/${branch}`], { cwd }).exitCode !== 0) {
|
|
243
|
-
return { isPushed: false, message: `${remote}/${branch} does not exist (not pushed)
|
|
244
|
+
return { isPushed: false, message: `${remote}/${branch} does not exist (not pushed)`, isDiverged: false };
|
|
244
245
|
}
|
|
245
246
|
}
|
|
246
247
|
catch (error) {
|
|
247
248
|
if (isFileNotFound(error))
|
|
248
|
-
return { isPushed: false, message: '(git rev-parse failed)' };
|
|
249
|
+
return { isPushed: false, message: '(git rev-parse failed)', isDiverged: false };
|
|
249
250
|
throw error;
|
|
250
251
|
}
|
|
251
252
|
const ahead = gitStdout(['rev-list', '--count', `${remote}/${branch}..${branch}`], { cwd });
|
|
@@ -268,10 +269,29 @@ export function validatePullRequestContext(directory, out) {
|
|
|
268
269
|
return stopWith(out, 'cannot read repository info from the remote URL\ncheck it with: git remote -v', 'git-unresolved');
|
|
269
270
|
return { remoteUrl: found.url, currentBranch, location: found.location, remoteName: found.name };
|
|
270
271
|
}
|
|
271
|
-
|
|
272
|
+
// diverged のときの Push Status の直し方。積んでいれば載せ直しが要るかを読んで決める。diverged でなければ undefined(git push)
|
|
273
|
+
async function pushFixHintFor(push, reading, target) {
|
|
274
|
+
if (!push.isDiverged)
|
|
275
|
+
return undefined;
|
|
276
|
+
if (reading?.kind !== 'stacked')
|
|
277
|
+
return DIVERGED_FIX_HINT;
|
|
278
|
+
const { config, location, directory, remote, client, lowerPullRequest } = target;
|
|
279
|
+
const developBranch = getDevelopBranch(config, location.owner, location.repository) ?? '';
|
|
280
|
+
try {
|
|
281
|
+
const read = await readRestackDecision({ client, owner: location.owner, repository: location.repository, cwd: directory, remote, reading, developBranch, lowerPullRequest });
|
|
282
|
+
return pushFixHintOf(read.kind === 'decided' ? read.decision : undefined);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
if (error instanceof TransportFailure)
|
|
286
|
+
return pushFixHintOf(undefined);
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function runPreflightChecksOrExit(directory, base, config, client, out) {
|
|
272
291
|
const context = validatePullRequestContext(directory, out);
|
|
273
292
|
const push = getPushStatus(context.currentBranch, directory, context.remoteName);
|
|
274
|
-
const
|
|
293
|
+
const pushFixHint = await pushFixHintFor(push, base.reading, { config, location: context.location, directory, remote: context.remoteName, client, lowerPullRequest: base.lowerPullRequest });
|
|
294
|
+
const warnings = collectPreflightWarnings({ gitStatus: getGitStatus(directory), stashList: getStashList(directory), isPushed: push.isPushed, pushMessage: push.message, pushFixHint });
|
|
275
295
|
if (warnings.length === 0)
|
|
276
296
|
return;
|
|
277
297
|
out.error('preflight found warnings; fix them before creating a PR');
|
|
@@ -332,8 +352,8 @@ async function moveWaitingIssuesSafely(client, config, location, issueNumber, pu
|
|
|
332
352
|
out.warning(`could not move the Issues waiting for #${String(issueNumber)}: ${describeRequestFailure(error)}`);
|
|
333
353
|
}
|
|
334
354
|
}
|
|
335
|
-
async function submitPullRequest(config, client, directory, draft, stackOn, out) {
|
|
336
|
-
runPreflightChecksOrExit(directory, out);
|
|
355
|
+
async function submitPullRequest(config, client, directory, draft, stackOn, base, out) {
|
|
356
|
+
await runPreflightChecksOrExit(directory, base, config, client, out);
|
|
337
357
|
let created;
|
|
338
358
|
try {
|
|
339
359
|
created = await client().createPullRequest(draft.location.owner, draft.location.repository, draft.title, draft.body, draft.head, draft.base, draft.isDraft);
|
|
@@ -363,7 +383,6 @@ async function submitPullRequest(config, client, directory, draft, stackOn, out)
|
|
|
363
383
|
finally {
|
|
364
384
|
out.result({ moves: moves.map(move => moveJson(move)) });
|
|
365
385
|
}
|
|
366
|
-
consumeFlag(FLAG_PR_CREATE_SLASH_PENDING);
|
|
367
386
|
if (typeof url !== 'string')
|
|
368
387
|
return stopWith(out, 'PR was created, but the response has no html_url; find it on GitHub', 'other');
|
|
369
388
|
out.data(url);
|
|
@@ -372,11 +391,9 @@ export function stopOnMalformedRecord(reading, out) {
|
|
|
372
391
|
if (reading.kind === 'malformed')
|
|
373
392
|
stopWith(out, describeBaseStop({ kind: 'stop', reason: 'malformed', content: reading.content }).join('\n'), 'content-invalid');
|
|
374
393
|
}
|
|
375
|
-
// merge-base --is-ancestor は、祖先でなければ 1、コミットを知らなければ 128 を返す
|
|
376
|
-
const NOT_ANCESTOR = 1;
|
|
377
394
|
// 記録を使うのは、head が今のブランチで、release のテンプレートでないときだけ。形が誤っていれば終了コード 1 で止める。
|
|
378
|
-
// 記録のコミットが head
|
|
379
|
-
function readBaseRecordFor(head, template, directory, out) {
|
|
395
|
+
// 記録のコミットが head の履歴に無ければ、別のブランチの記録か、手で載せ直した後の古い記録なので止める。開発ブランチ向けに作ると下の段の差分が入りうるため
|
|
396
|
+
async function readBaseRecordFor(head, template, directory, target, out) {
|
|
380
397
|
if (template === 'release' || head !== gitCurrentBranch(directory))
|
|
381
398
|
return undefined;
|
|
382
399
|
const reading = readBaseRecord();
|
|
@@ -384,22 +401,42 @@ function readBaseRecordFor(head, template, directory, out) {
|
|
|
384
401
|
if (reading.kind !== 'stacked')
|
|
385
402
|
return reading;
|
|
386
403
|
const { branch, sha } = reading.record;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
404
|
+
// 手元が知らないコミットは、履歴に無いと決められないので止めない
|
|
405
|
+
if (resolveCommit(directory, sha) === undefined || isAncestor(directory, sha, head))
|
|
406
|
+
return reading;
|
|
407
|
+
const isRestacked = await isRestackedLocally(reading, directory, target, out);
|
|
408
|
+
return stopWith(out, joinHinted([
|
|
409
|
+
`.pecot-base records ${branch} at ${sha.slice(0, 7)}, which is not in the history of ${head}`,
|
|
410
|
+
...isRestacked ? [hinted `${head} is already restacked; rewrite the record with: ${commandHint(RESTACK_PATH)}`] : [],
|
|
411
|
+
hinted `run pr create on the branch the record was written for, or pass ${inputHint(PR_CREATE_PATH, 'head', head)} to create the PR without the record`,
|
|
412
|
+
]), 'git-unresolved');
|
|
413
|
+
}
|
|
414
|
+
// pr restack と同じ判断で、載せ直し済み(rebased)か。下の段の PR か remote を読めなければ false
|
|
415
|
+
async function isRestackedLocally(reading, directory, target, out) {
|
|
416
|
+
const { config, location } = target;
|
|
417
|
+
const developBranch = getDevelopBranch(config, location.owner, location.repository) ?? '';
|
|
418
|
+
try {
|
|
419
|
+
const read = await readRestackDecision({ client: lazyClient(config, out), owner: location.owner, repository: location.repository, cwd: directory, remote: primaryRemoteName(directory), reading, developBranch });
|
|
420
|
+
return read.kind === 'decided' && read.decision.kind === 'rebased';
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
if (error instanceof TransportFailure)
|
|
424
|
+
return false;
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
391
427
|
}
|
|
392
428
|
// 積んだ記録なら、PR を作るリポで下の段の PR を読み、base を決める
|
|
393
429
|
async function decideBase(input, client, developBranch, out) {
|
|
394
430
|
const { reading, base, location } = input;
|
|
395
431
|
if (reading === undefined)
|
|
396
|
-
return { kind: 'use', base, stackOn: undefined, stackedBase: undefined, isLowerMerged: false };
|
|
432
|
+
return { decision: { kind: 'use', base, stackOn: undefined, stackedBase: undefined, isLowerMerged: false }, lowerPullRequest: undefined };
|
|
397
433
|
if (reading.kind !== 'stacked')
|
|
398
|
-
return decidePullRequestBase({ reading, base, developBranch });
|
|
434
|
+
return { decision: decidePullRequestBase({ reading, base, developBranch }), lowerPullRequest: undefined };
|
|
399
435
|
const { branch } = reading.record;
|
|
400
436
|
try {
|
|
401
437
|
const found = await client().listPullRequestsByHead(location.owner, location.repository, branch);
|
|
402
|
-
|
|
438
|
+
const lower = pickLowerPullRequest(found.pullRequests);
|
|
439
|
+
return { decision: decidePullRequestBase({ reading, base, developBranch, lowerPullRequest: lower }), lowerPullRequest: { pullRequest: lower } };
|
|
403
440
|
}
|
|
404
441
|
catch (error) {
|
|
405
442
|
if (error instanceof GitHubAPIError)
|
|
@@ -433,7 +470,8 @@ async function validateAndSubmit(input, out) {
|
|
|
433
470
|
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
434
471
|
const releaseBranch = getReleaseBranch(config, location.owner, location.repository);
|
|
435
472
|
exitOnUnsetBranch(template, input.base, head, developBranch, releaseBranch, out);
|
|
436
|
-
const
|
|
473
|
+
const decided = await decideBase(input, client, developBranch ?? '', out);
|
|
474
|
+
const { use, errors: baseErrors } = useOrStop(decided.decision, out);
|
|
437
475
|
const base = use?.base ?? input.base;
|
|
438
476
|
const stacked = stackedScopeOf(input.reading, use);
|
|
439
477
|
const requiredSections = readTemplateSections(templateFile('pr', templateKindOf(template)));
|
|
@@ -457,7 +495,7 @@ async function validateAndSubmit(input, out) {
|
|
|
457
495
|
const isRelease = template === 'release';
|
|
458
496
|
const draft = { location, title, body: input.body, head, base, isDraft: input.isDraft, isRelease };
|
|
459
497
|
if (!input.dryRun) {
|
|
460
|
-
await submitPullRequest(config, client, directory, draft, use?.stackOn, out);
|
|
498
|
+
await submitPullRequest(config, client, directory, draft, use?.stackOn, { reading: input.reading, lowerPullRequest: decided.lowerPullRequest }, out);
|
|
461
499
|
return;
|
|
462
500
|
}
|
|
463
501
|
out.planned(createOperation(draft));
|
|
@@ -487,7 +525,7 @@ async function createFromFile(input, directory, out) {
|
|
|
487
525
|
return stopWith(out, 'repository is required (e.g. owner/repo)', 'content-invalid');
|
|
488
526
|
const location = requireRepository(frontmatter.repository, out);
|
|
489
527
|
const head = resolveHeadBranch(frontmatter.head, directory, out);
|
|
490
|
-
const reading = readBaseRecordFor(head, input.template, directory, out);
|
|
528
|
+
const reading = await readBaseRecordFor(head, input.template, directory, { config, location }, out);
|
|
491
529
|
let body = parsed.body;
|
|
492
530
|
const issueNumber = extractIssueNumberFromBranch(head);
|
|
493
531
|
if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
|
|
@@ -522,7 +560,7 @@ async function createDirect(input, directory, out) {
|
|
|
522
560
|
location = requireRepository(input.repository, out);
|
|
523
561
|
}
|
|
524
562
|
const head = resolveHeadBranch(input.head, directory, out);
|
|
525
|
-
const reading = readBaseRecordFor(head, input.template, directory, out);
|
|
563
|
+
const reading = await readBaseRecordFor(head, input.template, directory, { config, location }, out);
|
|
526
564
|
let body = input.message;
|
|
527
565
|
const issueNumber = extractIssueNumberFromBranch(head);
|
|
528
566
|
if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
|
|
@@ -560,22 +598,11 @@ function addScopeHint(content, config, location, base, directory, stacked, out)
|
|
|
560
598
|
return hinted;
|
|
561
599
|
}
|
|
562
600
|
async function fillClosesInTemplate(content, config, directory, location, out) {
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
if (
|
|
566
|
-
const [activeOwner, activeRepository, digits] = segments;
|
|
567
|
-
const activeNumber = digits !== undefined && /^\p{Nd}+$/u.test(digits) ? parsePythonInteger(digits) : undefined;
|
|
568
|
-
if (activeOwner !== undefined && activeRepository !== undefined && activeNumber !== undefined)
|
|
569
|
-
target = { owner: activeOwner, repository: activeRepository, number: activeNumber };
|
|
570
|
-
}
|
|
571
|
-
if (target === undefined && location !== undefined) {
|
|
572
|
-
const branch = gitCurrentBranch(directory);
|
|
573
|
-
const branchNumber = branch === undefined || branch === '' ? undefined : extractIssueNumberFromBranch(branch);
|
|
574
|
-
if (isPositive(branchNumber))
|
|
575
|
-
target = { owner: location.owner, repository: location.repository, number: branchNumber };
|
|
576
|
-
}
|
|
577
|
-
if (target === undefined || target.owner === '' || target.repository === '')
|
|
601
|
+
// 作業中の Issue は remote とブランチ名から決める。古い .pecot-active は読まない
|
|
602
|
+
const active = activeIssueFromBranch(location, gitCurrentBranch(directory));
|
|
603
|
+
if (active === undefined)
|
|
578
604
|
return content;
|
|
605
|
+
const target = { owner: active.repository.owner, repository: active.repository.repository, number: active.number };
|
|
579
606
|
const label = `Issue #${String(target.number)}`;
|
|
580
607
|
try {
|
|
581
608
|
const kind = await createGitHubClient(out, config?.host).getIssueKind(target.owner, target.repository, target.number);
|
|
@@ -786,12 +813,7 @@ function isOnRemote(branch, cwd, remote, out) {
|
|
|
786
813
|
out.warning(`base branch ${branch} is on ${remote}, but ${remote}/${branch} is not fetched; compared with the develop branch\nrun: git fetch ${remote} ${branch}`);
|
|
787
814
|
return isTracked;
|
|
788
815
|
}
|
|
789
|
-
function determineBaseBranch(location, cwd, remote, out) {
|
|
790
|
-
const config = loadActiveConfig();
|
|
791
|
-
if (config === undefined)
|
|
792
|
-
return stopWith(out, hinted `project config not found\nactivate a project with: ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`, 'no-active-project');
|
|
793
|
-
const reading = readBaseRecord();
|
|
794
|
-
stopOnMalformedRecord(reading, out);
|
|
816
|
+
function determineBaseBranch(config, reading, location, cwd, remote, out) {
|
|
795
817
|
if (reading.kind === 'stacked' && isOnRemote(reading.record.branch, cwd, remote, out))
|
|
796
818
|
return `${remote}/${reading.record.branch}`;
|
|
797
819
|
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
@@ -861,11 +883,16 @@ function formatWorktreeInfo(info) {
|
|
|
861
883
|
const CheckInputSchema = z.strictObject({
|
|
862
884
|
directory: directorySchema,
|
|
863
885
|
});
|
|
864
|
-
function runCheck(input, io) {
|
|
886
|
+
async function runCheck(input, io) {
|
|
865
887
|
const out = createOutput(false, io);
|
|
866
888
|
const directory = input.directory;
|
|
867
889
|
const context = validatePullRequestContext(directory, out);
|
|
868
|
-
const
|
|
890
|
+
const config = loadActiveConfig();
|
|
891
|
+
if (config === undefined)
|
|
892
|
+
return stopWith(out, hinted `project config not found\nactivate a project with: ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`, 'no-active-project');
|
|
893
|
+
const reading = readBaseRecord();
|
|
894
|
+
stopOnMalformedRecord(reading, out);
|
|
895
|
+
const baseBranch = determineBaseBranch(config, reading, context.location, directory, context.remoteName, out);
|
|
869
896
|
const gitStatus = getGitStatus(directory);
|
|
870
897
|
const commits = gitStdout(['log', '--oneline', `${baseBranch}..HEAD`], { cwd: directory });
|
|
871
898
|
const diffSummary = gitStdout(['diff', '--stat', `${baseBranch}...HEAD`], { cwd: directory });
|
|
@@ -895,7 +922,8 @@ function runCheck(input, io) {
|
|
|
895
922
|
out.data(`${heading}\n`);
|
|
896
923
|
out.data(`${content}\n`);
|
|
897
924
|
}
|
|
898
|
-
const
|
|
925
|
+
const pushFixHint = await pushFixHintFor(push, reading, { config, location: context.location, directory, remote: context.remoteName, client: lazyClient(config, out) });
|
|
926
|
+
const warnings = collectPreflightWarnings({ gitStatus, stashList, isPushed: push.isPushed, pushMessage: push.message, pushFixHint });
|
|
899
927
|
out.count('preflight warnings', warnings.length);
|
|
900
928
|
printPreflightWarnings(out, warnings);
|
|
901
929
|
if (warnings.length > 0)
|
|
@@ -936,9 +964,9 @@ const prCheck = defineCommand({
|
|
|
936
964
|
positional: [],
|
|
937
965
|
shortFlags: { directory: '-D' },
|
|
938
966
|
interactive: false,
|
|
939
|
-
run: (input, io) => {
|
|
940
|
-
runCheck(input, io);
|
|
941
|
-
return
|
|
967
|
+
run: async (input, io) => {
|
|
968
|
+
await runCheck(input, io);
|
|
969
|
+
return 0;
|
|
942
970
|
},
|
|
943
971
|
});
|
|
944
972
|
export const PR_COMMANDS = [prCreate, prShow, prCheck, PR_MERGE_COMMAND];
|
|
@@ -424,7 +424,7 @@ async function activateFromConfigFile(out, configPath, host, isDryRun) {
|
|
|
424
424
|
const title = projectInfo['title'];
|
|
425
425
|
if (typeof title !== 'string' || title === '')
|
|
426
426
|
stopWith(out, `could not read the title of project #${String(config.project.number)}`, 'project-not-found');
|
|
427
|
-
reportSynced(out, await syncProjectConfig(out, client, { owner: config.owner, name: title, host: config.host, isDryRun }));
|
|
427
|
+
reportSynced(out, await syncProjectConfig(out, client, { owner: config.owner, name: title, host: config.host, suffix: config.workflow_suffix, isDryRun }));
|
|
428
428
|
});
|
|
429
429
|
}
|
|
430
430
|
async function resolveActivationOwner(out, client, owner) {
|
|
@@ -629,7 +629,7 @@ async function linkRepository(out, config, repositoryOwner, repositoryName) {
|
|
|
629
629
|
return await createGitHubClient(out, config.host).linkRepositoryToProject(config.owner, config.project.number, repositoryOwner, repositoryName);
|
|
630
630
|
}
|
|
631
631
|
catch (error) {
|
|
632
|
-
// API の失敗の文は、Python と同じく message
|
|
632
|
+
// API の失敗の文は、Python と同じく message をそのまま使う
|
|
633
633
|
if (error instanceof GitHubAPIError)
|
|
634
634
|
return { status: 'failed', detail: error.message };
|
|
635
635
|
throw error;
|
|
@@ -31,7 +31,6 @@ export function findRenamedCommand(path) {
|
|
|
31
31
|
}
|
|
32
32
|
export const RENAMED_INPUTS = [
|
|
33
33
|
{ command: 'issue comment', oldName: 'issue', newName: 'issue_ref' },
|
|
34
|
-
{ command: 'session restore', oldName: 'issue', newName: 'issue_ref' },
|
|
35
34
|
{ command: 'branch delete', oldName: 'repo_ref', newName: 'repo' },
|
|
36
35
|
{ command: 'project link', oldName: 'owner_repo', newName: 'repo' },
|
|
37
36
|
{ command: 'session start', oldName: 'branch_name', newName: 'branch' },
|
|
@@ -11,4 +11,10 @@ export declare function resolveCurrentRepository(cwd: string): ResolvedRepositor
|
|
|
11
11
|
止めるときは、stderr に行を書いて CommandExit(1) を投げる。warn の警告は stderr に書いて続ける
|
|
12
12
|
*/
|
|
13
13
|
export declare function requireRepositoryMatch(mode: PolicyMode, explicit: string | undefined, io: Readonly<CommandIo>, cwd: string): RepositoryReference | undefined;
|
|
14
|
+
/**
|
|
15
|
+
作業ディレクトリが remote を持つ git のリポジトリの中かだけを確かめる。remote の URL は読まない。
|
|
16
|
+
削除の先を引数で決めるコマンド(branch delete)が、`--repo` を使わずに使う。
|
|
17
|
+
git の外・remote 無しなら、stderr に行を書いて CommandExit(1) を投げる
|
|
18
|
+
*/
|
|
19
|
+
export declare function requireGitRemote(io: Readonly<CommandIo>, cwd: string): void;
|
|
14
20
|
//# sourceMappingURL=repository-match.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// グローバルの `--repo` と、今の git remote のリポジトリの食い違いを扱う(Python の `require_repo_match`)。
|
|
2
2
|
// 判定は domain/repository-policy.ts の applyRepositoryPolicy に任せ、ここは git の解決と行の出力、止めるときの終了コードだけを行う。
|
|
3
3
|
import { formatHinted } from '../domain/command-hint.js';
|
|
4
|
-
import { applyRepositoryPolicy } from '../domain/repository-policy.js';
|
|
4
|
+
import { AMBIGUOUS_REPOSITORY_LINE, applyRepositoryPolicy } from '../domain/repository-policy.js';
|
|
5
5
|
import { AmbiguousRepositoryError, resolveRepository } from '../domain/repository-resolver.js';
|
|
6
|
-
import { gitRunnerFor } from '../infra/git.js';
|
|
6
|
+
import { gitRunnerFor, listRemotes } from '../infra/git.js';
|
|
7
7
|
import { CommandExit } from './command-definition.js';
|
|
8
8
|
import { WARNING_PREFIX } from './output.js';
|
|
9
9
|
/**
|
|
@@ -26,14 +26,28 @@ export function resolveCurrentRepository(cwd) {
|
|
|
26
26
|
*/
|
|
27
27
|
export function requireRepositoryMatch(mode, explicit, io, cwd) {
|
|
28
28
|
const outcome = applyRepositoryPolicy({ explicit, resolved: resolveCurrentRepository(cwd), mode });
|
|
29
|
-
|
|
29
|
+
writeLines(io, outcome.stderr);
|
|
30
|
+
if (outcome.kind === 'exit')
|
|
31
|
+
throw new CommandExit(outcome.exitCode, outcome.failure);
|
|
32
|
+
return outcome.adopted;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
作業ディレクトリが remote を持つ git のリポジトリの中かだけを確かめる。remote の URL は読まない。
|
|
36
|
+
削除の先を引数で決めるコマンド(branch delete)が、`--repo` を使わずに使う。
|
|
37
|
+
git の外・remote 無しなら、stderr に行を書いて CommandExit(1) を投げる
|
|
38
|
+
*/
|
|
39
|
+
export function requireGitRemote(io, cwd) {
|
|
40
|
+
if ((listRemotes(cwd) ?? []).length > 0)
|
|
41
|
+
return;
|
|
42
|
+
writeLines(io, [AMBIGUOUS_REPOSITORY_LINE, ' run inside a git repository that has a remote']);
|
|
43
|
+
throw new CommandExit(1, 'git-unresolved');
|
|
44
|
+
}
|
|
45
|
+
function writeLines(io, lines) {
|
|
46
|
+
for (const line of lines) {
|
|
30
47
|
const text = formatHinted(line, io.surface ?? 'cli');
|
|
31
48
|
io.stderr(`${text}\n`);
|
|
32
49
|
if (text.startsWith(WARNING_PREFIX))
|
|
33
50
|
io.warning?.(text.slice(WARNING_PREFIX.length));
|
|
34
51
|
}
|
|
35
|
-
if (outcome.kind === 'exit')
|
|
36
|
-
throw new CommandExit(outcome.exitCode, outcome.failure);
|
|
37
|
-
return outcome.adopted;
|
|
38
52
|
}
|
|
39
53
|
//# sourceMappingURL=repository-match.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PullRequestReadout } from '../domain/issue-readout.js';
|
|
2
|
+
import type { RestackDecision } from '../domain/restack.js';
|
|
3
|
+
import type { BaseReading } from '../domain/state.js';
|
|
4
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
5
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
6
|
+
/**
|
|
7
|
+
既に読んだ下の段の PR。PR が無かったことも示せるよう、包んで渡す
|
|
8
|
+
*/
|
|
9
|
+
export interface KnownLowerPullRequest {
|
|
10
|
+
readonly pullRequest: PullRequestReadout | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface RestackTarget {
|
|
13
|
+
readonly client: () => Readonly<GitHubClient>;
|
|
14
|
+
readonly owner: string;
|
|
15
|
+
readonly repository: string;
|
|
16
|
+
readonly cwd: string;
|
|
17
|
+
/**
|
|
18
|
+
remote が無ければ undefined。そのときは remote に届かないのと同じに扱う
|
|
19
|
+
*/
|
|
20
|
+
readonly remote: string | undefined;
|
|
21
|
+
readonly reading: Extract<BaseReading, {
|
|
22
|
+
kind: 'stacked';
|
|
23
|
+
}>;
|
|
24
|
+
readonly developBranch: string;
|
|
25
|
+
/**
|
|
26
|
+
渡されたら、下の段の PR を読み直さない
|
|
27
|
+
*/
|
|
28
|
+
readonly lowerPullRequest?: KnownLowerPullRequest | undefined;
|
|
29
|
+
}
|
|
30
|
+
export type RestackReading = {
|
|
31
|
+
readonly kind: 'decided';
|
|
32
|
+
readonly decision: RestackDecision;
|
|
33
|
+
readonly lowerPullRequest: PullRequestReadout | undefined;
|
|
34
|
+
} | {
|
|
35
|
+
readonly kind: 'remote-unreachable';
|
|
36
|
+
readonly lowerPullRequest: PullRequestReadout | undefined;
|
|
37
|
+
} | {
|
|
38
|
+
readonly kind: 'pull-request-unreadable';
|
|
39
|
+
readonly error: GitHubAPIError;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
下の段の PR を読み、remote の先頭を尋ねて、載せ直す先を決める。PR を読めないか remote に届かなければ、その種類を返す
|
|
43
|
+
*/
|
|
44
|
+
export declare function readRestackDecision(target: Readonly<RestackTarget>): Promise<RestackReading>;
|
|
45
|
+
//# sourceMappingURL=restack-reading.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { pickLowerPullRequest } from '../domain/pull-request.js';
|
|
2
|
+
import { decideRestack } from '../domain/restack.js';
|
|
3
|
+
import { isAncestor, remoteBranchHead, resolveCommit } from '../infra/git.js';
|
|
4
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
5
|
+
/**
|
|
6
|
+
下の段の PR を読み、remote の先頭を尋ねて、載せ直す先を決める。PR を読めないか remote に届かなければ、その種類を返す
|
|
7
|
+
*/
|
|
8
|
+
export async function readRestackDecision(target) {
|
|
9
|
+
const { reading, remote } = target;
|
|
10
|
+
let lowerPullRequest = target.lowerPullRequest?.pullRequest;
|
|
11
|
+
if (target.lowerPullRequest === undefined) {
|
|
12
|
+
try {
|
|
13
|
+
const found = await target.client().listPullRequestsByHead(target.owner, target.repository, reading.record.branch);
|
|
14
|
+
lowerPullRequest = pickLowerPullRequest(found.pullRequests);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof GitHubAPIError)
|
|
18
|
+
return { kind: 'pull-request-unreadable', error };
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (remote === undefined)
|
|
23
|
+
return { kind: 'remote-unreachable', lowerPullRequest };
|
|
24
|
+
const lowerHead = remoteBranchHead(target.cwd, remote, reading.record.branch);
|
|
25
|
+
if (!lowerHead.isReachable)
|
|
26
|
+
return { kind: 'remote-unreachable', lowerPullRequest };
|
|
27
|
+
const decision = decideRestack({ reading, developBranch: target.developBranch, lowerPullRequest, lowerHead: lowerHead.sha });
|
|
28
|
+
return { kind: 'decided', decision: withRebased(target.cwd, remote, reading, decision, lowerHead.sha), lowerPullRequest };
|
|
29
|
+
}
|
|
30
|
+
// 新しい base の上に載り終えていれば rebased に替える。記録の位置が HEAD にあれば、それが新しい base の祖先であることも求める。
|
|
31
|
+
// merge で base を取り込んだブランチと、下の段が古い位置へ戻されたブランチを、載せ直し済みと見ないため
|
|
32
|
+
function withRebased(cwd, remote, reading, decision, lowerHead) {
|
|
33
|
+
if (decision.kind !== 'moved' && decision.kind !== 'merged')
|
|
34
|
+
return decision;
|
|
35
|
+
// moved は ls-remote の先頭を使う。fetch しない呼び出し元では、追跡参照が古い位置を指しうるため
|
|
36
|
+
const newBase = decision.kind === 'moved' ? lowerHead : resolveCommit(cwd, `${remote}/${decision.base}`);
|
|
37
|
+
if (newBase === undefined || !isAncestor(cwd, newBase, 'HEAD'))
|
|
38
|
+
return decision;
|
|
39
|
+
const { sha } = reading.record;
|
|
40
|
+
const isRecordLeftBehind = isAncestor(cwd, sha, 'HEAD') && !isAncestor(cwd, sha, newBase);
|
|
41
|
+
return isRecordLeftBehind ? decision : { kind: 'rebased', base: decision.base };
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=restack-reading.js.map
|
|
@@ -8,11 +8,12 @@ import { isEpicIssue } from '../domain/issue-kind.js';
|
|
|
8
8
|
import { extractClosingIssueNumbers } from '../domain/pull-request.js';
|
|
9
9
|
import { assumePullRequestState, describeReadinessChange, displayReference, hasReadinessChanged, isDone, isStackedOn } from '../domain/readiness.js';
|
|
10
10
|
import { createIssueReference } from '../domain/reference-parser.js';
|
|
11
|
-
import {
|
|
11
|
+
import { RESTACK_PATH } from '../domain/restack.js';
|
|
12
|
+
import { FLAG_PECOT_BASE, FLAG_PECOT_QUICK_MODE, FLAG_PECOT_SESSION_TITLE } from '../domain/state.js';
|
|
12
13
|
import { gitCurrentBranch, GitCommandError, runGit } from '../infra/git.js';
|
|
13
14
|
import { GitHubAPIError, GitHubNotFoundError, isClosedByAnotherRequest, isMissingReferenceError } from '../infra/github/errors.js';
|
|
14
15
|
import { isFileNotFound } from '../infra/os-error.js';
|
|
15
|
-
import {
|
|
16
|
+
import { removeFlag } from '../infra/state-store.js';
|
|
16
17
|
import { getCurrentWorktreeName, isWorktreeEnvironment } from '../infra/worktree.js';
|
|
17
18
|
import { commandHint, hinted } from './command-hint.js';
|
|
18
19
|
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
@@ -183,10 +184,10 @@ async function updateWaitingIssues(context, source) {
|
|
|
183
184
|
const lower = heads.filter(head => prerequisiteOf(result, head)?.wait === 'stack').map(head => displayReference(head, home)).join(', ');
|
|
184
185
|
const [branch] = result.target.branches;
|
|
185
186
|
record.restack.push({ issue: name, ...branch !== undefined && { branch } });
|
|
186
|
-
out.warning(hinted `${name} is stacked on ${lower}; run ${commandHint(
|
|
187
|
+
out.warning(hinted `${name} is stacked on ${lower}; run ${commandHint(RESTACK_PATH)} in the working directory of ${branch ?? 'its branch'}`);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
// head
|
|
190
|
+
// head ブランチを消す。無ければ unchanged、ほかの失敗は warning にして続ける
|
|
190
191
|
async function deleteMergedBranch(context, client, location, headBranch) {
|
|
191
192
|
const { out, isDryRun, record } = context;
|
|
192
193
|
const operation = { verb: 'delete', target: `remote branch ${headBranch}` };
|
|
@@ -209,18 +210,6 @@ async function deleteMergedBranch(context, client, location, headBranch) {
|
|
|
209
210
|
}
|
|
210
211
|
out.done({ verb: 'unchanged', target: `remote branch ${headBranch} (already deleted)` });
|
|
211
212
|
}
|
|
212
|
-
const wipBranch = `wip/${headBranch}`;
|
|
213
|
-
try {
|
|
214
|
-
await client.deleteBranch(location.owner, location.repository, wipBranch);
|
|
215
|
-
out.done({ verb: 'delete', target: `remote branch ${wipBranch}` });
|
|
216
|
-
record.deletedBranches.push({ branch: wipBranch, location: 'remote' });
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
if (!(error instanceof GitHubAPIError))
|
|
220
|
-
throw error;
|
|
221
|
-
if (!isMissingReferenceError(error))
|
|
222
|
-
out.warning(`deleting remote branch ${wipBranch} failed: ${describeApiError(error)}`);
|
|
223
|
-
}
|
|
224
213
|
}
|
|
225
214
|
// 手元と PR の repository が同じなら主の remote 名。違えば警告を出して undefined
|
|
226
215
|
function sameRepositoryRemote(cwd, location, out) {
|
|
@@ -314,7 +303,7 @@ function localCleanupAfterMerge(context, headBranch, config, location) {
|
|
|
314
303
|
}
|
|
315
304
|
function removeActiveFlags(out) {
|
|
316
305
|
try {
|
|
317
|
-
for (const flag of [
|
|
306
|
+
for (const flag of [FLAG_PECOT_BASE, FLAG_PECOT_SESSION_TITLE, FLAG_PECOT_QUICK_MODE])
|
|
318
307
|
removeFlag(flag);
|
|
319
308
|
}
|
|
320
309
|
catch (error) {
|
|
@@ -364,7 +353,6 @@ async function finish(input, context) {
|
|
|
364
353
|
return;
|
|
365
354
|
}
|
|
366
355
|
removeActiveFlags(out);
|
|
367
|
-
consumeFlag(FLAG_MERGE_SLASH_PENDING);
|
|
368
356
|
}
|
|
369
357
|
const sessionFinishCommand = defineCommand({
|
|
370
358
|
path: ['session', 'finish'],
|