@pecot/workflow-mcp 5.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +27 -22
- package/cli/dist/cli.js +6 -1
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +69 -0
- package/cli/dist/commands/board-judgment.d.ts +69 -0
- package/cli/dist/commands/board-judgment.js +150 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +65 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +75 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +120 -0
- package/cli/dist/commands/board-view.d.ts +151 -0
- package/cli/dist/commands/board-view.js +293 -0
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +111 -0
- package/cli/dist/commands/command-binding.js +4 -0
- package/cli/dist/commands/command-definition.d.ts +39 -8
- package/cli/dist/commands/command-definition.js +20 -7
- package/cli/dist/commands/command-help.js +2 -2
- package/cli/dist/commands/command-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +5 -3
- package/cli/dist/commands/command-stop.js +7 -6
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +35 -0
- package/cli/dist/commands/failure.d.ts +6 -0
- package/cli/dist/commands/failure.js +29 -3
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +13 -3
- package/cli/dist/commands/help.js +8 -13
- package/cli/dist/commands/issue-board.d.ts +61 -0
- package/cli/dist/commands/issue-board.js +85 -1
- package/cli/dist/commands/issue-comment.js +66 -30
- package/cli/dist/commands/issue-create.js +632 -92
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +310 -0
- package/cli/dist/commands/issue-readiness.d.ts +122 -0
- package/cli/dist/commands/issue-readiness.js +253 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +130 -0
- package/cli/dist/commands/issue-shared.d.ts +33 -20
- package/cli/dist/commands/issue-shared.js +84 -76
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +239 -0
- package/cli/dist/commands/issue.d.ts +0 -1
- package/cli/dist/commands/issue.js +6 -8
- package/cli/dist/commands/names.d.ts +33 -0
- package/cli/dist/commands/names.js +63 -0
- package/cli/dist/commands/output.d.ts +32 -4
- package/cli/dist/commands/output.js +28 -8
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +230 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +233 -0
- package/cli/dist/commands/pr-waiting.d.ts +59 -0
- package/cli/dist/commands/pr-waiting.js +143 -0
- package/cli/dist/commands/pr.d.ts +23 -0
- package/cli/dist/commands/pr.js +378 -366
- package/cli/dist/commands/project-sync.d.ts +12 -3
- package/cli/dist/commands/project-sync.js +23 -13
- package/cli/dist/commands/project.d.ts +3 -2
- package/cli/dist/commands/project.js +371 -177
- package/cli/dist/commands/registry.js +15 -10
- package/cli/dist/commands/release.d.ts +2 -2
- package/cli/dist/commands/release.js +118 -130
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-match.js +9 -3
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +383 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +252 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +186 -32
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
- package/cli/dist/commands/tracker-sync.d.ts +37 -0
- package/cli/dist/commands/tracker-sync.js +18 -6
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +20 -0
- package/cli/dist/commands/usage-error.d.ts +4 -0
- package/cli/dist/commands/usage-error.js +6 -0
- package/cli/dist/commands/work-target.d.ts +20 -3
- package/cli/dist/commands/work-target.js +49 -6
- package/cli/dist/commands/worktree.js +103 -33
- package/cli/dist/domain/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -0
- package/cli/dist/domain/branch-name.js +1 -1
- package/cli/dist/domain/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +4 -0
- package/cli/dist/domain/config.js +11 -1
- package/cli/dist/domain/dependabot.js +1 -1
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/format.d.ts +51 -4
- package/cli/dist/domain/format.js +72 -6
- package/cli/dist/domain/frontmatter.d.ts +18 -3
- package/cli/dist/domain/frontmatter.js +38 -12
- package/cli/dist/domain/issue-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +36 -4
- package/cli/dist/domain/pull-request.d.ts +71 -4
- package/cli/dist/domain/pull-request.js +59 -10
- package/cli/dist/domain/readiness.d.ts +44 -0
- package/cli/dist/domain/readiness.js +153 -5
- package/cli/dist/domain/reference-parser.d.ts +3 -1
- package/cli/dist/domain/reference-parser.js +6 -2
- package/cli/dist/domain/release.d.ts +7 -3
- package/cli/dist/domain/release.js +5 -12
- package/cli/dist/domain/repository-policy.d.ts +9 -3
- package/cli/dist/domain/repository-policy.js +8 -7
- package/cli/dist/domain/repository-resolver.js +4 -1
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/security-alerts.js +1 -1
- package/cli/dist/domain/state.d.ts +69 -0
- package/cli/dist/domain/state.js +67 -1
- package/cli/dist/domain/work-start.d.ts +30 -0
- package/cli/dist/domain/work-start.js +42 -0
- package/cli/dist/infra/authored-notes.d.ts +1 -1
- package/cli/dist/infra/authored-notes.js +10 -4
- package/cli/dist/infra/config-store.d.ts +4 -0
- package/cli/dist/infra/config-store.js +13 -0
- package/cli/dist/infra/git.d.ts +76 -0
- package/cli/dist/infra/git.js +123 -1
- package/cli/dist/infra/github/client.d.ts +5 -0
- package/cli/dist/infra/github/client.js +10 -7
- package/cli/dist/infra/github/errors.d.ts +18 -0
- package/cli/dist/infra/github/errors.js +22 -0
- package/cli/dist/infra/github/issues.d.ts +39 -3
- package/cli/dist/infra/github/issues.js +178 -23
- package/cli/dist/infra/github/projects.d.ts +35 -0
- package/cli/dist/infra/github/projects.js +89 -8
- package/cli/dist/infra/github/pulls.d.ts +105 -2
- package/cli/dist/infra/github/pulls.js +172 -5
- package/cli/dist/infra/github/queries.d.ts +15 -4
- package/cli/dist/infra/github/queries.js +203 -40
- package/cli/dist/infra/github/readout.d.ts +5 -1
- package/cli/dist/infra/github/readout.js +11 -33
- package/cli/dist/infra/github/repos.d.ts +18 -0
- package/cli/dist/infra/github/repos.js +31 -0
- package/cli/dist/infra/nx-scope.d.ts +1 -1
- package/cli/dist/infra/nx-scope.js +1 -1
- package/cli/dist/infra/state-store.d.ts +10 -1
- package/cli/dist/infra/state-store.js +14 -2
- package/cli/dist/infra/worktree-links.d.ts +3 -0
- package/cli/dist/infra/worktree-links.js +8 -1
- package/cli/dist/infra/worktree.d.ts +12 -1
- package/cli/dist/infra/worktree.js +40 -23
- package/cli/dist/mcp/result.d.ts +82 -7
- package/cli/dist/mcp/result.js +139 -19
- package/cli/dist/mcp/server.d.ts +2 -2
- package/cli/dist/mcp/server.js +57 -10
- package/cli/templates/comment/plan.md +14 -0
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task-implement.md +13 -6
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/cli/dist/commands/dependabot.d.ts +0 -3
- package/cli/dist/commands/issue-project.d.ts +0 -3
- package/cli/dist/commands/issue-project.js +0 -176
- package/cli/dist/commands/issue-quick.d.ts +0 -3
- package/cli/dist/commands/issue-quick.js +0 -126
- package/cli/dist/commands/issue-read.d.ts +0 -3
- package/cli/dist/commands/issue-read.js +0 -80
- package/cli/dist/commands/project-info.d.ts +0 -48
- package/cli/dist/commands/project-info.js +0 -181
- package/cli/dist/commands/repository.d.ts +0 -5
- package/cli/dist/commands/repository.js +0 -265
- package/cli/dist/commands/security.d.ts +0 -3
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
// project
|
|
1
|
+
// project のグループのコマンド。Python の cli/commands/project.py の移植。
|
|
2
2
|
import { readdirSync, statSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { RELEASE_TYPES, findRepository, parsePackage, withAggregationRepository, withRepositoryAppended, withRepositoryReplaced, parseProjectConfig, serializeProjectConfig } from '../domain/config.js';
|
|
6
6
|
import { choosePlacement, insertOption } from '../domain/field-options.js';
|
|
7
|
-
import { formatBoardOutput } from '../domain/format.js';
|
|
8
7
|
import { jsonField, parseJsonText } from '../domain/json.js';
|
|
9
8
|
import { compareStrings, pythonStrip, pythonStringRepr, splitCodePoints, truncateCodePoints } from '../domain/python-format.js';
|
|
10
|
-
import {
|
|
11
|
-
import { InvalidValueError } from '../domain/errors.js';
|
|
9
|
+
import { splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
12
10
|
import { getActiveConfigPath, loadConfig, projectsDirectory, saveConfig } from '../infra/config-store.js';
|
|
13
11
|
import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
|
|
14
12
|
import { asArray, isTruthy, requireNumber, requireString } from '../infra/github/payload.js';
|
|
15
13
|
import { resolveRealPath } from '../infra/paths.js';
|
|
16
14
|
import { hasErrorCode } from '../infra/os-error.js';
|
|
17
15
|
import { CommandExit, defineCommand } from './command-definition.js';
|
|
16
|
+
import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
|
|
18
17
|
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
18
|
+
import { kindOfFailure } from './failure.js';
|
|
19
19
|
import { createGitHubClient } from './github-client.js';
|
|
20
|
-
import { createOutput } from './output.js';
|
|
21
|
-
import { collectAlertStatuses, infoJson, infoMarkdown, pruneArchivedItems, readBoard } from './project-info.js';
|
|
20
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
22
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';
|
|
23
22
|
const DEFAULT_HOST = 'github.com';
|
|
23
|
+
function linkChange(existing) {
|
|
24
|
+
return existing === undefined ? 'create' : 'update';
|
|
25
|
+
}
|
|
26
|
+
function setChange(hasPrevious) {
|
|
27
|
+
return hasPrevious ? 'update' : 'create';
|
|
28
|
+
}
|
|
29
|
+
const dryRunInput = z.boolean().default(false).describe('Show what would change without writing anything');
|
|
24
30
|
const AGGREGATION_REPOSITORY_PATTERN = /^[\w.-]+\/[\w.-]+$/u;
|
|
25
31
|
const MISSING_PATH_CODES = new Set(['ENOENT', 'ENOTDIR', 'ELOOP']);
|
|
26
32
|
const SEARCH_TITLE_LIMIT = 38;
|
|
@@ -70,7 +76,7 @@ function padEndCodePoints(text, width) {
|
|
|
70
76
|
}
|
|
71
77
|
function requireActiveWithPath(out) {
|
|
72
78
|
const config = requireActiveConfig(out);
|
|
73
|
-
const configPath = getActiveConfigPath() ?? stopWith(out, 'cannot determine the config file path');
|
|
79
|
+
const configPath = getActiveConfigPath() ?? stopWith(out, 'cannot determine the config file path', 'config-invalid');
|
|
74
80
|
return { config, configPath };
|
|
75
81
|
}
|
|
76
82
|
// 保存の前に、設定として読み直せる形かを確かめる(読めなければ ValidationFailure)
|
|
@@ -78,10 +84,18 @@ function validated(config) {
|
|
|
78
84
|
return parseProjectConfig(parseJsonText(serializeProjectConfig(config)));
|
|
79
85
|
}
|
|
80
86
|
// project list
|
|
87
|
+
const LIST_ROW = z.strictObject({
|
|
88
|
+
name: z.string().describe('Name of the project config (the file name without .json)'),
|
|
89
|
+
active: z.boolean().describe('Whether this config is the active project'),
|
|
90
|
+
});
|
|
91
|
+
const LIST_OUTPUT = z.strictObject({
|
|
92
|
+
projects: z.array(LIST_ROW).describe('Project configs under the projects directory (an empty array when there is none)'),
|
|
93
|
+
});
|
|
81
94
|
const listCommand = defineCommand({
|
|
82
95
|
path: ['project', 'list'],
|
|
83
96
|
description: 'List available projects',
|
|
84
97
|
input: z.strictObject({}),
|
|
98
|
+
output: LIST_OUTPUT,
|
|
85
99
|
positional: [],
|
|
86
100
|
interactive: false,
|
|
87
101
|
run: (_input, io) => {
|
|
@@ -92,18 +106,32 @@ const listCommand = defineCommand({
|
|
|
92
106
|
if (files.length === 0) {
|
|
93
107
|
lines.push(' none');
|
|
94
108
|
out.data(lines.join('\n'));
|
|
109
|
+
out.result({ projects: [] });
|
|
95
110
|
return Promise.resolve(0);
|
|
96
111
|
}
|
|
97
112
|
const active = getActiveConfigPath();
|
|
113
|
+
const projects = [];
|
|
98
114
|
for (const file of files) {
|
|
99
115
|
const isActive = active !== undefined && resolveRealPath(path.join(directory, file)) === resolveRealPath(active);
|
|
100
116
|
lines.push(` ${path.parse(file).name}${isActive ? ' [ACTIVE]' : ''}`);
|
|
117
|
+
projects.push({ name: path.parse(file).name, active: isActive });
|
|
101
118
|
}
|
|
102
119
|
out.data(lines.join('\n'));
|
|
120
|
+
out.result({ projects });
|
|
103
121
|
return Promise.resolve(0);
|
|
104
122
|
},
|
|
105
123
|
});
|
|
106
124
|
// project search
|
|
125
|
+
const SEARCH_ROW = z.strictObject({
|
|
126
|
+
number: z.int().optional().describe('Project number (omitted when GitHub did not return it)'),
|
|
127
|
+
title: z.string().optional().describe('Project title (omitted when GitHub did not return it)'),
|
|
128
|
+
url: z.string().optional().describe('Project URL (omitted when GitHub did not return it)'),
|
|
129
|
+
});
|
|
130
|
+
const SEARCH_OUTPUT = z.strictObject({
|
|
131
|
+
owner: z.string().describe('Project owner that was searched'),
|
|
132
|
+
host: z.string().describe('GitHub host that was searched'),
|
|
133
|
+
projects: z.array(SEARCH_ROW).describe('Projects of the owner'),
|
|
134
|
+
});
|
|
107
135
|
const searchCommand = defineCommand({
|
|
108
136
|
path: ['project', 'search'],
|
|
109
137
|
description: 'Search projects through the GitHub API',
|
|
@@ -111,6 +139,7 @@ const searchCommand = defineCommand({
|
|
|
111
139
|
owner: z.string().describe('Project owner'),
|
|
112
140
|
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
113
141
|
}),
|
|
142
|
+
output: SEARCH_OUTPUT,
|
|
114
143
|
positional: ['owner'],
|
|
115
144
|
shortFlags: { host: '-h' },
|
|
116
145
|
interactive: false,
|
|
@@ -120,7 +149,7 @@ const searchCommand = defineCommand({
|
|
|
120
149
|
await guarded(out, 'list projects', async () => {
|
|
121
150
|
const projects = await createGitHubClient(out, host).listProjects(owner);
|
|
122
151
|
if (projects.length === 0)
|
|
123
|
-
stopWith(out, `no projects found for ${owner}
|
|
152
|
+
stopWith(out, `no projects found for ${owner}`, 'project-not-found');
|
|
124
153
|
const lines = [`=== Projects of ${owner} (${host}) ===`, '', `${padEndCodePoints('#', 4)} ${padEndCodePoints('Title', SEARCH_TITLE_WIDTH)} URL`, '-'.repeat(80)];
|
|
125
154
|
for (const project of projects) {
|
|
126
155
|
const number = project['number'] === undefined ? '?' : textOf(project['number']);
|
|
@@ -129,6 +158,11 @@ const searchCommand = defineCommand({
|
|
|
129
158
|
lines.push(`${padEndCodePoints(number, 4)} ${padEndCodePoints(title, SEARCH_TITLE_WIDTH)} ${project['url'] === undefined ? '' : textOf(project['url'])}`);
|
|
130
159
|
}
|
|
131
160
|
out.data(lines.join('\n'));
|
|
161
|
+
out.result({ owner, host, projects: projects.map(project => ({
|
|
162
|
+
...typeof project['number'] === 'number' && { number: project['number'] },
|
|
163
|
+
...typeof project['title'] === 'string' && { title: project['title'] },
|
|
164
|
+
...typeof project['url'] === 'string' && { url: project['url'] },
|
|
165
|
+
})) });
|
|
132
166
|
});
|
|
133
167
|
return 0;
|
|
134
168
|
},
|
|
@@ -146,15 +180,38 @@ function optionInputsOf(field) {
|
|
|
146
180
|
};
|
|
147
181
|
});
|
|
148
182
|
}
|
|
149
|
-
//
|
|
150
|
-
|
|
183
|
+
// フィールドごとの結果を溜め、進むたびに全体を渡す。
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- data の型が可変の配列
|
|
185
|
+
function fieldReporter(publish) {
|
|
186
|
+
const entries = new Map();
|
|
187
|
+
return (name, change, addedOption) => {
|
|
188
|
+
const entry = entries.get(name) ?? { name, change, addedOptions: [] };
|
|
189
|
+
entry.change = change;
|
|
190
|
+
if (addedOption !== undefined)
|
|
191
|
+
entry.addedOptions.push(addedOption);
|
|
192
|
+
entries.set(name, entry);
|
|
193
|
+
publish?.(Array.from(entries.values(), report => ({ ...report, addedOptions: [...report.addedOptions] })));
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
// 既にあるフィールドに選択肢を 1 つ足す。足した(予行では、足す予定の)数(0 か 1)を返す
|
|
197
|
+
async function addFieldOption(out, client, field, spec, run) {
|
|
198
|
+
const { isDryRun, mark } = run;
|
|
151
199
|
const { option } = spec;
|
|
152
200
|
const fieldName = textOf(field['name']);
|
|
153
201
|
const existing = optionInputsOf(field);
|
|
154
202
|
const merged = insertOption(existing, option, choosePlacement(existing, spec.placement ?? [{ end: true }]));
|
|
155
203
|
if (merged === undefined) {
|
|
156
|
-
|
|
157
|
-
|
|
204
|
+
const unchanged = { verb: 'unchanged', target: `option ${option.name} in field ${fieldName}` };
|
|
205
|
+
out.planned(unchanged);
|
|
206
|
+
out.done(unchanged);
|
|
207
|
+
mark(fieldName, 'unchanged');
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
const added = { verb: 'add', target: `option ${option.name} to field ${fieldName}` };
|
|
211
|
+
if (isDryRun) {
|
|
212
|
+
out.planned(added);
|
|
213
|
+
mark(fieldName, 'update', option.name);
|
|
214
|
+
return 1;
|
|
158
215
|
}
|
|
159
216
|
try {
|
|
160
217
|
await client.updateProjectFieldOptions(requireString(field['id'], 'field.id'), merged);
|
|
@@ -164,29 +221,40 @@ async function addFieldOption(out, client, field, spec) {
|
|
|
164
221
|
throw error;
|
|
165
222
|
// 選択肢の id を拒む GHES などで足せなくても、作ったフィールドと設定ファイルの同期は進める
|
|
166
223
|
out.warning(`could not add option ${option.name} to field ${fieldName}: ${error.message}`);
|
|
167
|
-
|
|
224
|
+
mark(fieldName, 'unchanged');
|
|
225
|
+
return 0;
|
|
168
226
|
}
|
|
169
|
-
out.done(
|
|
227
|
+
out.done(added);
|
|
228
|
+
mark(fieldName, 'update', option.name);
|
|
229
|
+
return 1;
|
|
170
230
|
}
|
|
171
231
|
// 既にあるフィールドに足す選択肢。fields は作る前の状態なので、作ったばかりの進行の欄は「無い」扱いで何も出さない(created の行が出ている)
|
|
172
|
-
|
|
232
|
+
// 足した(予行では、足す予定の)選択肢の数を返す
|
|
233
|
+
async function addMissingOptions(out, client, fields, workflowFieldName, run) {
|
|
173
234
|
const workflowField = lastFieldNamed(fields, workflowFieldName);
|
|
174
|
-
|
|
175
|
-
await addFieldOption(out, client, workflowField, BLOCKED_SPEC);
|
|
235
|
+
const blocked = workflowField === undefined ? 0 : await addFieldOption(out, client, workflowField, BLOCKED_SPEC, run);
|
|
176
236
|
const statusField = lastFieldNamed(fields, STATUS_FIELD_NAME);
|
|
177
|
-
if (statusField === undefined)
|
|
178
|
-
out
|
|
179
|
-
|
|
180
|
-
|
|
237
|
+
if (statusField === undefined) {
|
|
238
|
+
skipped(out, `field ${STATUS_FIELD_NAME} (not found)`);
|
|
239
|
+
run.mark(STATUS_FIELD_NAME, 'skip');
|
|
240
|
+
return blocked;
|
|
241
|
+
}
|
|
242
|
+
return blocked + await addFieldOption(out, client, statusField, NEEDS_ATTENTION_SPEC, run);
|
|
243
|
+
}
|
|
244
|
+
function skipped(out, target) {
|
|
245
|
+
out.planned({ verb: 'skip', target });
|
|
246
|
+
out.done({ verb: 'skip', target });
|
|
181
247
|
}
|
|
182
|
-
//
|
|
183
|
-
|
|
248
|
+
// フィールドを作り、既にあるフィールドには足りない選択肢を足す。既にある進行の欄の必須の値が欠けていれば、何も書かずに止める。
|
|
249
|
+
// 作る・足す(予行では、その予定の)フィールドと選択肢の数を返す
|
|
250
|
+
async function initializeFields(out, client, target, run) {
|
|
184
251
|
const { owner, name, suffix } = target;
|
|
252
|
+
const { isDryRun, mark } = run;
|
|
185
253
|
const project = await findProjectByTitle(out, client, owner, name);
|
|
186
254
|
const projectId = requireString(project['id'], 'project.id');
|
|
187
255
|
const projectInfo = await client.getProjectFields(owner, requireNumber(project['number'], 'project.number'));
|
|
188
256
|
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
189
|
-
stopWith(out, `could not read project fields: ${name}
|
|
257
|
+
stopWith(out, `could not read project fields: ${name}`, 'not-initialized');
|
|
190
258
|
const fields = fieldNodesOf(projectInfo);
|
|
191
259
|
const workflowFieldName = `pecot-workflow-${suffix}`;
|
|
192
260
|
const existingWorkflow = lastFieldNamed(fields, workflowFieldName);
|
|
@@ -200,16 +268,35 @@ async function initializeFields(out, client, target) {
|
|
|
200
268
|
['pecot-priority', PRIORITY_FIELD_OPTIONS],
|
|
201
269
|
['pecot-size', SIZE_FIELD_OPTIONS],
|
|
202
270
|
];
|
|
271
|
+
let newFieldCount = 0;
|
|
203
272
|
for (const [fieldName, options] of wanted) {
|
|
204
273
|
if (fields.some(field => jsonField(field, 'name') === fieldName)) {
|
|
205
|
-
out
|
|
274
|
+
skipped(out, `field ${fieldName} (already exists)`);
|
|
275
|
+
mark(fieldName, 'unchanged');
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
newFieldCount += 1;
|
|
279
|
+
if (isDryRun) {
|
|
280
|
+
out.planned({ verb: 'create', target: `field ${fieldName}` });
|
|
281
|
+
mark(fieldName, 'create');
|
|
206
282
|
continue;
|
|
207
283
|
}
|
|
208
284
|
const created = await client.createProjectField(projectId, fieldName, options);
|
|
209
285
|
out.done({ verb: 'create', target: `field ${fieldName} (ID: ${requireString(created['id'], 'field.id')})` });
|
|
286
|
+
mark(fieldName, 'create');
|
|
210
287
|
}
|
|
211
|
-
await addMissingOptions(out, client, fields, workflowFieldName);
|
|
288
|
+
return newFieldCount + await addMissingOptions(out, client, fields, workflowFieldName, run);
|
|
212
289
|
}
|
|
290
|
+
const FIELD_CHANGES = z.enum(['create', 'update', 'unchanged', 'skip']);
|
|
291
|
+
const INIT_ROW = z.strictObject({
|
|
292
|
+
name: z.string().describe('Name of the project field'),
|
|
293
|
+
change: FIELD_CHANGES.describe('create: the field was created; update: options were added to it; unchanged: nothing to do; skip: the field was not found'),
|
|
294
|
+
addedOptions: z.array(z.string()).describe('Names of the options added to the field (empty when none)'),
|
|
295
|
+
});
|
|
296
|
+
const INIT_OUTPUT = z.strictObject({
|
|
297
|
+
fields: z.array(INIT_ROW).describe('The workflow, priority and size fields, plus the Status field when its options were looked at'),
|
|
298
|
+
dryRun: DRY_RUN_FIELD,
|
|
299
|
+
});
|
|
213
300
|
const initCommand = defineCommand({
|
|
214
301
|
path: ['project', 'init'],
|
|
215
302
|
description: 'Add pecot-workflow fields to an existing project, and add the Blocked and Needs Attention options to the fields that already exist',
|
|
@@ -218,24 +305,39 @@ const initCommand = defineCommand({
|
|
|
218
305
|
name: z.string().describe('Project title'),
|
|
219
306
|
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
220
307
|
suffix: z.string().describe('Suffix of the workflow field'),
|
|
308
|
+
dry_run: dryRunInput,
|
|
221
309
|
}),
|
|
310
|
+
output: INIT_OUTPUT,
|
|
222
311
|
positional: ['owner', 'name'],
|
|
223
|
-
shortFlags: { host: '-h', suffix: '-s' },
|
|
312
|
+
shortFlags: { host: '-h', suffix: '-s', dry_run: '-n' },
|
|
224
313
|
interactive: false,
|
|
225
314
|
run: async (input, io) => {
|
|
226
|
-
const out = createOutput(
|
|
315
|
+
const out = createOutput(input.dry_run, io);
|
|
227
316
|
const { owner, name, host, suffix } = input;
|
|
228
317
|
const client = createGitHubClient(out, host);
|
|
229
|
-
|
|
230
|
-
|
|
318
|
+
if (input.dry_run)
|
|
319
|
+
out.result({});
|
|
320
|
+
const mark = fieldReporter((fields) => {
|
|
321
|
+
out.result({ fields });
|
|
231
322
|
});
|
|
323
|
+
const changeCount = await guarded(out, 'initialize project fields', async () => await initializeFields(out, client, input, { isDryRun: input.dry_run, mark }));
|
|
324
|
+
// 設定ファイルは作るフィールドと選択肢の ID を書くので、予行では作る前の設定を出さない
|
|
325
|
+
if (changeCount > 0 && input.dry_run)
|
|
326
|
+
return 0;
|
|
232
327
|
await guarded(out, 'sync project config', async () => {
|
|
233
|
-
await syncProjectConfig(out, client, { owner, name, host, suffix, skipIfUnchanged: true });
|
|
328
|
+
await syncProjectConfig(out, client, { owner, name, host, suffix, skipIfUnchanged: true, isDryRun: input.dry_run });
|
|
234
329
|
});
|
|
235
330
|
return 0;
|
|
236
331
|
},
|
|
237
332
|
});
|
|
238
333
|
// project create
|
|
334
|
+
const CREATE_OUTPUT = z.strictObject({
|
|
335
|
+
number: z.int().optional().describe('Number of the created project (omitted on dry_run)'),
|
|
336
|
+
url: z.string().optional().describe('URL of the created project (omitted on dry_run)'),
|
|
337
|
+
title: z.string().describe('Title of the project'),
|
|
338
|
+
owner: z.string().describe('Project owner'),
|
|
339
|
+
dryRun: DRY_RUN_FIELD,
|
|
340
|
+
});
|
|
239
341
|
const projectCreationCommand = defineCommand({
|
|
240
342
|
path: ['project', 'create'],
|
|
241
343
|
description: 'Create a new project (to add the fields to an existing project, use project init)',
|
|
@@ -244,12 +346,14 @@ const projectCreationCommand = defineCommand({
|
|
|
244
346
|
title: z.string().describe('Project title'),
|
|
245
347
|
host: z.string().default(DEFAULT_HOST).describe('GitHub host'),
|
|
246
348
|
suffix: z.string().describe('Suffix of the workflow field'),
|
|
349
|
+
dry_run: dryRunInput,
|
|
247
350
|
}),
|
|
351
|
+
output: CREATE_OUTPUT,
|
|
248
352
|
positional: ['owner', 'title'],
|
|
249
|
-
shortFlags: { host: '-h', suffix: '-s' },
|
|
353
|
+
shortFlags: { host: '-h', suffix: '-s', dry_run: '-n' },
|
|
250
354
|
interactive: false,
|
|
251
355
|
run: async (input, io) => {
|
|
252
|
-
const out = createOutput(
|
|
356
|
+
const out = createOutput(input.dry_run, io);
|
|
253
357
|
const { owner, title, host, suffix } = input;
|
|
254
358
|
await guarded(out, 'create project', async () => {
|
|
255
359
|
const client = createGitHubClient(out, host);
|
|
@@ -259,17 +363,29 @@ const projectCreationCommand = defineCommand({
|
|
|
259
363
|
}
|
|
260
364
|
catch (error) {
|
|
261
365
|
if (error instanceof GitHubNotFoundError)
|
|
262
|
-
stopWith(out, `owner not found: ${owner}
|
|
366
|
+
stopWith(out, `owner not found: ${owner}`, 'github-not-found');
|
|
263
367
|
throw error;
|
|
264
368
|
}
|
|
265
369
|
const owned = await client.listProjects(owner);
|
|
266
370
|
const existing = owned.find(project => jsonField(project, 'title') === title);
|
|
267
371
|
if (existing !== undefined)
|
|
268
|
-
stopWith(out, `project already exists: ${title}\nurl: ${textOf(existing['url'])}
|
|
372
|
+
stopWith(out, `project already exists: ${title}\nurl: ${textOf(existing['url'])}`, 'already-exists');
|
|
373
|
+
// フィールドと設定ファイルは作ったプロジェクトの ID を使うので、予行ではプロジェクトの行だけ出す
|
|
374
|
+
if (input.dry_run) {
|
|
375
|
+
out.planned({ verb: 'create', target: `project ${title} for ${owner}` });
|
|
376
|
+
out.result({ title, owner });
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
269
379
|
const created = await client.createProject(ownerId, title);
|
|
270
380
|
out.done({ verb: 'create', target: `project #${textOf(created['number'])} ${textOf(created['url'])}` });
|
|
381
|
+
out.result({
|
|
382
|
+
title,
|
|
383
|
+
owner,
|
|
384
|
+
...typeof created['number'] === 'number' && { number: created['number'] },
|
|
385
|
+
...typeof created['url'] === 'string' && { url: created['url'] },
|
|
386
|
+
});
|
|
271
387
|
await guarded(out, 'initialize project fields', async () => {
|
|
272
|
-
await initializeFields(out, client, { owner, name: title, suffix });
|
|
388
|
+
await initializeFields(out, client, { owner, name: title, suffix }, { isDryRun: false, mark: fieldReporter(undefined) });
|
|
273
389
|
});
|
|
274
390
|
await guarded(out, 'sync project config', async () => {
|
|
275
391
|
await syncProjectConfig(out, client, { owner, name: title, host, suffix });
|
|
@@ -286,7 +402,7 @@ function findConfigFileArgument(project) {
|
|
|
286
402
|
const named = path.join(projectsDirectory(), project.endsWith('.json') ? project : `${project}.json`);
|
|
287
403
|
return isFile(named) ? named : undefined;
|
|
288
404
|
}
|
|
289
|
-
async function activateFromConfigFile(out, configPath, host) {
|
|
405
|
+
async function activateFromConfigFile(out, configPath, host, isDryRun) {
|
|
290
406
|
let config;
|
|
291
407
|
try {
|
|
292
408
|
config = loadConfig(configPath);
|
|
@@ -295,20 +411,20 @@ async function activateFromConfigFile(out, configPath, host) {
|
|
|
295
411
|
// Python の `except Exception` と同じ範囲(あらゆる Error)で捕まえる
|
|
296
412
|
if (!(error instanceof Error) || error instanceof CommandExit)
|
|
297
413
|
throw error;
|
|
298
|
-
return stopWith(out, `could not load config file ${path.basename(configPath)}: ${error.message}
|
|
414
|
+
return stopWith(out, `could not load config file ${path.basename(configPath)}: ${error.message}`, 'config-invalid');
|
|
299
415
|
}
|
|
300
416
|
await guarded(out, 'sync project', async () => {
|
|
301
417
|
if (host !== undefined && config.host !== host) {
|
|
302
|
-
out.warning(
|
|
418
|
+
out.warning(hinted `${inputHint(ACTIVATE_PATH, 'host', host)} differs from the config file host (${config.host})\nusing the config file host`);
|
|
303
419
|
}
|
|
304
420
|
const client = createGitHubClient(out, config.host);
|
|
305
421
|
const projectInfo = await client.getProjectFields(config.owner, config.project.number);
|
|
306
422
|
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
307
|
-
stopWith(out, `project #${String(config.project.number)} not found
|
|
423
|
+
stopWith(out, `project #${String(config.project.number)} not found`, 'project-not-found');
|
|
308
424
|
const title = projectInfo['title'];
|
|
309
425
|
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 });
|
|
426
|
+
stopWith(out, `could not read the title of project #${String(config.project.number)}`, 'project-not-found');
|
|
427
|
+
reportSynced(out, await syncProjectConfig(out, client, { owner: config.owner, name: title, host: config.host, isDryRun }));
|
|
312
428
|
});
|
|
313
429
|
}
|
|
314
430
|
async function resolveActivationOwner(out, client, owner) {
|
|
@@ -320,10 +436,10 @@ async function resolveActivationOwner(out, client, owner) {
|
|
|
320
436
|
}
|
|
321
437
|
catch (error) {
|
|
322
438
|
if (error instanceof GitHubAPIError)
|
|
323
|
-
return stopWith(out, `could not read the authenticated user: ${error.message}\npass
|
|
439
|
+
return stopWith(out, hinted `could not read the authenticated user: ${error.message}\npass ${inputNameHint(ACTIVATE_PATH, 'owner')} to give the owner explicitly`, kindOfFailure(error));
|
|
324
440
|
throw error;
|
|
325
441
|
}
|
|
326
|
-
return typeof login === 'string' && login !== '' ? login : stopWith(out, 'could not read the authenticated user');
|
|
442
|
+
return typeof login === 'string' && login !== '' ? login : stopWith(out, 'could not read the authenticated user', 'github-api');
|
|
327
443
|
}
|
|
328
444
|
// 一覧の表示モード。初期化済みのプロジェクトに [ACTIVE] を付ける
|
|
329
445
|
async function echoInitializedProjects(out, client, host, owner) {
|
|
@@ -343,15 +459,20 @@ async function echoInitializedProjects(out, client, host, owner) {
|
|
|
343
459
|
if (initialized.length === 0) {
|
|
344
460
|
lines.push(' none');
|
|
345
461
|
out.data(lines.join('\n'));
|
|
462
|
+
out.result({ candidates: [] });
|
|
346
463
|
return;
|
|
347
464
|
}
|
|
348
465
|
const activeNumber = activeProjectNumber(host, owner);
|
|
466
|
+
const candidates = [];
|
|
349
467
|
for (const project of initialized) {
|
|
350
468
|
const number = jsonField(project, 'number');
|
|
351
469
|
const title = jsonField(project, 'title');
|
|
352
|
-
|
|
470
|
+
const isActive = activeNumber === number;
|
|
471
|
+
lines.push(` #${textOf(number)}: ${title === undefined ? '(untitled)' : textOf(title)}${isActive ? ' [ACTIVE]' : ''}`);
|
|
472
|
+
candidates.push({ ...typeof number === 'number' && { number }, ...typeof title === 'string' && { title }, active: isActive });
|
|
353
473
|
}
|
|
354
474
|
out.data(lines.join('\n'));
|
|
475
|
+
out.result({ candidates });
|
|
355
476
|
}
|
|
356
477
|
function activeProjectNumber(host, owner) {
|
|
357
478
|
const activePath = getActiveConfigPath();
|
|
@@ -372,20 +493,38 @@ function activeProjectNumber(host, owner) {
|
|
|
372
493
|
async function fetchProjectInfoByReference(out, client, owner, project) {
|
|
373
494
|
if (/^\d+$/u.test(project)) {
|
|
374
495
|
const number = Number(project);
|
|
375
|
-
return await client.getProjectFields(owner, number) ?? stopWith(out, `project #${String(number)} not found
|
|
496
|
+
return await client.getProjectFields(owner, number) ?? stopWith(out, `project #${String(number)} not found`, 'project-not-found');
|
|
376
497
|
}
|
|
377
498
|
const found = await findProjectByTitle(out, client, owner, project);
|
|
378
499
|
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}
|
|
500
|
+
return info !== undefined && isTruthy(info) ? info : stopWith(out, `could not read project fields: ${project}`, 'not-initialized');
|
|
380
501
|
}
|
|
381
502
|
async function activateByReference(out, client, target) {
|
|
382
|
-
const { host, owner, project } = target;
|
|
503
|
+
const { host, owner, project, isDryRun } = target;
|
|
383
504
|
const info = await fetchProjectInfoByReference(out, client, owner, project);
|
|
384
505
|
const title = textOf(info['title'] ?? '');
|
|
385
506
|
if (!hasWorkflowField(asArray(jsonField(info['fields'], 'nodes')))) {
|
|
386
|
-
stopWith(out, `project "${title}" is not initialized\nrun:
|
|
507
|
+
stopWith(out, hinted `project "${title}" is not initialized\nrun: ${commandHint(['project', 'init'], { owner, name: title, host, suffix: placeholder('suffix') })}`, 'not-initialized');
|
|
387
508
|
}
|
|
388
|
-
await syncProjectConfig(out, client, { owner, name: title, host });
|
|
509
|
+
reportSynced(out, await syncProjectConfig(out, client, { owner, name: title, host, isDryRun }));
|
|
510
|
+
}
|
|
511
|
+
const ACTIVATE_PATH = ['project', 'activate'];
|
|
512
|
+
const LINK_PATH = ['project', 'link'];
|
|
513
|
+
const CANDIDATE_ROW = z.strictObject({
|
|
514
|
+
number: z.int().optional().describe('Project number'),
|
|
515
|
+
title: z.string().optional().describe('Project title'),
|
|
516
|
+
active: z.boolean().describe('Whether this project is the active one'),
|
|
517
|
+
});
|
|
518
|
+
const ACTIVATE_OUTPUT = z.strictObject({
|
|
519
|
+
project: z.string().optional().describe('Name of the project config that was (on dry_run, would be) made active'),
|
|
520
|
+
configPath: z.string().optional().describe('Path of the project config file'),
|
|
521
|
+
change: z.enum(['create', 'update', 'unchanged']).optional().describe('What happened to the config file'),
|
|
522
|
+
candidates: z.array(CANDIDATE_ROW).optional().describe('Initialized projects of the owner, given only when no project was named (nothing was activated)'),
|
|
523
|
+
dryRun: DRY_RUN_FIELD,
|
|
524
|
+
});
|
|
525
|
+
// 設定ファイルの結果を data に渡す
|
|
526
|
+
function reportSynced(out, synced) {
|
|
527
|
+
out.result({ ...synced.activeProject !== undefined && { project: synced.activeProject }, configPath: synced.configPath, change: synced.change });
|
|
389
528
|
}
|
|
390
529
|
const activateCommand = defineCommand({
|
|
391
530
|
path: ['project', 'activate'],
|
|
@@ -394,103 +533,62 @@ const activateCommand = defineCommand({
|
|
|
394
533
|
project: z.string().optional().describe('Project number or name, or config file path/file name'),
|
|
395
534
|
owner: z.string().optional().describe('Project owner (defaults to the authenticated user)'),
|
|
396
535
|
host: z.string().optional().describe('GitHub host'),
|
|
536
|
+
dry_run: dryRunInput,
|
|
397
537
|
}),
|
|
538
|
+
output: ACTIVATE_OUTPUT,
|
|
398
539
|
positional: ['project'],
|
|
399
|
-
shortFlags: { owner: '-o', host: '-h' },
|
|
540
|
+
shortFlags: { owner: '-o', host: '-h', dry_run: '-n' },
|
|
400
541
|
interactive: false,
|
|
401
542
|
run: async (input, io) => {
|
|
402
|
-
const out = createOutput(
|
|
543
|
+
const out = createOutput(input.dry_run, io);
|
|
403
544
|
const { project, host } = input;
|
|
404
545
|
// --host の要らない形(設定ファイルのパスか名前)を先に見る
|
|
405
546
|
const configPath = project === undefined ? undefined : findConfigFileArgument(project);
|
|
406
547
|
if (configPath !== undefined) {
|
|
407
|
-
await activateFromConfigFile(out, configPath, host);
|
|
548
|
+
await activateFromConfigFile(out, configPath, host, input.dry_run);
|
|
408
549
|
return 0;
|
|
409
550
|
}
|
|
410
551
|
await guarded(out, 'activate project', async () => {
|
|
411
552
|
if (host === undefined) {
|
|
412
|
-
stopWith(out, '
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
553
|
+
stopWith(out, hinted `${inputNameHint(ACTIVATE_PATH, 'host')} is required
|
|
554
|
+
example: ${commandHint(ACTIVATE_PATH, { host: 'github.com', owner: 'example-org' })}
|
|
555
|
+
example: ${commandHint(ACTIVATE_PATH, { host: 'ghes.example.com', owner: 'example-org' })}
|
|
556
|
+
example: ${commandHint(ACTIVATE_PATH, { project: 'ghes.example.com_example-org_example-project_example-org' })}`, 'invalid-input');
|
|
416
557
|
}
|
|
417
558
|
const client = createGitHubClient(out, host);
|
|
418
559
|
const owner = await resolveActivationOwner(out, client, input.owner);
|
|
560
|
+
// 一覧は書き込まないので、dry_run でも data に dryRun を足さない
|
|
419
561
|
if (project === undefined)
|
|
420
|
-
await echoInitializedProjects(
|
|
562
|
+
await echoInitializedProjects(createOutput(false, io), client, host, owner);
|
|
421
563
|
else
|
|
422
|
-
await activateByReference(out, client, { host, owner, project });
|
|
564
|
+
await activateByReference(out, client, { host, owner, project, isDryRun: input.dry_run });
|
|
423
565
|
});
|
|
424
566
|
return 0;
|
|
425
567
|
},
|
|
426
568
|
});
|
|
427
|
-
// project
|
|
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
|
|
569
|
+
// project link
|
|
473
570
|
const packageList = z.array(z.string());
|
|
474
571
|
function parsePackages(out, input) {
|
|
475
572
|
const specs = input.package;
|
|
476
573
|
if (specs === undefined || specs.length === 0)
|
|
477
574
|
return undefined;
|
|
575
|
+
const packageFlag = inputNameHint(LINK_PATH, 'package');
|
|
478
576
|
if (input.changelog_file !== undefined)
|
|
479
|
-
stopWith(out,
|
|
577
|
+
stopWith(out, hinted `${packageFlag} and ${inputNameHint(LINK_PATH, 'changelog_file')} cannot be used together`, 'invalid-input');
|
|
480
578
|
if (input.clear_packages)
|
|
481
|
-
stopWith(out,
|
|
579
|
+
stopWith(out, hinted `${packageFlag} and ${inputHint(LINK_PATH, 'clear_packages')} cannot be used together`, 'invalid-input');
|
|
482
580
|
const parsed = [];
|
|
483
581
|
const seen = new Set();
|
|
484
582
|
for (const spec of specs) {
|
|
485
583
|
const separator = spec.indexOf(':');
|
|
486
584
|
if (separator === -1)
|
|
487
|
-
stopWith(out, `give
|
|
585
|
+
stopWith(out, hinted `give ${inputHint(LINK_PATH, 'package', placeholder('NAME:PATH'))}: ${pythonStringRepr(spec)}`, 'invalid-input');
|
|
488
586
|
const name = pythonStrip(spec.slice(0, separator));
|
|
489
587
|
const changelog = pythonStrip(spec.slice(separator + 1));
|
|
490
588
|
if (name === '' || changelog === '')
|
|
491
|
-
stopWith(out,
|
|
589
|
+
stopWith(out, hinted `${packageFlag} NAME and PATH must not be empty: ${pythonStringRepr(spec)}`, 'invalid-input');
|
|
492
590
|
if (seen.has(name))
|
|
493
|
-
stopWith(out,
|
|
591
|
+
stopWith(out, hinted `${packageFlag} NAME is duplicated: ${pythonStringRepr(name)}`, 'invalid-input');
|
|
494
592
|
seen.add(name);
|
|
495
593
|
// Python も Package(...) の作成で NAME の形を確かめるので、設定を読む前に止まる
|
|
496
594
|
parsed.push(parsePackage({ name, changelog }));
|
|
@@ -510,7 +608,7 @@ function updatedRepository(out, existing, edit) {
|
|
|
510
608
|
}
|
|
511
609
|
if (edit.changelog_file !== undefined) {
|
|
512
610
|
if (packages !== undefined && packages.length > 0) {
|
|
513
|
-
stopWith(out,
|
|
611
|
+
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');
|
|
514
612
|
}
|
|
515
613
|
changelogFile = edit.changelog_file;
|
|
516
614
|
}
|
|
@@ -537,47 +635,73 @@ async function linkRepository(out, config, repositoryOwner, repositoryName) {
|
|
|
537
635
|
throw error;
|
|
538
636
|
}
|
|
539
637
|
}
|
|
540
|
-
|
|
541
|
-
|
|
638
|
+
// 予行。リンクの有無を読むだけで、リンクしない
|
|
639
|
+
async function plannedLink(out, config, repositoryOwner, repositoryName) {
|
|
640
|
+
try {
|
|
641
|
+
const linked = await createGitHubClient(out, config.host).getLinkedRepositories(config.owner, config.project.number);
|
|
642
|
+
const isLinked = linked.some(entry => entry.owner === repositoryOwner && entry.name === repositoryName);
|
|
643
|
+
return { status: isLinked ? 'already_linked' : 'linked', detail: '' };
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
if (error instanceof GitHubAPIError)
|
|
647
|
+
return { status: 'failed', detail: error.message };
|
|
648
|
+
throw error;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const LINK_OUTPUT = z.strictObject({
|
|
652
|
+
repository: z.string().describe('Repository in owner/repo form'),
|
|
653
|
+
projectNumber: z.int().describe('Number of the active project'),
|
|
654
|
+
change: z.enum(['create', 'update']).describe('create: the repository was added to the config; update: its entry was changed'),
|
|
655
|
+
configPath: z.string().describe('Path of the project config file'),
|
|
656
|
+
dryRun: DRY_RUN_FIELD,
|
|
657
|
+
});
|
|
658
|
+
const projectLinkCommand = defineCommand({
|
|
659
|
+
path: ['project', 'link'],
|
|
660
|
+
hasOwnRepo: true,
|
|
661
|
+
ignoresGlobalRepo: true,
|
|
542
662
|
description: 'Add or update a repository in the project config',
|
|
543
663
|
input: z.strictObject({
|
|
544
|
-
|
|
664
|
+
repo: z.string().describe('Repository name in owner/repo form'),
|
|
545
665
|
develop_branch: z.string().optional().describe('Development branch name'),
|
|
546
666
|
release_branch: z.string().optional().describe('Release branch name'),
|
|
547
667
|
changelog_file: z.string().optional().describe('CHANGELOG file name'),
|
|
548
668
|
package: packageList.optional().describe('Register a monorepo package as NAME:PATH. Can be repeated. Example: --package pecot:plugins/pecot-workflow/CHANGELOG.md'),
|
|
549
669
|
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
670
|
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)'),
|
|
671
|
+
dry_run: dryRunInput,
|
|
551
672
|
}),
|
|
552
|
-
|
|
553
|
-
|
|
673
|
+
output: LINK_OUTPUT,
|
|
674
|
+
positional: ['repo'],
|
|
675
|
+
shortFlags: { develop_branch: '-b', dry_run: '-n' },
|
|
554
676
|
interactive: false,
|
|
555
677
|
run: async (input, io) => {
|
|
556
|
-
const out = createOutput(
|
|
678
|
+
const out = createOutput(input.dry_run, io);
|
|
557
679
|
if (input.release_type !== undefined && toReleaseType(input.release_type) === undefined) {
|
|
558
680
|
// Python は sorted() の順(multi, nx, single)で見せる
|
|
559
|
-
stopWith(out,
|
|
681
|
+
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');
|
|
560
682
|
}
|
|
561
683
|
const packages = parsePackages(out, input);
|
|
562
684
|
const { config, configPath } = requireActiveWithPath(out);
|
|
563
|
-
const parts = splitOwnerRepository(input.
|
|
685
|
+
const parts = splitOwnerRepository(input.repo);
|
|
564
686
|
if (parts === undefined)
|
|
565
|
-
stopWith(out,
|
|
687
|
+
stopWith(out, hinted `give the repository as owner/repo\nexample: ${commandHint(['project', 'link'], { repo: 'example-org/my-repo' })}`, 'invalid-input');
|
|
566
688
|
const { owner, repository: name } = parts;
|
|
567
689
|
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
|
|
690
|
+
stopWith(out, `repository owner ${owner} differs from project owner ${config.owner}\nGitHub Projects V2 links only repositories of the project owner`, 'invalid-input');
|
|
569
691
|
}
|
|
570
692
|
const existing = findRepository(config, owner, name);
|
|
571
693
|
let next;
|
|
572
694
|
let saved;
|
|
573
695
|
if (existing === undefined) {
|
|
574
|
-
const outcome = await linkRepository(out, config, owner, name);
|
|
575
696
|
const projectNumber = String(config.project.number);
|
|
697
|
+
const outcome = input.dry_run ? await plannedLink(out, config, owner, name) : await linkRepository(out, config, owner, name);
|
|
576
698
|
if (outcome.status === 'failed')
|
|
577
|
-
stopWith(out, `could not link ${input.
|
|
578
|
-
|
|
579
|
-
? { verb: 'unchanged', target: `${input.
|
|
580
|
-
: { verb: 'add', target: `${input.
|
|
699
|
+
stopWith(out, `could not link ${input.repo} to project #${projectNumber}: ${outcome.detail}`, 'github-api');
|
|
700
|
+
const linked = outcome.status === 'already_linked'
|
|
701
|
+
? { verb: 'unchanged', target: `${input.repo} in project #${projectNumber}` }
|
|
702
|
+
: { verb: 'add', target: `${input.repo} to project #${projectNumber}` };
|
|
703
|
+
out.planned(linked);
|
|
704
|
+
out.done(linked);
|
|
581
705
|
next = withRepositoryAppended(config, buildRepository({
|
|
582
706
|
owner,
|
|
583
707
|
name,
|
|
@@ -593,85 +717,155 @@ const repositorySettingCommand = defineCommand({
|
|
|
593
717
|
next = withRepositoryReplaced(config, updatedRepository(out, existing, { ...input, packages }));
|
|
594
718
|
saved = { verb: 'update', target: `${owner}/${name} in ${configPath}` };
|
|
595
719
|
}
|
|
596
|
-
|
|
720
|
+
const checked = validated(next);
|
|
721
|
+
out.planned(saved);
|
|
722
|
+
const reported = { repository: `${owner}/${name}`, projectNumber: config.project.number, change: linkChange(existing), configPath };
|
|
723
|
+
if (input.dry_run) {
|
|
724
|
+
out.result(reported);
|
|
725
|
+
return 0;
|
|
726
|
+
}
|
|
727
|
+
saveConfig(checked, configPath);
|
|
597
728
|
out.done(saved);
|
|
729
|
+
out.result(reported);
|
|
598
730
|
return 0;
|
|
599
731
|
},
|
|
600
732
|
});
|
|
601
|
-
// aggregation_repo
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
733
|
+
// 設定のキーの管理。今のキーは aggregation_repo だけ
|
|
734
|
+
const CONFIG_KEY = z.enum(['aggregation_repo']).describe('Key of the project config (aggregation_repo: the Epic aggregation repository)');
|
|
735
|
+
const CONFIG_KEY_FIELD = z.enum(['aggregation_repo']).describe('Key of the project config');
|
|
736
|
+
const GET_OUTPUT = z.strictObject({
|
|
737
|
+
key: CONFIG_KEY_FIELD,
|
|
738
|
+
value: z.string().optional().describe('Value of the key (omitted when it is not set)'),
|
|
739
|
+
});
|
|
740
|
+
const SET_OUTPUT = z.strictObject({
|
|
741
|
+
key: CONFIG_KEY_FIELD,
|
|
742
|
+
value: z.string().describe('Value of the key after the command (on dry_run, after it would run)'),
|
|
743
|
+
previous: z.string().optional().describe('Value before the command (omitted when the key was not set)'),
|
|
744
|
+
change: z.enum(['create', 'update', 'unchanged']).describe('create: the key was not set; update: its value was replaced; unchanged: it already had the value'),
|
|
745
|
+
configPath: z.string().describe('Path of the project config file'),
|
|
746
|
+
dryRun: DRY_RUN_FIELD,
|
|
747
|
+
});
|
|
748
|
+
const UNSET_OUTPUT = z.strictObject({
|
|
749
|
+
key: CONFIG_KEY_FIELD,
|
|
750
|
+
previous: z.string().optional().describe('Value before the command (omitted when the key was not set)'),
|
|
751
|
+
change: z.enum(['delete', 'unchanged']).describe('delete: the key was cleared; unchanged: it was not set'),
|
|
752
|
+
configPath: z.string().describe('Path of the project config file'),
|
|
753
|
+
dryRun: DRY_RUN_FIELD,
|
|
754
|
+
});
|
|
755
|
+
function setAggregationRepository(out, value, options) {
|
|
756
|
+
if (!AGGREGATION_REPOSITORY_PATTERN.test(value))
|
|
757
|
+
stopWith(out, `give aggregation_repo as owner/repo: ${pythonStringRepr(value)}`, 'invalid-input');
|
|
758
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
759
|
+
const current = config.aggregation_repo;
|
|
760
|
+
if (current === value) {
|
|
761
|
+
const unchanged = { verb: 'unchanged', target: `aggregation_repo ${value}` };
|
|
762
|
+
out.planned(unchanged);
|
|
763
|
+
out.done(unchanged);
|
|
764
|
+
out.result({ key: 'aggregation_repo', value, previous: value, change: 'unchanged', configPath });
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const operation = { verb: 'set', target: `aggregation_repo to ${value}` };
|
|
768
|
+
const hasPrevious = current !== undefined && current !== '';
|
|
769
|
+
const reported = { key: 'aggregation_repo', value, ...hasPrevious && { previous: current }, change: setChange(hasPrevious), configPath };
|
|
770
|
+
if (options.isDryRun) {
|
|
771
|
+
out.planned(current === undefined || current === '' ? operation : { ...operation, target: `${operation.target} (was ${current})` });
|
|
772
|
+
out.result(reported);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (current !== undefined && current !== '') {
|
|
776
|
+
out.warning(options.isConfirmed ? `overwriting aggregation_repo: ${current} -> ${value}` : hinted `overwriting aggregation_repo: ${current} -> ${value}\npass ${inputHint(['project', 'set'], 'yes')} to omit this hint`);
|
|
777
|
+
}
|
|
778
|
+
saveConfig(withAggregationRepository(config, value), configPath);
|
|
779
|
+
out.done(operation);
|
|
780
|
+
out.result(reported);
|
|
781
|
+
}
|
|
782
|
+
function unsetAggregationRepository(out, isDryRun) {
|
|
783
|
+
const { config, configPath } = requireActiveWithPath(out);
|
|
784
|
+
const previous = config.aggregation_repo;
|
|
785
|
+
if (previous === undefined) {
|
|
786
|
+
const unchanged = { verb: 'unchanged', target: 'aggregation_repo (not set)' };
|
|
787
|
+
out.planned(unchanged);
|
|
788
|
+
out.done(unchanged);
|
|
789
|
+
out.result({ key: 'aggregation_repo', change: 'unchanged', configPath });
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const operation = { verb: 'remove', target: `aggregation_repo (was ${previous})` };
|
|
793
|
+
out.planned(operation);
|
|
794
|
+
if (isDryRun) {
|
|
795
|
+
out.result({ key: 'aggregation_repo', previous, change: 'delete', configPath });
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
saveConfig(withAggregationRepository(config, undefined), configPath);
|
|
799
|
+
out.done(operation);
|
|
800
|
+
out.result({ key: 'aggregation_repo', previous, change: 'delete', configPath });
|
|
801
|
+
}
|
|
802
|
+
// キーを足したら、ここに操作を足さないと型の確認で止まる
|
|
803
|
+
const CONFIG_KEY_OPERATIONS = {
|
|
804
|
+
aggregation_repo: {
|
|
805
|
+
get: (out) => {
|
|
806
|
+
const value = requireActiveConfig(out).aggregation_repo;
|
|
807
|
+
out.data(value ?? 'none');
|
|
808
|
+
out.result({ key: 'aggregation_repo', ...value !== undefined && { value } });
|
|
809
|
+
},
|
|
810
|
+
set: setAggregationRepository,
|
|
811
|
+
unset: unsetAggregationRepository,
|
|
812
|
+
},
|
|
813
|
+
};
|
|
814
|
+
const projectSetCommand = defineCommand({
|
|
815
|
+
path: ['project', 'set'],
|
|
816
|
+
description: 'Set a key of the project config (aggregation_repo: the Epic aggregation repository)',
|
|
605
817
|
input: z.strictObject({
|
|
818
|
+
key: CONFIG_KEY,
|
|
606
819
|
value: z.string().describe('Aggregation repository (owner/repo form)'),
|
|
607
820
|
yes: z.boolean().default(false).describe('Overwrite an existing value without confirmation (a warning goes to stderr)'),
|
|
821
|
+
dry_run: dryRunInput,
|
|
608
822
|
}),
|
|
609
|
-
|
|
610
|
-
|
|
823
|
+
output: SET_OUTPUT,
|
|
824
|
+
positional: ['key', 'value'],
|
|
825
|
+
shortFlags: { yes: '-y', dry_run: '-n' },
|
|
611
826
|
interactive: false,
|
|
612
827
|
run: (input, io) => {
|
|
613
|
-
|
|
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}` });
|
|
828
|
+
CONFIG_KEY_OPERATIONS[input.key].set(createOutput(input.dry_run, io), input.value, { isConfirmed: input.yes, isDryRun: input.dry_run });
|
|
628
829
|
return Promise.resolve(0);
|
|
629
830
|
},
|
|
630
831
|
});
|
|
631
|
-
const
|
|
632
|
-
path: ['project', 'unset
|
|
633
|
-
description: 'Clear the
|
|
634
|
-
input: z.strictObject({}),
|
|
635
|
-
|
|
832
|
+
const projectUnsetCommand = defineCommand({
|
|
833
|
+
path: ['project', 'unset'],
|
|
834
|
+
description: 'Clear a key of the project config; without aggregation_repo, creating an Epic needs --repo',
|
|
835
|
+
input: z.strictObject({ key: CONFIG_KEY, dry_run: dryRunInput }),
|
|
836
|
+
output: UNSET_OUTPUT,
|
|
837
|
+
positional: ['key'],
|
|
838
|
+
shortFlags: { dry_run: '-n' },
|
|
636
839
|
interactive: false,
|
|
637
|
-
run: (
|
|
638
|
-
|
|
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})` });
|
|
840
|
+
run: (input, io) => {
|
|
841
|
+
CONFIG_KEY_OPERATIONS[input.key].unset(createOutput(input.dry_run, io), input.dry_run);
|
|
647
842
|
return Promise.resolve(0);
|
|
648
843
|
},
|
|
649
844
|
});
|
|
650
|
-
const
|
|
651
|
-
path: ['project', '
|
|
652
|
-
description: 'Show the Epic aggregation repository
|
|
653
|
-
input: z.strictObject({}),
|
|
654
|
-
|
|
845
|
+
const projectGetCommand = defineCommand({
|
|
846
|
+
path: ['project', 'get'],
|
|
847
|
+
description: 'Show the value of a key of the project config (aggregation_repo: the Epic aggregation repository)',
|
|
848
|
+
input: z.strictObject({ key: CONFIG_KEY }),
|
|
849
|
+
output: GET_OUTPUT,
|
|
850
|
+
positional: ['key'],
|
|
655
851
|
interactive: false,
|
|
656
|
-
run: (
|
|
657
|
-
|
|
658
|
-
out.data(requireActiveConfig(out).aggregation_repo ?? 'none');
|
|
852
|
+
run: (input, io) => {
|
|
853
|
+
CONFIG_KEY_OPERATIONS[input.key].get(createOutput(false, io));
|
|
659
854
|
return Promise.resolve(0);
|
|
660
855
|
},
|
|
661
856
|
});
|
|
662
857
|
/**
|
|
663
|
-
project
|
|
858
|
+
project のグループのコマンド。並びは help の一覧の順
|
|
664
859
|
*/
|
|
665
860
|
export const PROJECT_COMMANDS = [
|
|
666
861
|
listCommand,
|
|
667
862
|
searchCommand,
|
|
668
863
|
initCommand,
|
|
669
864
|
projectCreationCommand,
|
|
670
|
-
infoCommand,
|
|
671
865
|
activateCommand,
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
866
|
+
projectLinkCommand,
|
|
867
|
+
projectGetCommand,
|
|
868
|
+
projectSetCommand,
|
|
869
|
+
projectUnsetCommand,
|
|
676
870
|
];
|
|
677
871
|
//# sourceMappingURL=project.js.map
|