@pecot/workflow-mcp 0.0.0-stage → 5.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 +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -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 +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -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-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -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.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -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 +12 -0
- package/cli/dist/commands/github-client.js +23 -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 +55 -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 +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -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 +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -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 +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -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/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/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -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 +19 -0
- package/cli/dist/domain/errors.js +31 -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 +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -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-readout.d.ts +107 -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 +134 -0
- package/cli/dist/domain/pull-request.js +232 -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 +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -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 +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -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 +66 -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 +49 -0
- package/cli/dist/infra/config-store.js +121 -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 +74 -0
- package/cli/dist/infra/git.js +133 -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 +173 -0
- package/cli/dist/infra/github/client.js +576 -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 +47 -0
- package/cli/dist/infra/github/errors.js +42 -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 +129 -0
- package/cli/dist/infra/github/issues.js +273 -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 +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -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 +45 -0
- package/cli/dist/infra/state-store.js +118 -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 +139 -0
- package/cli/dist/infra/worktree-links.js +433 -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 +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -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 +128 -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 +181 -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 +67 -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/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
// project の 10 個のコマンド。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 { formatBoardOutput } from '../domain/format.js';
|
|
8
|
+
import { jsonField, parseJsonText } from '../domain/json.js';
|
|
9
|
+
import { compareStrings, pythonStrip, pythonStringRepr, splitCodePoints, truncateCodePoints } from '../domain/python-format.js';
|
|
10
|
+
import { parseOwnerRepository, splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
11
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
12
|
+
import { getActiveConfigPath, loadConfig, projectsDirectory, saveConfig } from '../infra/config-store.js';
|
|
13
|
+
import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
|
|
14
|
+
import { asArray, isTruthy, requireNumber, requireString } from '../infra/github/payload.js';
|
|
15
|
+
import { resolveRealPath } from '../infra/paths.js';
|
|
16
|
+
import { hasErrorCode } from '../infra/os-error.js';
|
|
17
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
18
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
19
|
+
import { createGitHubClient } from './github-client.js';
|
|
20
|
+
import { createOutput } from './output.js';
|
|
21
|
+
import { collectAlertStatuses, infoJson, infoMarkdown, pruneArchivedItems, readBoard } from './project-info.js';
|
|
22
|
+
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';
|
|
23
|
+
const DEFAULT_HOST = 'github.com';
|
|
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');
|
|
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}`);
|
|
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 つ足す
|
|
150
|
+
async function addFieldOption(out, client, field, spec) {
|
|
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
|
+
out.done({ verb: 'unchanged', target: `option ${option.name} in field ${fieldName}` });
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
await client.updateProjectFieldOptions(requireString(field['id'], 'field.id'), merged);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (!(error instanceof GitHubAPIError))
|
|
164
|
+
throw error;
|
|
165
|
+
// 選択肢の id を拒む GHES などで足せなくても、作ったフィールドと設定ファイルの同期は進める
|
|
166
|
+
out.warning(`could not add option ${option.name} to field ${fieldName}: ${error.message}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
out.done({ verb: 'add', target: `option ${option.name} to field ${fieldName}` });
|
|
170
|
+
}
|
|
171
|
+
// 既にあるフィールドに足す選択肢。fields は作る前の状態なので、作ったばかりの進行の欄は「無い」扱いで何も出さない(created の行が出ている)
|
|
172
|
+
async function addMissingOptions(out, client, fields, workflowFieldName) {
|
|
173
|
+
const workflowField = lastFieldNamed(fields, workflowFieldName);
|
|
174
|
+
if (workflowField !== undefined)
|
|
175
|
+
await addFieldOption(out, client, workflowField, BLOCKED_SPEC);
|
|
176
|
+
const statusField = lastFieldNamed(fields, STATUS_FIELD_NAME);
|
|
177
|
+
if (statusField === undefined)
|
|
178
|
+
out.done({ verb: 'skip', target: `field ${STATUS_FIELD_NAME} (not found)` });
|
|
179
|
+
else
|
|
180
|
+
await addFieldOption(out, client, statusField, NEEDS_ATTENTION_SPEC);
|
|
181
|
+
}
|
|
182
|
+
// フィールドを作り、既にあるフィールドには足りない選択肢を足す。既にある進行の欄の必須の値が欠けていれば、何も書かずに止める
|
|
183
|
+
async function initializeFields(out, client, target) {
|
|
184
|
+
const { owner, name, suffix } = target;
|
|
185
|
+
const project = await findProjectByTitle(out, client, owner, name);
|
|
186
|
+
const projectId = requireString(project['id'], 'project.id');
|
|
187
|
+
const projectInfo = await client.getProjectFields(owner, requireNumber(project['number'], 'project.number'));
|
|
188
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
189
|
+
stopWith(out, `could not read project fields: ${name}`);
|
|
190
|
+
const fields = fieldNodesOf(projectInfo);
|
|
191
|
+
const workflowFieldName = `pecot-workflow-${suffix}`;
|
|
192
|
+
const existingWorkflow = lastFieldNamed(fields, workflowFieldName);
|
|
193
|
+
if (existingWorkflow !== undefined) {
|
|
194
|
+
const missing = missingRequiredOptions(existingWorkflow);
|
|
195
|
+
if (missing.length > 0)
|
|
196
|
+
stopMissingOptions(out, missing);
|
|
197
|
+
}
|
|
198
|
+
const wanted = [
|
|
199
|
+
[workflowFieldName, WORKFLOW_FIELD_OPTIONS],
|
|
200
|
+
['pecot-priority', PRIORITY_FIELD_OPTIONS],
|
|
201
|
+
['pecot-size', SIZE_FIELD_OPTIONS],
|
|
202
|
+
];
|
|
203
|
+
for (const [fieldName, options] of wanted) {
|
|
204
|
+
if (fields.some(field => jsonField(field, 'name') === fieldName)) {
|
|
205
|
+
out.done({ verb: 'skip', target: `field ${fieldName} (already exists)` });
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const created = await client.createProjectField(projectId, fieldName, options);
|
|
209
|
+
out.done({ verb: 'create', target: `field ${fieldName} (ID: ${requireString(created['id'], 'field.id')})` });
|
|
210
|
+
}
|
|
211
|
+
await addMissingOptions(out, client, fields, workflowFieldName);
|
|
212
|
+
}
|
|
213
|
+
const initCommand = defineCommand({
|
|
214
|
+
path: ['project', 'init'],
|
|
215
|
+
description: 'Add pecot-workflow fields to an existing project, and add the Blocked and Needs Attention options to the fields that already exist',
|
|
216
|
+
input: z.strictObject({
|
|
217
|
+
owner: z.string().describe('Project owner'),
|
|
218
|
+
name: z.string().describe('Project title'),
|
|
219
|
+
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
220
|
+
suffix: z.string().describe('Suffix of the workflow field'),
|
|
221
|
+
}),
|
|
222
|
+
positional: ['owner', 'name'],
|
|
223
|
+
shortFlags: { host: '-h', suffix: '-s' },
|
|
224
|
+
interactive: false,
|
|
225
|
+
run: async (input, io) => {
|
|
226
|
+
const out = createOutput(false, io);
|
|
227
|
+
const { owner, name, host, suffix } = input;
|
|
228
|
+
const client = createGitHubClient(out, host);
|
|
229
|
+
await guarded(out, 'initialize project fields', async () => {
|
|
230
|
+
await initializeFields(out, client, input);
|
|
231
|
+
});
|
|
232
|
+
await guarded(out, 'sync project config', async () => {
|
|
233
|
+
await syncProjectConfig(out, client, { owner, name, host, suffix, skipIfUnchanged: true });
|
|
234
|
+
});
|
|
235
|
+
return 0;
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
// project create
|
|
239
|
+
const projectCreationCommand = defineCommand({
|
|
240
|
+
path: ['project', 'create'],
|
|
241
|
+
description: 'Create a new project (to add the fields to an existing project, use project init)',
|
|
242
|
+
input: z.strictObject({
|
|
243
|
+
owner: z.string().describe('Project owner'),
|
|
244
|
+
title: z.string().describe('Project title'),
|
|
245
|
+
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
246
|
+
suffix: z.string().describe('Suffix of the workflow field'),
|
|
247
|
+
}),
|
|
248
|
+
positional: ['owner', 'title'],
|
|
249
|
+
shortFlags: { host: '-h', suffix: '-s' },
|
|
250
|
+
interactive: false,
|
|
251
|
+
run: async (input, io) => {
|
|
252
|
+
const out = createOutput(false, io);
|
|
253
|
+
const { owner, title, host, suffix } = input;
|
|
254
|
+
await guarded(out, 'create project', async () => {
|
|
255
|
+
const client = createGitHubClient(out, host);
|
|
256
|
+
let ownerId;
|
|
257
|
+
try {
|
|
258
|
+
ownerId = await client.getOwnerNodeId(owner);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (error instanceof GitHubNotFoundError)
|
|
262
|
+
stopWith(out, `owner not found: ${owner}`);
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
const owned = await client.listProjects(owner);
|
|
266
|
+
const existing = owned.find(project => jsonField(project, 'title') === title);
|
|
267
|
+
if (existing !== undefined)
|
|
268
|
+
stopWith(out, `project already exists: ${title}\nurl: ${textOf(existing['url'])}`);
|
|
269
|
+
const created = await client.createProject(ownerId, title);
|
|
270
|
+
out.done({ verb: 'create', target: `project #${textOf(created['number'])} ${textOf(created['url'])}` });
|
|
271
|
+
await guarded(out, 'initialize project fields', async () => {
|
|
272
|
+
await initializeFields(out, client, { owner, name: title, suffix });
|
|
273
|
+
});
|
|
274
|
+
await guarded(out, 'sync project config', async () => {
|
|
275
|
+
await syncProjectConfig(out, client, { owner, name: title, host, suffix });
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
return 0;
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
// project activate
|
|
282
|
+
// 設定ファイルのパスか、projects/ にあるファイル名か
|
|
283
|
+
function findConfigFileArgument(project) {
|
|
284
|
+
if (isFile(path.resolve(project)))
|
|
285
|
+
return resolveRealPath(path.resolve(project));
|
|
286
|
+
const named = path.join(projectsDirectory(), project.endsWith('.json') ? project : `${project}.json`);
|
|
287
|
+
return isFile(named) ? named : undefined;
|
|
288
|
+
}
|
|
289
|
+
async function activateFromConfigFile(out, configPath, host) {
|
|
290
|
+
let config;
|
|
291
|
+
try {
|
|
292
|
+
config = loadConfig(configPath);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
// Python の `except Exception` と同じ範囲(あらゆる Error)で捕まえる
|
|
296
|
+
if (!(error instanceof Error) || error instanceof CommandExit)
|
|
297
|
+
throw error;
|
|
298
|
+
return stopWith(out, `could not load config file ${path.basename(configPath)}: ${error.message}`);
|
|
299
|
+
}
|
|
300
|
+
await guarded(out, 'sync project', async () => {
|
|
301
|
+
if (host !== undefined && config.host !== host) {
|
|
302
|
+
out.warning(`--host (${host}) differs from the config file host (${config.host})\nusing the config file host`);
|
|
303
|
+
}
|
|
304
|
+
const client = createGitHubClient(out, config.host);
|
|
305
|
+
const projectInfo = await client.getProjectFields(config.owner, config.project.number);
|
|
306
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
307
|
+
stopWith(out, `project #${String(config.project.number)} not found`);
|
|
308
|
+
const title = projectInfo['title'];
|
|
309
|
+
if (typeof title !== 'string' || title === '')
|
|
310
|
+
stopWith(out, `could not read the title of project #${String(config.project.number)}`);
|
|
311
|
+
await syncProjectConfig(out, client, { owner: config.owner, name: title, host: config.host });
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async function resolveActivationOwner(out, client, owner) {
|
|
315
|
+
if (owner !== undefined)
|
|
316
|
+
return owner;
|
|
317
|
+
let login;
|
|
318
|
+
try {
|
|
319
|
+
login = jsonField(await client.getAuthenticatedUser(), 'login');
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
if (error instanceof GitHubAPIError)
|
|
323
|
+
return stopWith(out, `could not read the authenticated user: ${error.message}\npass --owner to give the owner explicitly`);
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
return typeof login === 'string' && login !== '' ? login : stopWith(out, 'could not read the authenticated user');
|
|
327
|
+
}
|
|
328
|
+
// 一覧の表示モード。初期化済みのプロジェクトに [ACTIVE] を付ける
|
|
329
|
+
async function echoInitializedProjects(out, client, host, owner) {
|
|
330
|
+
const lines = [`=== Initialized projects (${host}/${owner}) ===`];
|
|
331
|
+
const initialized = [];
|
|
332
|
+
const owned = await client.listProjects(owner);
|
|
333
|
+
for (const project of owned) {
|
|
334
|
+
const number = project['number'];
|
|
335
|
+
if (number === undefined || number === null)
|
|
336
|
+
continue;
|
|
337
|
+
const projectInfo = await client.getProjectFields(owner, requireNumber(number, 'project.number'));
|
|
338
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
339
|
+
continue;
|
|
340
|
+
if (hasWorkflowField(fieldNodesOf(projectInfo)))
|
|
341
|
+
initialized.push(project);
|
|
342
|
+
}
|
|
343
|
+
if (initialized.length === 0) {
|
|
344
|
+
lines.push(' none');
|
|
345
|
+
out.data(lines.join('\n'));
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const activeNumber = activeProjectNumber(host, owner);
|
|
349
|
+
for (const project of initialized) {
|
|
350
|
+
const number = jsonField(project, 'number');
|
|
351
|
+
const title = jsonField(project, 'title');
|
|
352
|
+
lines.push(` #${textOf(number)}: ${title === undefined ? '(untitled)' : textOf(title)}${activeNumber === number ? ' [ACTIVE]' : ''}`);
|
|
353
|
+
}
|
|
354
|
+
out.data(lines.join('\n'));
|
|
355
|
+
}
|
|
356
|
+
function activeProjectNumber(host, owner) {
|
|
357
|
+
const activePath = getActiveConfigPath();
|
|
358
|
+
if (activePath === undefined)
|
|
359
|
+
return undefined;
|
|
360
|
+
try {
|
|
361
|
+
const active = loadConfig(activePath);
|
|
362
|
+
return active.host === host && active.owner === owner ? active.project.number : undefined;
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
// 読めない設定は、アクティブの印を付けないだけにする。Python の `except Exception` と同じ範囲で捕まえる
|
|
366
|
+
if (error instanceof Error)
|
|
367
|
+
return undefined;
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
// 番号か名前でプロジェクトの情報を取る
|
|
372
|
+
async function fetchProjectInfoByReference(out, client, owner, project) {
|
|
373
|
+
if (/^\d+$/u.test(project)) {
|
|
374
|
+
const number = Number(project);
|
|
375
|
+
return await client.getProjectFields(owner, number) ?? stopWith(out, `project #${String(number)} not found`);
|
|
376
|
+
}
|
|
377
|
+
const found = await findProjectByTitle(out, client, owner, project);
|
|
378
|
+
const info = await client.getProjectFields(owner, requireNumber(found['number'], 'project.number'));
|
|
379
|
+
return info !== undefined && isTruthy(info) ? info : stopWith(out, `could not read project fields: ${project}`);
|
|
380
|
+
}
|
|
381
|
+
async function activateByReference(out, client, target) {
|
|
382
|
+
const { host, owner, project } = target;
|
|
383
|
+
const info = await fetchProjectInfoByReference(out, client, owner, project);
|
|
384
|
+
const title = textOf(info['title'] ?? '');
|
|
385
|
+
if (!hasWorkflowField(asArray(jsonField(info['fields'], 'nodes')))) {
|
|
386
|
+
stopWith(out, `project "${title}" is not initialized\nrun: pecot project init --host ${host} --suffix <suffix> ${owner} "${title}"`);
|
|
387
|
+
}
|
|
388
|
+
await syncProjectConfig(out, client, { owner, name: title, host });
|
|
389
|
+
}
|
|
390
|
+
const activateCommand = defineCommand({
|
|
391
|
+
path: ['project', 'activate'],
|
|
392
|
+
description: 'Activate an initialized project',
|
|
393
|
+
input: z.strictObject({
|
|
394
|
+
project: z.string().optional().describe('Project number or name, or config file path/file name'),
|
|
395
|
+
owner: z.string().optional().describe('Project owner (defaults to the authenticated user)'),
|
|
396
|
+
host: z.string().optional().describe('GitHub host'),
|
|
397
|
+
}),
|
|
398
|
+
positional: ['project'],
|
|
399
|
+
shortFlags: { owner: '-o', host: '-h' },
|
|
400
|
+
interactive: false,
|
|
401
|
+
run: async (input, io) => {
|
|
402
|
+
const out = createOutput(false, io);
|
|
403
|
+
const { project, host } = input;
|
|
404
|
+
// --host の要らない形(設定ファイルのパスか名前)を先に見る
|
|
405
|
+
const configPath = project === undefined ? undefined : findConfigFileArgument(project);
|
|
406
|
+
if (configPath !== undefined) {
|
|
407
|
+
await activateFromConfigFile(out, configPath, host);
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
await guarded(out, 'activate project', async () => {
|
|
411
|
+
if (host === undefined) {
|
|
412
|
+
stopWith(out, '--host is required\n'
|
|
413
|
+
+ 'example: pecot project activate --host github.com --owner example-org\n'
|
|
414
|
+
+ 'example: pecot project activate --host ghes.example.com --owner example-org\n'
|
|
415
|
+
+ 'example: pecot project activate ghes.example.com_example-org_example-project_example-org');
|
|
416
|
+
}
|
|
417
|
+
const client = createGitHubClient(out, host);
|
|
418
|
+
const owner = await resolveActivationOwner(out, client, input.owner);
|
|
419
|
+
if (project === undefined)
|
|
420
|
+
await echoInitializedProjects(out, client, host, owner);
|
|
421
|
+
else
|
|
422
|
+
await activateByReference(out, client, { host, owner, project });
|
|
423
|
+
});
|
|
424
|
+
return 0;
|
|
425
|
+
},
|
|
426
|
+
});
|
|
427
|
+
// project info
|
|
428
|
+
const infoCommand = defineCommand({
|
|
429
|
+
path: ['project', 'info'],
|
|
430
|
+
description: 'Show the project info dashboard',
|
|
431
|
+
input: z.strictObject({
|
|
432
|
+
json: z.boolean().default(false).describe('Output as JSON'),
|
|
433
|
+
repo: z.string().superRefine((value, context) => {
|
|
434
|
+
try {
|
|
435
|
+
parseOwnerRepository(value);
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
if (!(error instanceof InvalidValueError))
|
|
439
|
+
throw error;
|
|
440
|
+
context.addIssue({ code: 'custom', message: `must be in 'owner/repo' form: ${error.message}` });
|
|
441
|
+
}
|
|
442
|
+
}).optional().describe('Target repository, given explicitly as \'owner/repo\''),
|
|
443
|
+
}),
|
|
444
|
+
hasOwnRepo: true,
|
|
445
|
+
positional: [],
|
|
446
|
+
shortFlags: { json: '-j' },
|
|
447
|
+
interactive: false,
|
|
448
|
+
run: async (input, io) => {
|
|
449
|
+
const out = createOutput(false, io);
|
|
450
|
+
const config = requireActiveConfig(out);
|
|
451
|
+
const configPath = getActiveConfigPath();
|
|
452
|
+
const projectName = configPath === undefined ? `${config.host}_${config.owner}_${String(config.project.number)}` : path.parse(configPath).name;
|
|
453
|
+
try {
|
|
454
|
+
const client = createGitHubClient(out, config.host);
|
|
455
|
+
const { allItems, items } = await readBoard(client, config, input.repo);
|
|
456
|
+
const statuses = await collectAlertStatuses(client, config);
|
|
457
|
+
await pruneArchivedItems(out, client, config, allItems);
|
|
458
|
+
const view = { config, projectName, statuses };
|
|
459
|
+
out.data(input.json ? infoJson(view, items) : infoMarkdown(view, input.repo, formatBoardOutput(items)));
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
if (error instanceof GitHubAPIError)
|
|
463
|
+
return failApi(out, 'read project board', error);
|
|
464
|
+
// Python の `except Exception` と同じ範囲(あらゆる Error)で捕まえる
|
|
465
|
+
if (error instanceof Error && !(error instanceof CommandExit))
|
|
466
|
+
return stopWith(out, `unexpected error: ${error.message}`);
|
|
467
|
+
throw error;
|
|
468
|
+
}
|
|
469
|
+
return 0;
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
// project set-repo
|
|
473
|
+
const packageList = z.array(z.string());
|
|
474
|
+
function parsePackages(out, input) {
|
|
475
|
+
const specs = input.package;
|
|
476
|
+
if (specs === undefined || specs.length === 0)
|
|
477
|
+
return undefined;
|
|
478
|
+
if (input.changelog_file !== undefined)
|
|
479
|
+
stopWith(out, '--package and --changelog-file cannot be used together');
|
|
480
|
+
if (input.clear_packages)
|
|
481
|
+
stopWith(out, '--package and --clear-packages cannot be used together');
|
|
482
|
+
const parsed = [];
|
|
483
|
+
const seen = new Set();
|
|
484
|
+
for (const spec of specs) {
|
|
485
|
+
const separator = spec.indexOf(':');
|
|
486
|
+
if (separator === -1)
|
|
487
|
+
stopWith(out, `give --package as NAME:PATH: ${pythonStringRepr(spec)}`);
|
|
488
|
+
const name = pythonStrip(spec.slice(0, separator));
|
|
489
|
+
const changelog = pythonStrip(spec.slice(separator + 1));
|
|
490
|
+
if (name === '' || changelog === '')
|
|
491
|
+
stopWith(out, `--package NAME and PATH must not be empty: ${pythonStringRepr(spec)}`);
|
|
492
|
+
if (seen.has(name))
|
|
493
|
+
stopWith(out, `--package NAME is duplicated: ${pythonStringRepr(name)}`);
|
|
494
|
+
seen.add(name);
|
|
495
|
+
// Python も Package(...) の作成で NAME の形を確かめるので、設定を読む前に止まる
|
|
496
|
+
parsed.push(parsePackage({ name, changelog }));
|
|
497
|
+
}
|
|
498
|
+
return parsed;
|
|
499
|
+
}
|
|
500
|
+
// 登録済みのエントリを、指定されたオプションの分だけ更新する
|
|
501
|
+
function updatedRepository(out, existing, edit) {
|
|
502
|
+
let { packages, changelog_file: changelogFile } = existing;
|
|
503
|
+
if (edit.packages === undefined) {
|
|
504
|
+
if (edit.clear_packages)
|
|
505
|
+
packages = undefined;
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
packages = edit.packages;
|
|
509
|
+
changelogFile = undefined;
|
|
510
|
+
}
|
|
511
|
+
if (edit.changelog_file !== undefined) {
|
|
512
|
+
if (packages !== undefined && packages.length > 0) {
|
|
513
|
+
stopWith(out, 'this repository has packages set\nrun with --clear-packages before switching to --changelog-file');
|
|
514
|
+
}
|
|
515
|
+
changelogFile = edit.changelog_file;
|
|
516
|
+
}
|
|
517
|
+
return buildRepository({
|
|
518
|
+
...existing,
|
|
519
|
+
develop_branch: edit.develop_branch ?? existing.develop_branch,
|
|
520
|
+
release_branch: edit.release_branch ?? existing.release_branch,
|
|
521
|
+
changelog_file: changelogFile,
|
|
522
|
+
packages,
|
|
523
|
+
release_type: toReleaseType(edit.release_type) ?? existing.release_type,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
function toReleaseType(value) {
|
|
527
|
+
return RELEASE_TYPES.find(type => type === value);
|
|
528
|
+
}
|
|
529
|
+
async function linkRepository(out, config, repositoryOwner, repositoryName) {
|
|
530
|
+
try {
|
|
531
|
+
return await createGitHubClient(out, config.host).linkRepositoryToProject(config.owner, config.project.number, repositoryOwner, repositoryName);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
// API の失敗の文は、Python と同じく message をそのまま使う(応答の本文の詳細は、wip ブランチの削除の警告だけが足す)
|
|
535
|
+
if (error instanceof GitHubAPIError)
|
|
536
|
+
return { status: 'failed', detail: error.message };
|
|
537
|
+
throw error;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const repositorySettingCommand = defineCommand({
|
|
541
|
+
path: ['project', 'set-repo'],
|
|
542
|
+
description: 'Add or update a repository in the project config',
|
|
543
|
+
input: z.strictObject({
|
|
544
|
+
owner_repo: z.string().describe('Repository name in owner/repo form'),
|
|
545
|
+
develop_branch: z.string().optional().describe('Development branch name'),
|
|
546
|
+
release_branch: z.string().optional().describe('Release branch name'),
|
|
547
|
+
changelog_file: z.string().optional().describe('CHANGELOG file name'),
|
|
548
|
+
package: packageList.optional().describe('Register a monorepo package as NAME:PATH. Can be repeated. Example: --package pecot:plugins/pecot-workflow/CHANGELOG.md'),
|
|
549
|
+
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'),
|
|
550
|
+
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)'),
|
|
551
|
+
}),
|
|
552
|
+
positional: ['owner_repo'],
|
|
553
|
+
shortFlags: { develop_branch: '-b' },
|
|
554
|
+
interactive: false,
|
|
555
|
+
run: async (input, io) => {
|
|
556
|
+
const out = createOutput(false, io);
|
|
557
|
+
if (input.release_type !== undefined && toReleaseType(input.release_type) === undefined) {
|
|
558
|
+
// Python は sorted() の順(multi, nx, single)で見せる
|
|
559
|
+
stopWith(out, `--release-type must be one of [${RELEASE_TYPES.toSorted(compareStrings).map(type => pythonStringRepr(type)).join(', ')}] (got: ${pythonStringRepr(input.release_type)})`);
|
|
560
|
+
}
|
|
561
|
+
const packages = parsePackages(out, input);
|
|
562
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
563
|
+
const parts = splitOwnerRepository(input.owner_repo);
|
|
564
|
+
if (parts === undefined)
|
|
565
|
+
stopWith(out, 'give the repository as owner/repo\nexample: pecot project set-repo example-org/my-repo');
|
|
566
|
+
const { owner, repository: name } = parts;
|
|
567
|
+
if (owner !== config.owner) {
|
|
568
|
+
stopWith(out, `repository owner ${owner} differs from project owner ${config.owner}\nGitHub Projects V2 links only repositories of the project owner`);
|
|
569
|
+
}
|
|
570
|
+
const existing = findRepository(config, owner, name);
|
|
571
|
+
let next;
|
|
572
|
+
let saved;
|
|
573
|
+
if (existing === undefined) {
|
|
574
|
+
const outcome = await linkRepository(out, config, owner, name);
|
|
575
|
+
const projectNumber = String(config.project.number);
|
|
576
|
+
if (outcome.status === 'failed')
|
|
577
|
+
stopWith(out, `could not link ${input.owner_repo} to project #${projectNumber}: ${outcome.detail}`);
|
|
578
|
+
out.done(outcome.status === 'already_linked'
|
|
579
|
+
? { verb: 'unchanged', target: `${input.owner_repo} in project #${projectNumber}` }
|
|
580
|
+
: { verb: 'add', target: `${input.owner_repo} to project #${projectNumber}` });
|
|
581
|
+
next = withRepositoryAppended(config, buildRepository({
|
|
582
|
+
owner,
|
|
583
|
+
name,
|
|
584
|
+
develop_branch: input.develop_branch,
|
|
585
|
+
release_branch: input.release_branch,
|
|
586
|
+
changelog_file: packages === undefined ? input.changelog_file : undefined,
|
|
587
|
+
packages,
|
|
588
|
+
release_type: toReleaseType(input.release_type),
|
|
589
|
+
}));
|
|
590
|
+
saved = { verb: 'add', target: `${owner}/${name} to ${configPath}` };
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
next = withRepositoryReplaced(config, updatedRepository(out, existing, { ...input, packages }));
|
|
594
|
+
saved = { verb: 'update', target: `${owner}/${name} in ${configPath}` };
|
|
595
|
+
}
|
|
596
|
+
saveConfig(validated(next), configPath);
|
|
597
|
+
out.done(saved);
|
|
598
|
+
return 0;
|
|
599
|
+
},
|
|
600
|
+
});
|
|
601
|
+
// aggregation_repo の管理
|
|
602
|
+
const aggregationSettingCommand = defineCommand({
|
|
603
|
+
path: ['project', 'set-aggregation-repo'],
|
|
604
|
+
description: 'Set the Epic aggregation repository (``aggregation_repo``)',
|
|
605
|
+
input: z.strictObject({
|
|
606
|
+
value: z.string().describe('Aggregation repository (owner/repo form)'),
|
|
607
|
+
yes: z.boolean().default(false).describe('Overwrite an existing value without confirmation (a warning goes to stderr)'),
|
|
608
|
+
}),
|
|
609
|
+
positional: ['value'],
|
|
610
|
+
shortFlags: { yes: '-y' },
|
|
611
|
+
interactive: false,
|
|
612
|
+
run: (input, io) => {
|
|
613
|
+
const out = createOutput(false, io);
|
|
614
|
+
const { value, yes } = input;
|
|
615
|
+
if (!AGGREGATION_REPOSITORY_PATTERN.test(value))
|
|
616
|
+
stopWith(out, `give aggregation_repo as owner/repo: ${pythonStringRepr(value)}`);
|
|
617
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
618
|
+
const current = config.aggregation_repo;
|
|
619
|
+
if (current !== undefined && current !== '' && current !== value) {
|
|
620
|
+
out.warning(`overwriting aggregation_repo: ${current} -> ${value}${yes ? '' : '\npass --yes to omit this hint'}`);
|
|
621
|
+
}
|
|
622
|
+
else if (current === value) {
|
|
623
|
+
out.done({ verb: 'unchanged', target: `aggregation_repo ${value}` });
|
|
624
|
+
return Promise.resolve(0);
|
|
625
|
+
}
|
|
626
|
+
saveConfig(withAggregationRepository(config, value), configPath);
|
|
627
|
+
out.done({ verb: 'set', target: `aggregation_repo to ${value}` });
|
|
628
|
+
return Promise.resolve(0);
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
const aggregationClearCommand = defineCommand({
|
|
632
|
+
path: ['project', 'unset-aggregation-repo'],
|
|
633
|
+
description: 'Clear the Epic aggregation repository (``aggregation_repo``); creating an Epic after this needs --repo',
|
|
634
|
+
input: z.strictObject({}),
|
|
635
|
+
positional: [],
|
|
636
|
+
interactive: false,
|
|
637
|
+
run: (_input, io) => {
|
|
638
|
+
const out = createOutput(false, io);
|
|
639
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
640
|
+
const previous = config.aggregation_repo;
|
|
641
|
+
if (previous === undefined) {
|
|
642
|
+
out.done({ verb: 'unchanged', target: 'aggregation_repo (not set)' });
|
|
643
|
+
return Promise.resolve(0);
|
|
644
|
+
}
|
|
645
|
+
saveConfig(withAggregationRepository(config, undefined), configPath);
|
|
646
|
+
out.done({ verb: 'remove', target: `aggregation_repo (was ${previous})` });
|
|
647
|
+
return Promise.resolve(0);
|
|
648
|
+
},
|
|
649
|
+
});
|
|
650
|
+
const showAggregationCommand = defineCommand({
|
|
651
|
+
path: ['project', 'show-aggregation-repo'],
|
|
652
|
+
description: 'Show the Epic aggregation repository (``aggregation_repo``)',
|
|
653
|
+
input: z.strictObject({}),
|
|
654
|
+
positional: [],
|
|
655
|
+
interactive: false,
|
|
656
|
+
run: (_input, io) => {
|
|
657
|
+
const out = createOutput(false, io);
|
|
658
|
+
out.data(requireActiveConfig(out).aggregation_repo ?? 'none');
|
|
659
|
+
return Promise.resolve(0);
|
|
660
|
+
},
|
|
661
|
+
});
|
|
662
|
+
/**
|
|
663
|
+
project のコマンド。並びは tests/parity/commands.ts と同じ
|
|
664
|
+
*/
|
|
665
|
+
export const PROJECT_COMMANDS = [
|
|
666
|
+
listCommand,
|
|
667
|
+
searchCommand,
|
|
668
|
+
initCommand,
|
|
669
|
+
projectCreationCommand,
|
|
670
|
+
infoCommand,
|
|
671
|
+
activateCommand,
|
|
672
|
+
repositorySettingCommand,
|
|
673
|
+
aggregationSettingCommand,
|
|
674
|
+
aggregationClearCommand,
|
|
675
|
+
showAggregationCommand,
|
|
676
|
+
];
|
|
677
|
+
//# sourceMappingURL=project.js.map
|