@pecot/workflow-mcp 0.0.0-stage → 6.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 +8 -0
- package/LICENSE +21 -0
- package/README.md +184 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +227 -0
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +59 -0
- package/cli/dist/commands/board-judgment.d.ts +60 -0
- package/cli/dist/commands/board-judgment.js +144 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +57 -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 +72 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +111 -0
- package/cli/dist/commands/board-view.d.ts +62 -0
- package/cli/dist/commands/board-view.js +191 -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 +100 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +270 -0
- package/cli/dist/commands/command-definition.d.ts +150 -0
- package/cli/dist/commands/command-definition.js +105 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- 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 +21 -0
- package/cli/dist/commands/command-stop.js +31 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +34 -0
- package/cli/dist/commands/failure.d.ts +19 -0
- package/cli/dist/commands/failure.js +59 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +16 -0
- package/cli/dist/commands/github-client.js +33 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +50 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +71 -0
- package/cli/dist/commands/issue-board.js +122 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +215 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +786 -0
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +282 -0
- package/cli/dist/commands/issue-readiness.d.ts +94 -0
- package/cli/dist/commands/issue-readiness.js +218 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +115 -0
- package/cli/dist/commands/issue-shared.d.ts +172 -0
- package/cli/dist/commands/issue-shared.js +426 -0
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +169 -0
- package/cli/dist/commands/issue.d.ts +3 -0
- package/cli/dist/commands/issue.js +13 -0
- package/cli/dist/commands/names.d.ts +42 -0
- package/cli/dist/commands/names.js +78 -0
- package/cli/dist/commands/output.d.ts +90 -0
- package/cli/dist/commands/output.js +194 -0
- package/cli/dist/commands/pr-waiting.d.ts +20 -0
- package/cli/dist/commands/pr-waiting.js +106 -0
- package/cli/dist/commands/pr.d.ts +22 -0
- package/cli/dist/commands/pr.js +852 -0
- package/cli/dist/commands/project-sync.d.ts +92 -0
- package/cli/dist/commands/project-sync.js +282 -0
- package/cli/dist/commands/project.d.ts +6 -0
- package/cli/dist/commands/project.js +714 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +30 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +353 -0
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +34 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +267 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +236 -0
- package/cli/dist/commands/session.d.ts +6 -0
- package/cli/dist/commands/session.js +214 -0
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-security.js +153 -0
- package/cli/dist/commands/tracker-sync.d.ts +65 -0
- package/cli/dist/commands/tracker-sync.js +50 -0
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +18 -0
- package/cli/dist/commands/usage-error.d.ts +51 -0
- package/cli/dist/commands/usage-error.js +78 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +22 -0
- package/cli/dist/commands/work-target.js +82 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +339 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- 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.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- 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 +219 -0
- package/cli/dist/domain/config.js +310 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +24 -0
- package/cli/dist/domain/errors.js +36 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +94 -0
- package/cli/dist/domain/format.js +234 -0
- package/cli/dist/domain/frontmatter.d.ts +137 -0
- package/cli/dist/domain/frontmatter.js +290 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- 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 +143 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +201 -0
- package/cli/dist/domain/pull-request.js +281 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +199 -0
- package/cli/dist/domain/readiness.js +391 -0
- package/cli/dist/domain/reference-parser.d.ts +51 -0
- package/cli/dist/domain/reference-parser.js +123 -0
- package/cli/dist/domain/release.d.ts +53 -0
- package/cli/dist/domain/release.js +65 -0
- package/cli/dist/domain/repository-policy.d.ts +38 -0
- package/cli/dist/domain/repository-policy.js +66 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +122 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +59 -0
- package/cli/dist/domain/state.js +95 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +72 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +53 -0
- package/cli/dist/infra/config-store.js +134 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +86 -0
- package/cli/dist/infra/git.js +145 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +178 -0
- package/cli/dist/infra/github/client.js +579 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +65 -0
- package/cli/dist/infra/github/errors.js +64 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +165 -0
- package/cli/dist/infra/github/issues.js +428 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +143 -0
- package/cli/dist/infra/github/projects.js +384 -0
- package/cli/dist/infra/github/pulls.d.ts +104 -0
- package/cli/dist/infra/github/pulls.js +217 -0
- package/cli/dist/infra/github/queries.d.ts +44 -0
- package/cli/dist/infra/github/queries.js +1031 -0
- package/cli/dist/infra/github/readout.d.ts +22 -0
- package/cli/dist/infra/github/readout.js +167 -0
- package/cli/dist/infra/github/repos.d.ts +86 -0
- package/cli/dist/infra/github/repos.js +168 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +54 -0
- package/cli/dist/infra/state-store.js +130 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +142 -0
- package/cli/dist/infra/worktree-links.js +440 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +185 -0
- package/cli/dist/infra/worktree.js +584 -0
- package/cli/dist/mcp/result.d.ts +61 -0
- package/cli/dist/mcp/result.js +96 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +142 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +195 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +74 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスは検証済みの -D と、main worktree 配下の設定ファイル */
|
|
2
|
+
// worktree add / remove / init / link。4 個とも、本体の前に --repo と git の remote の食い違いを reject で止める。
|
|
3
|
+
import { mkdirSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
7
|
+
import { aggregationRepositoryReference, ConfigError } from '../domain/config.js';
|
|
8
|
+
import { loadActiveConfig } from '../infra/config-store.js';
|
|
9
|
+
import { gitToplevel } from '../infra/git.js';
|
|
10
|
+
import { hasErrorCode, OsError, toOsError } from '../infra/os-error.js';
|
|
11
|
+
import { resolveRealPath, WORKTREE_CONFIG_FILENAME, WORKTREE_IGNORE_FILENAME } from '../infra/paths.js';
|
|
12
|
+
import { createWorktree, detectProjectRoot, ensureDevcontainerEnvironment, findMainWorktree, findWorktreeConfigFile, getWorktreeDirectories, removeWorktree, WorktreeRuntimeError, } from '../infra/worktree.js';
|
|
13
|
+
import { createSymlinksSafe, DEFAULT_WORKTREEIGNORE_CONTENT, decideOverwrite, getDefaultConfig, loadConfig, planLink, saveConfig, WorktreeConfigError, } from '../infra/worktree-links.js';
|
|
14
|
+
import { createOutput, isConfirmed } from './output.js';
|
|
15
|
+
import { defineCommand } from './command-definition.js';
|
|
16
|
+
import { commandHint, hinted, hintedTextOf, inputHint, placeholder } from './command-hint.js';
|
|
17
|
+
import { stopWith } from './command-stop.js';
|
|
18
|
+
import { directorySchema } from './directory-option.js';
|
|
19
|
+
import { requireRepositoryMatch } from './repository-match.js';
|
|
20
|
+
// click の realpath と同じく、解決できない所は字面のまま残して投げない
|
|
21
|
+
function lenientRealPath(value) {
|
|
22
|
+
try {
|
|
23
|
+
return resolveRealPath(value);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!hasErrorCode(error))
|
|
27
|
+
throw error;
|
|
28
|
+
return path.resolve(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const dryRunInput = z.boolean().default(false).describe('Show what would happen without changing anything');
|
|
32
|
+
// WorktreeRuntimeError は最上位の網にかからないので、ここで error の行と終了コード 1 にする
|
|
33
|
+
function reportRuntimeError(out, error) {
|
|
34
|
+
if (!(error instanceof WorktreeRuntimeError))
|
|
35
|
+
throw error;
|
|
36
|
+
return stopWith(out, hintedTextOf(error) ?? error.message, error.failure);
|
|
37
|
+
}
|
|
38
|
+
function countLinkResults(results, out) {
|
|
39
|
+
out.count('symlinks created', results.filter(result => result.action === 'created').length);
|
|
40
|
+
const skipped = results.filter(result => result.action === 'skipped').length;
|
|
41
|
+
if (skipped > 0)
|
|
42
|
+
out.count('symlinks skipped', skipped);
|
|
43
|
+
const failed = results.filter(result => result.action === 'error').length;
|
|
44
|
+
if (failed > 0)
|
|
45
|
+
out.count('symlink errors', failed);
|
|
46
|
+
}
|
|
47
|
+
function countCopyResults(results, out) {
|
|
48
|
+
out.count('files copied', results.filter(result => result.action === 'copied').length);
|
|
49
|
+
const skipped = results.filter(result => result.action === 'skipped').length;
|
|
50
|
+
if (skipped > 0)
|
|
51
|
+
out.count('files skipped', skipped);
|
|
52
|
+
const failed = results.filter(result => result.action === 'error');
|
|
53
|
+
if (failed.length === 0)
|
|
54
|
+
return;
|
|
55
|
+
out.count('copy errors', failed.length);
|
|
56
|
+
for (const result of failed)
|
|
57
|
+
out.warning(`copy ${result.source}: ${result.message}`);
|
|
58
|
+
}
|
|
59
|
+
const worktreeAddInput = z.object({
|
|
60
|
+
directory: directorySchema,
|
|
61
|
+
base: z.string().optional().describe('Base branch (default: the develop_branch of the repository in the active project)'),
|
|
62
|
+
path: z.string().transform(lenientRealPath).optional().describe('Where to create the worktree (default: <project_root>/<auto-numbered>/<repository name>)'),
|
|
63
|
+
no_copy: z.boolean().default(false).describe('Skip copying untracked files'),
|
|
64
|
+
no_link: z.boolean().default(false).describe('Skip creating symlinks'),
|
|
65
|
+
setup: z.string().optional().describe('Command to run after creation'),
|
|
66
|
+
dry_run: dryRunInput,
|
|
67
|
+
allow_existing_branch: z.boolean().default(false).describe('Allow reusing an existing branch even if its upstream differs from develop_branch'),
|
|
68
|
+
});
|
|
69
|
+
const worktreeAddCommand = defineCommand({
|
|
70
|
+
path: ['worktree', 'add'],
|
|
71
|
+
description: 'Create a new worktree',
|
|
72
|
+
input: worktreeAddInput,
|
|
73
|
+
positional: [],
|
|
74
|
+
shortFlags: { directory: '-D' },
|
|
75
|
+
aliases: { allow_existing_branch: '--force' },
|
|
76
|
+
interactive: false,
|
|
77
|
+
run: (input, io) => Promise.resolve(runAdd(input, io)),
|
|
78
|
+
});
|
|
79
|
+
function runAdd(input, io) {
|
|
80
|
+
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
81
|
+
const out = createOutput(input.dry_run, io);
|
|
82
|
+
try {
|
|
83
|
+
ensureDevcontainerEnvironment();
|
|
84
|
+
const result = createWorktree(input.directory, out, {
|
|
85
|
+
baseBranch: input.base,
|
|
86
|
+
path: input.path,
|
|
87
|
+
shouldCopy: !input.no_copy,
|
|
88
|
+
shouldLink: !input.no_link,
|
|
89
|
+
setupCommand: input.setup,
|
|
90
|
+
isDryRun: input.dry_run,
|
|
91
|
+
isExistingBranchAllowed: input.allow_existing_branch,
|
|
92
|
+
});
|
|
93
|
+
const operation = { verb: 'create', target: `worktree ${result.name} at ${result.path} (branch ${result.branch} from ${result.baseBranch})` };
|
|
94
|
+
out.planned(operation);
|
|
95
|
+
out.done(operation);
|
|
96
|
+
out.data(result.path);
|
|
97
|
+
if (result.linkedFiles.length > 0)
|
|
98
|
+
countLinkResults(result.linkedFiles, out);
|
|
99
|
+
if (result.copiedFiles.length > 0)
|
|
100
|
+
countCopyResults(result.copiedFiles, out);
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return reportRuntimeError(out, error);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const worktreeRemoveInput = z.object({
|
|
108
|
+
name: z.string().describe('Name of the worktree to remove (the recorded wtN, the wtN directory, or the branch name)'),
|
|
109
|
+
directory: directorySchema,
|
|
110
|
+
force: z.boolean().default(false).describe('Force removal even if there are changes'),
|
|
111
|
+
keep_branch: z.boolean().default(false).describe('Keep the branch'),
|
|
112
|
+
dry_run: dryRunInput,
|
|
113
|
+
});
|
|
114
|
+
const worktreeRemoveCommand = defineCommand({
|
|
115
|
+
path: ['worktree', 'remove'],
|
|
116
|
+
description: 'Remove a worktree',
|
|
117
|
+
input: worktreeRemoveInput,
|
|
118
|
+
positional: ['name'],
|
|
119
|
+
shortFlags: { directory: '-D', dry_run: '-n' },
|
|
120
|
+
interactive: false,
|
|
121
|
+
run: (input, io) => Promise.resolve(runRemove(input, io)),
|
|
122
|
+
});
|
|
123
|
+
function runRemove(input, io) {
|
|
124
|
+
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
125
|
+
const out = createOutput(input.dry_run, io);
|
|
126
|
+
try {
|
|
127
|
+
ensureDevcontainerEnvironment();
|
|
128
|
+
const branchError = removeWorktree(input.directory, input.name, out, { isForced: input.force, shouldKeepBranch: input.keep_branch, isDryRun: input.dry_run });
|
|
129
|
+
const removed = { verb: 'remove', target: `worktree ${input.name}` };
|
|
130
|
+
out.planned(removed);
|
|
131
|
+
out.done(removed);
|
|
132
|
+
if (input.dry_run) {
|
|
133
|
+
if (!input.keep_branch)
|
|
134
|
+
out.planned({ verb: 'delete', target: `local branch ${input.name}` });
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
if (!input.keep_branch) {
|
|
138
|
+
if (branchError === undefined)
|
|
139
|
+
out.done({ verb: 'delete', target: `local branch ${input.name}` });
|
|
140
|
+
else
|
|
141
|
+
out.warning(`could not delete local branch ${input.name}: ${branchError}`);
|
|
142
|
+
}
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
return reportRuntimeError(out, error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const worktreeInitInput = z.object({ directory: directorySchema, dry_run: dryRunInput });
|
|
150
|
+
const worktreeInitCommand = defineCommand({
|
|
151
|
+
path: ['worktree', 'init'],
|
|
152
|
+
description: 'Create the worktree config files in the main worktree',
|
|
153
|
+
input: worktreeInitInput,
|
|
154
|
+
positional: [],
|
|
155
|
+
shortFlags: { directory: '-D', dry_run: '-n' },
|
|
156
|
+
interactive: false,
|
|
157
|
+
run: (input, io) => Promise.resolve(runInit(input, io)),
|
|
158
|
+
});
|
|
159
|
+
// 共有する 3 つのリンクの向き先は、アクティブなプロジェクトの aggregation_repo。無ければこのリポジトリ
|
|
160
|
+
function sharedLinkTarget(mainWorktree) {
|
|
161
|
+
const config = loadActiveConfig();
|
|
162
|
+
const aggregation = config === undefined ? undefined : aggregationRepositoryReference(config);
|
|
163
|
+
return aggregation === undefined ? path.basename(mainWorktree) : aggregation.repository;
|
|
164
|
+
}
|
|
165
|
+
function writeInitFiles(configFile, ignoreFile, config, out) {
|
|
166
|
+
try {
|
|
167
|
+
saveConfig(config, configFile);
|
|
168
|
+
out.done({ verb: 'create', target: `worktree config ${configFile}` });
|
|
169
|
+
mkdirSync(path.dirname(ignoreFile), { recursive: true });
|
|
170
|
+
writeFileSync(ignoreFile, DEFAULT_WORKTREEIGNORE_CONTENT);
|
|
171
|
+
out.done({ verb: 'create', target: `worktree ignore file ${ignoreFile}` });
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
throw hasErrorCode(error) ? toOsError(error) : error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function runInit(input, io) {
|
|
178
|
+
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
179
|
+
const out = createOutput(input.dry_run, io);
|
|
180
|
+
let mainWorktree;
|
|
181
|
+
try {
|
|
182
|
+
ensureDevcontainerEnvironment();
|
|
183
|
+
mainWorktree = findMainWorktree(input.directory);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
return reportRuntimeError(out, error);
|
|
187
|
+
}
|
|
188
|
+
const configFile = path.join(mainWorktree, WORKTREE_CONFIG_FILENAME);
|
|
189
|
+
const ignoreFile = path.join(mainWorktree, WORKTREE_IGNORE_FILENAME);
|
|
190
|
+
const existing = [configFile, ignoreFile].filter(file => isExistingFile(file));
|
|
191
|
+
if (existing.length > 0)
|
|
192
|
+
stopWith(out, ['worktree config already exists', ...existing].join('\n'), 'already-exists');
|
|
193
|
+
let targetRepository;
|
|
194
|
+
try {
|
|
195
|
+
targetRepository = sharedLinkTarget(mainWorktree);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (!(error instanceof InvalidValueError || error instanceof OsError || error instanceof ConfigError))
|
|
199
|
+
throw error;
|
|
200
|
+
return stopWith(out, `could not read the active config: ${error.message}`, 'config-invalid');
|
|
201
|
+
}
|
|
202
|
+
if (input.dry_run) {
|
|
203
|
+
out.planned({ verb: 'create', target: `worktree config ${configFile}` });
|
|
204
|
+
out.planned({ verb: 'create', target: `worktree ignore file ${ignoreFile}` });
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
writeInitFiles(configFile, ignoreFile, getDefaultConfig(targetRepository, path.basename(mainWorktree)), out);
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
function isMissingPath(error) {
|
|
211
|
+
return hasErrorCode(error) && (error.code === 'ENOENT' || error.code === 'ENOTDIR');
|
|
212
|
+
}
|
|
213
|
+
function isExistingFile(file) {
|
|
214
|
+
try {
|
|
215
|
+
statSync(file);
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (isMissingPath(error))
|
|
220
|
+
return false;
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const worktreeLinkInput = z.object({
|
|
225
|
+
directory: directorySchema,
|
|
226
|
+
force: z.boolean().default(false).describe('Overwrite real files and directories without asking'),
|
|
227
|
+
all: z.boolean().default(false).describe('Apply to all sub-worktrees'),
|
|
228
|
+
dry_run: dryRunInput,
|
|
229
|
+
});
|
|
230
|
+
const worktreeLinkCommand = defineCommand({
|
|
231
|
+
path: ['worktree', 'link'],
|
|
232
|
+
description: 'Apply or update symlinks in existing worktrees',
|
|
233
|
+
input: worktreeLinkInput,
|
|
234
|
+
positional: [],
|
|
235
|
+
shortFlags: { directory: '-D' },
|
|
236
|
+
interactive: true,
|
|
237
|
+
run: (input, io) => Promise.resolve(runLink(input, io)),
|
|
238
|
+
});
|
|
239
|
+
// 対象の worktree。--all はサブの全部(0 個もある)、無ければ -D を含む worktree のルート
|
|
240
|
+
function linkTargets(directory, mainWorktree, isAll) {
|
|
241
|
+
if (isAll)
|
|
242
|
+
return { kind: 'worktrees', directories: getWorktreeDirectories(directory) };
|
|
243
|
+
const resolvedDirectory = resolveRealPath(gitToplevel({ cwd: directory }) ?? directory);
|
|
244
|
+
return resolvedDirectory === resolveRealPath(mainWorktree) ? { kind: 'main-needs-all' } : { kind: 'worktrees', directories: [resolvedDirectory] };
|
|
245
|
+
}
|
|
246
|
+
function skipReason(plan) {
|
|
247
|
+
switch (plan) {
|
|
248
|
+
case 'skip-missing': {
|
|
249
|
+
return 'target does not exist';
|
|
250
|
+
}
|
|
251
|
+
case 'skip-dangling': {
|
|
252
|
+
return 'target is a dangling symlink';
|
|
253
|
+
}
|
|
254
|
+
case 'skip-real-file': {
|
|
255
|
+
return 'a real file exists';
|
|
256
|
+
}
|
|
257
|
+
case 'skip-tracked': {
|
|
258
|
+
return 'tracked by git';
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function plannedOperation(plan, symlinkPath, destination) {
|
|
263
|
+
if (plan === 'create')
|
|
264
|
+
return { verb: 'create', target: `symlink ${symlinkPath} -> ${destination}` };
|
|
265
|
+
if (plan === 'update')
|
|
266
|
+
return { verb: 'update', target: `symlink ${symlinkPath} -> ${destination}` };
|
|
267
|
+
if (plan === 'ask')
|
|
268
|
+
return { verb: 'update', target: `symlink ${symlinkPath} -> ${destination} (real file, asks first)` };
|
|
269
|
+
return { verb: 'skip', target: `symlink ${symlinkPath} (${skipReason(plan)})` };
|
|
270
|
+
}
|
|
271
|
+
function previewLinks(targets, config, projectRoot, options, out) {
|
|
272
|
+
const decision = decideOverwrite({ force: options.force, allWorktrees: options.all });
|
|
273
|
+
for (const target of targets) {
|
|
274
|
+
for (const link of config.links) {
|
|
275
|
+
const destination = path.join(projectRoot, 'base', link.target_repo, link.target_path);
|
|
276
|
+
out.planned(plannedOperation(planLink(link, projectRoot, target, decision), path.join(target, link.path), destination));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 1 つの worktree にリンクを作り、(作った数, 飛ばした数, 失敗した数) を返す
|
|
281
|
+
function applyLinks(target, config, projectRoot, options, io, out) {
|
|
282
|
+
const decision = decideOverwrite({ force: options.force, allWorktrees: options.all });
|
|
283
|
+
const results = createSymlinksSafe(config, projectRoot, target, out, {
|
|
284
|
+
force: decision.force,
|
|
285
|
+
confirm: decision.ask ? symlinkPath => isConfirmed(io, `real file exists: ${symlinkPath}\noverwrite it?`) : undefined,
|
|
286
|
+
});
|
|
287
|
+
const created = results.filter(result => result.action === 'created');
|
|
288
|
+
const skipped = results.filter(result => result.action === 'skipped');
|
|
289
|
+
out.count(`symlinks created in ${target}`, created.length);
|
|
290
|
+
for (const result of skipped)
|
|
291
|
+
out.done({ verb: 'skip', target: `symlink ${result.symlinkPath} (${result.message})` });
|
|
292
|
+
return [created.length, skipped.length, results.filter(result => result.action === 'error').length];
|
|
293
|
+
}
|
|
294
|
+
function runLink(input, io) {
|
|
295
|
+
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
296
|
+
const out = createOutput(input.dry_run, io);
|
|
297
|
+
try {
|
|
298
|
+
ensureDevcontainerEnvironment();
|
|
299
|
+
const configFile = findWorktreeConfigFile(input.directory);
|
|
300
|
+
if (configFile === undefined)
|
|
301
|
+
stopWith(out, hinted `worktree config not found\nrun: ${commandHint(['worktree', 'init'], { directory: placeholder('directory') })}`, 'not-initialized');
|
|
302
|
+
const config = loadConfig(configFile);
|
|
303
|
+
const mainWorktree = findMainWorktree(input.directory);
|
|
304
|
+
const projectRoot = detectProjectRoot(input.directory);
|
|
305
|
+
const resolved = linkTargets(input.directory, mainWorktree, input.all);
|
|
306
|
+
if (resolved.kind === 'main-needs-all')
|
|
307
|
+
stopWith(out, hinted `use ${inputHint(['worktree', 'link'], 'all')} in the main worktree`, 'invalid-input');
|
|
308
|
+
const targets = resolved.directories;
|
|
309
|
+
if (targets.length === 0) {
|
|
310
|
+
out.count('sub-worktrees', 0);
|
|
311
|
+
return 0;
|
|
312
|
+
}
|
|
313
|
+
const options = { force: input.force, all: input.all };
|
|
314
|
+
if (input.dry_run) {
|
|
315
|
+
previewLinks(targets, config, projectRoot, options, out);
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
let [created, skipped, failed] = [0, 0, 0];
|
|
319
|
+
for (const target of targets) {
|
|
320
|
+
const [targetCreated, targetSkipped, targetFailed] = applyLinks(target, config, projectRoot, options, io, out);
|
|
321
|
+
created += targetCreated;
|
|
322
|
+
skipped += targetSkipped;
|
|
323
|
+
failed += targetFailed;
|
|
324
|
+
}
|
|
325
|
+
if (targets.length > 1) {
|
|
326
|
+
out.count('symlinks created', created);
|
|
327
|
+
out.count('symlinks skipped', skipped);
|
|
328
|
+
out.count('symlink errors', failed);
|
|
329
|
+
}
|
|
330
|
+
return 0;
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
if (error instanceof WorktreeConfigError)
|
|
334
|
+
stopWith(out, error.message, 'config-invalid');
|
|
335
|
+
return reportRuntimeError(out, error);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
export const WORKTREE_COMMANDS = [worktreeAddCommand, worktreeRemoveCommand, worktreeInitCommand, worktreeLinkCommand];
|
|
339
|
+
//# sourceMappingURL=worktree.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
API の失敗の message に、応答本文の詳細を添える。GitHubAPIError と DependabotFailure をそのまま渡せる。
|
|
3
|
+
本文が JSON でない(HTML 等)か、添える文が無いときは message のまま返す。
|
|
4
|
+
422 では理由が errors[].message にだけ入ることがある
|
|
5
|
+
*/
|
|
6
|
+
export declare function describeApiError(failure: Readonly<{
|
|
7
|
+
message: string;
|
|
8
|
+
responseBody?: string | undefined;
|
|
9
|
+
}>): string;
|
|
10
|
+
//# sourceMappingURL=api-error-detail.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// API エラーの message に、応答本文 JSON の message と errors[].message を添える。GitHub API の失敗の説明の、唯一の実装。
|
|
2
|
+
import { isJsonObject, jsonField, tryParseJsonText } from './json.js';
|
|
3
|
+
import { pythonStrip } from './python-format.js';
|
|
4
|
+
function textOf(value) {
|
|
5
|
+
return typeof value === 'string' && pythonStrip(value) !== '' ? pythonStrip(value) : undefined;
|
|
6
|
+
}
|
|
7
|
+
function errorMessages(errors) {
|
|
8
|
+
if (!Array.isArray(errors))
|
|
9
|
+
return [];
|
|
10
|
+
const items = errors;
|
|
11
|
+
return items.map(item => textOf(jsonField(item, 'message')));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
API の失敗の message に、応答本文の詳細を添える。GitHubAPIError と DependabotFailure をそのまま渡せる。
|
|
15
|
+
本文が JSON でない(HTML 等)か、添える文が無いときは message のまま返す。
|
|
16
|
+
422 では理由が errors[].message にだけ入ることがある
|
|
17
|
+
*/
|
|
18
|
+
export function describeApiError(failure) {
|
|
19
|
+
const body = tryParseJsonText(failure.responseBody ?? '');
|
|
20
|
+
if (!isJsonObject(body))
|
|
21
|
+
return failure.message;
|
|
22
|
+
const details = [textOf(body['message']), ...errorMessages(body['errors'])].filter(detail => detail !== undefined);
|
|
23
|
+
return details.length === 0 ? failure.message : `${failure.message} ${details.join(' ')}`;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=api-error-detail.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Progression, Wait } from './readiness.js';
|
|
2
|
+
import type { IssueReference } from './reference-parser.js';
|
|
3
|
+
import type { RepositoryReference } from './repository-resolver.js';
|
|
4
|
+
export interface BatchEntry {
|
|
5
|
+
readonly issue: string;
|
|
6
|
+
readonly wait: Wait;
|
|
7
|
+
readonly reason: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface BatchFile {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/**
|
|
12
|
+
代表のキー。suffix があれば suffix、無ければ幹
|
|
13
|
+
*/
|
|
14
|
+
readonly key: string;
|
|
15
|
+
/**
|
|
16
|
+
前提に書けるキーすべて(幹と suffix)
|
|
17
|
+
*/
|
|
18
|
+
readonly keys: readonly string[];
|
|
19
|
+
readonly blockedBy: readonly BatchEntry[];
|
|
20
|
+
}
|
|
21
|
+
export type PrerequisiteTarget = {
|
|
22
|
+
readonly kind: 'file';
|
|
23
|
+
readonly index: number;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'existing';
|
|
26
|
+
readonly reference: IssueReference;
|
|
27
|
+
};
|
|
28
|
+
export interface ResolvedPrerequisite {
|
|
29
|
+
readonly target: PrerequisiteTarget;
|
|
30
|
+
/**
|
|
31
|
+
進め方の判定に使うキー。ファイルは代表のキー、既存の Issue は issueReferenceKey
|
|
32
|
+
*/
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly wait: Wait;
|
|
35
|
+
readonly reason: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
export type BatchResolution = {
|
|
38
|
+
readonly kind: 'ok';
|
|
39
|
+
/**
|
|
40
|
+
ファイルごとの、書いた順の前提
|
|
41
|
+
*/
|
|
42
|
+
readonly prerequisites: readonly (readonly ResolvedPrerequisite[])[];
|
|
43
|
+
/**
|
|
44
|
+
キー(ファイルの代表のキー、既存の Issue は issueReferenceKey)→ 進め方
|
|
45
|
+
*/
|
|
46
|
+
readonly progressions: ReadonlyMap<string, Progression>;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'error';
|
|
49
|
+
readonly message: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
前提を解決して確かめる。順は、知らないキー → 輪 → 後ろのファイル → 同じ相手を 2 回指す前提。
|
|
53
|
+
輪はファイルどうしの前提だけで探す(新しい Issue を前提に持つ既存の Issue は無い)
|
|
54
|
+
*/
|
|
55
|
+
export declare function resolveBatch(files: readonly BatchFile[]): BatchResolution;
|
|
56
|
+
export interface PlanRow {
|
|
57
|
+
readonly file: string;
|
|
58
|
+
/**
|
|
59
|
+
親 Epic の無いファイルは undefined
|
|
60
|
+
*/
|
|
61
|
+
readonly order: number | undefined;
|
|
62
|
+
readonly prerequisites: readonly ResolvedPrerequisite[];
|
|
63
|
+
readonly progression: Progression | undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
`--plan` の表。列は File・Number・Blocked by・Approach。既存の Issue の表記は、一括の先頭のファイルのリポジトリ home を基準にする
|
|
67
|
+
*/
|
|
68
|
+
export declare function formatPlanTable(rows: readonly PlanRow[], home: RepositoryReference): string;
|
|
69
|
+
/**
|
|
70
|
+
積める並び。キーを label で表記に直し、並びが無ければ undefined。並びは `Stackable chains:` の見出しと `- a -> b` の行にする
|
|
71
|
+
*/
|
|
72
|
+
export declare function formatStackableChains(progressions: ReadonlyMap<string, Progression>, label: (key: string) => string): string | undefined;
|
|
73
|
+
//# sourceMappingURL=batch-plan.d.ts.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// 一括投稿の前提の確認と、進め方の表(specs/024 の contracts/cli-commands.md の `pecot issue create`)。I/O を持たない。
|
|
2
|
+
import { displayReference, planProgression, stackChains } from './readiness.js';
|
|
3
|
+
import { issueReferenceKey, issueReferenceToCliReference, parseIssueReference, ReferenceParseError } from './reference-parser.js';
|
|
4
|
+
// `owner/repo/N` の形なら既存の Issue。これに当たらない値は、一括の中のファイルのキーとして探す
|
|
5
|
+
function existingReference(raw) {
|
|
6
|
+
try {
|
|
7
|
+
return parseIssueReference(raw);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error instanceof ReferenceParseError)
|
|
11
|
+
return undefined;
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// 前提の書いたキーを、一括の中のファイルか既存の Issue に解く。どちらでもないキーがあれば、その message を返す
|
|
16
|
+
function resolveTargets(files) {
|
|
17
|
+
const owners = new Map(files.flatMap((file, index) => file.keys.map((key) => [key, { index, key: file.key }])));
|
|
18
|
+
const prerequisites = [];
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
const resolved = [];
|
|
21
|
+
for (const entry of file.blockedBy) {
|
|
22
|
+
const reference = existingReference(entry.issue);
|
|
23
|
+
const owner = owners.get(entry.issue);
|
|
24
|
+
if (reference !== undefined)
|
|
25
|
+
resolved.push({ target: { kind: 'existing', reference }, key: issueReferenceKey(reference), wait: entry.wait, reason: entry.reason });
|
|
26
|
+
else if (owner === undefined)
|
|
27
|
+
return { message: `blocked_by in ${file.name} refers to unknown key ${entry.issue}` };
|
|
28
|
+
else
|
|
29
|
+
resolved.push({ target: { kind: 'file', index: owner.index }, key: owner.key, wait: entry.wait, reason: entry.reason });
|
|
30
|
+
}
|
|
31
|
+
prerequisites.push(resolved);
|
|
32
|
+
}
|
|
33
|
+
return { prerequisites };
|
|
34
|
+
}
|
|
35
|
+
// 前提を書いたキーの表記。ファイルは代表のキー、既存の Issue は `owner/repo/N`
|
|
36
|
+
function targetLabel({ target, key }) {
|
|
37
|
+
return target.kind === 'file' ? key : issueReferenceToCliReference(target.reference);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
前提を解決して確かめる。順は、知らないキー → 輪 → 後ろのファイル → 同じ相手を 2 回指す前提。
|
|
41
|
+
輪はファイルどうしの前提だけで探す(新しい Issue を前提に持つ既存の Issue は無い)
|
|
42
|
+
*/
|
|
43
|
+
export function resolveBatch(files) {
|
|
44
|
+
const resolved = resolveTargets(files);
|
|
45
|
+
if ('message' in resolved)
|
|
46
|
+
return { kind: 'error', message: resolved.message };
|
|
47
|
+
const { prerequisites } = resolved;
|
|
48
|
+
const plan = planProgression(files.map((file, index) => ({
|
|
49
|
+
key: file.key,
|
|
50
|
+
prerequisites: (prerequisites.at(index) ?? []).map(({ key, wait }) => ({ key, wait })),
|
|
51
|
+
})));
|
|
52
|
+
if (plan.kind === 'cycle')
|
|
53
|
+
return { kind: 'error', message: `blocked_by forms a cycle: ${plan.cycle.join(' -> ')}` };
|
|
54
|
+
for (const [index, file] of files.entries()) {
|
|
55
|
+
const own = prerequisites.at(index) ?? [];
|
|
56
|
+
const later = own.find(({ target }) => target.kind === 'file' && target.index > index);
|
|
57
|
+
if (later !== undefined)
|
|
58
|
+
return { kind: 'error', message: `blocked_by in ${file.name} refers to ${targetLabel(later)}, which comes later` };
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
for (const prerequisite of own) {
|
|
61
|
+
if (seen.has(prerequisite.key))
|
|
62
|
+
return { kind: 'error', message: `blocked_by in ${file.name} refers to ${targetLabel(prerequisite)} more than once` };
|
|
63
|
+
seen.add(prerequisite.key);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { kind: 'ok', prerequisites, progressions: plan.progressions };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
進め方の表に出すキーの表記。ファイルは代表のキー、既存の Issue は home と同じリポジトリなら `#N`、別なら `owner/repo#N`
|
|
70
|
+
*/
|
|
71
|
+
function displayTarget({ target, key }, home) {
|
|
72
|
+
return target.kind === 'file' ? key : displayReference(target.reference, home);
|
|
73
|
+
}
|
|
74
|
+
function approachOf(row, labelOf) {
|
|
75
|
+
const { progression } = row;
|
|
76
|
+
switch (progression?.kind) {
|
|
77
|
+
case undefined:
|
|
78
|
+
case 'alone': {
|
|
79
|
+
return 'alone';
|
|
80
|
+
}
|
|
81
|
+
case 'wait-merge': {
|
|
82
|
+
return `wait for merge of ${row.prerequisites.filter(({ wait }) => wait === 'merge').map(prerequisite => labelOf(prerequisite)).join(', ')}`;
|
|
83
|
+
}
|
|
84
|
+
case 'join': {
|
|
85
|
+
return `join (wait for ${row.prerequisites.map(prerequisite => labelOf(prerequisite)).join(', ')})`;
|
|
86
|
+
}
|
|
87
|
+
case 'stack': {
|
|
88
|
+
const on = row.prerequisites.find(({ key }) => key === progression.on);
|
|
89
|
+
return `stack on ${on === undefined ? progression.on : labelOf(on)}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
`--plan` の表。列は File・Number・Blocked by・Approach。既存の Issue の表記は、一括の先頭のファイルのリポジトリ home を基準にする
|
|
95
|
+
*/
|
|
96
|
+
export function formatPlanTable(rows, home) {
|
|
97
|
+
const lines = ['| File | Number | Blocked by | Approach |', '|---|---|---|---|'];
|
|
98
|
+
const labelOf = (prerequisite) => displayTarget(prerequisite, home);
|
|
99
|
+
for (const row of rows) {
|
|
100
|
+
const blockedBy = row.prerequisites.length === 0
|
|
101
|
+
? '-'
|
|
102
|
+
: row.prerequisites.map(prerequisite => `${labelOf(prerequisite)}${prerequisite.wait === 'merge' ? ' (merge)' : ''}`).join(', ');
|
|
103
|
+
lines.push(`| ${row.file} | ${row.order === undefined ? '-' : String(row.order)} | ${blockedBy} | ${approachOf(row, labelOf)} |`);
|
|
104
|
+
}
|
|
105
|
+
return lines.join('\n');
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
積める並び。キーを label で表記に直し、並びが無ければ undefined。並びは `Stackable chains:` の見出しと `- a -> b` の行にする
|
|
109
|
+
*/
|
|
110
|
+
export function formatStackableChains(progressions, label) {
|
|
111
|
+
const chains = stackChains(progressions).filter(chain => chain.length >= 2);
|
|
112
|
+
return chains.length === 0 ? undefined : ['Stackable chains:', ...chains.map(chain => `- ${chain.map(key => label(key)).join(' -> ')}`)].join('\n');
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=batch-plan.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { BlockedByReferences } from './issue-readout.js';
|
|
2
|
+
import type { Prerequisite, Wait } from './readiness.js';
|
|
3
|
+
import type { IssueReference } from './reference-parser.js';
|
|
4
|
+
import type { RepositoryReference } from './repository-resolver.js';
|
|
5
|
+
export type BlockDecision = {
|
|
6
|
+
readonly kind: 'malformed';
|
|
7
|
+
readonly reason: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: 'unchanged';
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'add' | 'update';
|
|
12
|
+
readonly body: string;
|
|
13
|
+
};
|
|
14
|
+
export interface BlockInput {
|
|
15
|
+
readonly body: string;
|
|
16
|
+
/**
|
|
17
|
+
待つ側の Issue のリポジトリ。本文の `#N` が指す先
|
|
18
|
+
*/
|
|
19
|
+
readonly home: RepositoryReference;
|
|
20
|
+
readonly by: IssueReference;
|
|
21
|
+
readonly wait: Wait;
|
|
22
|
+
/**
|
|
23
|
+
wait が merge のときの理由
|
|
24
|
+
*/
|
|
25
|
+
readonly reason: string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
by が、すでに blocked by に付いている
|
|
28
|
+
*/
|
|
29
|
+
readonly isLinked: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
付ける・種類を変える・何もしないのどれにするかと、書く本文を決める。
|
|
33
|
+
節が読めないときは本文を書き換えられないので malformed を返す
|
|
34
|
+
*/
|
|
35
|
+
export declare function decideBlock(input: Readonly<BlockInput>): BlockDecision;
|
|
36
|
+
export type UnblockDecision = {
|
|
37
|
+
readonly kind: 'unchanged';
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'remove';
|
|
40
|
+
readonly body: string;
|
|
41
|
+
/**
|
|
42
|
+
節が読めないときの理由。このとき body は元のまま
|
|
43
|
+
*/
|
|
44
|
+
readonly malformedReason: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
export interface UnblockInput {
|
|
47
|
+
readonly body: string;
|
|
48
|
+
readonly home: RepositoryReference;
|
|
49
|
+
readonly by: IssueReference;
|
|
50
|
+
readonly isLinked: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
外すか何もしないかを決める。付いていなければ、節に古い行が残っていても本文は書き換えない
|
|
54
|
+
*/
|
|
55
|
+
export declare function decideUnblock(input: Readonly<UnblockInput>): UnblockDecision;
|
|
56
|
+
export type ReadBlockedByLevel = (ids: readonly string[]) => Promise<ReadonlyMap<string, BlockedByReferences>>;
|
|
57
|
+
export interface CycleSearchInput {
|
|
58
|
+
readonly target: IssueReference;
|
|
59
|
+
readonly by: IssueReference;
|
|
60
|
+
readonly byId: string;
|
|
61
|
+
readonly read: ReadBlockedByLevel;
|
|
62
|
+
/**
|
|
63
|
+
たどる Issue の数の上限(by を含む)
|
|
64
|
+
*/
|
|
65
|
+
readonly limit: number;
|
|
66
|
+
}
|
|
67
|
+
export type CycleSearchResult = {
|
|
68
|
+
readonly kind: 'cycle';
|
|
69
|
+
readonly path: readonly IssueReference[];
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'none';
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'unverifiable';
|
|
74
|
+
readonly reason: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
by から blocked by を 1 段ずつたどり、target に戻れば輪として道(target → by → … → target)を返す。
|
|
78
|
+
読めない Issue・件数の不足・上限は unverifiable。GitHub は 3 つ以上の輪を通すので、確かめずに付けない
|
|
79
|
+
*/
|
|
80
|
+
export declare function searchCycle(input: Readonly<CycleSearchInput>): Promise<CycleSearchResult>;
|
|
81
|
+
export interface ExpectedPrerequisites {
|
|
82
|
+
/**
|
|
83
|
+
書いた後の前提のキー(issueReferenceKey)
|
|
84
|
+
*/
|
|
85
|
+
readonly keys: ReadonlySet<string>;
|
|
86
|
+
readonly by: IssueReference;
|
|
87
|
+
/**
|
|
88
|
+
by の種類と理由。外したときは undefined
|
|
89
|
+
*/
|
|
90
|
+
readonly wait: {
|
|
91
|
+
readonly wait: Wait;
|
|
92
|
+
readonly reason: string | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
書いた後の読み直しが、書いた内容と一致するか。GitHub は書いた直後の読み取りの一致を保証しない
|
|
97
|
+
*/
|
|
98
|
+
export declare function hasExpectedPrerequisites(prerequisites: readonly Prerequisite[], expected: Readonly<ExpectedPrerequisites>): boolean;
|
|
99
|
+
//# sourceMappingURL=blocked-by-change.d.ts.map
|