@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,714 @@
|
|
|
1
|
+
// project のグループのコマンド。Python の cli/commands/project.py の移植。
|
|
2
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { RELEASE_TYPES, findRepository, parsePackage, withAggregationRepository, withRepositoryAppended, withRepositoryReplaced, parseProjectConfig, serializeProjectConfig } from '../domain/config.js';
|
|
6
|
+
import { choosePlacement, insertOption } from '../domain/field-options.js';
|
|
7
|
+
import { jsonField, parseJsonText } from '../domain/json.js';
|
|
8
|
+
import { compareStrings, pythonStrip, pythonStringRepr, splitCodePoints, truncateCodePoints } from '../domain/python-format.js';
|
|
9
|
+
import { splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
10
|
+
import { getActiveConfigPath, loadConfig, projectsDirectory, saveConfig } from '../infra/config-store.js';
|
|
11
|
+
import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
|
|
12
|
+
import { asArray, isTruthy, requireNumber, requireString } from '../infra/github/payload.js';
|
|
13
|
+
import { resolveRealPath } from '../infra/paths.js';
|
|
14
|
+
import { hasErrorCode } from '../infra/os-error.js';
|
|
15
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
16
|
+
import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
|
|
17
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
18
|
+
import { kindOfFailure } from './failure.js';
|
|
19
|
+
import { createGitHubClient } from './github-client.js';
|
|
20
|
+
import { createOutput } from './output.js';
|
|
21
|
+
import { BLOCKED_SPEC, NEEDS_ATTENTION_SPEC, PRIORITY_FIELD_OPTIONS, SIZE_FIELD_OPTIONS, STATUS_FIELD_NAME, WORKFLOW_FIELD_OPTIONS, buildRepository, failApi, fieldNodesOf, findProjectByTitle, hasWorkflowField, lastFieldNamed, missingRequiredOptions, stopMissingOptions, syncProjectConfig, textOf, } from './project-sync.js';
|
|
22
|
+
const DEFAULT_HOST = 'github.com';
|
|
23
|
+
const dryRunInput = z.boolean().default(false).describe('Show what would change without writing anything');
|
|
24
|
+
const AGGREGATION_REPOSITORY_PATTERN = /^[\w.-]+\/[\w.-]+$/u;
|
|
25
|
+
const MISSING_PATH_CODES = new Set(['ENOENT', 'ENOTDIR', 'ELOOP']);
|
|
26
|
+
const SEARCH_TITLE_LIMIT = 38;
|
|
27
|
+
const SEARCH_TITLE_WIDTH = 40;
|
|
28
|
+
/**
|
|
29
|
+
GitHub API の失敗を `could not <action>` の行にして、終了コード 1 で止める
|
|
30
|
+
*/
|
|
31
|
+
async function guarded(out, action, body) {
|
|
32
|
+
try {
|
|
33
|
+
return await body();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof GitHubAPIError)
|
|
37
|
+
return failApi(out, action, error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// パスが無い・辿れない(ENOENT・ENOTDIR・ELOOP)。Python の Path.exists() が False を返す場合と同じ
|
|
42
|
+
function isMissingPath(error) {
|
|
43
|
+
return hasErrorCode(error) && MISSING_PATH_CODES.has(error.code);
|
|
44
|
+
}
|
|
45
|
+
// projects/ の *.json のファイル名(名前順)。ディレクトリが無ければ空
|
|
46
|
+
function readProjectFiles(directory) {
|
|
47
|
+
try {
|
|
48
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- プロジェクトルート配下の設定ディレクトリ
|
|
49
|
+
return readdirSync(directory).filter(name => name.endsWith('.json')).toSorted(compareStrings);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (isMissingPath(error))
|
|
53
|
+
return [];
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function isFile(target) {
|
|
58
|
+
try {
|
|
59
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- 利用者が渡した設定ファイルのパス
|
|
60
|
+
return statSync(target).isFile();
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (isMissingPath(error))
|
|
64
|
+
return false;
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function padEndCodePoints(text, width) {
|
|
69
|
+
return text + ' '.repeat(Math.max(0, width - splitCodePoints(text).length));
|
|
70
|
+
}
|
|
71
|
+
function requireActiveWithPath(out) {
|
|
72
|
+
const config = requireActiveConfig(out);
|
|
73
|
+
const configPath = getActiveConfigPath() ?? stopWith(out, 'cannot determine the config file path', 'config-invalid');
|
|
74
|
+
return { config, configPath };
|
|
75
|
+
}
|
|
76
|
+
// 保存の前に、設定として読み直せる形かを確かめる(読めなければ ValidationFailure)
|
|
77
|
+
function validated(config) {
|
|
78
|
+
return parseProjectConfig(parseJsonText(serializeProjectConfig(config)));
|
|
79
|
+
}
|
|
80
|
+
// project list
|
|
81
|
+
const listCommand = defineCommand({
|
|
82
|
+
path: ['project', 'list'],
|
|
83
|
+
description: 'List available projects',
|
|
84
|
+
input: z.strictObject({}),
|
|
85
|
+
positional: [],
|
|
86
|
+
interactive: false,
|
|
87
|
+
run: (_input, io) => {
|
|
88
|
+
const out = createOutput(false, io);
|
|
89
|
+
const lines = ['=== Projects ==='];
|
|
90
|
+
const directory = projectsDirectory();
|
|
91
|
+
const files = readProjectFiles(directory);
|
|
92
|
+
if (files.length === 0) {
|
|
93
|
+
lines.push(' none');
|
|
94
|
+
out.data(lines.join('\n'));
|
|
95
|
+
return Promise.resolve(0);
|
|
96
|
+
}
|
|
97
|
+
const active = getActiveConfigPath();
|
|
98
|
+
for (const file of files) {
|
|
99
|
+
const isActive = active !== undefined && resolveRealPath(path.join(directory, file)) === resolveRealPath(active);
|
|
100
|
+
lines.push(` ${path.parse(file).name}${isActive ? ' [ACTIVE]' : ''}`);
|
|
101
|
+
}
|
|
102
|
+
out.data(lines.join('\n'));
|
|
103
|
+
return Promise.resolve(0);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
// project search
|
|
107
|
+
const searchCommand = defineCommand({
|
|
108
|
+
path: ['project', 'search'],
|
|
109
|
+
description: 'Search projects through the GitHub API',
|
|
110
|
+
input: z.strictObject({
|
|
111
|
+
owner: z.string().describe('Project owner'),
|
|
112
|
+
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
113
|
+
}),
|
|
114
|
+
positional: ['owner'],
|
|
115
|
+
shortFlags: { host: '-h' },
|
|
116
|
+
interactive: false,
|
|
117
|
+
run: async (input, io) => {
|
|
118
|
+
const out = createOutput(false, io);
|
|
119
|
+
const { owner, host } = input;
|
|
120
|
+
await guarded(out, 'list projects', async () => {
|
|
121
|
+
const projects = await createGitHubClient(out, host).listProjects(owner);
|
|
122
|
+
if (projects.length === 0)
|
|
123
|
+
stopWith(out, `no projects found for ${owner}`, 'project-not-found');
|
|
124
|
+
const lines = [`=== Projects of ${owner} (${host}) ===`, '', `${padEndCodePoints('#', 4)} ${padEndCodePoints('Title', SEARCH_TITLE_WIDTH)} URL`, '-'.repeat(80)];
|
|
125
|
+
for (const project of projects) {
|
|
126
|
+
const number = project['number'] === undefined ? '?' : textOf(project['number']);
|
|
127
|
+
const rawTitle = project['title'] === undefined ? '(untitled)' : textOf(project['title']);
|
|
128
|
+
const title = splitCodePoints(rawTitle).length > SEARCH_TITLE_LIMIT ? `${truncateCodePoints(rawTitle, 35)}...` : rawTitle;
|
|
129
|
+
lines.push(`${padEndCodePoints(number, 4)} ${padEndCodePoints(title, SEARCH_TITLE_WIDTH)} ${project['url'] === undefined ? '' : textOf(project['url'])}`);
|
|
130
|
+
}
|
|
131
|
+
out.data(lines.join('\n'));
|
|
132
|
+
});
|
|
133
|
+
return 0;
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
// project init
|
|
137
|
+
// 読んだ選択肢を更新の入力にそろえる。color が読めないときは、既存の色を上書きしないよう止める
|
|
138
|
+
function optionInputsOf(field) {
|
|
139
|
+
return asArray(field['options']).map((option) => {
|
|
140
|
+
const description = jsonField(option, 'description');
|
|
141
|
+
return {
|
|
142
|
+
id: requireString(jsonField(option, 'id'), 'option.id'),
|
|
143
|
+
name: requireString(jsonField(option, 'name'), 'option.name'),
|
|
144
|
+
color: requireString(jsonField(option, 'color'), 'option.color'),
|
|
145
|
+
description: typeof description === 'string' ? description : '',
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
// 既にあるフィールドに選択肢を 1 つ足す。足した(予行では、足す予定の)数(0 か 1)を返す
|
|
150
|
+
async function addFieldOption(out, client, field, spec, isDryRun) {
|
|
151
|
+
const { option } = spec;
|
|
152
|
+
const fieldName = textOf(field['name']);
|
|
153
|
+
const existing = optionInputsOf(field);
|
|
154
|
+
const merged = insertOption(existing, option, choosePlacement(existing, spec.placement ?? [{ end: true }]));
|
|
155
|
+
if (merged === undefined) {
|
|
156
|
+
const unchanged = { verb: 'unchanged', target: `option ${option.name} in field ${fieldName}` };
|
|
157
|
+
out.planned(unchanged);
|
|
158
|
+
out.done(unchanged);
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
const added = { verb: 'add', target: `option ${option.name} to field ${fieldName}` };
|
|
162
|
+
if (isDryRun) {
|
|
163
|
+
out.planned(added);
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
await client.updateProjectFieldOptions(requireString(field['id'], 'field.id'), merged);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (!(error instanceof GitHubAPIError))
|
|
171
|
+
throw error;
|
|
172
|
+
// 選択肢の id を拒む GHES などで足せなくても、作ったフィールドと設定ファイルの同期は進める
|
|
173
|
+
out.warning(`could not add option ${option.name} to field ${fieldName}: ${error.message}`);
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
out.done(added);
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
// 既にあるフィールドに足す選択肢。fields は作る前の状態なので、作ったばかりの進行の欄は「無い」扱いで何も出さない(created の行が出ている)
|
|
180
|
+
// 足した(予行では、足す予定の)選択肢の数を返す
|
|
181
|
+
async function addMissingOptions(out, client, fields, workflowFieldName, isDryRun) {
|
|
182
|
+
const workflowField = lastFieldNamed(fields, workflowFieldName);
|
|
183
|
+
const blocked = workflowField === undefined ? 0 : await addFieldOption(out, client, workflowField, BLOCKED_SPEC, isDryRun);
|
|
184
|
+
const statusField = lastFieldNamed(fields, STATUS_FIELD_NAME);
|
|
185
|
+
if (statusField === undefined) {
|
|
186
|
+
skipped(out, `field ${STATUS_FIELD_NAME} (not found)`);
|
|
187
|
+
return blocked;
|
|
188
|
+
}
|
|
189
|
+
return blocked + await addFieldOption(out, client, statusField, NEEDS_ATTENTION_SPEC, isDryRun);
|
|
190
|
+
}
|
|
191
|
+
function skipped(out, target) {
|
|
192
|
+
out.planned({ verb: 'skip', target });
|
|
193
|
+
out.done({ verb: 'skip', target });
|
|
194
|
+
}
|
|
195
|
+
// フィールドを作り、既にあるフィールドには足りない選択肢を足す。既にある進行の欄の必須の値が欠けていれば、何も書かずに止める。
|
|
196
|
+
// 作る・足す(予行では、その予定の)フィールドと選択肢の数を返す
|
|
197
|
+
async function initializeFields(out, client, target, isDryRun) {
|
|
198
|
+
const { owner, name, suffix } = target;
|
|
199
|
+
const project = await findProjectByTitle(out, client, owner, name);
|
|
200
|
+
const projectId = requireString(project['id'], 'project.id');
|
|
201
|
+
const projectInfo = await client.getProjectFields(owner, requireNumber(project['number'], 'project.number'));
|
|
202
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
203
|
+
stopWith(out, `could not read project fields: ${name}`, 'not-initialized');
|
|
204
|
+
const fields = fieldNodesOf(projectInfo);
|
|
205
|
+
const workflowFieldName = `pecot-workflow-${suffix}`;
|
|
206
|
+
const existingWorkflow = lastFieldNamed(fields, workflowFieldName);
|
|
207
|
+
if (existingWorkflow !== undefined) {
|
|
208
|
+
const missing = missingRequiredOptions(existingWorkflow);
|
|
209
|
+
if (missing.length > 0)
|
|
210
|
+
stopMissingOptions(out, missing);
|
|
211
|
+
}
|
|
212
|
+
const wanted = [
|
|
213
|
+
[workflowFieldName, WORKFLOW_FIELD_OPTIONS],
|
|
214
|
+
['pecot-priority', PRIORITY_FIELD_OPTIONS],
|
|
215
|
+
['pecot-size', SIZE_FIELD_OPTIONS],
|
|
216
|
+
];
|
|
217
|
+
let newFieldCount = 0;
|
|
218
|
+
for (const [fieldName, options] of wanted) {
|
|
219
|
+
if (fields.some(field => jsonField(field, 'name') === fieldName)) {
|
|
220
|
+
skipped(out, `field ${fieldName} (already exists)`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
newFieldCount += 1;
|
|
224
|
+
if (isDryRun) {
|
|
225
|
+
out.planned({ verb: 'create', target: `field ${fieldName}` });
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const created = await client.createProjectField(projectId, fieldName, options);
|
|
229
|
+
out.done({ verb: 'create', target: `field ${fieldName} (ID: ${requireString(created['id'], 'field.id')})` });
|
|
230
|
+
}
|
|
231
|
+
return newFieldCount + await addMissingOptions(out, client, fields, workflowFieldName, isDryRun);
|
|
232
|
+
}
|
|
233
|
+
const initCommand = defineCommand({
|
|
234
|
+
path: ['project', 'init'],
|
|
235
|
+
description: 'Add pecot-workflow fields to an existing project, and add the Blocked and Needs Attention options to the fields that already exist',
|
|
236
|
+
input: z.strictObject({
|
|
237
|
+
owner: z.string().describe('Project owner'),
|
|
238
|
+
name: z.string().describe('Project title'),
|
|
239
|
+
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
240
|
+
suffix: z.string().describe('Suffix of the workflow field'),
|
|
241
|
+
dry_run: dryRunInput,
|
|
242
|
+
}),
|
|
243
|
+
positional: ['owner', 'name'],
|
|
244
|
+
shortFlags: { host: '-h', suffix: '-s', dry_run: '-n' },
|
|
245
|
+
interactive: false,
|
|
246
|
+
run: async (input, io) => {
|
|
247
|
+
const out = createOutput(input.dry_run, io);
|
|
248
|
+
const { owner, name, host, suffix } = input;
|
|
249
|
+
const client = createGitHubClient(out, host);
|
|
250
|
+
const changeCount = await guarded(out, 'initialize project fields', async () => await initializeFields(out, client, input, input.dry_run));
|
|
251
|
+
// 設定ファイルは作るフィールドと選択肢の ID を書くので、予行では作る前の設定を出さない
|
|
252
|
+
if (changeCount > 0 && input.dry_run)
|
|
253
|
+
return 0;
|
|
254
|
+
await guarded(out, 'sync project config', async () => {
|
|
255
|
+
await syncProjectConfig(out, client, { owner, name, host, suffix, skipIfUnchanged: true, isDryRun: input.dry_run });
|
|
256
|
+
});
|
|
257
|
+
return 0;
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
// project create
|
|
261
|
+
const projectCreationCommand = defineCommand({
|
|
262
|
+
path: ['project', 'create'],
|
|
263
|
+
description: 'Create a new project (to add the fields to an existing project, use project init)',
|
|
264
|
+
input: z.strictObject({
|
|
265
|
+
owner: z.string().describe('Project owner'),
|
|
266
|
+
title: z.string().describe('Project title'),
|
|
267
|
+
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
268
|
+
suffix: z.string().describe('Suffix of the workflow field'),
|
|
269
|
+
dry_run: dryRunInput,
|
|
270
|
+
}),
|
|
271
|
+
positional: ['owner', 'title'],
|
|
272
|
+
shortFlags: { host: '-h', suffix: '-s', dry_run: '-n' },
|
|
273
|
+
interactive: false,
|
|
274
|
+
run: async (input, io) => {
|
|
275
|
+
const out = createOutput(input.dry_run, io);
|
|
276
|
+
const { owner, title, host, suffix } = input;
|
|
277
|
+
await guarded(out, 'create project', async () => {
|
|
278
|
+
const client = createGitHubClient(out, host);
|
|
279
|
+
let ownerId;
|
|
280
|
+
try {
|
|
281
|
+
ownerId = await client.getOwnerNodeId(owner);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
if (error instanceof GitHubNotFoundError)
|
|
285
|
+
stopWith(out, `owner not found: ${owner}`, 'github-not-found');
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
const owned = await client.listProjects(owner);
|
|
289
|
+
const existing = owned.find(project => jsonField(project, 'title') === title);
|
|
290
|
+
if (existing !== undefined)
|
|
291
|
+
stopWith(out, `project already exists: ${title}\nurl: ${textOf(existing['url'])}`, 'already-exists');
|
|
292
|
+
// フィールドと設定ファイルは作ったプロジェクトの ID を使うので、予行ではプロジェクトの行だけ出す
|
|
293
|
+
if (input.dry_run) {
|
|
294
|
+
out.planned({ verb: 'create', target: `project ${title} for ${owner}` });
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const created = await client.createProject(ownerId, title);
|
|
298
|
+
out.done({ verb: 'create', target: `project #${textOf(created['number'])} ${textOf(created['url'])}` });
|
|
299
|
+
await guarded(out, 'initialize project fields', async () => {
|
|
300
|
+
await initializeFields(out, client, { owner, name: title, suffix }, false);
|
|
301
|
+
});
|
|
302
|
+
await guarded(out, 'sync project config', async () => {
|
|
303
|
+
await syncProjectConfig(out, client, { owner, name: title, host, suffix });
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
return 0;
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
// project activate
|
|
310
|
+
// 設定ファイルのパスか、projects/ にあるファイル名か
|
|
311
|
+
function findConfigFileArgument(project) {
|
|
312
|
+
if (isFile(path.resolve(project)))
|
|
313
|
+
return resolveRealPath(path.resolve(project));
|
|
314
|
+
const named = path.join(projectsDirectory(), project.endsWith('.json') ? project : `${project}.json`);
|
|
315
|
+
return isFile(named) ? named : undefined;
|
|
316
|
+
}
|
|
317
|
+
async function activateFromConfigFile(out, configPath, host, isDryRun) {
|
|
318
|
+
let config;
|
|
319
|
+
try {
|
|
320
|
+
config = loadConfig(configPath);
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
// Python の `except Exception` と同じ範囲(あらゆる Error)で捕まえる
|
|
324
|
+
if (!(error instanceof Error) || error instanceof CommandExit)
|
|
325
|
+
throw error;
|
|
326
|
+
return stopWith(out, `could not load config file ${path.basename(configPath)}: ${error.message}`, 'config-invalid');
|
|
327
|
+
}
|
|
328
|
+
await guarded(out, 'sync project', async () => {
|
|
329
|
+
if (host !== undefined && config.host !== host) {
|
|
330
|
+
out.warning(hinted `${inputHint(ACTIVATE_PATH, 'host', host)} differs from the config file host (${config.host})\nusing the config file host`);
|
|
331
|
+
}
|
|
332
|
+
const client = createGitHubClient(out, config.host);
|
|
333
|
+
const projectInfo = await client.getProjectFields(config.owner, config.project.number);
|
|
334
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
335
|
+
stopWith(out, `project #${String(config.project.number)} not found`, 'project-not-found');
|
|
336
|
+
const title = projectInfo['title'];
|
|
337
|
+
if (typeof title !== 'string' || title === '')
|
|
338
|
+
stopWith(out, `could not read the title of project #${String(config.project.number)}`, 'project-not-found');
|
|
339
|
+
await syncProjectConfig(out, client, { owner: config.owner, name: title, host: config.host, isDryRun });
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
async function resolveActivationOwner(out, client, owner) {
|
|
343
|
+
if (owner !== undefined)
|
|
344
|
+
return owner;
|
|
345
|
+
let login;
|
|
346
|
+
try {
|
|
347
|
+
login = jsonField(await client.getAuthenticatedUser(), 'login');
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
if (error instanceof GitHubAPIError)
|
|
351
|
+
return stopWith(out, hinted `could not read the authenticated user: ${error.message}\npass ${inputNameHint(ACTIVATE_PATH, 'owner')} to give the owner explicitly`, kindOfFailure(error));
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
354
|
+
return typeof login === 'string' && login !== '' ? login : stopWith(out, 'could not read the authenticated user', 'github-api');
|
|
355
|
+
}
|
|
356
|
+
// 一覧の表示モード。初期化済みのプロジェクトに [ACTIVE] を付ける
|
|
357
|
+
async function echoInitializedProjects(out, client, host, owner) {
|
|
358
|
+
const lines = [`=== Initialized projects (${host}/${owner}) ===`];
|
|
359
|
+
const initialized = [];
|
|
360
|
+
const owned = await client.listProjects(owner);
|
|
361
|
+
for (const project of owned) {
|
|
362
|
+
const number = project['number'];
|
|
363
|
+
if (number === undefined || number === null)
|
|
364
|
+
continue;
|
|
365
|
+
const projectInfo = await client.getProjectFields(owner, requireNumber(number, 'project.number'));
|
|
366
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
367
|
+
continue;
|
|
368
|
+
if (hasWorkflowField(fieldNodesOf(projectInfo)))
|
|
369
|
+
initialized.push(project);
|
|
370
|
+
}
|
|
371
|
+
if (initialized.length === 0) {
|
|
372
|
+
lines.push(' none');
|
|
373
|
+
out.data(lines.join('\n'));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const activeNumber = activeProjectNumber(host, owner);
|
|
377
|
+
for (const project of initialized) {
|
|
378
|
+
const number = jsonField(project, 'number');
|
|
379
|
+
const title = jsonField(project, 'title');
|
|
380
|
+
lines.push(` #${textOf(number)}: ${title === undefined ? '(untitled)' : textOf(title)}${activeNumber === number ? ' [ACTIVE]' : ''}`);
|
|
381
|
+
}
|
|
382
|
+
out.data(lines.join('\n'));
|
|
383
|
+
}
|
|
384
|
+
function activeProjectNumber(host, owner) {
|
|
385
|
+
const activePath = getActiveConfigPath();
|
|
386
|
+
if (activePath === undefined)
|
|
387
|
+
return undefined;
|
|
388
|
+
try {
|
|
389
|
+
const active = loadConfig(activePath);
|
|
390
|
+
return active.host === host && active.owner === owner ? active.project.number : undefined;
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
// 読めない設定は、アクティブの印を付けないだけにする。Python の `except Exception` と同じ範囲で捕まえる
|
|
394
|
+
if (error instanceof Error)
|
|
395
|
+
return undefined;
|
|
396
|
+
throw error;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
// 番号か名前でプロジェクトの情報を取る
|
|
400
|
+
async function fetchProjectInfoByReference(out, client, owner, project) {
|
|
401
|
+
if (/^\d+$/u.test(project)) {
|
|
402
|
+
const number = Number(project);
|
|
403
|
+
return await client.getProjectFields(owner, number) ?? stopWith(out, `project #${String(number)} not found`, 'project-not-found');
|
|
404
|
+
}
|
|
405
|
+
const found = await findProjectByTitle(out, client, owner, project);
|
|
406
|
+
const info = await client.getProjectFields(owner, requireNumber(found['number'], 'project.number'));
|
|
407
|
+
return info !== undefined && isTruthy(info) ? info : stopWith(out, `could not read project fields: ${project}`, 'not-initialized');
|
|
408
|
+
}
|
|
409
|
+
async function activateByReference(out, client, target) {
|
|
410
|
+
const { host, owner, project, isDryRun } = target;
|
|
411
|
+
const info = await fetchProjectInfoByReference(out, client, owner, project);
|
|
412
|
+
const title = textOf(info['title'] ?? '');
|
|
413
|
+
if (!hasWorkflowField(asArray(jsonField(info['fields'], 'nodes')))) {
|
|
414
|
+
stopWith(out, hinted `project "${title}" is not initialized\nrun: ${commandHint(['project', 'init'], { owner, name: title, host, suffix: placeholder('suffix') })}`, 'not-initialized');
|
|
415
|
+
}
|
|
416
|
+
await syncProjectConfig(out, client, { owner, name: title, host, isDryRun });
|
|
417
|
+
}
|
|
418
|
+
const ACTIVATE_PATH = ['project', 'activate'];
|
|
419
|
+
const LINK_PATH = ['project', 'link'];
|
|
420
|
+
const activateCommand = defineCommand({
|
|
421
|
+
path: ['project', 'activate'],
|
|
422
|
+
description: 'Activate an initialized project',
|
|
423
|
+
input: z.strictObject({
|
|
424
|
+
project: z.string().optional().describe('Project number or name, or config file path/file name'),
|
|
425
|
+
owner: z.string().optional().describe('Project owner (defaults to the authenticated user)'),
|
|
426
|
+
host: z.string().optional().describe('GitHub host'),
|
|
427
|
+
dry_run: dryRunInput,
|
|
428
|
+
}),
|
|
429
|
+
positional: ['project'],
|
|
430
|
+
shortFlags: { owner: '-o', host: '-h', dry_run: '-n' },
|
|
431
|
+
interactive: false,
|
|
432
|
+
run: async (input, io) => {
|
|
433
|
+
const out = createOutput(input.dry_run, io);
|
|
434
|
+
const { project, host } = input;
|
|
435
|
+
// --host の要らない形(設定ファイルのパスか名前)を先に見る
|
|
436
|
+
const configPath = project === undefined ? undefined : findConfigFileArgument(project);
|
|
437
|
+
if (configPath !== undefined) {
|
|
438
|
+
await activateFromConfigFile(out, configPath, host, input.dry_run);
|
|
439
|
+
return 0;
|
|
440
|
+
}
|
|
441
|
+
await guarded(out, 'activate project', async () => {
|
|
442
|
+
if (host === undefined) {
|
|
443
|
+
stopWith(out, hinted `${inputNameHint(ACTIVATE_PATH, 'host')} is required
|
|
444
|
+
example: ${commandHint(ACTIVATE_PATH, { host: 'github.com', owner: 'example-org' })}
|
|
445
|
+
example: ${commandHint(ACTIVATE_PATH, { host: 'ghes.example.com', owner: 'example-org' })}
|
|
446
|
+
example: ${commandHint(ACTIVATE_PATH, { project: 'ghes.example.com_example-org_example-project_example-org' })}`, 'invalid-input');
|
|
447
|
+
}
|
|
448
|
+
const client = createGitHubClient(out, host);
|
|
449
|
+
const owner = await resolveActivationOwner(out, client, input.owner);
|
|
450
|
+
if (project === undefined)
|
|
451
|
+
await echoInitializedProjects(out, client, host, owner);
|
|
452
|
+
else
|
|
453
|
+
await activateByReference(out, client, { host, owner, project, isDryRun: input.dry_run });
|
|
454
|
+
});
|
|
455
|
+
return 0;
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
// project link
|
|
459
|
+
const packageList = z.array(z.string());
|
|
460
|
+
function parsePackages(out, input) {
|
|
461
|
+
const specs = input.package;
|
|
462
|
+
if (specs === undefined || specs.length === 0)
|
|
463
|
+
return undefined;
|
|
464
|
+
const packageFlag = inputNameHint(LINK_PATH, 'package');
|
|
465
|
+
if (input.changelog_file !== undefined)
|
|
466
|
+
stopWith(out, hinted `${packageFlag} and ${inputNameHint(LINK_PATH, 'changelog_file')} cannot be used together`, 'invalid-input');
|
|
467
|
+
if (input.clear_packages)
|
|
468
|
+
stopWith(out, hinted `${packageFlag} and ${inputHint(LINK_PATH, 'clear_packages')} cannot be used together`, 'invalid-input');
|
|
469
|
+
const parsed = [];
|
|
470
|
+
const seen = new Set();
|
|
471
|
+
for (const spec of specs) {
|
|
472
|
+
const separator = spec.indexOf(':');
|
|
473
|
+
if (separator === -1)
|
|
474
|
+
stopWith(out, hinted `give ${inputHint(LINK_PATH, 'package', placeholder('NAME:PATH'))}: ${pythonStringRepr(spec)}`, 'invalid-input');
|
|
475
|
+
const name = pythonStrip(spec.slice(0, separator));
|
|
476
|
+
const changelog = pythonStrip(spec.slice(separator + 1));
|
|
477
|
+
if (name === '' || changelog === '')
|
|
478
|
+
stopWith(out, hinted `${packageFlag} NAME and PATH must not be empty: ${pythonStringRepr(spec)}`, 'invalid-input');
|
|
479
|
+
if (seen.has(name))
|
|
480
|
+
stopWith(out, hinted `${packageFlag} NAME is duplicated: ${pythonStringRepr(name)}`, 'invalid-input');
|
|
481
|
+
seen.add(name);
|
|
482
|
+
// Python も Package(...) の作成で NAME の形を確かめるので、設定を読む前に止まる
|
|
483
|
+
parsed.push(parsePackage({ name, changelog }));
|
|
484
|
+
}
|
|
485
|
+
return parsed;
|
|
486
|
+
}
|
|
487
|
+
// 登録済みのエントリを、指定されたオプションの分だけ更新する
|
|
488
|
+
function updatedRepository(out, existing, edit) {
|
|
489
|
+
let { packages, changelog_file: changelogFile } = existing;
|
|
490
|
+
if (edit.packages === undefined) {
|
|
491
|
+
if (edit.clear_packages)
|
|
492
|
+
packages = undefined;
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
packages = edit.packages;
|
|
496
|
+
changelogFile = undefined;
|
|
497
|
+
}
|
|
498
|
+
if (edit.changelog_file !== undefined) {
|
|
499
|
+
if (packages !== undefined && packages.length > 0) {
|
|
500
|
+
stopWith(out, hinted `this repository has packages set\nrun with ${inputHint(['project', 'link'], 'clear_packages')} before switching to ${inputNameHint(['project', 'link'], 'changelog_file')}`, 'invalid-input');
|
|
501
|
+
}
|
|
502
|
+
changelogFile = edit.changelog_file;
|
|
503
|
+
}
|
|
504
|
+
return buildRepository({
|
|
505
|
+
...existing,
|
|
506
|
+
develop_branch: edit.develop_branch ?? existing.develop_branch,
|
|
507
|
+
release_branch: edit.release_branch ?? existing.release_branch,
|
|
508
|
+
changelog_file: changelogFile,
|
|
509
|
+
packages,
|
|
510
|
+
release_type: toReleaseType(edit.release_type) ?? existing.release_type,
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function toReleaseType(value) {
|
|
514
|
+
return RELEASE_TYPES.find(type => type === value);
|
|
515
|
+
}
|
|
516
|
+
async function linkRepository(out, config, repositoryOwner, repositoryName) {
|
|
517
|
+
try {
|
|
518
|
+
return await createGitHubClient(out, config.host).linkRepositoryToProject(config.owner, config.project.number, repositoryOwner, repositoryName);
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
// API の失敗の文は、Python と同じく message をそのまま使う(応答の本文の詳細は、wip ブランチの削除の警告だけが足す)
|
|
522
|
+
if (error instanceof GitHubAPIError)
|
|
523
|
+
return { status: 'failed', detail: error.message };
|
|
524
|
+
throw error;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
// 予行。リンクの有無を読むだけで、リンクしない
|
|
528
|
+
async function plannedLink(out, config, repositoryOwner, repositoryName) {
|
|
529
|
+
try {
|
|
530
|
+
const linked = await createGitHubClient(out, config.host).getLinkedRepositories(config.owner, config.project.number);
|
|
531
|
+
const isLinked = linked.some(entry => entry.owner === repositoryOwner && entry.name === repositoryName);
|
|
532
|
+
return { status: isLinked ? 'already_linked' : 'linked', detail: '' };
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
if (error instanceof GitHubAPIError)
|
|
536
|
+
return { status: 'failed', detail: error.message };
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const projectLinkCommand = defineCommand({
|
|
541
|
+
path: ['project', 'link'],
|
|
542
|
+
hasOwnRepo: true,
|
|
543
|
+
ignoresGlobalRepo: true,
|
|
544
|
+
description: 'Add or update a repository in the project config',
|
|
545
|
+
input: z.strictObject({
|
|
546
|
+
repo: z.string().describe('Repository name in owner/repo form'),
|
|
547
|
+
develop_branch: z.string().optional().describe('Development branch name'),
|
|
548
|
+
release_branch: z.string().optional().describe('Release branch name'),
|
|
549
|
+
changelog_file: z.string().optional().describe('CHANGELOG file name'),
|
|
550
|
+
package: packageList.optional().describe('Register a monorepo package as NAME:PATH. Can be repeated. Example: --package pecot:plugins/pecot-workflow/CHANGELOG.md'),
|
|
551
|
+
clear_packages: z.boolean().default(false).describe('Clear the existing packages setting. After clearing, the CHANGELOG falls back to --changelog-file or the default CHANGELOG.md'),
|
|
552
|
+
release_type: z.string().optional().describe('Declare the release method explicitly; the w-release skill picks its procedure from it. single (1 CHANGELOG) / multi (packages) / nx (Nx Release). When omitted, it is inferred from the packages (with packages: multi, without: single)'),
|
|
553
|
+
dry_run: dryRunInput,
|
|
554
|
+
}),
|
|
555
|
+
positional: ['repo'],
|
|
556
|
+
shortFlags: { develop_branch: '-b', dry_run: '-n' },
|
|
557
|
+
interactive: false,
|
|
558
|
+
run: async (input, io) => {
|
|
559
|
+
const out = createOutput(input.dry_run, io);
|
|
560
|
+
if (input.release_type !== undefined && toReleaseType(input.release_type) === undefined) {
|
|
561
|
+
// Python は sorted() の順(multi, nx, single)で見せる
|
|
562
|
+
stopWith(out, hinted `${inputNameHint(LINK_PATH, 'release_type')} must be one of [${RELEASE_TYPES.toSorted(compareStrings).map(type => pythonStringRepr(type)).join(', ')}] (got: ${pythonStringRepr(input.release_type)})`, 'invalid-input');
|
|
563
|
+
}
|
|
564
|
+
const packages = parsePackages(out, input);
|
|
565
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
566
|
+
const parts = splitOwnerRepository(input.repo);
|
|
567
|
+
if (parts === undefined)
|
|
568
|
+
stopWith(out, hinted `give the repository as owner/repo\nexample: ${commandHint(['project', 'link'], { repo: 'example-org/my-repo' })}`, 'invalid-input');
|
|
569
|
+
const { owner, repository: name } = parts;
|
|
570
|
+
if (owner !== config.owner) {
|
|
571
|
+
stopWith(out, `repository owner ${owner} differs from project owner ${config.owner}\nGitHub Projects V2 links only repositories of the project owner`, 'invalid-input');
|
|
572
|
+
}
|
|
573
|
+
const existing = findRepository(config, owner, name);
|
|
574
|
+
let next;
|
|
575
|
+
let saved;
|
|
576
|
+
if (existing === undefined) {
|
|
577
|
+
const projectNumber = String(config.project.number);
|
|
578
|
+
const outcome = input.dry_run ? await plannedLink(out, config, owner, name) : await linkRepository(out, config, owner, name);
|
|
579
|
+
if (outcome.status === 'failed')
|
|
580
|
+
stopWith(out, `could not link ${input.repo} to project #${projectNumber}: ${outcome.detail}`, 'github-api');
|
|
581
|
+
const linked = outcome.status === 'already_linked'
|
|
582
|
+
? { verb: 'unchanged', target: `${input.repo} in project #${projectNumber}` }
|
|
583
|
+
: { verb: 'add', target: `${input.repo} to project #${projectNumber}` };
|
|
584
|
+
out.planned(linked);
|
|
585
|
+
out.done(linked);
|
|
586
|
+
next = withRepositoryAppended(config, buildRepository({
|
|
587
|
+
owner,
|
|
588
|
+
name,
|
|
589
|
+
develop_branch: input.develop_branch,
|
|
590
|
+
release_branch: input.release_branch,
|
|
591
|
+
changelog_file: packages === undefined ? input.changelog_file : undefined,
|
|
592
|
+
packages,
|
|
593
|
+
release_type: toReleaseType(input.release_type),
|
|
594
|
+
}));
|
|
595
|
+
saved = { verb: 'add', target: `${owner}/${name} to ${configPath}` };
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
next = withRepositoryReplaced(config, updatedRepository(out, existing, { ...input, packages }));
|
|
599
|
+
saved = { verb: 'update', target: `${owner}/${name} in ${configPath}` };
|
|
600
|
+
}
|
|
601
|
+
const checked = validated(next);
|
|
602
|
+
out.planned(saved);
|
|
603
|
+
if (input.dry_run)
|
|
604
|
+
return 0;
|
|
605
|
+
saveConfig(checked, configPath);
|
|
606
|
+
out.done(saved);
|
|
607
|
+
return 0;
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
// 設定のキーの管理。今のキーは aggregation_repo だけ
|
|
611
|
+
const CONFIG_KEY = z.enum(['aggregation_repo']).describe('Key of the project config (aggregation_repo: the Epic aggregation repository)');
|
|
612
|
+
function setAggregationRepository(out, value, options) {
|
|
613
|
+
if (!AGGREGATION_REPOSITORY_PATTERN.test(value))
|
|
614
|
+
stopWith(out, `give aggregation_repo as owner/repo: ${pythonStringRepr(value)}`, 'invalid-input');
|
|
615
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
616
|
+
const current = config.aggregation_repo;
|
|
617
|
+
if (current === value) {
|
|
618
|
+
const unchanged = { verb: 'unchanged', target: `aggregation_repo ${value}` };
|
|
619
|
+
out.planned(unchanged);
|
|
620
|
+
out.done(unchanged);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const operation = { verb: 'set', target: `aggregation_repo to ${value}` };
|
|
624
|
+
if (options.isDryRun) {
|
|
625
|
+
out.planned(current === undefined || current === '' ? operation : { ...operation, target: `${operation.target} (was ${current})` });
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (current !== undefined && current !== '') {
|
|
629
|
+
out.warning(options.isConfirmed ? `overwriting aggregation_repo: ${current} -> ${value}` : hinted `overwriting aggregation_repo: ${current} -> ${value}\npass ${inputHint(['project', 'set'], 'yes')} to omit this hint`);
|
|
630
|
+
}
|
|
631
|
+
saveConfig(withAggregationRepository(config, value), configPath);
|
|
632
|
+
out.done(operation);
|
|
633
|
+
}
|
|
634
|
+
function unsetAggregationRepository(out, isDryRun) {
|
|
635
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
636
|
+
const previous = config.aggregation_repo;
|
|
637
|
+
if (previous === undefined) {
|
|
638
|
+
const unchanged = { verb: 'unchanged', target: 'aggregation_repo (not set)' };
|
|
639
|
+
out.planned(unchanged);
|
|
640
|
+
out.done(unchanged);
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const operation = { verb: 'remove', target: `aggregation_repo (was ${previous})` };
|
|
644
|
+
out.planned(operation);
|
|
645
|
+
if (isDryRun)
|
|
646
|
+
return;
|
|
647
|
+
saveConfig(withAggregationRepository(config, undefined), configPath);
|
|
648
|
+
out.done(operation);
|
|
649
|
+
}
|
|
650
|
+
// キーを足したら、ここに操作を足さないと型の確認で止まる
|
|
651
|
+
const CONFIG_KEY_OPERATIONS = {
|
|
652
|
+
aggregation_repo: {
|
|
653
|
+
get: (out) => {
|
|
654
|
+
out.data(requireActiveConfig(out).aggregation_repo ?? 'none');
|
|
655
|
+
},
|
|
656
|
+
set: setAggregationRepository,
|
|
657
|
+
unset: unsetAggregationRepository,
|
|
658
|
+
},
|
|
659
|
+
};
|
|
660
|
+
const projectSetCommand = defineCommand({
|
|
661
|
+
path: ['project', 'set'],
|
|
662
|
+
description: 'Set a key of the project config (aggregation_repo: the Epic aggregation repository)',
|
|
663
|
+
input: z.strictObject({
|
|
664
|
+
key: CONFIG_KEY,
|
|
665
|
+
value: z.string().describe('Aggregation repository (owner/repo form)'),
|
|
666
|
+
yes: z.boolean().default(false).describe('Overwrite an existing value without confirmation (a warning goes to stderr)'),
|
|
667
|
+
dry_run: dryRunInput,
|
|
668
|
+
}),
|
|
669
|
+
positional: ['key', 'value'],
|
|
670
|
+
shortFlags: { yes: '-y', dry_run: '-n' },
|
|
671
|
+
interactive: false,
|
|
672
|
+
run: (input, io) => {
|
|
673
|
+
CONFIG_KEY_OPERATIONS[input.key].set(createOutput(input.dry_run, io), input.value, { isConfirmed: input.yes, isDryRun: input.dry_run });
|
|
674
|
+
return Promise.resolve(0);
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
const projectUnsetCommand = defineCommand({
|
|
678
|
+
path: ['project', 'unset'],
|
|
679
|
+
description: 'Clear a key of the project config; without aggregation_repo, creating an Epic needs --repo',
|
|
680
|
+
input: z.strictObject({ key: CONFIG_KEY, dry_run: dryRunInput }),
|
|
681
|
+
positional: ['key'],
|
|
682
|
+
shortFlags: { dry_run: '-n' },
|
|
683
|
+
interactive: false,
|
|
684
|
+
run: (input, io) => {
|
|
685
|
+
CONFIG_KEY_OPERATIONS[input.key].unset(createOutput(input.dry_run, io), input.dry_run);
|
|
686
|
+
return Promise.resolve(0);
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
const projectGetCommand = defineCommand({
|
|
690
|
+
path: ['project', 'get'],
|
|
691
|
+
description: 'Show the value of a key of the project config (aggregation_repo: the Epic aggregation repository)',
|
|
692
|
+
input: z.strictObject({ key: CONFIG_KEY }),
|
|
693
|
+
positional: ['key'],
|
|
694
|
+
interactive: false,
|
|
695
|
+
run: (input, io) => {
|
|
696
|
+
CONFIG_KEY_OPERATIONS[input.key].get(createOutput(false, io));
|
|
697
|
+
return Promise.resolve(0);
|
|
698
|
+
},
|
|
699
|
+
});
|
|
700
|
+
/**
|
|
701
|
+
project のグループのコマンド。並びは help の一覧の順
|
|
702
|
+
*/
|
|
703
|
+
export const PROJECT_COMMANDS = [
|
|
704
|
+
listCommand,
|
|
705
|
+
searchCommand,
|
|
706
|
+
initCommand,
|
|
707
|
+
projectCreationCommand,
|
|
708
|
+
activateCommand,
|
|
709
|
+
projectLinkCommand,
|
|
710
|
+
projectGetCommand,
|
|
711
|
+
projectSetCommand,
|
|
712
|
+
projectUnsetCommand,
|
|
713
|
+
];
|
|
714
|
+
//# sourceMappingURL=project.js.map
|