@pecot/workflow-mcp 6.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 +4 -57
- 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 +12 -1
- 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 +90 -7
- package/cli/dist/commands/issue-dependency.js +32 -4
- 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 +3 -3
- package/cli/dist/commands/issue-shared.js +3 -2
- package/cli/dist/commands/issue-show.js +78 -8
- package/cli/dist/commands/names.js +1 -0
- 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 +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 +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 +160 -67
- 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 +173 -16
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +67 -18
- package/cli/dist/commands/repository-match.js +7 -2
- package/cli/dist/commands/session-finish.js +128 -12
- package/cli/dist/commands/session-start.js +22 -6
- package/cli/dist/commands/session.js +121 -20
- 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 +10 -2
- package/cli/dist/commands/work-target.js +6 -4
- package/cli/dist/commands/worktree.js +71 -5
- package/cli/dist/domain/issue-readout.d.ts +0 -4
- package/cli/dist/domain/pull-request.d.ts +1 -1
- package/cli/dist/domain/readiness.d.ts +17 -0
- package/cli/dist/domain/readiness.js +39 -2
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/state.d.ts +39 -0
- package/cli/dist/domain/state.js +28 -1
- 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 +64 -0
- package/cli/dist/infra/git.js +110 -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/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 +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -3,12 +3,14 @@ import { z } from 'zod';
|
|
|
3
3
|
import { extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
4
4
|
import { ConfigError } from '../domain/config.js';
|
|
5
5
|
import { PecotError } from '../domain/errors.js';
|
|
6
|
+
import { pickLowerPullRequest } from '../domain/pull-request.js';
|
|
6
7
|
import { describeReadiness } from '../domain/readiness.js';
|
|
7
|
-
import {
|
|
8
|
+
import { decideRestack, describeNeedsRestack, needsRestack } from '../domain/restack.js';
|
|
9
|
+
import { issueReferenceToCliReference, parseIssueReference, ReferenceParseError } from '../domain/reference-parser.js';
|
|
8
10
|
import { FLAG_PECOT_ACTIVE } from '../domain/state.js';
|
|
9
|
-
import { describeStackBase
|
|
11
|
+
import { describeStackBase } from '../domain/work-start.js';
|
|
10
12
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
11
|
-
import { gitCurrentBranch, primaryRemoteRepository } from '../infra/git.js';
|
|
13
|
+
import { gitCurrentBranch, primaryRemoteName, primaryRemoteRepository, remoteBranchHead } from '../infra/git.js';
|
|
12
14
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
13
15
|
import { hasFlag, readBaseRecord, readFlag } from '../infra/state-store.js';
|
|
14
16
|
import { defineCommand } from './command-definition.js';
|
|
@@ -18,7 +20,8 @@ import { stopWith } from './command-stop.js';
|
|
|
18
20
|
import { directorySchema } from './directory-option.js';
|
|
19
21
|
import { createGitHubClient } from './github-client.js';
|
|
20
22
|
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
21
|
-
import {
|
|
23
|
+
import { issuePath } from './issue-shared.js';
|
|
24
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
22
25
|
import { SESSION_FINISH_COMMANDS } from './session-finish.js';
|
|
23
26
|
import { SESSION_START_COMMANDS } from './session-start.js';
|
|
24
27
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
@@ -30,6 +33,40 @@ function collectFlagStatuses() {
|
|
|
30
33
|
return { name, isSet, content: isSet ? readFlag(name) ?? '' : '' };
|
|
31
34
|
});
|
|
32
35
|
}
|
|
36
|
+
const FLAG_DATA = z.strictObject({
|
|
37
|
+
name: z.string().describe('Name of the session flag'),
|
|
38
|
+
isSet: z.boolean().describe('Whether the flag is set'),
|
|
39
|
+
content: z.string().describe('Content of the flag (empty when unset)'),
|
|
40
|
+
});
|
|
41
|
+
const ACTIVE_ISSUE_DATA = z.strictObject({
|
|
42
|
+
reference: z.string().describe('Issue in .pecot-active (owner/repo/N)'),
|
|
43
|
+
title: z.string().describe('Title of the Issue'),
|
|
44
|
+
state: z.string().describe('State of the Issue (OPEN or CLOSED)'),
|
|
45
|
+
});
|
|
46
|
+
const BASE_PULL_REQUEST_DATA = z.strictObject({
|
|
47
|
+
number: z.int().describe('PR number'),
|
|
48
|
+
state: z.string().describe('State of the PR'),
|
|
49
|
+
});
|
|
50
|
+
const STACK_DATA = z.strictObject({
|
|
51
|
+
branch: z.string().describe('Base branch the work branch is stacked on'),
|
|
52
|
+
stackedOn: z.string().describe('Issue stacked on (owner/repo/N)'),
|
|
53
|
+
pullRequest: BASE_PULL_REQUEST_DATA.optional().describe('PR of the base branch (omitted when there is none or it cannot be read)'),
|
|
54
|
+
needsRestack: z.boolean().optional().describe('Whether the branch needs pr restack: the base branch moved or its PR is merged (omitted when it cannot be decided)'),
|
|
55
|
+
readiness: z.string().optional().describe('Readiness of the active Issue (only when blocked)'),
|
|
56
|
+
});
|
|
57
|
+
const STACKED_ABOVE_DATA = z.strictObject({
|
|
58
|
+
number: z.int().describe('PR number'),
|
|
59
|
+
branch: z.string().describe('Head branch of the PR'),
|
|
60
|
+
});
|
|
61
|
+
const SESSION_SHOW_OUTPUT = z.strictObject({
|
|
62
|
+
branch: z.string().optional().describe('Current branch (omitted when it cannot be read)'),
|
|
63
|
+
repository: z.string().optional().describe('Repository of the git remote (owner/repo; omitted when it cannot be read)'),
|
|
64
|
+
inferredIssue: z.int().optional().describe('Issue number inferred from the branch name (omitted when none)'),
|
|
65
|
+
flags: z.array(FLAG_DATA).describe('Session flags'),
|
|
66
|
+
activeIssue: ACTIVE_ISSUE_DATA.optional().describe('Issue in .pecot-active as read from GitHub (omitted when unset or unreadable)'),
|
|
67
|
+
stack: STACK_DATA.optional().describe('Base the work was stacked on (omitted when not stacked)'),
|
|
68
|
+
stackedAbove: z.array(STACKED_ABOVE_DATA).optional().describe('Open PRs whose base is the current branch (omitted when there are none or they cannot be read)'),
|
|
69
|
+
});
|
|
33
70
|
// .pecot-active の Issue を GitHub から読んで、Markdown の行にする。読めなければ warning だけ出して undefined にする
|
|
34
71
|
async function readActiveIssue(statuses, output) {
|
|
35
72
|
const active = statuses.find(status => status.name === FLAG_PECOT_ACTIVE && status.isSet && status.content !== '');
|
|
@@ -66,21 +103,24 @@ async function readActiveIssue(statuses, output) {
|
|
|
66
103
|
const lines = ['', '## Active Issue', '', `#${String(issue.number)} ${issue.title} (${issue.state})`];
|
|
67
104
|
if (issue.body !== '')
|
|
68
105
|
lines.push('', issue.body);
|
|
69
|
-
return { reference, config, client, lines };
|
|
106
|
+
return { reference, config, client, lines, data: { reference: issueReferenceToCliReference(reference), title: issue.title, state: issue.state } };
|
|
70
107
|
}
|
|
71
108
|
// 積んで着手した作業ディレクトリの `## Stack` の節。積んでいなければ空
|
|
72
|
-
async function
|
|
109
|
+
async function stackSection(active, origin, directory, output) {
|
|
73
110
|
const reading = readBaseRecord();
|
|
74
111
|
if (reading.kind === 'malformed')
|
|
75
112
|
output.warning(`.pecot-base is malformed: ${reading.content}`);
|
|
76
113
|
if (reading.kind !== 'stacked')
|
|
77
|
-
return [];
|
|
114
|
+
return { lines: [] };
|
|
78
115
|
const { record, stackedOn } = reading;
|
|
79
|
-
|
|
116
|
+
// ブランチは作業ディレクトリのリポにあるので、PR もそこで探す(pr restack と同じ)
|
|
117
|
+
const { owner, repository } = origin ?? stackedOn.repository;
|
|
80
118
|
let pullRequest;
|
|
119
|
+
let restack;
|
|
81
120
|
try {
|
|
82
121
|
const found = await active.client.listPullRequestsByHead(owner, repository, record.branch);
|
|
83
|
-
pullRequest =
|
|
122
|
+
pullRequest = pickLowerPullRequest(found.pullRequests);
|
|
123
|
+
restack = restackDecision(reading, pullRequest, directory);
|
|
84
124
|
}
|
|
85
125
|
catch (error) {
|
|
86
126
|
if (!(error instanceof GitHubAPIError))
|
|
@@ -88,25 +128,65 @@ async function stackLines(active, output) {
|
|
|
88
128
|
output.warning(`cannot read the PR of the base branch: ${error.message}`);
|
|
89
129
|
pullRequest = 'unknown';
|
|
90
130
|
}
|
|
91
|
-
const readiness = await
|
|
92
|
-
|
|
131
|
+
const readiness = await blockedReadiness(active, output);
|
|
132
|
+
const needsLine = restack === undefined ? undefined : describeNeedsRestack(restack);
|
|
133
|
+
const needed = restack === undefined ? undefined : needsRestack(restack);
|
|
134
|
+
return {
|
|
135
|
+
lines: ['', '## Stack', describeStackBase(record.branch, stackedOn, pullRequest), ...needsLine === undefined ? [] : [needsLine], ...readiness === undefined ? [] : [`- readiness: ${readiness}`]],
|
|
136
|
+
data: {
|
|
137
|
+
branch: record.branch,
|
|
138
|
+
stackedOn: issueReferenceToCliReference(stackedOn),
|
|
139
|
+
...pullRequest !== 'unknown' && pullRequest !== undefined && { pullRequest: { number: pullRequest.number, state: pullRequest.state } },
|
|
140
|
+
...needed !== undefined && { needsRestack: needed },
|
|
141
|
+
...readiness !== undefined && { readiness },
|
|
142
|
+
},
|
|
143
|
+
};
|
|
93
144
|
}
|
|
94
|
-
//
|
|
95
|
-
|
|
145
|
+
// 載せ直す先の判断。fetch せずに、下の段の remote の先頭を尋ねて記録と比べる。remote に届かなければ undefined
|
|
146
|
+
function restackDecision(reading, lowerPullRequest, directory) {
|
|
147
|
+
const remote = primaryRemoteName(directory);
|
|
148
|
+
if (remote === undefined)
|
|
149
|
+
return undefined;
|
|
150
|
+
const lowerHead = remoteBranchHead(directory, remote, reading.record.branch);
|
|
151
|
+
return lowerHead.isReachable ? decideRestack({ reading, developBranch: '', lowerPullRequest, lowerHead: lowerHead.sha }) : undefined;
|
|
152
|
+
}
|
|
153
|
+
// 今のブランチを base にした、同じリポの開いている PR。読めなければ warning を出して undefined にする
|
|
154
|
+
async function readStackedAbove(active, origin, branch, output) {
|
|
155
|
+
try {
|
|
156
|
+
const found = await active.client.listPullRequestsByBase(origin.owner, origin.repository, branch);
|
|
157
|
+
return found.pullRequests.map(pullRequest => ({ number: pullRequest.number, branch: pullRequest.headRefName }));
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (!(error instanceof GitHubAPIError))
|
|
161
|
+
throw error;
|
|
162
|
+
output.warning(`cannot read the PRs stacked above: ${error.message}`);
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// 積んだ記録の節に上の段の行を足す。積んだ記録が無くても、上の段があれば節を出す
|
|
167
|
+
function withStackedAbove(stackLines, above) {
|
|
168
|
+
if (above === undefined || above.length === 0)
|
|
169
|
+
return stackLines;
|
|
170
|
+
const lines = above.map(pullRequest => `- stacked above: PR #${String(pullRequest.number)} (${pullRequest.branch})`);
|
|
171
|
+
return stackLines.length === 0 ? ['', '## Stack', ...lines] : [...stackLines, ...lines];
|
|
172
|
+
}
|
|
173
|
+
// 着手中の Issue の判定が blocked のときだけ、判定の文を返す
|
|
174
|
+
async function blockedReadiness(active, output) {
|
|
96
175
|
const result = await readIssueReadinessIfSupported(active.client, active.config, active.reference, createReadinessCache());
|
|
97
176
|
if (result === undefined)
|
|
98
|
-
return
|
|
177
|
+
return undefined;
|
|
99
178
|
if (result.kind === 'unreadable') {
|
|
100
179
|
output.warning(`cannot judge readiness of the active Issue: ${result.reason}`);
|
|
101
|
-
return
|
|
180
|
+
return undefined;
|
|
102
181
|
}
|
|
103
182
|
const { readiness } = result;
|
|
104
|
-
return readiness?.kind === 'blocked' ?
|
|
183
|
+
return readiness?.kind === 'blocked' ? describeReadiness(readiness, result.prerequisites, active.reference.repository) : undefined;
|
|
105
184
|
}
|
|
106
185
|
const SESSION_SHOW = defineCommand({
|
|
107
186
|
path: ['session', 'show'],
|
|
108
187
|
description: 'Show the session flag state, branch information, and inferred Issue',
|
|
109
188
|
input: z.object({ directory: directorySchema }),
|
|
189
|
+
output: SESSION_SHOW_OUTPUT,
|
|
110
190
|
positional: [],
|
|
111
191
|
shortFlags: { directory: '-D' },
|
|
112
192
|
interactive: false,
|
|
@@ -117,6 +197,17 @@ const SESSION_SHOW = defineCommand({
|
|
|
117
197
|
const issueNumber = branch === undefined ? undefined : extractIssueNumberFromBranch(branch);
|
|
118
198
|
const statuses = collectFlagStatuses();
|
|
119
199
|
const active = await readActiveIssue(statuses, output);
|
|
200
|
+
const stack = active === undefined ? { lines: [] } : await stackSection(active, origin, input.directory, output);
|
|
201
|
+
const above = active === undefined || origin === undefined || branch === undefined ? undefined : await readStackedAbove(active, origin, branch, output);
|
|
202
|
+
output.result({
|
|
203
|
+
...branch !== undefined && { branch },
|
|
204
|
+
...origin !== undefined && { repository: `${origin.owner}/${origin.repository}` },
|
|
205
|
+
...issueNumber !== undefined && { inferredIssue: issueNumber },
|
|
206
|
+
flags: statuses.map(status => ({ ...status })),
|
|
207
|
+
...active !== undefined && { activeIssue: active.data },
|
|
208
|
+
...stack.data !== undefined && { stack: stack.data },
|
|
209
|
+
...above !== undefined && above.length > 0 && { stackedAbove: above },
|
|
210
|
+
});
|
|
120
211
|
const lines = [
|
|
121
212
|
'# Session status',
|
|
122
213
|
'',
|
|
@@ -128,7 +219,7 @@ const SESSION_SHOW = defineCommand({
|
|
|
128
219
|
'|------|-------|---------|',
|
|
129
220
|
...statuses.map(status => `| ${status.name} | ${status.isSet ? 'set' : 'unset'} | ${status.content} |`),
|
|
130
221
|
...active?.lines ?? [],
|
|
131
|
-
...
|
|
222
|
+
...withStackedAbove(stack.lines, above),
|
|
132
223
|
];
|
|
133
224
|
output.data(lines.join('\n'));
|
|
134
225
|
return 0;
|
|
@@ -177,6 +268,11 @@ function parseTarget(issue, output) {
|
|
|
177
268
|
return stopWith(output, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
178
269
|
}
|
|
179
270
|
}
|
|
271
|
+
const SESSION_RESTORE_OUTPUT = z.strictObject({
|
|
272
|
+
issue: z.string().describe('Work Issue recorded (owner/repo/N)'),
|
|
273
|
+
workDirectory: z.string().optional().describe('Absolute path of the work directory (omitted on dry_run or when it could not be created)'),
|
|
274
|
+
dryRun: DRY_RUN_FIELD,
|
|
275
|
+
});
|
|
180
276
|
const SESSION_RESTORE = defineCommand({
|
|
181
277
|
path: ['session', 'restore'],
|
|
182
278
|
description: 'Restore lost session flags (such as .pecot-active) from the branch information',
|
|
@@ -185,6 +281,7 @@ const SESSION_RESTORE = defineCommand({
|
|
|
185
281
|
directory: directorySchema,
|
|
186
282
|
dry_run: z.boolean().default(false).describe('Show what would be recorded without writing anything'),
|
|
187
283
|
}),
|
|
284
|
+
output: SESSION_RESTORE_OUTPUT,
|
|
188
285
|
positional: [],
|
|
189
286
|
shortFlags: { issue_ref: '-i', directory: '-D', dry_run: '-n' },
|
|
190
287
|
interactive: false,
|
|
@@ -200,10 +297,14 @@ const SESSION_RESTORE = defineCommand({
|
|
|
200
297
|
throw error;
|
|
201
298
|
return stopWith(output, error.message, 'config-invalid', FAILURE_EXIT_CODE);
|
|
202
299
|
}
|
|
203
|
-
|
|
300
|
+
const issue = issuePath(target.owner, target.repository, target.number);
|
|
301
|
+
if (input.dry_run) {
|
|
302
|
+
output.result({ issue });
|
|
204
303
|
planWorkTarget(output, target.owner, target.repository, target.number);
|
|
205
|
-
|
|
206
|
-
|
|
304
|
+
return 0;
|
|
305
|
+
}
|
|
306
|
+
const recorded = recordWorkTarget(output, target.owner, target.repository, target.number, title, { failWithExit: true });
|
|
307
|
+
output.result({ issue, ...recorded.workDirectory !== undefined && { workDirectory: recorded.workDirectory } });
|
|
207
308
|
return 0;
|
|
208
309
|
},
|
|
209
310
|
});
|
|
@@ -42,10 +42,18 @@ function operationsFor(plan, tracker, title, isUnchanged) {
|
|
|
42
42
|
rewrite.push({ verb: 'update', target: `Tracker #${String(tracker)} body` });
|
|
43
43
|
return { create: [], rewrite, close: plan.close ? [{ verb: 'close', target: `Tracker #${String(tracker)}` }] : [] };
|
|
44
44
|
}
|
|
45
|
+
// 足す行と外す行。open の Tracker が無ければ、立てる Tracker に載せる行を足す行にする
|
|
46
|
+
function rowsOf(plan, tracker) {
|
|
47
|
+
const added = tracker === undefined ? (plan.create ? plan.entries : []) : plan.added;
|
|
48
|
+
return {
|
|
49
|
+
added: added.map(entry => ({ kind: 'pull-request', number: entry.number })),
|
|
50
|
+
removed: plan.removed.map(number => ({ kind: 'pull-request', number })),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
45
53
|
// Tracker を作る・書き直す・閉じる・ボードに載せる。失敗の数を返す。
|
|
46
54
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は可変
|
|
47
55
|
async function applyChanges(out, input) {
|
|
48
|
-
const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged } = input;
|
|
56
|
+
const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows } = input;
|
|
49
57
|
try {
|
|
50
58
|
if (number === undefined) {
|
|
51
59
|
if (!plan.create) {
|
|
@@ -56,7 +64,9 @@ async function applyChanges(out, input) {
|
|
|
56
64
|
const issue = await createIssue(client, owner, repository, title, body, [PR_LABEL]);
|
|
57
65
|
for (const operation of stages.create)
|
|
58
66
|
out.done(operation);
|
|
59
|
-
|
|
67
|
+
const created = requireNumber(issue['number'], 'number');
|
|
68
|
+
out.result({ tracker: created, created: true, added: rows.added });
|
|
69
|
+
await putOnBoard(client, config, owner, repository, created, PRIORITY, { onlyIfEmpty: false });
|
|
60
70
|
return 0;
|
|
61
71
|
}
|
|
62
72
|
if (!isUnchanged) {
|
|
@@ -74,6 +84,7 @@ async function applyChanges(out, input) {
|
|
|
74
84
|
}
|
|
75
85
|
for (const operation of stages.rewrite)
|
|
76
86
|
out.done(operation);
|
|
87
|
+
out.result(rows);
|
|
77
88
|
const [closing] = stages.close;
|
|
78
89
|
if (closing !== undefined) {
|
|
79
90
|
try {
|
|
@@ -87,6 +98,7 @@ async function applyChanges(out, input) {
|
|
|
87
98
|
return 1;
|
|
88
99
|
}
|
|
89
100
|
out.done(closing);
|
|
101
|
+
out.result({ closed: true });
|
|
90
102
|
return 0;
|
|
91
103
|
}
|
|
92
104
|
// 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
|
|
@@ -146,9 +158,14 @@ export async function runDependabotSync(input, io) {
|
|
|
146
158
|
const stages = operationsFor(plan, number, title, isUnchanged);
|
|
147
159
|
for (const operation of [...stages.create, ...stages.rewrite, ...stages.close])
|
|
148
160
|
out.planned(operation);
|
|
149
|
-
|
|
161
|
+
const rows = rowsOf(plan, number);
|
|
162
|
+
const synced = { source: 'dependabot', ...number !== undefined && { tracker: number } };
|
|
163
|
+
if (input.dry_run) {
|
|
164
|
+
out.result({ ...synced, created: number === undefined && plan.create, ...rows, closed: plan.close });
|
|
150
165
|
return 0;
|
|
151
|
-
|
|
166
|
+
}
|
|
167
|
+
out.result({ ...synced, created: false, added: [], removed: [], closed: false });
|
|
168
|
+
const failures = await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows });
|
|
152
169
|
if (failures > 0)
|
|
153
170
|
throw new CommandExit(1, 'partial-failure');
|
|
154
171
|
return 0;
|
|
@@ -57,10 +57,21 @@ function operationsOf(plan, tracker, title, isUnchanged) {
|
|
|
57
57
|
];
|
|
58
58
|
return { create: [], rewrite: rewrite.length === 0 ? [{ verb: 'update', target: `Tracker ${label} body` }] : rewrite };
|
|
59
59
|
}
|
|
60
|
+
// 足す行と外す行。open の Tracker が無ければ、立てる Tracker に載せる行を足す行にする。本文が変わらなければどちらも空
|
|
61
|
+
function rowsOf(plan, tracker, isUnchanged) {
|
|
62
|
+
if (tracker !== undefined && isUnchanged)
|
|
63
|
+
return { added: [], removed: [] };
|
|
64
|
+
const added = tracker === undefined ? (plan.create ? plan.entries : []) : plan.added;
|
|
65
|
+
const removed = tracker === undefined ? [] : plan.removed;
|
|
66
|
+
return {
|
|
67
|
+
added: added.map(entry => ({ kind: entry.kind, number: entry.number })),
|
|
68
|
+
removed: removed.map(entry => ({ kind: entry.kind, number: entry.number })),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
60
71
|
// Tracker を作る・書き直す・ボードに載せる。失敗の数を返す。
|
|
61
72
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は可変
|
|
62
73
|
async function applyChanges(out, input) {
|
|
63
|
-
const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged } = input;
|
|
74
|
+
const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows } = input;
|
|
64
75
|
const priority = maxPriority(plan.entries);
|
|
65
76
|
try {
|
|
66
77
|
if (number === undefined) {
|
|
@@ -72,7 +83,9 @@ async function applyChanges(out, input) {
|
|
|
72
83
|
const issue = await createIssue(client, owner, repository, title, body, [ALERT_LABEL]);
|
|
73
84
|
for (const operation of stages.create)
|
|
74
85
|
out.done(operation);
|
|
75
|
-
|
|
86
|
+
const created = requireNumber(issue['number'], 'number');
|
|
87
|
+
out.result({ tracker: created, created: true, added: rows.added });
|
|
88
|
+
await putOnBoard(client, config, owner, repository, created, priority, { onlyIfEmpty: false });
|
|
76
89
|
return 0;
|
|
77
90
|
}
|
|
78
91
|
let failures = 0;
|
|
@@ -91,9 +104,11 @@ async function applyChanges(out, input) {
|
|
|
91
104
|
out.error(`could not update Tracker #${String(number)} body: ${text}`);
|
|
92
105
|
}
|
|
93
106
|
}
|
|
94
|
-
if (isUpdated)
|
|
107
|
+
if (isUpdated) {
|
|
95
108
|
for (const operation of stages.rewrite)
|
|
96
109
|
out.done(operation);
|
|
110
|
+
out.result(rows);
|
|
111
|
+
}
|
|
97
112
|
// 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
|
|
98
113
|
await putOnBoard(client, config, owner, repository, number, priority, { onlyIfEmpty: true });
|
|
99
114
|
return failures;
|
|
@@ -145,7 +160,10 @@ export async function runSecuritySync(input, io) {
|
|
|
145
160
|
const stages = operationsOf(plan, number, title, isUnchanged);
|
|
146
161
|
for (const operation of [...stages.create, ...stages.rewrite])
|
|
147
162
|
out.planned(operation);
|
|
148
|
-
const
|
|
163
|
+
const rows = rowsOf(plan, number, isUnchanged);
|
|
164
|
+
const synced = { source: 'security', ...number !== undefined && { tracker: number }, closed: false };
|
|
165
|
+
out.result(input.dry_run ? { ...synced, created: number === undefined && plan.create, ...rows } : { ...synced, created: false, added: [], removed: [] });
|
|
166
|
+
const failures = input.dry_run ? 0 : await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows });
|
|
149
167
|
if (failed.size > 0 || failures > 0)
|
|
150
168
|
throw new CommandExit(1, 'partial-failure');
|
|
151
169
|
return 0;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import type { ProjectConfig } from '../domain/config.js';
|
|
2
3
|
import type { TrackerIssue } from '../domain/tracker-body.js';
|
|
3
4
|
import type { GitHubClient } from '../infra/github/index.js';
|
|
@@ -6,6 +7,35 @@ import type { Operation, Output } from './output.js';
|
|
|
6
7
|
API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
|
|
7
8
|
*/
|
|
8
9
|
export declare function settle(out: Output, operation: Operation): void;
|
|
10
|
+
export declare const TRACKER_SYNC_OUTPUT: z.ZodObject<{
|
|
11
|
+
source: z.ZodEnum<{
|
|
12
|
+
dependabot: "dependabot";
|
|
13
|
+
security: "security";
|
|
14
|
+
}>;
|
|
15
|
+
tracker: z.ZodOptional<z.ZodInt>;
|
|
16
|
+
created: z.ZodBoolean;
|
|
17
|
+
added: z.ZodArray<z.ZodObject<{
|
|
18
|
+
kind: z.ZodEnum<{
|
|
19
|
+
"code-scanning": "code-scanning";
|
|
20
|
+
dependabot: "dependabot";
|
|
21
|
+
"pull-request": "pull-request";
|
|
22
|
+
"secret-scanning": "secret-scanning";
|
|
23
|
+
}>;
|
|
24
|
+
number: z.ZodInt;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
removed: z.ZodArray<z.ZodObject<{
|
|
27
|
+
kind: z.ZodEnum<{
|
|
28
|
+
"code-scanning": "code-scanning";
|
|
29
|
+
dependabot: "dependabot";
|
|
30
|
+
"pull-request": "pull-request";
|
|
31
|
+
"secret-scanning": "secret-scanning";
|
|
32
|
+
}>;
|
|
33
|
+
number: z.ZodInt;
|
|
34
|
+
}, z.core.$strict>>;
|
|
35
|
+
closed: z.ZodBoolean;
|
|
36
|
+
dryRun: z.ZodOptional<z.ZodLiteral<true>>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export type TrackerSyncData = z.input<typeof TRACKER_SYNC_OUTPUT>;
|
|
9
39
|
/**
|
|
10
40
|
tracker sync の各 source の本体が受ける入力
|
|
11
41
|
*/
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// tracker sync と session finish が共有する出力の補助。
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { TransportFailure } from '../infra/github/client.js';
|
|
3
4
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
4
5
|
import { requireActiveConfigPlain } from './command-stop.js';
|
|
6
|
+
import { DRY_RUN_FIELD } from './output.js';
|
|
5
7
|
import { requireReleaseTargetRepository } from './release.js';
|
|
6
8
|
/**
|
|
7
9
|
API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
|
|
@@ -10,6 +12,19 @@ export function settle(out, operation) {
|
|
|
10
12
|
out.planned(operation);
|
|
11
13
|
out.done(operation);
|
|
12
14
|
}
|
|
15
|
+
const TRACKER_ENTRY_JSON = z.strictObject({
|
|
16
|
+
kind: z.enum(['pull-request', 'dependabot', 'code-scanning', 'secret-scanning']).describe('Kind of the row: a Dependabot PR, or the kind of security alert'),
|
|
17
|
+
number: z.int().describe('PR or alert number'),
|
|
18
|
+
});
|
|
19
|
+
export const TRACKER_SYNC_OUTPUT = z.strictObject({
|
|
20
|
+
source: z.enum(['dependabot', 'security']).describe('Source synced'),
|
|
21
|
+
tracker: z.int().optional().describe('Number of the Tracker used or created (omitted when there is none, or on dry_run before creation)'),
|
|
22
|
+
created: z.boolean().describe('Whether a new Tracker was created (on dry_run, would be created)'),
|
|
23
|
+
added: z.array(TRACKER_ENTRY_JSON).describe('Rows added to the Tracker list (on dry_run, to be added)'),
|
|
24
|
+
removed: z.array(TRACKER_ENTRY_JSON).describe('Rows removed from the Tracker list (on dry_run, to be removed)'),
|
|
25
|
+
closed: z.boolean().describe('Whether the Tracker was closed because its list became none (on dry_run, would be closed)'),
|
|
26
|
+
dryRun: DRY_RUN_FIELD,
|
|
27
|
+
});
|
|
13
28
|
/**
|
|
14
29
|
対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
|
|
15
30
|
設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
|
|
@@ -3,6 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { defineCommand } from './command-definition.js';
|
|
4
4
|
import { runDependabotSync } from './tracker-sync-dependabot.js';
|
|
5
5
|
import { runSecuritySync } from './tracker-sync-security.js';
|
|
6
|
+
import { TRACKER_SYNC_OUTPUT } from './tracker-sync.js';
|
|
6
7
|
const syncCommand = defineCommand({
|
|
7
8
|
path: ['tracker', 'sync'],
|
|
8
9
|
description: 'Rewrite the open Tracker\'s list for a source: Dependabot PRs waiting for a human decision, or open security alerts',
|
|
@@ -10,6 +11,7 @@ const syncCommand = defineCommand({
|
|
|
10
11
|
source: z.enum(['dependabot', 'security']).describe('What to put into the Tracker: dependabot (Dependabot PRs waiting for a human decision) or security (open security alerts)'),
|
|
11
12
|
dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
|
|
12
13
|
}),
|
|
14
|
+
output: TRACKER_SYNC_OUTPUT,
|
|
13
15
|
positional: ['source'],
|
|
14
16
|
interactive: false,
|
|
15
17
|
run: async (input, io) => await (input.source === 'dependabot' ? runDependabotSync(input, io) : runSecuritySync(input, io)),
|
|
@@ -11,10 +11,18 @@ export interface RecordWorkTargetOptions {
|
|
|
11
11
|
readonly base?: Readonly<BaseRecord>;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
+
recordWorkTarget の結果。workDirectory は作れた作業ディレクトリの絶対パス
|
|
15
|
+
*/
|
|
16
|
+
export interface RecordedWorkTarget {
|
|
17
|
+
readonly status: 'recorded' | 'failed';
|
|
18
|
+
readonly issue: string;
|
|
19
|
+
readonly workDirectory?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
14
22
|
.pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
|
|
15
|
-
失敗は warning の行。failWithExit なら error の行と CommandExit(1)
|
|
23
|
+
失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかと、行に出した参照・作業ディレクトリを返す
|
|
16
24
|
*/
|
|
17
|
-
export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>):
|
|
25
|
+
export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>): RecordedWorkTarget;
|
|
18
26
|
/**
|
|
19
27
|
予行の行。recordWorkTarget が書く作業対象(.pecot-active・.pecot-session-title・.pecot-base)を書かずに出す
|
|
20
28
|
*/
|
|
@@ -17,16 +17,18 @@ function describeFailure(error) {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
.pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
|
|
20
|
-
失敗は warning の行。failWithExit なら error の行と CommandExit(1)
|
|
20
|
+
失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかと、行に出した参照・作業ディレクトリを返す
|
|
21
21
|
*/
|
|
22
22
|
export function recordWorkTarget(out, owner, repository, issueNumber, title, options = {}) {
|
|
23
23
|
const issueReference = `${owner}/${repository}/${String(issueNumber)}`;
|
|
24
24
|
clearBase(out);
|
|
25
25
|
let target;
|
|
26
|
+
let workDirectory;
|
|
26
27
|
try {
|
|
27
28
|
writeWorkTarget(issueReference, title);
|
|
28
29
|
target = `work target ${issueReference}`;
|
|
29
|
-
|
|
30
|
+
workDirectory = ensureWorkDirectory(issueReference);
|
|
31
|
+
if (workDirectory !== undefined)
|
|
30
32
|
target += ` (work directory ${WORK_DIR}/${String(issueNumber)}/)`;
|
|
31
33
|
}
|
|
32
34
|
catch (error) {
|
|
@@ -36,12 +38,12 @@ export function recordWorkTarget(out, owner, repository, issueNumber, title, opt
|
|
|
36
38
|
stopWith(out, `could not record the work target: ${describeFailure(error)}`, 'other');
|
|
37
39
|
}
|
|
38
40
|
out.warning(`could not record the work target: ${describeFailure(error)}`);
|
|
39
|
-
return 'failed';
|
|
41
|
+
return { status: 'failed', issue: issueReference };
|
|
40
42
|
}
|
|
41
43
|
out.done({ verb: 'set', target });
|
|
42
44
|
if (options.base !== undefined)
|
|
43
45
|
recordBase(options.base, out);
|
|
44
|
-
return 'recorded';
|
|
46
|
+
return { status: 'recorded', issue: issueReference, workDirectory };
|
|
45
47
|
}
|
|
46
48
|
function warnBase(out, error) {
|
|
47
49
|
if (!isRecordingFailure(error))
|