@pecot/workflow-mcp 5.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 +27 -22
- package/cli/dist/cli.js +6 -1
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +69 -0
- package/cli/dist/commands/board-judgment.d.ts +69 -0
- package/cli/dist/commands/board-judgment.js +150 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +65 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +75 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +120 -0
- package/cli/dist/commands/board-view.d.ts +151 -0
- package/cli/dist/commands/board-view.js +293 -0
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +111 -0
- package/cli/dist/commands/command-binding.js +4 -0
- package/cli/dist/commands/command-definition.d.ts +39 -8
- package/cli/dist/commands/command-definition.js +20 -7
- package/cli/dist/commands/command-help.js +2 -2
- package/cli/dist/commands/command-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +5 -3
- package/cli/dist/commands/command-stop.js +7 -6
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +35 -0
- package/cli/dist/commands/failure.d.ts +6 -0
- package/cli/dist/commands/failure.js +29 -3
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +13 -3
- package/cli/dist/commands/help.js +8 -13
- package/cli/dist/commands/issue-board.d.ts +61 -0
- package/cli/dist/commands/issue-board.js +85 -1
- package/cli/dist/commands/issue-comment.js +66 -30
- package/cli/dist/commands/issue-create.js +632 -92
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +310 -0
- package/cli/dist/commands/issue-readiness.d.ts +122 -0
- package/cli/dist/commands/issue-readiness.js +253 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +130 -0
- package/cli/dist/commands/issue-shared.d.ts +33 -20
- package/cli/dist/commands/issue-shared.js +84 -76
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +239 -0
- package/cli/dist/commands/issue.d.ts +0 -1
- package/cli/dist/commands/issue.js +6 -8
- package/cli/dist/commands/names.d.ts +33 -0
- package/cli/dist/commands/names.js +63 -0
- package/cli/dist/commands/output.d.ts +32 -4
- package/cli/dist/commands/output.js +28 -8
- 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 +59 -0
- package/cli/dist/commands/pr-waiting.js +143 -0
- package/cli/dist/commands/pr.d.ts +23 -0
- package/cli/dist/commands/pr.js +378 -366
- package/cli/dist/commands/project-sync.d.ts +12 -3
- package/cli/dist/commands/project-sync.js +23 -13
- package/cli/dist/commands/project.d.ts +3 -2
- package/cli/dist/commands/project.js +371 -177
- package/cli/dist/commands/registry.js +15 -10
- package/cli/dist/commands/release.d.ts +2 -2
- package/cli/dist/commands/release.js +118 -130
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-match.js +9 -3
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +383 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +252 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +186 -32
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
- package/cli/dist/commands/tracker-sync.d.ts +37 -0
- package/cli/dist/commands/tracker-sync.js +18 -6
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +20 -0
- package/cli/dist/commands/usage-error.d.ts +4 -0
- package/cli/dist/commands/usage-error.js +6 -0
- package/cli/dist/commands/work-target.d.ts +20 -3
- package/cli/dist/commands/work-target.js +49 -6
- package/cli/dist/commands/worktree.js +103 -33
- package/cli/dist/domain/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -0
- package/cli/dist/domain/branch-name.js +1 -1
- package/cli/dist/domain/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +4 -0
- package/cli/dist/domain/config.js +11 -1
- package/cli/dist/domain/dependabot.js +1 -1
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/format.d.ts +51 -4
- package/cli/dist/domain/format.js +72 -6
- package/cli/dist/domain/frontmatter.d.ts +18 -3
- package/cli/dist/domain/frontmatter.js +38 -12
- package/cli/dist/domain/issue-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +36 -4
- package/cli/dist/domain/pull-request.d.ts +71 -4
- package/cli/dist/domain/pull-request.js +59 -10
- package/cli/dist/domain/readiness.d.ts +44 -0
- package/cli/dist/domain/readiness.js +153 -5
- package/cli/dist/domain/reference-parser.d.ts +3 -1
- package/cli/dist/domain/reference-parser.js +6 -2
- package/cli/dist/domain/release.d.ts +7 -3
- package/cli/dist/domain/release.js +5 -12
- package/cli/dist/domain/repository-policy.d.ts +9 -3
- package/cli/dist/domain/repository-policy.js +8 -7
- package/cli/dist/domain/repository-resolver.js +4 -1
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/security-alerts.js +1 -1
- package/cli/dist/domain/state.d.ts +69 -0
- package/cli/dist/domain/state.js +67 -1
- package/cli/dist/domain/work-start.d.ts +30 -0
- package/cli/dist/domain/work-start.js +42 -0
- package/cli/dist/infra/authored-notes.d.ts +1 -1
- package/cli/dist/infra/authored-notes.js +10 -4
- package/cli/dist/infra/config-store.d.ts +4 -0
- package/cli/dist/infra/config-store.js +13 -0
- package/cli/dist/infra/git.d.ts +76 -0
- package/cli/dist/infra/git.js +123 -1
- package/cli/dist/infra/github/client.d.ts +5 -0
- package/cli/dist/infra/github/client.js +10 -7
- package/cli/dist/infra/github/errors.d.ts +18 -0
- package/cli/dist/infra/github/errors.js +22 -0
- package/cli/dist/infra/github/issues.d.ts +39 -3
- package/cli/dist/infra/github/issues.js +178 -23
- package/cli/dist/infra/github/projects.d.ts +35 -0
- package/cli/dist/infra/github/projects.js +89 -8
- package/cli/dist/infra/github/pulls.d.ts +105 -2
- package/cli/dist/infra/github/pulls.js +172 -5
- package/cli/dist/infra/github/queries.d.ts +15 -4
- package/cli/dist/infra/github/queries.js +203 -40
- package/cli/dist/infra/github/readout.d.ts +5 -1
- package/cli/dist/infra/github/readout.js +11 -33
- package/cli/dist/infra/github/repos.d.ts +18 -0
- package/cli/dist/infra/github/repos.js +31 -0
- package/cli/dist/infra/nx-scope.d.ts +1 -1
- package/cli/dist/infra/nx-scope.js +1 -1
- package/cli/dist/infra/state-store.d.ts +10 -1
- package/cli/dist/infra/state-store.js +14 -2
- package/cli/dist/infra/worktree-links.d.ts +3 -0
- package/cli/dist/infra/worktree-links.js +8 -1
- package/cli/dist/infra/worktree.d.ts +12 -1
- package/cli/dist/infra/worktree.js +40 -23
- package/cli/dist/mcp/result.d.ts +82 -7
- package/cli/dist/mcp/result.js +139 -19
- package/cli/dist/mcp/server.d.ts +2 -2
- package/cli/dist/mcp/server.js +57 -10
- package/cli/templates/comment/plan.md +14 -0
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task-implement.md +13 -6
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/cli/dist/commands/dependabot.d.ts +0 -3
- package/cli/dist/commands/issue-project.d.ts +0 -3
- package/cli/dist/commands/issue-project.js +0 -176
- package/cli/dist/commands/issue-quick.d.ts +0 -3
- package/cli/dist/commands/issue-quick.js +0 -126
- package/cli/dist/commands/issue-read.d.ts +0 -3
- package/cli/dist/commands/issue-read.js +0 -80
- package/cli/dist/commands/project-info.d.ts +0 -48
- package/cli/dist/commands/project-info.js +0 -181
- package/cli/dist/commands/repository.d.ts +0 -5
- package/cli/dist/commands/repository.js +0 -265
- package/cli/dist/commands/security.d.ts +0 -3
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// session start。Python の cli/commands/repo.py の create_branch の移植。
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { findRepository, getFieldId, getOptionId, isRepositoryInProject } from '../domain/config.js';
|
|
4
|
+
import { ReferenceParseError, parseIssueReference } from '../domain/reference-parser.js';
|
|
5
|
+
import { pythonStringRepr } from '../domain/python-format.js';
|
|
6
|
+
import { repositoryFullName } from '../domain/repository-resolver.js';
|
|
7
|
+
import { displayReference } from '../domain/readiness.js';
|
|
8
|
+
import { FLAG_PECOT_ACTIVE } from '../domain/state.js';
|
|
9
|
+
import { decideStart, describeBaseMismatch } from '../domain/work-start.js';
|
|
10
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
11
|
+
import { readFlag } from '../infra/state-store.js';
|
|
12
|
+
import { issuePath } from './issue-shared.js';
|
|
13
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
14
|
+
import { defineCommand } from './command-definition.js';
|
|
15
|
+
import { commandHint, hinted, inputHint, joinHinted } from './command-hint.js';
|
|
16
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
17
|
+
import { kindOfFailure } from './failure.js';
|
|
18
|
+
import { createGitHubClient } from './github-client.js';
|
|
19
|
+
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
20
|
+
import { requireRepositoryMatch, resolveCurrentRepository } from './repository-match.js';
|
|
21
|
+
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
22
|
+
import { planWorkTarget, recordWorkTarget } from './work-target.js';
|
|
23
|
+
const START_PATH = ['session', 'start'];
|
|
24
|
+
/**
|
|
25
|
+
A-1. 作業ディレクトリの git remote のリポジトリが Issue のリポジトリと違えば、終了コード 2 で止める
|
|
26
|
+
*/
|
|
27
|
+
function rejectCwdRepositoryMismatch(out, owner, repository) {
|
|
28
|
+
const resolved = resolveCurrentRepository(process.cwd());
|
|
29
|
+
if (resolved?.source !== 'current-git')
|
|
30
|
+
return;
|
|
31
|
+
const current = resolved.repository;
|
|
32
|
+
if (current.owner === owner && current.repository === repository)
|
|
33
|
+
return;
|
|
34
|
+
stopWith(out, joinHinted([
|
|
35
|
+
`the repository of the work Issue (${owner}/${repository}) differs from `
|
|
36
|
+
+ `the CWD git remote (${repositoryFullName(current)})\n`
|
|
37
|
+
+ 'move to the worktree of the target repository and run again:\n'
|
|
38
|
+
+ `<project-root>/base/${repository}/ or <project-root>/<wtN>/${repository}/\n`
|
|
39
|
+
+ 'create one with /pecot-w:w-worktree-add only if the repository has no worktree\n'
|
|
40
|
+
+ 'to issue the command on purpose from outside the CWD (for example in a script), ',
|
|
41
|
+
hinted `give ${inputHint(START_PATH, 'allow_cross_repo')}`,
|
|
42
|
+
], ''), 'repo-mismatch', USAGE_EXIT_CODE);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
develop_branch を設定する直し方の行
|
|
46
|
+
*/
|
|
47
|
+
function developBranchGuide(owner, repository) {
|
|
48
|
+
return hinted `set it with: ${commandHint(['project', 'link'], { repo: `${owner}/${repository}`, develop_branch: 'develop' })}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
3. ベースブランチを決める(--base を先に、無ければ設定の develop_branch)
|
|
52
|
+
*/
|
|
53
|
+
function resolveBaseBranch(out, query) {
|
|
54
|
+
const { config, owner, repository, issueNumber, branch, base } = query;
|
|
55
|
+
if (base !== undefined && base !== '')
|
|
56
|
+
return base;
|
|
57
|
+
const developBranch = findRepository(config, owner, repository)?.develop_branch;
|
|
58
|
+
if (developBranch === undefined || developBranch === '') {
|
|
59
|
+
const withBase = commandHint(START_PATH, { issue_ref: issuePath(owner, repository, issueNumber), branch, base: 'main' });
|
|
60
|
+
stopWith(out, joinHinted([`develop_branch is not set for ${owner}/${repository}`, developBranchGuide(owner, repository), hinted `or give the base: ${withBase}`]), 'repo-setting-missing');
|
|
61
|
+
}
|
|
62
|
+
return developBranch;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
3.5. 着手の判定を読み、積む先を決める。blocked と読めないときは止める。依存関係を持たない GHES は、warning を出して判定なしで進める
|
|
66
|
+
*/
|
|
67
|
+
async function decideWorkStart(out, client, config, issue) {
|
|
68
|
+
const label = displayReference(issue, issue.repository);
|
|
69
|
+
const warnNotChecked = (reason) => {
|
|
70
|
+
out.warning(`readiness is not checked: ${reason}`);
|
|
71
|
+
};
|
|
72
|
+
const result = await readIssueReadinessIfSupported(client, config, issue, createReadinessCache(), warnNotChecked);
|
|
73
|
+
if (result === undefined)
|
|
74
|
+
return { kind: 'start' };
|
|
75
|
+
if (result.kind === 'unreadable') {
|
|
76
|
+
if (result.snapshot === undefined)
|
|
77
|
+
return stopWith(out, `could not read blocked-by of ${label}: ${result.reason}`, 'dependency-unreadable');
|
|
78
|
+
const isUnset = result.snapshot.developmentBranch === undefined || result.snapshot.developmentBranch === '';
|
|
79
|
+
const guide = isUnset ? [developBranchGuide(issue.repository.owner, issue.repository.repository)] : [];
|
|
80
|
+
return stopWith(out, joinHinted([`could not judge readiness of ${label}: ${result.reason}`, ...guide]), 'dependency-unreadable');
|
|
81
|
+
}
|
|
82
|
+
const decision = decideStart(result.readiness, result.prerequisites, issue);
|
|
83
|
+
return decision.kind === 'blocked' ? stopWith(out, decision.message, 'not-ready', USAGE_EXIT_CODE) : decision;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
A-2. .pecot-active が別の OPEN な Issue を指していれば、終了コード 2 で止める
|
|
87
|
+
*/
|
|
88
|
+
async function guardActiveOverwrite(out, client, issueReference) {
|
|
89
|
+
const existing = readFlag(FLAG_PECOT_ACTIVE) ?? '';
|
|
90
|
+
if (existing === '' || existing === issueReference)
|
|
91
|
+
return;
|
|
92
|
+
let existingReference;
|
|
93
|
+
try {
|
|
94
|
+
existingReference = parseIssueReference(existing);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (!(error instanceof ReferenceParseError))
|
|
98
|
+
throw error;
|
|
99
|
+
out.warning(`the content of .pecot-active (${pythonStringRepr(existing)}) is malformed; overwriting it`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const { repository, number } = existingReference;
|
|
103
|
+
const { state } = await client.getIssueSlim(repository.owner, repository.repository, number);
|
|
104
|
+
if (state === 'OPEN') {
|
|
105
|
+
stopWith(out, joinHinted([
|
|
106
|
+
`this worktree is already working on another Issue (${existing}, OPEN)\n`
|
|
107
|
+
+ 'overwriting .pecot-active could mix up the tasks\n'
|
|
108
|
+
+ 'finish the other Issue first, or create another worktree with '
|
|
109
|
+
+ '/pecot-w:w-worktree-add and run /pecot-w:w-active again in its session',
|
|
110
|
+
hinted `if it is stale and you want to overwrite it on purpose, give ${inputHint(START_PATH, 'force_overwrite_active')}`,
|
|
111
|
+
]), 'guard-blocked', USAGE_EXIT_CODE);
|
|
112
|
+
}
|
|
113
|
+
out.warning(state === 'CLOSED'
|
|
114
|
+
? `.pecot-active points to closed Issue ${existing}; overwriting it`
|
|
115
|
+
: `the state of ${existing} in .pecot-active is unexpected (${pythonStringRepr(state)}); overwriting it`);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
7.5. プロジェクトアイテムのステータスを active にする(失敗は warning にとどめる)
|
|
119
|
+
*/
|
|
120
|
+
async function setIssueStatusActive(out, client, config, issue) {
|
|
121
|
+
const { owner, repository, number } = issue;
|
|
122
|
+
const target = `Issue ${issuePath(owner, repository, number)} status active`;
|
|
123
|
+
try {
|
|
124
|
+
const itemId = await client.getItemIdByIssue(config.project.id, owner, repository, number);
|
|
125
|
+
if (itemId === undefined || itemId === '') {
|
|
126
|
+
out.warning(`could not set ${target}: the Issue is not on the project board`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const fieldId = getFieldId(config, 'workflow');
|
|
130
|
+
const optionId = getOptionId(config, 'workflow', 'active');
|
|
131
|
+
if (fieldId === undefined || fieldId === '' || optionId === undefined || optionId === '') {
|
|
132
|
+
out.warning(`could not set ${target}: the workflow status field has no 'active' option`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
await client.updateProjectItemField(config.project.id, itemId, fieldId, optionId);
|
|
136
|
+
out.done({ verb: 'set', target });
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
// ブランチは作成済みなので、ステータスの失敗でコマンドは止めない
|
|
140
|
+
if (!(error instanceof GitHubAPIError))
|
|
141
|
+
throw error;
|
|
142
|
+
out.warning(`could not set ${target}: ${error.message}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const SESSION_START_OUTPUT = z.strictObject({
|
|
146
|
+
branch: z.string().describe('Branch created (or to be created), with the Issue number appended'),
|
|
147
|
+
repository: z.string().describe('Repository of the branch (owner/repo)'),
|
|
148
|
+
base: z.string().describe('Base branch the branch starts from'),
|
|
149
|
+
stackedOn: z.int().optional().describe('Issue number whose branch this one is stacked on (omitted when not stacked)'),
|
|
150
|
+
issue: z.string().describe('Work Issue (owner/repo/N)'),
|
|
151
|
+
workDirectory: z.string().optional().describe('Absolute path of the work directory (omitted on dry_run or when it could not be created)'),
|
|
152
|
+
dryRun: DRY_RUN_FIELD,
|
|
153
|
+
});
|
|
154
|
+
const sessionStartCommand = defineCommand({
|
|
155
|
+
path: START_PATH,
|
|
156
|
+
description: 'Create a branch linked to an Issue (shown in the Development section of the Issue)',
|
|
157
|
+
input: z.strictObject({
|
|
158
|
+
issue_ref: z.string().describe('Issue reference (owner/repo/123)'),
|
|
159
|
+
branch: z.string().describe('Name of the branch to create'),
|
|
160
|
+
base: z.string().optional().describe('Base branch (default: chosen by readiness, else develop_branch from the config)'),
|
|
161
|
+
checkout: z.boolean().default(true).describe('Kept for compatibility; has no effect'),
|
|
162
|
+
allow_cross_repo: z.boolean().default(false).describe('Allow the CWD repository to differ from the Issue ref (for scripts and runs outside the CWD)'),
|
|
163
|
+
force_overwrite_active: z.boolean().default(false).describe('Disable the .pecot-active overwrite guard (when sure it is stale)'),
|
|
164
|
+
dry_run: z.boolean().default(false).describe('Show what would be created and recorded without writing anything'),
|
|
165
|
+
}),
|
|
166
|
+
output: SESSION_START_OUTPUT,
|
|
167
|
+
positional: ['issue_ref', 'branch'],
|
|
168
|
+
shortFlags: { base: '-b', allow_cross_repo: '-X', force_overwrite_active: '-F', dry_run: '-n' },
|
|
169
|
+
negations: { checkout: '--no-checkout' },
|
|
170
|
+
interactive: false,
|
|
171
|
+
run: async (input, io) => {
|
|
172
|
+
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
173
|
+
const out = createOutput(input.dry_run, io);
|
|
174
|
+
// 1. 設定取得
|
|
175
|
+
const config = requireActiveConfig(out);
|
|
176
|
+
// 2. issue_ref をパース(フル形式必須、基準リポは渡さない)
|
|
177
|
+
let issue;
|
|
178
|
+
try {
|
|
179
|
+
issue = parseIssueReference(input.issue_ref);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
if (!(error instanceof ReferenceParseError))
|
|
183
|
+
throw error;
|
|
184
|
+
return stopWith(out, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
185
|
+
}
|
|
186
|
+
const { owner, repository } = issue.repository;
|
|
187
|
+
const issueNumber = issue.number;
|
|
188
|
+
// A-1. 作業ディレクトリと Issue ref のリポジトリの整合チェック
|
|
189
|
+
if (!input.allow_cross_repo)
|
|
190
|
+
rejectCwdRepositoryMismatch(out, owner, repository);
|
|
191
|
+
const finalBranchName = `${input.branch}/${String(issueNumber)}`;
|
|
192
|
+
try {
|
|
193
|
+
const client = createGitHubClient(out, config.host);
|
|
194
|
+
// A-2. .pecot-active 上書きガード
|
|
195
|
+
if (!input.force_overwrite_active)
|
|
196
|
+
await guardActiveOverwrite(out, client, issuePath(owner, repository, issueNumber));
|
|
197
|
+
// 4. リポジトリがプロジェクトに含まれているか確認
|
|
198
|
+
if (!await isRepositoryInProject(config, owner, repository, client)) {
|
|
199
|
+
stopWith(out, `${owner}/${repository} is not in the project`, 'repo-not-in-project');
|
|
200
|
+
}
|
|
201
|
+
// 4.5. 着手の判定で base を選ぶ。--base は積む先と比べる
|
|
202
|
+
const decision = await decideWorkStart(out, client, config, issue);
|
|
203
|
+
const mismatch = describeBaseMismatch(input.base, decision, issue);
|
|
204
|
+
if (mismatch !== undefined)
|
|
205
|
+
stopWith(out, mismatch, 'invalid-input', USAGE_EXIT_CODE);
|
|
206
|
+
// 3. ベースブランチ決定(積まないときだけ、--base か設定の develop_branch を求める)
|
|
207
|
+
const baseBranch = decision.kind === 'stack' ? decision.branch : resolveBaseBranch(out, { config, owner, repository, issueNumber, branch: input.branch, base: input.base });
|
|
208
|
+
// 5. Issue Node ID とタイトル取得(タイトルはセッション名用)
|
|
209
|
+
const { id: issueNodeId, title: issueTitle } = await client.getIssueNodeIdAndTitle(owner, repository, issueNumber);
|
|
210
|
+
// 6. ベースブランチの commit SHA 取得
|
|
211
|
+
let baseSha;
|
|
212
|
+
try {
|
|
213
|
+
baseSha = await client.getBranchSha(owner, repository, baseBranch);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (error instanceof GitHubAPIError && decision.kind === 'stack') {
|
|
217
|
+
return stopWith(out, `base branch ${baseBranch} of ${displayReference(decision.issue, issue.repository)} not found: ${error.message}`, 'git-unresolved');
|
|
218
|
+
}
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const stackedNote = decision.kind === 'stack' ? ` (stacked on ${displayReference(decision.issue, issue.repository)})` : '';
|
|
222
|
+
const started = { repository: `${owner}/${repository}`, base: baseBranch, ...decision.kind === 'stack' && { stackedOn: decision.issue.number }, issue: issuePath(owner, repository, issueNumber) };
|
|
223
|
+
if (input.dry_run) {
|
|
224
|
+
out.result({ ...started, branch: finalBranchName });
|
|
225
|
+
out.planned({ verb: 'create', target: `branch ${finalBranchName} in ${owner}/${repository} from ${baseBranch}${stackedNote}` });
|
|
226
|
+
out.planned({ verb: 'set', target: `Issue ${issuePath(owner, repository, issueNumber)} status active` });
|
|
227
|
+
planWorkTarget(out, owner, repository, issueNumber);
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
// 7. リンクブランチ作成(ブランチ名末尾に Issue 番号を自動付与)
|
|
231
|
+
const createdBranch = await client.createLinkedBranch(issueNodeId, baseSha, finalBranchName);
|
|
232
|
+
out.done({ verb: 'create', target: `branch ${createdBranch} in ${owner}/${repository} from ${baseBranch}${stackedNote}` });
|
|
233
|
+
out.result({ ...started, branch: createdBranch });
|
|
234
|
+
// 7.5. プロジェクトアイテムのステータスを active に更新
|
|
235
|
+
await setIssueStatusActive(out, client, config, { owner, repository, number: issueNumber });
|
|
236
|
+
// 9. 作業対象を .pecot-active と .pecot-session-title に保存(hook の自動投稿とセッション名用)
|
|
237
|
+
const recorded = recordWorkTarget(out, owner, repository, issueNumber, issueTitle, {
|
|
238
|
+
base: { branch: baseBranch, sha: baseSha, stackedOn: decision.kind === 'stack' ? decision.issue : undefined },
|
|
239
|
+
});
|
|
240
|
+
if (recorded.workDirectory !== undefined)
|
|
241
|
+
out.result({ workDirectory: recorded.workDirectory });
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
if (!(error instanceof GitHubAPIError))
|
|
246
|
+
throw error;
|
|
247
|
+
return stopWith(out, `could not create branch ${finalBranchName} in ${owner}/${repository}: ${error.message}`, kindOfFailure(error));
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
export const SESSION_START_COMMANDS = [sessionStartCommand];
|
|
252
|
+
//# sourceMappingURL=session-start.js.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { CommandDefinition } from './command-definition.js';
|
|
2
|
+
/**
|
|
3
|
+
session のグループのコマンド。start は session-start.ts、finish は session-finish.ts にある。並びは help の一覧に出る順
|
|
4
|
+
*/
|
|
2
5
|
export declare const SESSION_COMMANDS: readonly CommandDefinition[];
|
|
3
6
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
// session
|
|
1
|
+
// session show・session restore。cli/commands/session.py の移植。
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
4
4
|
import { ConfigError } from '../domain/config.js';
|
|
5
5
|
import { PecotError } from '../domain/errors.js';
|
|
6
|
-
import {
|
|
6
|
+
import { pickLowerPullRequest } from '../domain/pull-request.js';
|
|
7
|
+
import { describeReadiness } from '../domain/readiness.js';
|
|
8
|
+
import { decideRestack, describeNeedsRestack, needsRestack } from '../domain/restack.js';
|
|
9
|
+
import { issueReferenceToCliReference, parseIssueReference, ReferenceParseError } from '../domain/reference-parser.js';
|
|
7
10
|
import { FLAG_PECOT_ACTIVE } from '../domain/state.js';
|
|
11
|
+
import { describeStackBase } from '../domain/work-start.js';
|
|
8
12
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
9
|
-
import { gitCurrentBranch, primaryRemoteRepository } from '../infra/git.js';
|
|
13
|
+
import { gitCurrentBranch, primaryRemoteName, primaryRemoteRepository, remoteBranchHead } from '../infra/git.js';
|
|
10
14
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
11
|
-
import { hasFlag, readFlag } from '../infra/state-store.js';
|
|
15
|
+
import { hasFlag, readBaseRecord, readFlag } from '../infra/state-store.js';
|
|
12
16
|
import { defineCommand } from './command-definition.js';
|
|
13
17
|
import { FAILURE_EXIT_CODE } from './failure.js';
|
|
18
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
14
19
|
import { stopWith } from './command-stop.js';
|
|
15
20
|
import { directorySchema } from './directory-option.js';
|
|
16
21
|
import { createGitHubClient } from './github-client.js';
|
|
17
|
-
import {
|
|
22
|
+
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
23
|
+
import { issuePath } from './issue-shared.js';
|
|
24
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
25
|
+
import { SESSION_FINISH_COMMANDS } from './session-finish.js';
|
|
26
|
+
import { SESSION_START_COMMANDS } from './session-start.js';
|
|
18
27
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
19
|
-
import { recordWorkTarget } from './work-target.js';
|
|
28
|
+
import { planWorkTarget, recordWorkTarget } from './work-target.js';
|
|
20
29
|
const ALL_FLAGS = [FLAG_PECOT_ACTIVE];
|
|
21
30
|
function collectFlagStatuses() {
|
|
22
31
|
return ALL_FLAGS.map((name) => {
|
|
@@ -24,45 +33,160 @@ function collectFlagStatuses() {
|
|
|
24
33
|
return { name, isSet, content: isSet ? readFlag(name) ?? '' : '' };
|
|
25
34
|
});
|
|
26
35
|
}
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
const FLAG_DATA = z.strictObject({
|
|
37
|
+
name: z.string().describe('Name of the session flag'),
|
|
38
|
+
isSet: z.boolean().describe('Whether the flag is set'),
|
|
39
|
+
content: z.string().describe('Content of the flag (empty when unset)'),
|
|
40
|
+
});
|
|
41
|
+
const ACTIVE_ISSUE_DATA = z.strictObject({
|
|
42
|
+
reference: z.string().describe('Issue in .pecot-active (owner/repo/N)'),
|
|
43
|
+
title: z.string().describe('Title of the Issue'),
|
|
44
|
+
state: z.string().describe('State of the Issue (OPEN or CLOSED)'),
|
|
45
|
+
});
|
|
46
|
+
const BASE_PULL_REQUEST_DATA = z.strictObject({
|
|
47
|
+
number: z.int().describe('PR number'),
|
|
48
|
+
state: z.string().describe('State of the PR'),
|
|
49
|
+
});
|
|
50
|
+
const STACK_DATA = z.strictObject({
|
|
51
|
+
branch: z.string().describe('Base branch the work branch is stacked on'),
|
|
52
|
+
stackedOn: z.string().describe('Issue stacked on (owner/repo/N)'),
|
|
53
|
+
pullRequest: BASE_PULL_REQUEST_DATA.optional().describe('PR of the base branch (omitted when there is none or it cannot be read)'),
|
|
54
|
+
needsRestack: z.boolean().optional().describe('Whether the branch needs pr restack: the base branch moved or its PR is merged (omitted when it cannot be decided)'),
|
|
55
|
+
readiness: z.string().optional().describe('Readiness of the active Issue (only when blocked)'),
|
|
56
|
+
});
|
|
57
|
+
const STACKED_ABOVE_DATA = z.strictObject({
|
|
58
|
+
number: z.int().describe('PR number'),
|
|
59
|
+
branch: z.string().describe('Head branch of the PR'),
|
|
60
|
+
});
|
|
61
|
+
const SESSION_SHOW_OUTPUT = z.strictObject({
|
|
62
|
+
branch: z.string().optional().describe('Current branch (omitted when it cannot be read)'),
|
|
63
|
+
repository: z.string().optional().describe('Repository of the git remote (owner/repo; omitted when it cannot be read)'),
|
|
64
|
+
inferredIssue: z.int().optional().describe('Issue number inferred from the branch name (omitted when none)'),
|
|
65
|
+
flags: z.array(FLAG_DATA).describe('Session flags'),
|
|
66
|
+
activeIssue: ACTIVE_ISSUE_DATA.optional().describe('Issue in .pecot-active as read from GitHub (omitted when unset or unreadable)'),
|
|
67
|
+
stack: STACK_DATA.optional().describe('Base the work was stacked on (omitted when not stacked)'),
|
|
68
|
+
stackedAbove: z.array(STACKED_ABOVE_DATA).optional().describe('Open PRs whose base is the current branch (omitted when there are none or they cannot be read)'),
|
|
69
|
+
});
|
|
70
|
+
// .pecot-active の Issue を GitHub から読んで、Markdown の行にする。読めなければ warning だけ出して undefined にする
|
|
71
|
+
async function readActiveIssue(statuses, output) {
|
|
29
72
|
const active = statuses.find(status => status.name === FLAG_PECOT_ACTIVE && status.isSet && status.content !== '');
|
|
30
73
|
if (active === undefined)
|
|
31
|
-
return
|
|
74
|
+
return undefined;
|
|
32
75
|
let reference;
|
|
33
76
|
try {
|
|
34
77
|
reference = parseIssueReference(active.content);
|
|
35
78
|
}
|
|
36
79
|
catch (error) {
|
|
37
80
|
if (error instanceof ReferenceParseError)
|
|
38
|
-
return
|
|
81
|
+
return undefined;
|
|
39
82
|
throw error;
|
|
40
83
|
}
|
|
41
84
|
let issue;
|
|
85
|
+
let config;
|
|
86
|
+
let client;
|
|
42
87
|
try {
|
|
43
|
-
|
|
88
|
+
config = loadActiveConfig();
|
|
44
89
|
if (config === undefined) {
|
|
45
90
|
output.warning('cannot read the active Issue: no active project');
|
|
46
|
-
return
|
|
91
|
+
return undefined;
|
|
47
92
|
}
|
|
48
|
-
|
|
93
|
+
client = createGitHubClient(output, config.host);
|
|
94
|
+
issue = await client.getIssueSlim(reference.repository.owner, reference.repository.repository, reference.number, 0);
|
|
49
95
|
}
|
|
50
96
|
catch (error) {
|
|
51
97
|
if (error instanceof ConfigError || error instanceof GitHubAPIError) {
|
|
52
98
|
output.warning(`cannot read the active Issue: ${error.message}`);
|
|
53
|
-
return
|
|
99
|
+
return undefined;
|
|
54
100
|
}
|
|
55
101
|
throw error;
|
|
56
102
|
}
|
|
57
103
|
const lines = ['', '## Active Issue', '', `#${String(issue.number)} ${issue.title} (${issue.state})`];
|
|
58
104
|
if (issue.body !== '')
|
|
59
105
|
lines.push('', issue.body);
|
|
60
|
-
return lines;
|
|
106
|
+
return { reference, config, client, lines, data: { reference: issueReferenceToCliReference(reference), title: issue.title, state: issue.state } };
|
|
107
|
+
}
|
|
108
|
+
// 積んで着手した作業ディレクトリの `## Stack` の節。積んでいなければ空
|
|
109
|
+
async function stackSection(active, origin, directory, output) {
|
|
110
|
+
const reading = readBaseRecord();
|
|
111
|
+
if (reading.kind === 'malformed')
|
|
112
|
+
output.warning(`.pecot-base is malformed: ${reading.content}`);
|
|
113
|
+
if (reading.kind !== 'stacked')
|
|
114
|
+
return { lines: [] };
|
|
115
|
+
const { record, stackedOn } = reading;
|
|
116
|
+
// ブランチは作業ディレクトリのリポにあるので、PR もそこで探す(pr restack と同じ)
|
|
117
|
+
const { owner, repository } = origin ?? stackedOn.repository;
|
|
118
|
+
let pullRequest;
|
|
119
|
+
let restack;
|
|
120
|
+
try {
|
|
121
|
+
const found = await active.client.listPullRequestsByHead(owner, repository, record.branch);
|
|
122
|
+
pullRequest = pickLowerPullRequest(found.pullRequests);
|
|
123
|
+
restack = restackDecision(reading, pullRequest, directory);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (!(error instanceof GitHubAPIError))
|
|
127
|
+
throw error;
|
|
128
|
+
output.warning(`cannot read the PR of the base branch: ${error.message}`);
|
|
129
|
+
pullRequest = 'unknown';
|
|
130
|
+
}
|
|
131
|
+
const readiness = await blockedReadiness(active, output);
|
|
132
|
+
const needsLine = restack === undefined ? undefined : describeNeedsRestack(restack);
|
|
133
|
+
const needed = restack === undefined ? undefined : needsRestack(restack);
|
|
134
|
+
return {
|
|
135
|
+
lines: ['', '## Stack', describeStackBase(record.branch, stackedOn, pullRequest), ...needsLine === undefined ? [] : [needsLine], ...readiness === undefined ? [] : [`- readiness: ${readiness}`]],
|
|
136
|
+
data: {
|
|
137
|
+
branch: record.branch,
|
|
138
|
+
stackedOn: issueReferenceToCliReference(stackedOn),
|
|
139
|
+
...pullRequest !== 'unknown' && pullRequest !== undefined && { pullRequest: { number: pullRequest.number, state: pullRequest.state } },
|
|
140
|
+
...needed !== undefined && { needsRestack: needed },
|
|
141
|
+
...readiness !== undefined && { readiness },
|
|
142
|
+
},
|
|
143
|
+
};
|
|
61
144
|
}
|
|
62
|
-
|
|
63
|
-
|
|
145
|
+
// 載せ直す先の判断。fetch せずに、下の段の remote の先頭を尋ねて記録と比べる。remote に届かなければ undefined
|
|
146
|
+
function restackDecision(reading, lowerPullRequest, directory) {
|
|
147
|
+
const remote = primaryRemoteName(directory);
|
|
148
|
+
if (remote === undefined)
|
|
149
|
+
return undefined;
|
|
150
|
+
const lowerHead = remoteBranchHead(directory, remote, reading.record.branch);
|
|
151
|
+
return lowerHead.isReachable ? decideRestack({ reading, developBranch: '', lowerPullRequest, lowerHead: lowerHead.sha }) : undefined;
|
|
152
|
+
}
|
|
153
|
+
// 今のブランチを base にした、同じリポの開いている PR。読めなければ warning を出して undefined にする
|
|
154
|
+
async function readStackedAbove(active, origin, branch, output) {
|
|
155
|
+
try {
|
|
156
|
+
const found = await active.client.listPullRequestsByBase(origin.owner, origin.repository, branch);
|
|
157
|
+
return found.pullRequests.map(pullRequest => ({ number: pullRequest.number, branch: pullRequest.headRefName }));
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (!(error instanceof GitHubAPIError))
|
|
161
|
+
throw error;
|
|
162
|
+
output.warning(`cannot read the PRs stacked above: ${error.message}`);
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// 積んだ記録の節に上の段の行を足す。積んだ記録が無くても、上の段があれば節を出す
|
|
167
|
+
function withStackedAbove(stackLines, above) {
|
|
168
|
+
if (above === undefined || above.length === 0)
|
|
169
|
+
return stackLines;
|
|
170
|
+
const lines = above.map(pullRequest => `- stacked above: PR #${String(pullRequest.number)} (${pullRequest.branch})`);
|
|
171
|
+
return stackLines.length === 0 ? ['', '## Stack', ...lines] : [...stackLines, ...lines];
|
|
172
|
+
}
|
|
173
|
+
// 着手中の Issue の判定が blocked のときだけ、判定の文を返す
|
|
174
|
+
async function blockedReadiness(active, output) {
|
|
175
|
+
const result = await readIssueReadinessIfSupported(active.client, active.config, active.reference, createReadinessCache());
|
|
176
|
+
if (result === undefined)
|
|
177
|
+
return undefined;
|
|
178
|
+
if (result.kind === 'unreadable') {
|
|
179
|
+
output.warning(`cannot judge readiness of the active Issue: ${result.reason}`);
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const { readiness } = result;
|
|
183
|
+
return readiness?.kind === 'blocked' ? describeReadiness(readiness, result.prerequisites, active.reference.repository) : undefined;
|
|
184
|
+
}
|
|
185
|
+
const SESSION_SHOW = defineCommand({
|
|
186
|
+
path: ['session', 'show'],
|
|
64
187
|
description: 'Show the session flag state, branch information, and inferred Issue',
|
|
65
188
|
input: z.object({ directory: directorySchema }),
|
|
189
|
+
output: SESSION_SHOW_OUTPUT,
|
|
66
190
|
positional: [],
|
|
67
191
|
shortFlags: { directory: '-D' },
|
|
68
192
|
interactive: false,
|
|
@@ -72,6 +196,18 @@ const STATUS = defineCommand({
|
|
|
72
196
|
const origin = primaryRemoteRepository(input.directory);
|
|
73
197
|
const issueNumber = branch === undefined ? undefined : extractIssueNumberFromBranch(branch);
|
|
74
198
|
const statuses = collectFlagStatuses();
|
|
199
|
+
const active = await readActiveIssue(statuses, output);
|
|
200
|
+
const stack = active === undefined ? { lines: [] } : await stackSection(active, origin, input.directory, output);
|
|
201
|
+
const above = active === undefined || origin === undefined || branch === undefined ? undefined : await readStackedAbove(active, origin, branch, output);
|
|
202
|
+
output.result({
|
|
203
|
+
...branch !== undefined && { branch },
|
|
204
|
+
...origin !== undefined && { repository: `${origin.owner}/${origin.repository}` },
|
|
205
|
+
...issueNumber !== undefined && { inferredIssue: issueNumber },
|
|
206
|
+
flags: statuses.map(status => ({ ...status })),
|
|
207
|
+
...active !== undefined && { activeIssue: active.data },
|
|
208
|
+
...stack.data !== undefined && { stack: stack.data },
|
|
209
|
+
...above !== undefined && above.length > 0 && { stackedAbove: above },
|
|
210
|
+
});
|
|
75
211
|
const lines = [
|
|
76
212
|
'# Session status',
|
|
77
213
|
'',
|
|
@@ -82,7 +218,8 @@ const STATUS = defineCommand({
|
|
|
82
218
|
'| Flag | State | Content |',
|
|
83
219
|
'|------|-------|---------|',
|
|
84
220
|
...statuses.map(status => `| ${status.name} | ${status.isSet ? 'set' : 'unset'} | ${status.content} |`),
|
|
85
|
-
...
|
|
221
|
+
...active?.lines ?? [],
|
|
222
|
+
...withStackedAbove(stack.lines, above),
|
|
86
223
|
];
|
|
87
224
|
output.data(lines.join('\n'));
|
|
88
225
|
return 0;
|
|
@@ -105,21 +242,21 @@ async function fetchIssueTitle(owner, repository, number, output) {
|
|
|
105
242
|
throw error;
|
|
106
243
|
}
|
|
107
244
|
}
|
|
108
|
-
//
|
|
245
|
+
// issue_ref が無いときの、ブランチ名と remote からの推定。決められなければ error を出して終了コード 1
|
|
109
246
|
function inferTarget(directory, output) {
|
|
110
247
|
const branch = gitCurrentBranch(directory);
|
|
111
248
|
if (branch === undefined) {
|
|
112
|
-
return stopWith(output, 'cannot read the branch name', FAILURE_EXIT_CODE);
|
|
249
|
+
return stopWith(output, 'cannot read the branch name', 'git-unresolved', FAILURE_EXIT_CODE);
|
|
113
250
|
}
|
|
114
251
|
const number = extractIssueNumberFromBranch(branch);
|
|
115
252
|
if (number === undefined) {
|
|
116
|
-
return stopWith(output, `cannot infer the Issue number from the branch name: ${branch}\nrun:
|
|
253
|
+
return stopWith(output, hinted `cannot infer the Issue number from the branch name: ${branch}\nrun: ${commandHint(['session', 'restore'], { issue_ref: placeholder('owner/repo/N') })}`, 'git-unresolved', FAILURE_EXIT_CODE);
|
|
117
254
|
}
|
|
118
255
|
const origin = primaryRemoteRepository(directory);
|
|
119
256
|
const message = 'cannot read the repository information';
|
|
120
|
-
return origin === undefined ? stopWith(output, message, FAILURE_EXIT_CODE) : { owner: origin.owner, repository: origin.repository, number };
|
|
257
|
+
return origin === undefined ? stopWith(output, message, 'git-unresolved', FAILURE_EXIT_CODE) : { owner: origin.owner, repository: origin.repository, number };
|
|
121
258
|
}
|
|
122
|
-
//
|
|
259
|
+
// issue_ref の参照を分ける。形が誤っていれば error を出して終了コード 2
|
|
123
260
|
function parseTarget(issue, output) {
|
|
124
261
|
try {
|
|
125
262
|
const reference = parseIssueReference(issue);
|
|
@@ -128,22 +265,29 @@ function parseTarget(issue, output) {
|
|
|
128
265
|
catch (error) {
|
|
129
266
|
if (!(error instanceof ReferenceParseError))
|
|
130
267
|
throw error;
|
|
131
|
-
return stopWith(output, error.message, USAGE_EXIT_CODE);
|
|
268
|
+
return stopWith(output, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
132
269
|
}
|
|
133
270
|
}
|
|
134
|
-
const
|
|
271
|
+
const SESSION_RESTORE_OUTPUT = z.strictObject({
|
|
272
|
+
issue: z.string().describe('Work Issue recorded (owner/repo/N)'),
|
|
273
|
+
workDirectory: z.string().optional().describe('Absolute path of the work directory (omitted on dry_run or when it could not be created)'),
|
|
274
|
+
dryRun: DRY_RUN_FIELD,
|
|
275
|
+
});
|
|
276
|
+
const SESSION_RESTORE = defineCommand({
|
|
135
277
|
path: ['session', 'restore'],
|
|
136
278
|
description: 'Restore lost session flags (such as .pecot-active) from the branch information',
|
|
137
279
|
input: z.object({
|
|
138
|
-
|
|
280
|
+
issue_ref: z.string().optional().describe('Issue reference (owner/repo/number)'),
|
|
139
281
|
directory: directorySchema,
|
|
282
|
+
dry_run: z.boolean().default(false).describe('Show what would be recorded without writing anything'),
|
|
140
283
|
}),
|
|
284
|
+
output: SESSION_RESTORE_OUTPUT,
|
|
141
285
|
positional: [],
|
|
142
|
-
shortFlags: {
|
|
286
|
+
shortFlags: { issue_ref: '-i', directory: '-D', dry_run: '-n' },
|
|
143
287
|
interactive: false,
|
|
144
288
|
run: async (input, io) => {
|
|
145
|
-
const output = createOutput(
|
|
146
|
-
const target = input.
|
|
289
|
+
const output = createOutput(input.dry_run, io);
|
|
290
|
+
const target = input.issue_ref === undefined ? inferTarget(input.directory, output) : parseTarget(input.issue_ref, output);
|
|
147
291
|
let title;
|
|
148
292
|
try {
|
|
149
293
|
title = await fetchIssueTitle(target.owner, target.repository, target.number, output);
|
|
@@ -151,11 +295,21 @@ const RESTORE = defineCommand({
|
|
|
151
295
|
catch (error) {
|
|
152
296
|
if (!(error instanceof ConfigError))
|
|
153
297
|
throw error;
|
|
154
|
-
return stopWith(output, error.message, FAILURE_EXIT_CODE);
|
|
298
|
+
return stopWith(output, error.message, 'config-invalid', FAILURE_EXIT_CODE);
|
|
299
|
+
}
|
|
300
|
+
const issue = issuePath(target.owner, target.repository, target.number);
|
|
301
|
+
if (input.dry_run) {
|
|
302
|
+
output.result({ issue });
|
|
303
|
+
planWorkTarget(output, target.owner, target.repository, target.number);
|
|
304
|
+
return 0;
|
|
155
305
|
}
|
|
156
|
-
recordWorkTarget(output, target.owner, target.repository, target.number, title, { failWithExit: true });
|
|
306
|
+
const recorded = recordWorkTarget(output, target.owner, target.repository, target.number, title, { failWithExit: true });
|
|
307
|
+
output.result({ issue, ...recorded.workDirectory !== undefined && { workDirectory: recorded.workDirectory } });
|
|
157
308
|
return 0;
|
|
158
309
|
},
|
|
159
310
|
});
|
|
160
|
-
|
|
311
|
+
/**
|
|
312
|
+
session のグループのコマンド。start は session-start.ts、finish は session-finish.ts にある。並びは help の一覧に出る順
|
|
313
|
+
*/
|
|
314
|
+
export const SESSION_COMMANDS = [...SESSION_START_COMMANDS, SESSION_SHOW, SESSION_RESTORE, ...SESSION_FINISH_COMMANDS];
|
|
161
315
|
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandIo } from './command-definition.js';
|
|
2
|
+
import type { TrackerSyncInput } from './tracker-sync.js';
|
|
3
|
+
/**
|
|
4
|
+
tracker sync の source dependabot の本体。Tracker の Dependabot PRs waiting for a human decision の一覧を書き直す
|
|
5
|
+
*/
|
|
6
|
+
export declare function runDependabotSync(input: Readonly<TrackerSyncInput>, io: CommandIo): Promise<0>;
|
|
7
|
+
//# sourceMappingURL=tracker-sync-dependabot.d.ts.map
|