@pecot/workflow-mcp 6.0.0 → 7.0.1-dev.19
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 +5 -58
- package/cli/dist/commands/board-add.js +11 -1
- package/cli/dist/commands/board-judgment.d.ts +12 -3
- package/cli/dist/commands/board-judgment.js +12 -6
- package/cli/dist/commands/board-move.js +9 -1
- package/cli/dist/commands/board-readiness.d.ts +3 -3
- package/cli/dist/commands/board-show.js +5 -2
- package/cli/dist/commands/board-sync.js +14 -5
- package/cli/dist/commands/board-view.d.ts +94 -5
- package/cli/dist/commands/board-view.js +119 -17
- package/cli/dist/commands/branch.js +11 -17
- package/cli/dist/commands/command-definition.d.ts +19 -2
- package/cli/dist/commands/command-definition.js +9 -0
- package/cli/dist/commands/failure-kind.d.ts +1 -1
- package/cli/dist/commands/failure-kind.js +1 -0
- package/cli/dist/commands/issue-board.d.ts +31 -3
- package/cli/dist/commands/issue-board.js +28 -4
- package/cli/dist/commands/issue-comment.js +19 -2
- package/cli/dist/commands/issue-create.js +96 -17
- package/cli/dist/commands/issue-dependency.js +51 -14
- package/cli/dist/commands/issue-readiness.d.ts +30 -2
- package/cli/dist/commands/issue-readiness.js +35 -0
- package/cli/dist/commands/issue-reopen.js +18 -3
- package/cli/dist/commands/issue-shared.d.ts +11 -5
- package/cli/dist/commands/issue-shared.js +25 -6
- package/cli/dist/commands/issue-show.js +78 -8
- package/cli/dist/commands/names.d.ts +1 -1
- package/cli/dist/commands/names.js +3 -3
- package/cli/dist/commands/output.d.ts +18 -2
- package/cli/dist/commands/output.js +16 -3
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +225 -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 +231 -0
- package/cli/dist/commands/pr-waiting.d.ts +41 -2
- package/cli/dist/commands/pr-waiting.js +74 -37
- package/cli/dist/commands/pr.d.ts +10 -6
- package/cli/dist/commands/pr.js +214 -111
- package/cli/dist/commands/project-sync.d.ts +10 -2
- package/cli/dist/commands/project-sync.js +7 -6
- package/cli/dist/commands/project.js +174 -17
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +67 -18
- package/cli/dist/commands/renamed-commands.js +0 -1
- package/cli/dist/commands/repository-match.js +7 -2
- package/cli/dist/commands/restack-reading.d.ts +45 -0
- package/cli/dist/commands/restack-reading.js +29 -0
- package/cli/dist/commands/session-finish.js +132 -28
- package/cli/dist/commands/session-start.js +31 -60
- package/cli/dist/commands/session.js +119 -135
- package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
- package/cli/dist/commands/tracker-sync-security.js +22 -4
- package/cli/dist/commands/tracker-sync.d.ts +30 -0
- package/cli/dist/commands/tracker-sync.js +15 -0
- package/cli/dist/commands/tracker.js +2 -0
- package/cli/dist/commands/work-target.d.ts +14 -9
- package/cli/dist/commands/work-target.js +19 -19
- package/cli/dist/commands/worktree.js +71 -5
- package/cli/dist/domain/branch-name.d.ts +7 -0
- package/cli/dist/domain/branch-name.js +23 -1
- package/cli/dist/domain/command-hint.d.ts +1 -1
- package/cli/dist/domain/issue-readout.d.ts +0 -4
- package/cli/dist/domain/pull-request.d.ts +20 -3
- package/cli/dist/domain/pull-request.js +25 -9
- package/cli/dist/domain/readiness.d.ts +17 -0
- package/cli/dist/domain/readiness.js +39 -2
- package/cli/dist/domain/restack.d.ts +66 -0
- package/cli/dist/domain/restack.js +57 -0
- package/cli/dist/domain/state.d.ts +41 -12
- package/cli/dist/domain/state.js +30 -14
- package/cli/dist/domain/work-start.d.ts +0 -4
- package/cli/dist/domain/work-start.js +0 -7
- package/cli/dist/infra/git.d.ts +69 -0
- package/cli/dist/infra/git.js +117 -0
- package/cli/dist/infra/github/pulls.d.ts +81 -2
- package/cli/dist/infra/github/pulls.js +116 -5
- package/cli/dist/infra/github/queries.d.ts +4 -1
- package/cli/dist/infra/github/queries.js +47 -32
- package/cli/dist/infra/github/readout.js +0 -33
- package/cli/dist/infra/paths.d.ts +1 -3
- package/cli/dist/infra/paths.js +2 -45
- package/cli/dist/infra/state-store.d.ts +3 -8
- package/cli/dist/infra/state-store.js +6 -24
- package/cli/dist/mcp/result.d.ts +63 -16
- package/cli/dist/mcp/result.js +106 -30
- package/cli/dist/mcp/server.js +37 -4
- package/cli/templates/comment/plan.md +2 -2
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +3 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -12,15 +12,15 @@ import { splitOwnerRepository, createRepositoryReference } from '../domain/repos
|
|
|
12
12
|
import { FrontmatterError, stripFrontmatter, stripLeadingHtmlComment } from '../domain/frontmatter.js';
|
|
13
13
|
import { findBatchDuplicate, planOrders } from '../domain/issue-order.js';
|
|
14
14
|
import { upsertWaitsForMerge } from '../domain/prerequisites.js';
|
|
15
|
-
import {
|
|
15
|
+
import { FLAG_PECOT_QUICK_MODE } from '../domain/state.js';
|
|
16
16
|
import { compareStrings, pythonRightStrip, pythonStrip, pythonStringRepr, truncateCodePoints } from '../domain/python-format.js';
|
|
17
17
|
import { createIssueReference, issueReferenceKey, issueReferenceToCliReference } from '../domain/reference-parser.js';
|
|
18
|
-
import { describeReadiness, displayReference, hasStarted } from '../domain/readiness.js';
|
|
18
|
+
import { describeReadiness, displayReference, hasStarted, stackChains } from '../domain/readiness.js';
|
|
19
19
|
import { parseIssueFile } from '../infra/frontmatter-file.js';
|
|
20
20
|
import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
|
|
21
21
|
import { DEPENDENCIES_UNSUPPORTED } from '../infra/github/issues.js';
|
|
22
22
|
import { OutputPathReservationError, normalizePath, outputDirectory, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
|
|
23
|
-
import {
|
|
23
|
+
import { touchFlag } from '../infra/state-store.js';
|
|
24
24
|
import { templateFile } from '../infra/template-store.js';
|
|
25
25
|
import { readTextFile } from '../infra/text-file.js';
|
|
26
26
|
import { CommandExit, defineCommand } from './command-definition.js';
|
|
@@ -31,7 +31,7 @@ import { createGitHubClient } from './github-client.js';
|
|
|
31
31
|
import { applyBoardMove } from './issue-board.js';
|
|
32
32
|
import { createReadinessCache, readIssueReadiness } from './issue-readiness.js';
|
|
33
33
|
import { addToBoardOrWarn, BACKLOG_TYPES, buildIssueTitle, clientForIssueCreate, createIssueOrExit, ensureRepositoryInProject, ISSUE_TYPE_SCHEMA, issuePath, linkToParentEpic, normalizeParentEpicCli, PARENT_EPIC_DESCRIPTION, readUsedOrders, resolveEpicTargetRepository, resolveParentEpicReference, runWithExit, setIssueFields, stopForDuplicateOrder, summarizeCreatedIssue, TYPE_DEFAULT_STATUS, validateIssueTemplate, validateStatusForType, warnEpicRepositoryException, } from './issue-shared.js';
|
|
34
|
-
import { createOutput } from './output.js';
|
|
34
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
35
35
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
36
36
|
const FILES_SCHEMA = z.array(z.string()).optional().describe('Path of a Markdown file with frontmatter (several for a batch post)');
|
|
37
37
|
const LABEL_SCHEMA = z.array(z.string()).optional().describe('Label (can be given several times)');
|
|
@@ -43,6 +43,44 @@ const PLACEHOLDER_PATTERN = /\{\{issue:([^{}\s]+)\}\}/gu;
|
|
|
43
43
|
const PREPARED_FILENAME_PATTERN = /^issue-.+-\d{8}-\d{6}-(?<suffix>.+)$/u;
|
|
44
44
|
// Python の `$` は末尾の改行の前にも当たる
|
|
45
45
|
const REPOSITORY_SEGMENT_PATTERN = /^[\w.-]+\n?$/u;
|
|
46
|
+
// validateStatusForType が、作るときの status を型の既定(backlog・ready)か、前提があるときの blocked に限る
|
|
47
|
+
const CREATED_STATUS = z.enum(['backlog', 'blocked', 'ready']);
|
|
48
|
+
function isCreatedStatus(value) {
|
|
49
|
+
return CREATED_STATUS.safeParse(value).success;
|
|
50
|
+
}
|
|
51
|
+
const CREATED_ISSUE_DATA = z.strictObject({
|
|
52
|
+
owner: z.string().describe('Owner of the repository of the Issue'),
|
|
53
|
+
repository: z.string().describe('Name of the repository of the Issue'),
|
|
54
|
+
number: z.int().describe('Issue number'),
|
|
55
|
+
url: z.string().describe('URL of the Issue'),
|
|
56
|
+
status: CREATED_STATUS.optional().describe('Workflow status written on the board (ready when it was moved out of blocked; omitted when not written)'),
|
|
57
|
+
parent: z.string().optional().describe('Parent Epic the Issue was added to as a sub-issue (owner/repo/N; omitted when none)'),
|
|
58
|
+
});
|
|
59
|
+
const STACKABLE_CHAINS = z.array(z.array(z.string())).optional().describe('Stackable chains, each from the bottom; files by key, existing Issues as #N or owner/repo#N (omitted when none)');
|
|
60
|
+
const PLAN_PREREQUISITE_DATA = z.strictObject({
|
|
61
|
+
issue: z.string().describe('Prerequisite: key of a file, or #N / owner/repo#N for an existing Issue'),
|
|
62
|
+
wait: z.enum(['stack', 'merge']).describe('How to wait for the prerequisite'),
|
|
63
|
+
});
|
|
64
|
+
const PLAN_ROW_DATA = z.strictObject({
|
|
65
|
+
file: z.string().describe('Key of the file (the --prepare suffix, else the file stem)'),
|
|
66
|
+
order: z.int().optional().describe('Order number in the title (omitted without a parent Epic)'),
|
|
67
|
+
blockedBy: z.array(PLAN_PREREQUISITE_DATA).describe('Prerequisites in the order written'),
|
|
68
|
+
approach: z.enum(['alone', 'wait-merge', 'stack', 'join']).describe('How to proceed'),
|
|
69
|
+
stackOn: z.string().optional().describe('Prerequisite to stack on (only when approach is stack)'),
|
|
70
|
+
});
|
|
71
|
+
const PLANNED_ISSUE_DATA = z.strictObject({
|
|
72
|
+
owner: z.string().describe('Owner of the repository'),
|
|
73
|
+
repository: z.string().describe('Name of the repository'),
|
|
74
|
+
title: z.string().describe('Title of the Issue'),
|
|
75
|
+
});
|
|
76
|
+
const ISSUE_CREATE_OUTPUT = z.strictObject({
|
|
77
|
+
issues: z.array(CREATED_ISSUE_DATA).optional().describe('Issues created, in the order of creation (also kept on a failure after some were created)'),
|
|
78
|
+
stackableChains: STACKABLE_CHAINS,
|
|
79
|
+
plan: z.array(PLAN_ROW_DATA).optional().describe('Progression table of the files (only on dry_run with files)'),
|
|
80
|
+
plannedIssue: PLANNED_ISSUE_DATA.optional().describe('Issue that would be created (only on dry_run with message or freeform)'),
|
|
81
|
+
file: z.string().optional().describe('Absolute path of the template file copied (only with prepare)'),
|
|
82
|
+
dryRun: DRY_RUN_FIELD,
|
|
83
|
+
});
|
|
46
84
|
// --- 共通 ---
|
|
47
85
|
// owner/repo の形が不正なら error と終了コード 2。正しければ owner と name を返す
|
|
48
86
|
function validateRepositoryShape(output, repository) {
|
|
@@ -51,6 +89,16 @@ function validateRepositoryShape(output, repository) {
|
|
|
51
89
|
const message = `invalid repository format: ${repository}\nexpected: owner/repo`;
|
|
52
90
|
return isValid ? [parts.owner, parts.repository] : stopWith(output, message, 'invalid-input', USAGE_EXIT_CODE);
|
|
53
91
|
}
|
|
92
|
+
function newSession() {
|
|
93
|
+
return { failures: [], cache: createReadinessCache(), issues: [], fieldHint: { hasHinted: false } };
|
|
94
|
+
}
|
|
95
|
+
// 投稿中の Issue は常に末尾にある。isUpdate なら末尾を書き換え、そうでなければ足す
|
|
96
|
+
function recordIssue(output, session, entry, isUpdate) {
|
|
97
|
+
if (isUpdate)
|
|
98
|
+
session.issues.pop();
|
|
99
|
+
session.issues.push(entry);
|
|
100
|
+
output.result({ issues: [...session.issues] });
|
|
101
|
+
}
|
|
54
102
|
function reAddCommand(issue, prerequisite) {
|
|
55
103
|
const base = { issue_ref: issueReferenceToCliReference(issue), by: issueReferenceToCliReference(prerequisite.reference) };
|
|
56
104
|
return commandHint(['issue', 'block'], prerequisite.wait === 'merge' ? { ...base, wait: 'merge', reason: prerequisite.reason ?? '' } : base);
|
|
@@ -131,11 +179,10 @@ async function postIssue(output, client, config, session, posting) {
|
|
|
131
179
|
const { owner, repository } = posting;
|
|
132
180
|
const issue = await createIssueOrExit(output, client, owner, repository, posting.title, posting.body, posting.labels, posting.source);
|
|
133
181
|
const { number, url, nodeId } = summarizeCreatedIssue(issue);
|
|
182
|
+
const entry = { owner, repository, number, url };
|
|
183
|
+
recordIssue(output, session, entry, false);
|
|
134
184
|
const target = `Issue ${issuePath(owner, repository, number)}`;
|
|
135
185
|
const reference = createIssueReference(createRepositoryReference(owner, repository), number);
|
|
136
|
-
consumeFlag(FLAG_ISSUE_PENDING);
|
|
137
|
-
if (posting.consumeSlashPending === true)
|
|
138
|
-
consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
|
|
139
186
|
// 応答に node_id が無いときだけ、ボードへの追加の結果から取るので、先にボードへ足す
|
|
140
187
|
let added;
|
|
141
188
|
let hasTriedBoard = false;
|
|
@@ -149,17 +196,26 @@ async function postIssue(output, client, config, session, posting) {
|
|
|
149
196
|
if (!hasTriedBoard)
|
|
150
197
|
added = await addToBoardOrWarn(output, client, config, owner, repository, number, posting.useResponseNodeId ? nodeId : undefined, url);
|
|
151
198
|
let isMovedToReady = false;
|
|
199
|
+
let status;
|
|
152
200
|
if (added !== undefined) {
|
|
153
|
-
const written = await setIssueFields(output, client, config, added.itemId, target, posting.fields);
|
|
201
|
+
const written = await setIssueFields(output, client, config, added.itemId, target, posting.fields, session.fieldHint);
|
|
202
|
+
const option = written.includes('workflow') ? posting.fields.find(field => field.fieldName === 'workflow')?.optionName : undefined;
|
|
203
|
+
if (option !== undefined && isCreatedStatus(option))
|
|
204
|
+
status = option;
|
|
205
|
+
recordIssue(output, session, { ...entry, ...status !== undefined && { status } }, true);
|
|
154
206
|
if (posting.settleColumn && written.includes('workflow') && linked === posting.prerequisites.length) {
|
|
155
207
|
isMovedToReady = await settleColumn(output, client, config, session, reference, added, linked) === 'Ready';
|
|
208
|
+
if (isMovedToReady)
|
|
209
|
+
status = 'ready';
|
|
156
210
|
}
|
|
157
211
|
}
|
|
158
212
|
const knownNodeId = added?.issueNodeId ?? issueNodeId;
|
|
213
|
+
let parent;
|
|
159
214
|
if (posting.parentReference !== undefined) {
|
|
160
215
|
// ボードへの追加に失敗したときは、URL を出し済み
|
|
161
|
-
await linkToParentEpic(output, client, target, posting.parentReference, knownNodeId ?? (() => client.getIssueNodeId(owner, repository, number)), added === undefined ? undefined : url);
|
|
216
|
+
parent = await linkToParentEpic(output, client, target, posting.parentReference, knownNodeId ?? (() => client.getIssueNodeId(owner, repository, number)), added === undefined ? undefined : url);
|
|
162
217
|
}
|
|
218
|
+
recordIssue(output, session, { ...entry, ...status !== undefined && { status }, ...parent !== undefined && { parent } }, true);
|
|
163
219
|
if (added !== undefined)
|
|
164
220
|
output.data(url);
|
|
165
221
|
return { number, nodeId: knownNodeId, isMovedToReady, isOnBoard: added !== undefined };
|
|
@@ -168,6 +224,7 @@ async function postIssue(output, client, config, session, posting) {
|
|
|
168
224
|
予行の行。番号の要るボード・欄・親 Epic の書き込みは出さない
|
|
169
225
|
*/
|
|
170
226
|
function planIssue(output, owner, repository, title) {
|
|
227
|
+
output.result({ plannedIssue: { owner, repository, title } });
|
|
171
228
|
output.planned({ verb: 'create', target: `Issue in ${owner}/${repository}: ${title}` });
|
|
172
229
|
}
|
|
173
230
|
function parentReferenceOf(raw, config, owner, repository) {
|
|
@@ -185,6 +242,7 @@ function prepareTemplate(output, template, repository, suffix, isDryRun) {
|
|
|
185
242
|
stopWith(output, `template not found: ${source}`, 'other');
|
|
186
243
|
}
|
|
187
244
|
if (isDryRun) {
|
|
245
|
+
output.result({});
|
|
188
246
|
output.planned({ verb: 'create', target: `Issue template ${template} in ${outputDirectory()}` });
|
|
189
247
|
return;
|
|
190
248
|
}
|
|
@@ -196,6 +254,7 @@ function prepareTemplate(output, template, repository, suffix, isDryRun) {
|
|
|
196
254
|
try {
|
|
197
255
|
withReservedOutputPath(outputDirectory(), timestamp => `issue-${template}-${timestamp}${nameSuffix}.md`, (reserved) => {
|
|
198
256
|
writeFileSync(reserved, content, 'utf8');
|
|
257
|
+
output.result({ file: path.resolve(reserved) });
|
|
199
258
|
output.data(reserved);
|
|
200
259
|
});
|
|
201
260
|
}
|
|
@@ -419,6 +478,11 @@ async function readExistingPrerequisites(output, client, files, prerequisites) {
|
|
|
419
478
|
function chainsText(progressions, labels) {
|
|
420
479
|
return formatStackableChains(progressions, key => labels.get(key) ?? key);
|
|
421
480
|
}
|
|
481
|
+
// formatStackableChains と同じ並びを、表記に直した配列で返す
|
|
482
|
+
function chainsData(progressions, labels) {
|
|
483
|
+
const chains = stackChains(progressions).filter(chain => chain.length >= 2).map(chain => chain.map(key => labels.get(key) ?? key));
|
|
484
|
+
return chains.length === 0 ? {} : { stackableChains: chains };
|
|
485
|
+
}
|
|
422
486
|
function expandPlaceholders(body, created, owner, repository) {
|
|
423
487
|
return body.replaceAll(PLACEHOLDER_PATTERN, (whole, key) => {
|
|
424
488
|
const issue = created.get(key);
|
|
@@ -494,6 +558,18 @@ function existingLabels(context) {
|
|
|
494
558
|
}
|
|
495
559
|
return labels;
|
|
496
560
|
}
|
|
561
|
+
function planRowData(row, home) {
|
|
562
|
+
const label = ({ target, key }) => target.kind === 'file' ? key : displayReference(target.reference, home);
|
|
563
|
+
const { progression } = row;
|
|
564
|
+
const stackOn = progression?.kind === 'stack' ? row.prerequisites.find(({ key }) => key === progression.on) : undefined;
|
|
565
|
+
return {
|
|
566
|
+
file: row.file,
|
|
567
|
+
...row.order !== undefined && { order: row.order },
|
|
568
|
+
blockedBy: row.prerequisites.map(prerequisite => ({ issue: label(prerequisite), wait: prerequisite.wait })),
|
|
569
|
+
approach: progression?.kind ?? 'alone',
|
|
570
|
+
...progression?.kind === 'stack' && { stackOn: stackOn === undefined ? progression.on : label(stackOn) },
|
|
571
|
+
};
|
|
572
|
+
}
|
|
497
573
|
function printPlan(output, context) {
|
|
498
574
|
const rows = context.locals.map((local, index) => ({
|
|
499
575
|
file: local.key,
|
|
@@ -501,7 +577,9 @@ function printPlan(output, context) {
|
|
|
501
577
|
prerequisites: context.prerequisites.at(index) ?? [],
|
|
502
578
|
progression: context.progressions.get(local.key),
|
|
503
579
|
}));
|
|
504
|
-
const
|
|
580
|
+
const labels = existingLabels(context);
|
|
581
|
+
output.result({ plan: rows.map(row => planRowData(row, context.home)), ...chainsData(context.progressions, labels) });
|
|
582
|
+
const chains = chainsText(context.progressions, labels);
|
|
505
583
|
output.data([formatPlanTable(rows, context.home), ...chains === undefined ? [] : ['', chains]].join('\n'));
|
|
506
584
|
}
|
|
507
585
|
function postPrerequisites(context, index, posted) {
|
|
@@ -525,7 +603,7 @@ function postPrerequisites(context, index, posted) {
|
|
|
525
603
|
}
|
|
526
604
|
async function postFiles(output, context) {
|
|
527
605
|
const { locals, client, config } = context;
|
|
528
|
-
const session =
|
|
606
|
+
const session = newSession();
|
|
529
607
|
const created = new Map();
|
|
530
608
|
const posted = [];
|
|
531
609
|
const labels = existingLabels(context);
|
|
@@ -566,9 +644,9 @@ async function postFiles(output, context) {
|
|
|
566
644
|
if (session.failures.length > 0)
|
|
567
645
|
output.error(joinHinted(['could not add some blocked-by; add them again with:', ...session.failures.map(hint => [hint])]));
|
|
568
646
|
}
|
|
569
|
-
consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
|
|
570
647
|
if (session.failures.length > 0)
|
|
571
648
|
throw new CommandExit(1, 'partial-failure');
|
|
649
|
+
output.result(chainsData(progressions, labels));
|
|
572
650
|
const chains = chainsText(progressions, labels);
|
|
573
651
|
if (chains !== undefined)
|
|
574
652
|
output.data(`\n${chains}`);
|
|
@@ -580,6 +658,9 @@ function isBatchReference(reference, posted) {
|
|
|
580
658
|
async function createFromFiles(output, files, isDryRun) {
|
|
581
659
|
const context = await prepareBatch(output, files);
|
|
582
660
|
if (isDryRun) {
|
|
661
|
+
// 番号は投稿まで決まらないので、本番の created の行から番号を除いた対象にする
|
|
662
|
+
for (const local of context.locals)
|
|
663
|
+
output.planned({ verb: 'create', target: `Issue in ${local.owner}/${local.repository} from ${local.name}` });
|
|
583
664
|
printPlan(output, context);
|
|
584
665
|
return;
|
|
585
666
|
}
|
|
@@ -613,7 +694,7 @@ async function createDirect(output, options, loadedConfig, isDryRun) {
|
|
|
613
694
|
fields.push({ fieldName: 'priority', optionName: options.priority, label: `priority ${options.priority}` });
|
|
614
695
|
if (options.size !== undefined && options.size !== '')
|
|
615
696
|
fields.push({ fieldName: 'size', optionName: options.size, label: `size ${options.size}` });
|
|
616
|
-
await postIssue(output, client, config,
|
|
697
|
+
await postIssue(output, client, config, newSession(), {
|
|
617
698
|
owner,
|
|
618
699
|
repository,
|
|
619
700
|
title,
|
|
@@ -693,7 +774,7 @@ async function createFreeform(output, input, isDryRun) {
|
|
|
693
774
|
planIssue(output, owner, repository, title);
|
|
694
775
|
return;
|
|
695
776
|
}
|
|
696
|
-
const posted = await postIssue(output, client, config,
|
|
777
|
+
const posted = await postIssue(output, client, config, newSession(), {
|
|
697
778
|
owner,
|
|
698
779
|
repository,
|
|
699
780
|
title,
|
|
@@ -705,7 +786,6 @@ async function createFreeform(output, input, isDryRun) {
|
|
|
705
786
|
parentReference,
|
|
706
787
|
prerequisites: [],
|
|
707
788
|
settleColumn: false,
|
|
708
|
-
consumeSlashPending: true,
|
|
709
789
|
});
|
|
710
790
|
if (posted.isOnBoard && !BACKLOG_TYPES.has(issueType))
|
|
711
791
|
touchFlag(FLAG_PECOT_QUICK_MODE);
|
|
@@ -728,8 +808,6 @@ async function createFromMessage(output, input, message, isDryRun) {
|
|
|
728
808
|
labels: input.label,
|
|
729
809
|
order: input.order,
|
|
730
810
|
}, target.config, isDryRun);
|
|
731
|
-
if (!isDryRun)
|
|
732
|
-
consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
|
|
733
811
|
}
|
|
734
812
|
const ISSUE_CREATE = defineCommand({
|
|
735
813
|
path: ['issue', 'create'],
|
|
@@ -754,6 +832,7 @@ const ISSUE_CREATE = defineCommand({
|
|
|
754
832
|
template: TEMPLATE_SCHEMA,
|
|
755
833
|
suffix: z.string().optional().describe('Suffix of the output file name (only with --prepare)'),
|
|
756
834
|
}),
|
|
835
|
+
output: ISSUE_CREATE_OUTPUT,
|
|
757
836
|
positional: ['files'],
|
|
758
837
|
shortFlags: { message: '-m', title: '-t', repo: '-r', label: '-l', prepare: '-p', suffix: '-s', dry_run: '-n' },
|
|
759
838
|
interactive: false,
|
|
@@ -5,7 +5,7 @@ import { hasExpectedPrerequisites, decideBlock, decideUnblock, searchCycle } fro
|
|
|
5
5
|
import { decideBoardMove } from '../domain/board-move.js';
|
|
6
6
|
import { getOptionId } from '../domain/config.js';
|
|
7
7
|
import { describeReadiness, displayReference, hasStarted } from '../domain/readiness.js';
|
|
8
|
-
import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
|
|
8
|
+
import { createIssueReference, issueReferenceKey, issueReferenceToCliReference } from '../domain/reference-parser.js';
|
|
9
9
|
import { createRepositoryReference } from '../domain/repository-resolver.js';
|
|
10
10
|
import { MAX_BLOCKED_BY } from '../infra/github/issues.js';
|
|
11
11
|
import { defineCommand } from './command-definition.js';
|
|
@@ -13,15 +13,33 @@ import { commandHint, hinted, inputHint, inputNameHint, joinHinted } from './com
|
|
|
13
13
|
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
14
14
|
import { kindOfFailure } from './failure.js';
|
|
15
15
|
import { apiFailureMessage, createGitHubClient } from './github-client.js';
|
|
16
|
-
import { applyBoardMove } from './issue-board.js';
|
|
16
|
+
import { applyBoardMove, BOARD_MOVE_JSON, moveJson } from './issue-board.js';
|
|
17
17
|
import { createReadinessCache, readIssueReadiness } from './issue-readiness.js';
|
|
18
18
|
import { ensureRepositoryInProject, ISSUE_REF_DESCRIPTION, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
|
|
19
|
-
import { createOutput } from './output.js';
|
|
19
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
20
20
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
21
21
|
const CONTENT_EXIT_CODE = 3;
|
|
22
22
|
// たどる Issue の数の上限。大きな連鎖で止まらないことより、確かめずに付けないことを優先する
|
|
23
23
|
const MAX_CYCLE_ISSUES = 200;
|
|
24
24
|
const BLOCK_PATH = ['issue', 'block'];
|
|
25
|
+
const ISSUE_FIELD = z.string().describe('The waiting Issue (owner/repo/N)');
|
|
26
|
+
const BY_FIELD = z.string().describe('The prerequisite Issue (owner/repo/N)');
|
|
27
|
+
const MOVES_FIELD = z.array(BOARD_MOVE_JSON).optional().describe('The waiting Issue when its column or Status was written (at most one; empty when nothing was written; omitted on dry_run)');
|
|
28
|
+
const ISSUE_BLOCK_OUTPUT = z.strictObject({
|
|
29
|
+
issue: ISSUE_FIELD,
|
|
30
|
+
by: BY_FIELD,
|
|
31
|
+
wait: z.enum(['stack', 'merge']).describe('Wait kind of the blocked-by after the command'),
|
|
32
|
+
change: z.enum(['added', 'updated', 'unchanged']).describe('added (new blocked-by), updated (wait kind or reason changed), or unchanged'),
|
|
33
|
+
moves: MOVES_FIELD,
|
|
34
|
+
dryRun: DRY_RUN_FIELD,
|
|
35
|
+
});
|
|
36
|
+
const ISSUE_UNBLOCK_OUTPUT = z.strictObject({
|
|
37
|
+
issue: ISSUE_FIELD,
|
|
38
|
+
by: BY_FIELD,
|
|
39
|
+
change: z.enum(['removed', 'unchanged']).describe('removed, or unchanged when it was not a blocked-by'),
|
|
40
|
+
moves: MOVES_FIELD,
|
|
41
|
+
dryRun: DRY_RUN_FIELD,
|
|
42
|
+
});
|
|
25
43
|
function toReference(target) {
|
|
26
44
|
return createIssueReference(createRepositoryReference(target.owner, target.repository), target.number);
|
|
27
45
|
}
|
|
@@ -73,21 +91,21 @@ async function readConfirmed(context, expected) {
|
|
|
73
91
|
}
|
|
74
92
|
return { failure: `could not confirm that GitHub reflects the blocked-by change of ${name}` };
|
|
75
93
|
}
|
|
76
|
-
//
|
|
94
|
+
// 書いた後の判定で、列と札を動かし、書けた列と札を返す。読めない・確かめられないときは動かさず warning にする(前提の変更は済んでいる)
|
|
77
95
|
async function moveBoard(context, expected, hasPrerequisites) {
|
|
78
96
|
const { out, client, config, home, target } = context;
|
|
79
97
|
const name = displayReference(target, home);
|
|
80
98
|
const read = await readConfirmed(context, expected);
|
|
81
99
|
if ('failure' in read) {
|
|
82
100
|
out.warning(`${read.failure}; the column and label of ${name} were not moved`);
|
|
83
|
-
return;
|
|
101
|
+
return undefined;
|
|
84
102
|
}
|
|
85
103
|
const { judged } = read;
|
|
86
104
|
if (judged.readiness === undefined)
|
|
87
|
-
return;
|
|
105
|
+
return undefined;
|
|
88
106
|
const move = decideBoardMove(boardMoveInput(judged, config, hasPrerequisites));
|
|
89
107
|
if (move === undefined)
|
|
90
|
-
return;
|
|
108
|
+
return undefined;
|
|
91
109
|
const hasWrite = move.column !== undefined || move.label !== undefined;
|
|
92
110
|
let itemId = '';
|
|
93
111
|
try {
|
|
@@ -96,14 +114,18 @@ async function moveBoard(context, expected, hasPrerequisites) {
|
|
|
96
114
|
}
|
|
97
115
|
catch (error) {
|
|
98
116
|
out.warning(`could not move ${name}: ${apiFailureMessage(error)}`);
|
|
99
|
-
return;
|
|
117
|
+
return undefined;
|
|
100
118
|
}
|
|
101
119
|
if (hasWrite && itemId === '')
|
|
102
|
-
return;
|
|
103
|
-
const { missing } = await applyBoardMove(out, client, config, itemId, { ref: target, home }, move, describeReadiness(judged.readiness, judged.prerequisites, home));
|
|
120
|
+
return undefined;
|
|
121
|
+
const { missing, written } = await applyBoardMove(out, client, config, itemId, { ref: target, home }, move, describeReadiness(judged.readiness, judged.prerequisites, home));
|
|
104
122
|
for (const value of missing) {
|
|
105
123
|
out.warning(joinHinted([`the ${value} option is not on the board, so ${name} was not moved`, hintFor(value)]));
|
|
106
124
|
}
|
|
125
|
+
return written;
|
|
126
|
+
}
|
|
127
|
+
function movesOf(written) {
|
|
128
|
+
return written === undefined ? [] : [moveJson(written)];
|
|
107
129
|
}
|
|
108
130
|
function keysOf(issues) {
|
|
109
131
|
return new Set(issues.map(issue => issueReferenceKey({ repository: issue.repository, number: issue.number })));
|
|
@@ -159,10 +181,12 @@ async function runBlock(out, input) {
|
|
|
159
181
|
if (linked === undefined && total >= MAX_BLOCKED_BY)
|
|
160
182
|
stopWith(out, `${name} already has ${String(MAX_BLOCKED_BY)} blocked-by issues`, 'dependency-rejected');
|
|
161
183
|
const decision = decideBlock({ body: read.body, home, by, wait: input.wait, reason, isLinked: linked !== undefined });
|
|
184
|
+
const result = { issue: issueReferenceToCliReference(target), by: issueReferenceToCliReference(by), wait: input.wait };
|
|
162
185
|
if (decision.kind === 'malformed') {
|
|
163
186
|
stopWith(out, `Waits for merge of ${name} is malformed: ${decision.reason}; fix the section in the Issue body and run the command again`, 'content-invalid', CONTENT_EXIT_CODE);
|
|
164
187
|
}
|
|
165
188
|
else if (decision.kind === 'unchanged') {
|
|
189
|
+
out.result({ ...result, change: 'unchanged', ...!input.dry_run && { moves: [] } });
|
|
166
190
|
out.planned({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
|
|
167
191
|
out.done({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
|
|
168
192
|
return;
|
|
@@ -176,8 +200,11 @@ async function runBlock(out, input) {
|
|
|
176
200
|
? { verb: 'add', target: `blocked-by ${byName} to ${name}` }
|
|
177
201
|
: { verb: 'update', target: `blocked-by ${byName} on ${name} (wait: ${input.wait})` };
|
|
178
202
|
out.planned(operation);
|
|
179
|
-
|
|
203
|
+
const change = decision.kind === 'add' ? 'added' : 'updated';
|
|
204
|
+
if (input.dry_run) {
|
|
205
|
+
out.result({ ...result, change });
|
|
180
206
|
return;
|
|
207
|
+
}
|
|
181
208
|
if (byId !== undefined && decision.kind === 'add') {
|
|
182
209
|
const blockingId = byId;
|
|
183
210
|
await wrapped(out, `could not add blocked-by ${byName} to ${name}`, async () => {
|
|
@@ -193,8 +220,10 @@ async function runBlock(out, input) {
|
|
|
193
220
|
}
|
|
194
221
|
if (decision.kind === 'update')
|
|
195
222
|
out.done(operation);
|
|
223
|
+
out.result({ ...result, change });
|
|
196
224
|
const keys = new Set([...keysOf(issues), issueReferenceKey(by)]);
|
|
197
|
-
await moveBoard(context, { keys, by, wait: { wait: input.wait, reason } }, true);
|
|
225
|
+
const written = await moveBoard(context, { keys, by, wait: { wait: input.wait, reason } }, true);
|
|
226
|
+
out.result({ moves: movesOf(written) });
|
|
198
227
|
}
|
|
199
228
|
async function runUnblock(out, input) {
|
|
200
229
|
const config = requireActiveConfigPlain(out);
|
|
@@ -216,19 +245,24 @@ async function runUnblock(out, input) {
|
|
|
216
245
|
if (linked === undefined && total > issues.length)
|
|
217
246
|
stopWith(out, `could not read blocked-by of ${name}: ${String(issues.length)} of ${String(total)} issues were read`, 'dependency-unreadable');
|
|
218
247
|
const decision = decideUnblock({ body: read.body, home, by, isLinked: linked !== undefined });
|
|
248
|
+
const result = { issue: issueReferenceToCliReference(target), by: issueReferenceToCliReference(by) };
|
|
219
249
|
if (linked === undefined || decision.kind === 'unchanged') {
|
|
250
|
+
out.result({ ...result, change: 'unchanged', ...!input.dry_run && { moves: [] } });
|
|
220
251
|
out.planned({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
|
|
221
252
|
out.done({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
|
|
222
253
|
return;
|
|
223
254
|
}
|
|
224
255
|
const operation = { verb: 'remove', target: `blocked-by ${byName} from ${name}` };
|
|
225
256
|
out.planned(operation);
|
|
226
|
-
if (input.dry_run)
|
|
257
|
+
if (input.dry_run) {
|
|
258
|
+
out.result({ ...result, change: 'removed' });
|
|
227
259
|
return;
|
|
260
|
+
}
|
|
228
261
|
await wrapped(out, `could not remove blocked-by ${byName} from ${name}`, async () => {
|
|
229
262
|
await client.removeBlockedBy(read.id, linked.id);
|
|
230
263
|
});
|
|
231
264
|
out.done(operation);
|
|
265
|
+
out.result({ ...result, change: 'removed' });
|
|
232
266
|
if (decision.malformedReason !== undefined) {
|
|
233
267
|
out.warning(`Waits for merge of ${name} is malformed: ${decision.malformedReason}; the section was not changed`);
|
|
234
268
|
}
|
|
@@ -240,7 +274,8 @@ async function runUnblock(out, input) {
|
|
|
240
274
|
const remaining = issues.filter(issue => issue.id !== linked.id);
|
|
241
275
|
// 人が別の理由で付けた札を、最後の前提を外しただけで戻さない
|
|
242
276
|
const hasPrerequisites = remaining.length > 0 || linked.state === 'CLOSED';
|
|
243
|
-
await moveBoard(context, { keys: keysOf(remaining), by, wait: undefined }, hasPrerequisites);
|
|
277
|
+
const written = await moveBoard(context, { keys: keysOf(remaining), by, wait: undefined }, hasPrerequisites);
|
|
278
|
+
out.result({ moves: movesOf(written) });
|
|
244
279
|
}
|
|
245
280
|
const ISSUE_BLOCK = defineCommand({
|
|
246
281
|
path: BLOCK_PATH,
|
|
@@ -252,6 +287,7 @@ const ISSUE_BLOCK = defineCommand({
|
|
|
252
287
|
reason: z.string().optional().describe('Why it waits for the merge (required with --wait merge)'),
|
|
253
288
|
dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
|
|
254
289
|
}),
|
|
290
|
+
output: ISSUE_BLOCK_OUTPUT,
|
|
255
291
|
positional: ['issue_ref'],
|
|
256
292
|
interactive: false,
|
|
257
293
|
run: async (input, io) => {
|
|
@@ -269,6 +305,7 @@ const ISSUE_UNBLOCK = defineCommand({
|
|
|
269
305
|
by: z.string().describe('The prerequisite Issue to remove (`owner/repo/N`; another repository is allowed)'),
|
|
270
306
|
dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
|
|
271
307
|
}),
|
|
308
|
+
output: ISSUE_UNBLOCK_OUTPUT,
|
|
272
309
|
positional: ['issue_ref'],
|
|
273
310
|
interactive: false,
|
|
274
311
|
run: async (input, io) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
-
import type { JsonObject } from '../domain/json.js';
|
|
3
3
|
import type { FactsMismatch, IssueFacts, IssuePullRequest, Prerequisite, Readiness } from '../domain/readiness.js';
|
|
4
4
|
import type { IssueReference } from '../domain/reference-parser.js';
|
|
5
5
|
import type { GitHubClient } from '../infra/github/index.js';
|
|
@@ -80,13 +80,41 @@ DependenciesUnsupportedError はそのまま投げる。
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function judgeSnapshot(client: Readonly<GitHubClient>, snapshot: Readonly<IssueSnapshot>, cache: ReadinessCache, cycle?: readonly string[]): Promise<IssueReadiness>;
|
|
82
82
|
/**
|
|
83
|
+
判定済みの Issue の前提を assume で置き換え、同じ judgeSnapshot で判定し直す。API は、積んだ並びを引き足すときだけ呼ぶ
|
|
84
|
+
*/
|
|
85
|
+
export declare function judgeAssuming(client: Readonly<GitHubClient>, config: ProjectConfig, judged: Readonly<JudgedIssue>, assume: (prerequisites: readonly Prerequisite[]) => readonly Prerequisite[], cache: ReadinessCache): Promise<IssueReadiness>;
|
|
86
|
+
/**
|
|
83
87
|
Issue 1 件の読み取りから判定までを通す。輪は呼ぶ側が渡す(issue show は輪を見ない)
|
|
84
88
|
*/
|
|
85
89
|
export declare function readIssueReadiness(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, cache: ReadinessCache, cycle?: readonly string[], blockedByFirst?: number): Promise<IssueReadiness>;
|
|
86
90
|
/**
|
|
91
|
+
readinessJson の形。キーの並びは readinessJson と同じにする
|
|
92
|
+
*/
|
|
93
|
+
export declare const READINESS_JSON: z.ZodObject<{
|
|
94
|
+
kind: z.ZodEnum<{
|
|
95
|
+
blocked: "blocked";
|
|
96
|
+
stackable: "stackable";
|
|
97
|
+
startable: "startable";
|
|
98
|
+
}>;
|
|
99
|
+
stackOn: z.ZodNullable<z.ZodObject<{
|
|
100
|
+
number: z.ZodInt;
|
|
101
|
+
repository: z.ZodString;
|
|
102
|
+
branch: z.ZodString;
|
|
103
|
+
}, z.core.$strict>>;
|
|
104
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
105
|
+
text: z.ZodString;
|
|
106
|
+
}, z.core.$strict>;
|
|
107
|
+
export type ReadinessJson = z.input<typeof READINESS_JSON>;
|
|
108
|
+
/**
|
|
109
|
+
board show の判定。前提を読めなかった Issue の kind は unknown
|
|
110
|
+
*/
|
|
111
|
+
export type BoardReadinessJson = Omit<ReadinessJson, 'kind'> & {
|
|
112
|
+
readonly kind: ReadinessJson['kind'] | 'unknown';
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
87
115
|
JSON の出力に使う判定。reason は blocked のときだけの理由のコード、stackOn は積む先
|
|
88
116
|
*/
|
|
89
|
-
export declare function readinessJson(readiness: Readonly<Readiness>, text: string):
|
|
117
|
+
export declare function readinessJson(readiness: Readonly<Readiness>, text: string): ReadinessJson;
|
|
90
118
|
/**
|
|
91
119
|
readIssueReadiness の、依存関係を持たない GHES を判定なしで通す形。GHES なら undefined を返し、onUnsupported に理由を渡す
|
|
92
120
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Issue の着手の可否の読み取り。前提を読み、判定する。board show と issue show が使う。
|
|
2
2
|
// 流れは getIssuePrerequisites → readWaitsForMerge → toIssueFacts → judgeReadiness。
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
import { findRepository, workflowFieldName } from '../domain/config.js';
|
|
4
5
|
import { JSON_NULL } from '../domain/json-null.js';
|
|
5
6
|
import { readWaitsForMerge } from '../domain/prerequisites.js';
|
|
@@ -183,6 +184,27 @@ export async function judgeSnapshot(client, snapshot, cache, cycle) {
|
|
|
183
184
|
};
|
|
184
185
|
}
|
|
185
186
|
/**
|
|
187
|
+
判定済みの Issue の前提を assume で置き換え、同じ judgeSnapshot で判定し直す。API は、積んだ並びを引き足すときだけ呼ぶ
|
|
188
|
+
*/
|
|
189
|
+
export async function judgeAssuming(client, config, judged, assume, cache) {
|
|
190
|
+
const { repository } = judged.ref;
|
|
191
|
+
const snapshot = {
|
|
192
|
+
kind: 'snapshot',
|
|
193
|
+
ref: judged.ref,
|
|
194
|
+
title: judged.title,
|
|
195
|
+
target: judged.target,
|
|
196
|
+
prerequisites: assume(judged.prerequisites),
|
|
197
|
+
titles: judged.titles,
|
|
198
|
+
mismatches: judged.mismatches,
|
|
199
|
+
malformedReason: judged.malformedReason,
|
|
200
|
+
parent: judged.parent,
|
|
201
|
+
developmentBranch: findRepository(config, repository.owner, repository.repository)?.develop_branch,
|
|
202
|
+
};
|
|
203
|
+
// 輪は前提の辺だけで決まり、状態の置き換えで変わらない
|
|
204
|
+
const reason = judged.readiness?.reason;
|
|
205
|
+
return await judgeSnapshot(client, snapshot, cache, reason?.code === 'cycle' ? reason.cycle : undefined);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
186
208
|
Issue 1 件の読み取りから判定までを通す。輪は呼ぶ側が渡す(issue show は輪を見ない)
|
|
187
209
|
*/
|
|
188
210
|
export async function readIssueReadiness(client, config, reference, cache, cycle, blockedByFirst) {
|
|
@@ -190,6 +212,19 @@ export async function readIssueReadiness(client, config, reference, cache, cycle
|
|
|
190
212
|
return snapshot.kind === 'unreadable' ? snapshot : await judgeSnapshot(client, snapshot, cache, cycle);
|
|
191
213
|
}
|
|
192
214
|
/**
|
|
215
|
+
readinessJson の形。キーの並びは readinessJson と同じにする
|
|
216
|
+
*/
|
|
217
|
+
export const READINESS_JSON = z.strictObject({
|
|
218
|
+
kind: z.enum(['startable', 'stackable', 'blocked']).describe('Readiness judgment'),
|
|
219
|
+
stackOn: z.strictObject({
|
|
220
|
+
number: z.int().describe('Issue number to stack on'),
|
|
221
|
+
repository: z.string().describe('Repository of that Issue (owner/repo)'),
|
|
222
|
+
branch: z.string().describe('Branch to stack on'),
|
|
223
|
+
}).nullable().describe('Prerequisite to stack on (null unless stackable)'),
|
|
224
|
+
reason: z.string().nullable().describe('Code of the reason for blocked (null unless blocked)'),
|
|
225
|
+
text: z.string().describe('Readiness as shown in the Readiness line'),
|
|
226
|
+
});
|
|
227
|
+
/**
|
|
193
228
|
JSON の出力に使う判定。reason は blocked のときだけの理由のコード、stackOn は積む先
|
|
194
229
|
*/
|
|
195
230
|
export function readinessJson(readiness, text) {
|
|
@@ -8,14 +8,22 @@ import { isStatusConfigured, setIssueField } from './issue-board.js';
|
|
|
8
8
|
import { stopWith, requireActiveConfigPlain } from './command-stop.js';
|
|
9
9
|
import { kindOfFailure } from './failure.js';
|
|
10
10
|
import { connectToProject, exitInvalidStatus, ISSUE_REF_DESCRIPTION, issuePath, notConfiguredMessage, parseIssueReferenceOrExit, runWithExit, VALID_STATUSES, } from './issue-shared.js';
|
|
11
|
-
import { createOutput } from './output.js';
|
|
11
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
12
12
|
// Projects V2 の自動化が Issue をもう一度閉じることがあるため、status を設定した後に待つ
|
|
13
13
|
const AUTOMATION_WAIT_MILLISECONDS = 3000;
|
|
14
|
+
const ISSUE_REOPEN_OUTPUT = z.strictObject({
|
|
15
|
+
issue: z.string().describe('Issue reopened (owner/repo/N)'),
|
|
16
|
+
status: z.string().optional().describe('Workflow status set on the board (omitted when the Issue is not on the board or the status is not configured)'),
|
|
17
|
+
unarchived: z.boolean().describe('Whether the item was unarchived on the board'),
|
|
18
|
+
commented: z.boolean().describe('Whether the reason was posted as a comment'),
|
|
19
|
+
dryRun: DRY_RUN_FIELD,
|
|
20
|
+
});
|
|
14
21
|
// アーカイブの解除、1 回目の reopen、ボードの status の更新。設定できたら自動化を待つ
|
|
15
22
|
async function reopenAndSetStatus(output, client, config, issue, status) {
|
|
16
23
|
const { owner, repository, number } = issue;
|
|
17
24
|
const target = `Issue ${issuePath(owner, repository, number)}`;
|
|
18
25
|
const item = await client.getIssueProjectItem(config.project.id, owner, repository, number);
|
|
26
|
+
output.result({ issue: issuePath(issue.owner, issue.repository, issue.number), unarchived: false, commented: false });
|
|
19
27
|
// アーカイブ済みの項目はボードの列に出ないので戻す。失敗したら Issue を開かずに止める
|
|
20
28
|
if (item?.isArchived === true) {
|
|
21
29
|
try {
|
|
@@ -27,6 +35,7 @@ async function reopenAndSetStatus(output, client, config, issue, status) {
|
|
|
27
35
|
stopWith(output, `could not unarchive ${target} on the board: ${error.message}`, kindOfFailure(error));
|
|
28
36
|
}
|
|
29
37
|
output.done({ verb: 'update', target: `${target} unarchived on the board` });
|
|
38
|
+
output.result({ unarchived: true });
|
|
30
39
|
}
|
|
31
40
|
await client.reopenIssue(owner, repository, number);
|
|
32
41
|
const itemId = item?.id;
|
|
@@ -35,6 +44,7 @@ async function reopenAndSetStatus(output, client, config, issue, status) {
|
|
|
35
44
|
}
|
|
36
45
|
else if (await setIssueField(client, config, itemId, 'workflow', status)) {
|
|
37
46
|
output.done({ verb: 'set', target: `${target} status ${status}` });
|
|
47
|
+
output.result({ status });
|
|
38
48
|
await delay(AUTOMATION_WAIT_MILLISECONDS);
|
|
39
49
|
}
|
|
40
50
|
else {
|
|
@@ -55,22 +65,26 @@ async function confirmReopened(output, client, issue, comment) {
|
|
|
55
65
|
return;
|
|
56
66
|
await client.addIssueComment(owner, repository, number, comment);
|
|
57
67
|
output.done({ verb: 'create', target: `comment on ${issuePath(owner, repository, number)}` });
|
|
68
|
+
output.result({ commented: true });
|
|
58
69
|
}
|
|
59
70
|
// 予行。ボードの項目を読み、書く操作を並べる
|
|
60
71
|
async function planReopen(output, client, config, issue, status, comment) {
|
|
61
72
|
const { owner, repository, number } = issue;
|
|
62
73
|
const target = `Issue ${issuePath(owner, repository, number)}`;
|
|
63
74
|
const item = await client.getIssueProjectItem(config.project.id, owner, repository, number);
|
|
75
|
+
const hasComment = comment !== undefined && comment !== '';
|
|
76
|
+
const willSetStatus = item !== undefined && isStatusConfigured(config, status);
|
|
77
|
+
output.result({ issue: issuePath(issue.owner, issue.repository, issue.number), ...willSetStatus && { status }, unarchived: item?.isArchived === true, commented: hasComment });
|
|
64
78
|
output.planned({ verb: 'reopen', target });
|
|
65
79
|
if (item?.isArchived === true)
|
|
66
80
|
output.planned({ verb: 'update', target: `${target} unarchived on the board` });
|
|
67
81
|
if (item === undefined)
|
|
68
82
|
output.warning(`${target} is not on the project board`);
|
|
69
|
-
else if (
|
|
83
|
+
else if (willSetStatus)
|
|
70
84
|
output.planned({ verb: 'set', target: `${target} status ${status}` });
|
|
71
85
|
else
|
|
72
86
|
output.warning(notConfiguredMessage(status));
|
|
73
|
-
if (
|
|
87
|
+
if (hasComment)
|
|
74
88
|
output.planned({ verb: 'create', target: `comment on ${issuePath(owner, repository, number)}` });
|
|
75
89
|
}
|
|
76
90
|
async function reopenIssue(output, client, config, issue, status, comment) {
|
|
@@ -86,6 +100,7 @@ const ISSUE_REOPEN = defineCommand({
|
|
|
86
100
|
comment: z.string().optional().describe('Reason for reopening (posted as a comment)'),
|
|
87
101
|
dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
|
|
88
102
|
}),
|
|
103
|
+
output: ISSUE_REOPEN_OUTPUT,
|
|
89
104
|
positional: ['issue_ref'],
|
|
90
105
|
shortFlags: { status: '-s', comment: '-c', dry_run: '-n' },
|
|
91
106
|
interactive: false,
|