@pecot/workflow-mcp 0.0.0-stage → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +184 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +227 -0
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +59 -0
- package/cli/dist/commands/board-judgment.d.ts +60 -0
- package/cli/dist/commands/board-judgment.js +144 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +57 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +72 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +111 -0
- package/cli/dist/commands/board-view.d.ts +62 -0
- package/cli/dist/commands/board-view.js +191 -0
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +100 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +270 -0
- package/cli/dist/commands/command-definition.d.ts +150 -0
- package/cli/dist/commands/command-definition.js +105 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +21 -0
- package/cli/dist/commands/command-stop.js +31 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +34 -0
- package/cli/dist/commands/failure.d.ts +19 -0
- package/cli/dist/commands/failure.js +59 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +16 -0
- package/cli/dist/commands/github-client.js +33 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +50 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +71 -0
- package/cli/dist/commands/issue-board.js +122 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +215 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +786 -0
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +282 -0
- package/cli/dist/commands/issue-readiness.d.ts +94 -0
- package/cli/dist/commands/issue-readiness.js +218 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +115 -0
- package/cli/dist/commands/issue-shared.d.ts +172 -0
- package/cli/dist/commands/issue-shared.js +426 -0
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +169 -0
- package/cli/dist/commands/issue.d.ts +3 -0
- package/cli/dist/commands/issue.js +13 -0
- package/cli/dist/commands/names.d.ts +42 -0
- package/cli/dist/commands/names.js +78 -0
- package/cli/dist/commands/output.d.ts +90 -0
- package/cli/dist/commands/output.js +194 -0
- package/cli/dist/commands/pr-waiting.d.ts +20 -0
- package/cli/dist/commands/pr-waiting.js +106 -0
- package/cli/dist/commands/pr.d.ts +22 -0
- package/cli/dist/commands/pr.js +852 -0
- package/cli/dist/commands/project-sync.d.ts +92 -0
- package/cli/dist/commands/project-sync.js +282 -0
- package/cli/dist/commands/project.d.ts +6 -0
- package/cli/dist/commands/project.js +714 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +30 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +353 -0
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +34 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +267 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +236 -0
- package/cli/dist/commands/session.d.ts +6 -0
- package/cli/dist/commands/session.js +214 -0
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-security.js +153 -0
- package/cli/dist/commands/tracker-sync.d.ts +65 -0
- package/cli/dist/commands/tracker-sync.js +50 -0
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +18 -0
- package/cli/dist/commands/usage-error.d.ts +51 -0
- package/cli/dist/commands/usage-error.js +78 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +22 -0
- package/cli/dist/commands/work-target.js +82 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +339 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +219 -0
- package/cli/dist/domain/config.js +310 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +24 -0
- package/cli/dist/domain/errors.js +36 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +94 -0
- package/cli/dist/domain/format.js +234 -0
- package/cli/dist/domain/frontmatter.d.ts +137 -0
- package/cli/dist/domain/frontmatter.js +290 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +143 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +201 -0
- package/cli/dist/domain/pull-request.js +281 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +199 -0
- package/cli/dist/domain/readiness.js +391 -0
- package/cli/dist/domain/reference-parser.d.ts +51 -0
- package/cli/dist/domain/reference-parser.js +123 -0
- package/cli/dist/domain/release.d.ts +53 -0
- package/cli/dist/domain/release.js +65 -0
- package/cli/dist/domain/repository-policy.d.ts +38 -0
- package/cli/dist/domain/repository-policy.js +66 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +122 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +59 -0
- package/cli/dist/domain/state.js +95 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +72 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +53 -0
- package/cli/dist/infra/config-store.js +134 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +86 -0
- package/cli/dist/infra/git.js +145 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +178 -0
- package/cli/dist/infra/github/client.js +579 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +65 -0
- package/cli/dist/infra/github/errors.js +64 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +165 -0
- package/cli/dist/infra/github/issues.js +428 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +143 -0
- package/cli/dist/infra/github/projects.js +384 -0
- package/cli/dist/infra/github/pulls.d.ts +104 -0
- package/cli/dist/infra/github/pulls.js +217 -0
- package/cli/dist/infra/github/queries.d.ts +44 -0
- package/cli/dist/infra/github/queries.js +1031 -0
- package/cli/dist/infra/github/readout.d.ts +22 -0
- package/cli/dist/infra/github/readout.js +167 -0
- package/cli/dist/infra/github/repos.d.ts +86 -0
- package/cli/dist/infra/github/repos.js +168 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +54 -0
- package/cli/dist/infra/state-store.js +130 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +142 -0
- package/cli/dist/infra/worktree-links.js +440 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +185 -0
- package/cli/dist/infra/worktree.js +584 -0
- package/cli/dist/mcp/result.d.ts +61 -0
- package/cli/dist/mcp/result.js +96 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +142 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +195 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +74 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
|
+
// ボードの Issue の読み取り・判定と、列と札の動かし方。board show(数えるだけ)と、board sync・pr create(書く)が共有する。
|
|
3
|
+
import { decideBoardMove } from '../domain/board-move.js';
|
|
4
|
+
import { getOptionId } from '../domain/config.js';
|
|
5
|
+
import { boardItemKey } from '../domain/format.js';
|
|
6
|
+
import { compareStrings } from '../domain/python-format.js';
|
|
7
|
+
import { cycleThrough, describeReadiness, displayReference, hasStarted, TRACKER_TITLE_PREFIX } from '../domain/readiness.js';
|
|
8
|
+
import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
|
|
9
|
+
import { createRepositoryReference, splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
10
|
+
import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
|
|
11
|
+
import { blockedByReadCount, createReadinessCache, judgeSnapshot, prerequisiteKeys, readIssueSnapshot } from './issue-readiness.js';
|
|
12
|
+
import { mapWithLimit } from './board-view.js';
|
|
13
|
+
import { commandHint, hinted } from './command-hint.js';
|
|
14
|
+
import { applyBoardMove, planBoardMove } from './issue-board.js';
|
|
15
|
+
/**
|
|
16
|
+
前提の読み取りを並列に行う数の上限
|
|
17
|
+
*/
|
|
18
|
+
const READ_MAX_WORKERS = 8;
|
|
19
|
+
/**
|
|
20
|
+
board sync と pr create が判定し直す列
|
|
21
|
+
*/
|
|
22
|
+
export const SYNCED_COLUMNS = new Set(['Ready', 'Blocked', 'Active', 'In Review']);
|
|
23
|
+
/**
|
|
24
|
+
動かす先の値がボードに無いときの warning の文
|
|
25
|
+
*/
|
|
26
|
+
export function missingWarning(missing) {
|
|
27
|
+
const names = [...missing].toSorted(compareStrings);
|
|
28
|
+
return hinted `the board has no option ${names.join(', ')}; add ${names.length === 1 ? 'it' : 'them'} with ${commandHint(['project', 'init'])}`;
|
|
29
|
+
}
|
|
30
|
+
// 対象の列の Issue か。PR と Tracker は対象にしない
|
|
31
|
+
function toTarget(item, columns) {
|
|
32
|
+
const key = boardItemKey(item);
|
|
33
|
+
const split = splitOwnerRepository(item.content.repository ?? '');
|
|
34
|
+
const { number } = item.content;
|
|
35
|
+
const url = typeof item.content.url === 'string' ? item.content.url : '';
|
|
36
|
+
const title = typeof item.title === 'string' ? item.title : '';
|
|
37
|
+
const isExcluded = url.includes('/pull/') || title.startsWith(TRACKER_TITLE_PREFIX);
|
|
38
|
+
const isTarget = !isExcluded && typeof item.workflow === 'string' && columns.has(item.workflow) && key !== undefined && split !== undefined && typeof number === 'number';
|
|
39
|
+
return isTarget ? { item, key, ref: createIssueReference(createRepositoryReference(split.owner, split.repository), number) } : undefined;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
対象の列の Issue の前提と着手の跡を読み、輪も含めて判定する。
|
|
43
|
+
Issue の依存関係に対応しない GHES では undefined を返す。warning は呼ぶ側が出す
|
|
44
|
+
*/
|
|
45
|
+
export async function judgeBoard(client, config, items, progress, options) {
|
|
46
|
+
const targets = items.flatMap(item => toTarget(item, options.columns) ?? []);
|
|
47
|
+
const state = { isUnsupported: false };
|
|
48
|
+
const reads = await mapWithLimit(targets, READ_MAX_WORKERS, async (target) => {
|
|
49
|
+
if (state.isUnsupported)
|
|
50
|
+
return undefined;
|
|
51
|
+
const known = progress.get(target.key);
|
|
52
|
+
const local = options.withoutRead(target, known);
|
|
53
|
+
if (local === 'skip')
|
|
54
|
+
return undefined;
|
|
55
|
+
if (local !== undefined)
|
|
56
|
+
return { target, snapshot: local };
|
|
57
|
+
try {
|
|
58
|
+
return { target, snapshot: await readIssueSnapshot(client, config, target.ref, blockedByReadCount(known?.blockedBy)) };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (!(error instanceof DependenciesUnsupportedError))
|
|
62
|
+
throw error;
|
|
63
|
+
state.isUnsupported = true;
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (state.isUnsupported)
|
|
68
|
+
return undefined;
|
|
69
|
+
const pairs = reads.flatMap(read => read ?? []);
|
|
70
|
+
const edges = new Map();
|
|
71
|
+
for (const { target, snapshot } of pairs) {
|
|
72
|
+
if (snapshot.kind === 'snapshot')
|
|
73
|
+
edges.set(issueReferenceKey(target.ref), prerequisiteKeys(snapshot));
|
|
74
|
+
}
|
|
75
|
+
const cache = createReadinessCache();
|
|
76
|
+
return await mapWithLimit(pairs, READ_MAX_WORKERS, async ({ target, snapshot }) => {
|
|
77
|
+
if (snapshot.kind === 'unreadable')
|
|
78
|
+
return { target, result: snapshot };
|
|
79
|
+
try {
|
|
80
|
+
return { target, result: await judgeSnapshot(client, snapshot, cache, cycleThrough(issueReferenceKey(target.ref), edges)) };
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof GitHubAPIError)
|
|
84
|
+
return { target, result: { kind: 'unreadable', reason: error.message } };
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
判定の結果に合わせて、列と札を動かす。読めない Issue は warning にし、ボードに無い値は最後に 1 行の warning にまとめる。
|
|
91
|
+
isDryRun は同じ文を予定の行で出し、書かない。書き込みに失敗した Issue の数を返す
|
|
92
|
+
*/
|
|
93
|
+
export async function applyJudgedMoves(context, judged, isDryRun = false) {
|
|
94
|
+
const { out, client, config, home } = context;
|
|
95
|
+
const missing = new Set();
|
|
96
|
+
let failures = 0;
|
|
97
|
+
for (const { target, result } of judged) {
|
|
98
|
+
if (result.kind === 'unreadable') {
|
|
99
|
+
out.warning(`could not judge ${displayReference(target.ref, home)}: ${result.reason.replaceAll(/\s+/gu, ' ')}`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const { readiness } = result;
|
|
103
|
+
const move = boardMoveOf(config, target, result);
|
|
104
|
+
if (readiness === undefined || move === undefined)
|
|
105
|
+
continue;
|
|
106
|
+
for (const value of move.missing)
|
|
107
|
+
missing.add(value);
|
|
108
|
+
const text = describeReadiness(readiness, result.prerequisites, target.ref.repository);
|
|
109
|
+
const destination = { ref: target.ref, home };
|
|
110
|
+
const itemId = target.item.id;
|
|
111
|
+
if (isDryRun)
|
|
112
|
+
planBoardMove(out, destination, move, text);
|
|
113
|
+
else if (typeof itemId === 'string') {
|
|
114
|
+
const applied = await applyBoardMove(out, client, config, itemId, destination, move, text);
|
|
115
|
+
if (applied.hasFailed)
|
|
116
|
+
failures += 1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (missing.size > 0)
|
|
120
|
+
out.warning(missingWarning(missing));
|
|
121
|
+
return failures;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
判定から、列と札の動かし方を決める。info の数え方と board sync の書き込みが同じ規則を使う(FR-083)
|
|
125
|
+
*/
|
|
126
|
+
export function boardMoveOf(config, target, result) {
|
|
127
|
+
return decideBoardMove({
|
|
128
|
+
// 常に真でよい。readBoard が返すのは OPEN の Issue だけで、Tracker を対象から外し、Epic の readiness が undefined になる
|
|
129
|
+
eligible: true,
|
|
130
|
+
column: target.item.workflow ?? undefined,
|
|
131
|
+
label: result.target.label,
|
|
132
|
+
hasStarted: hasStarted(result.target),
|
|
133
|
+
hasPrerequisites: result.prerequisites.length > 0,
|
|
134
|
+
readiness: result.readiness,
|
|
135
|
+
// 札を書いたのが自動処理かは記録していない(data-model.md の 6)
|
|
136
|
+
labelWrittenByAutomation: false,
|
|
137
|
+
available: {
|
|
138
|
+
blocked: getOptionId(config, 'workflow', 'blocked') !== undefined,
|
|
139
|
+
needsAttention: getOptionId(config, 'status', 'needs_attention') !== undefined,
|
|
140
|
+
todo: getOptionId(config, 'status', 'todo') !== undefined,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=board-judgment.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// board move。cli/commands/issue.py の update_issue_status の移植。
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
4
|
+
import { defineCommand } from './command-definition.js';
|
|
5
|
+
import { isStatusConfigured, setIssueField } from './issue-board.js';
|
|
6
|
+
import { commandHint, hinted } from './command-hint.js';
|
|
7
|
+
import { stopWith, requireActiveConfigPlain } from './command-stop.js';
|
|
8
|
+
import { kindOfFailure } from './failure.js';
|
|
9
|
+
import { connectToProject, exitInvalidStatus, ISSUE_REF_DESCRIPTION, issuePath, notConfiguredMessage, parseIssueReferenceOrExit, runWithExit, VALID_STATUSES, } from './issue-shared.js';
|
|
10
|
+
import { createOutput } from './output.js';
|
|
11
|
+
const BOARD_MOVE = defineCommand({
|
|
12
|
+
path: ['board', 'move'],
|
|
13
|
+
description: 'Update the status of an Issue on the project board by Issue number (pecot commands normally set the status themselves)',
|
|
14
|
+
input: z.object({
|
|
15
|
+
issue_ref: z.string().describe(ISSUE_REF_DESCRIPTION),
|
|
16
|
+
status: z.string().describe('Status (backlog/pending/blocked/ready/active/in_review/archived)'),
|
|
17
|
+
dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
|
|
18
|
+
}),
|
|
19
|
+
positional: ['issue_ref', 'status'],
|
|
20
|
+
shortFlags: { dry_run: '-n' },
|
|
21
|
+
interactive: false,
|
|
22
|
+
run: async (input, io) => {
|
|
23
|
+
const output = createOutput(input.dry_run, io);
|
|
24
|
+
return await runWithExit(async () => {
|
|
25
|
+
const { status } = input;
|
|
26
|
+
if (!VALID_STATUSES.has(status))
|
|
27
|
+
exitInvalidStatus(output, status);
|
|
28
|
+
const config = requireActiveConfigPlain(output);
|
|
29
|
+
const { owner, repository, number } = parseIssueReferenceOrExit(output, input.repo, input.issue_ref);
|
|
30
|
+
const target = `Issue ${issuePath(owner, repository, number)}`;
|
|
31
|
+
try {
|
|
32
|
+
const client = await connectToProject(output, config, owner, repository);
|
|
33
|
+
const itemId = await client.getItemIdByIssue(config.project.id, owner, repository, number);
|
|
34
|
+
if (itemId === undefined) {
|
|
35
|
+
stopWith(output, hinted `${target} is not on the project board\nhint: add it to the board first with ${commandHint(['board', 'add'], { issue_ref: `${owner}/${repository}/${String(number)}` })}`, 'not-on-board');
|
|
36
|
+
}
|
|
37
|
+
if (input.dry_run) {
|
|
38
|
+
if (!isStatusConfigured(config, status))
|
|
39
|
+
stopWith(output, notConfiguredMessage(status), 'status-not-configured');
|
|
40
|
+
output.planned({ verb: 'set', target: `${target} status ${status}` });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!await setIssueField(client, config, itemId, 'workflow', status)) {
|
|
44
|
+
stopWith(output, notConfiguredMessage(status), 'status-not-configured');
|
|
45
|
+
}
|
|
46
|
+
output.done({ verb: 'set', target: `${target} status ${status}` });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (!(error instanceof GitHubAPIError))
|
|
50
|
+
throw error;
|
|
51
|
+
stopWith(output, `could not set ${target} status ${status}: ${error.message}`, kindOfFailure(error));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
export const BOARD_MOVE_COMMANDS = [BOARD_MOVE];
|
|
57
|
+
//# sourceMappingURL=board-move.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { BoardItem, BoardProgress, StackableChain } from '../domain/format.js';
|
|
3
|
+
import type { JsonObject } from '../domain/json.js';
|
|
4
|
+
import { JSON_NULL } from '../domain/json-null.js';
|
|
5
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
6
|
+
import type { Output } from './output.js';
|
|
7
|
+
export interface BoardReadiness {
|
|
8
|
+
/**
|
|
9
|
+
boardItemKey → 表の Readiness の列の文。undefined なら列を出さない
|
|
10
|
+
*/
|
|
11
|
+
readonly texts: ReadonlyMap<string, string> | undefined;
|
|
12
|
+
/**
|
|
13
|
+
boardItemKey → JSON の readiness。undefined なら JSON に足さない
|
|
14
|
+
*/
|
|
15
|
+
readonly json: ReadonlyMap<string, JsonObject> | undefined;
|
|
16
|
+
readonly chains: readonly StackableChain[];
|
|
17
|
+
/**
|
|
18
|
+
board sync が列か札を動かしそうな Ready・Blocked の Issue の数
|
|
19
|
+
*/
|
|
20
|
+
readonly mismatches: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
判定を読まずに、依存関係に対応しない GHES と同じ扱いにする。warning を 1 回出す
|
|
24
|
+
*/
|
|
25
|
+
export declare function skipBoardReadiness(out: Readonly<Output>): BoardReadiness;
|
|
26
|
+
/**
|
|
27
|
+
Ready・Blocked の Issue の前提を読んで判定する。items は表示するアイテム(--repo で絞った後)。列と札は動かさない
|
|
28
|
+
*/
|
|
29
|
+
export declare function readBoardReadiness(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, items: readonly BoardItem[], repository: string | undefined, progress?: ReadonlyMap<string, BoardProgress>): Promise<BoardReadiness>;
|
|
30
|
+
/**
|
|
31
|
+
アイテムのキーを引いて JSON の readiness を返す。判定が無ければ null
|
|
32
|
+
*/
|
|
33
|
+
export declare function readinessOf(readiness: BoardReadiness, item: BoardItem): JsonObject | typeof JSON_NULL;
|
|
34
|
+
//# sourceMappingURL=board-readiness.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
|
+
// board show の着手の判定。盤上の Ready・Blocked の Issue の前提を読んで表示する。列と札は動かさない。
|
|
3
|
+
import { homeRepositoryOf } from '../domain/config.js';
|
|
4
|
+
import { boardItemKey } from '../domain/format.js';
|
|
5
|
+
import { isEpicIssue } from '../domain/issue-kind.js';
|
|
6
|
+
import { JSON_NULL } from '../domain/json-null.js';
|
|
7
|
+
import { describeReadiness, describeUnknown, displayReference, progressionsFromReadiness, stackChains } from '../domain/readiness.js';
|
|
8
|
+
import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
|
|
9
|
+
import { createRepositoryReference, splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
10
|
+
import { boardMoveOf, judgeBoard } from './board-judgment.js';
|
|
11
|
+
import { readinessJson, snapshotWithoutPrerequisites } from './issue-readiness.js';
|
|
12
|
+
const JUDGED_STATUSES = new Set(['Ready', 'Blocked']);
|
|
13
|
+
// 前提の無い Issue を、一覧の値だけで判定の入力にする。前提の件数が一覧に無ければ undefined
|
|
14
|
+
function localSnapshot(config, target, progress) {
|
|
15
|
+
if (progress?.blockedBy !== 0)
|
|
16
|
+
return undefined;
|
|
17
|
+
const split = splitOwnerRepository(progress.parent?.repository ?? '');
|
|
18
|
+
const parent = split === undefined || progress.parent === undefined ? undefined : createIssueReference(createRepositoryReference(split.owner, split.repository), progress.parent.number);
|
|
19
|
+
const isEpic = isEpicIssue({ issue_type: progress.issueType, sub_issues_total: progress.subIssues });
|
|
20
|
+
return snapshotWithoutPrerequisites(config, {
|
|
21
|
+
title: typeof target.item.title === 'string' ? target.item.title : '',
|
|
22
|
+
parent,
|
|
23
|
+
target: {
|
|
24
|
+
ref: target.ref,
|
|
25
|
+
state: 'open',
|
|
26
|
+
column: target.item.workflow ?? undefined,
|
|
27
|
+
label: progress.label,
|
|
28
|
+
kind: isEpic ? 'epic' : 'task',
|
|
29
|
+
// 着手の跡は一覧に無いので、info の案内は「may be」と書く
|
|
30
|
+
branches: [],
|
|
31
|
+
pullRequests: [],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
// 小文字のキーを、元の参照(無ければキーから作る)に戻して表記する
|
|
36
|
+
function displayKey(key, references, home) {
|
|
37
|
+
const known = references.get(key);
|
|
38
|
+
const [repository = '', number = ''] = key.split('#', 2);
|
|
39
|
+
const split = splitOwnerRepository(repository);
|
|
40
|
+
return known === undefined && split === undefined ? key : displayReference(known ?? createIssueReference(createRepositoryReference(split?.owner ?? '', split?.repository ?? ''), Number(number)), home);
|
|
41
|
+
}
|
|
42
|
+
function unsupportedWarning(out) {
|
|
43
|
+
out.warning('this GitHub Enterprise Server does not support issue dependencies (blockedBy); the Readiness column is omitted');
|
|
44
|
+
}
|
|
45
|
+
const PLAIN = { texts: undefined, json: undefined, chains: [], mismatches: 0 };
|
|
46
|
+
/**
|
|
47
|
+
判定を読まずに、依存関係に対応しない GHES と同じ扱いにする。warning を 1 回出す
|
|
48
|
+
*/
|
|
49
|
+
export function skipBoardReadiness(out) {
|
|
50
|
+
unsupportedWarning(out);
|
|
51
|
+
return PLAIN;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
Ready・Blocked の Issue の前提を読んで判定する。items は表示するアイテム(--repo で絞った後)。列と札は動かさない
|
|
55
|
+
*/
|
|
56
|
+
export async function readBoardReadiness(out, client, config, items, repository, progress = new Map()) {
|
|
57
|
+
const judged = await judgeBoard(client, config, items, progress, {
|
|
58
|
+
columns: JUDGED_STATUSES,
|
|
59
|
+
withoutRead: (target, known) => localSnapshot(config, target, known),
|
|
60
|
+
});
|
|
61
|
+
if (judged === undefined) {
|
|
62
|
+
unsupportedWarning(out);
|
|
63
|
+
return PLAIN;
|
|
64
|
+
}
|
|
65
|
+
const home = homeRepositoryOf(config, repository);
|
|
66
|
+
const texts = new Map();
|
|
67
|
+
const json = new Map();
|
|
68
|
+
const readinessByKey = new Map();
|
|
69
|
+
const parents = new Map();
|
|
70
|
+
const references = new Map(judged.map(({ target }) => [target.key, target.ref]));
|
|
71
|
+
let mismatches = 0;
|
|
72
|
+
for (const { target, result } of judged) {
|
|
73
|
+
if (result.kind === 'unreadable') {
|
|
74
|
+
const text = describeUnknown(result.reason.replaceAll(/\s+/gu, ' '));
|
|
75
|
+
texts.set(target.key, text);
|
|
76
|
+
json.set(target.key, { kind: 'unknown', stackOn: JSON_NULL, reason: JSON_NULL, text });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (result.parent !== undefined)
|
|
80
|
+
parents.set(target.key, result.parent);
|
|
81
|
+
const { readiness } = result;
|
|
82
|
+
if (readiness === undefined)
|
|
83
|
+
continue;
|
|
84
|
+
const text = describeReadiness(readiness, result.prerequisites, target.ref.repository);
|
|
85
|
+
texts.set(target.key, text);
|
|
86
|
+
json.set(target.key, readinessJson(readiness, text));
|
|
87
|
+
readinessByKey.set(target.key, readiness);
|
|
88
|
+
const move = boardMoveOf(config, target, result);
|
|
89
|
+
if (move?.column !== undefined || move?.label !== undefined)
|
|
90
|
+
mismatches += 1;
|
|
91
|
+
if (readiness.stackOn !== undefined)
|
|
92
|
+
references.set(issueReferenceKey(readiness.stackOn.issue), readiness.stackOn.issue);
|
|
93
|
+
}
|
|
94
|
+
const chains = stackChains(progressionsFromReadiness(readinessByKey)).filter(chain => chain.length >= 2).map((chain) => {
|
|
95
|
+
const parentKey = chain.find(key => parents.has(key));
|
|
96
|
+
const parent = parentKey === undefined ? undefined : parents.get(parentKey);
|
|
97
|
+
return { epic: parent === undefined ? undefined : displayReference(parent, home), chain: chain.map(key => displayKey(key, references, home)) };
|
|
98
|
+
});
|
|
99
|
+
return { texts, json, chains, mismatches };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
アイテムのキーを引いて JSON の readiness を返す。判定が無ければ null
|
|
103
|
+
*/
|
|
104
|
+
export function readinessOf(readiness, item) {
|
|
105
|
+
const key = boardItemKey(item);
|
|
106
|
+
return (key === undefined ? undefined : readiness.json?.get(key)) ?? JSON_NULL;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=board-readiness.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// board show。表示と alert の収集は board-view.ts、着手の判定は board-readiness.ts が持つ。何も書き換えない。
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
5
|
+
import { formatBoardOutput, formatStackableChains } from '../domain/format.js';
|
|
6
|
+
import { parseOwnerRepository } from '../domain/repository-resolver.js';
|
|
7
|
+
import { getActiveConfigPath } from '../infra/config-store.js';
|
|
8
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
9
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
10
|
+
import { commandHint, hinted, inputHint } from './command-hint.js';
|
|
11
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
12
|
+
import { createGitHubClient } from './github-client.js';
|
|
13
|
+
import { createOutput } from './output.js';
|
|
14
|
+
import { readBoardReadiness, readinessOf, skipBoardReadiness } from './board-readiness.js';
|
|
15
|
+
import { boardShowJson, boardShowMarkdown, collectAlertStatuses, readBoard } from './board-view.js';
|
|
16
|
+
import { failApi } from './project-sync.js';
|
|
17
|
+
const SYNC_PATH = ['board', 'sync'];
|
|
18
|
+
function mismatchNote(count) {
|
|
19
|
+
const subject = count === 1 ? '1 Ready or Blocked Issue may be' : `${String(count)} Ready or Blocked Issues may be`;
|
|
20
|
+
return hinted `${subject} in a column or Status that does not match its judgment; run ${commandHint(SYNC_PATH)} (${inputHint(SYNC_PATH, 'dry_run')} to preview) to fix`;
|
|
21
|
+
}
|
|
22
|
+
const boardShowCommand = defineCommand({
|
|
23
|
+
path: ['board', 'show'],
|
|
24
|
+
description: 'Show the dashboard of the project board',
|
|
25
|
+
input: z.strictObject({
|
|
26
|
+
json: z.boolean().default(false).describe('Output as JSON'),
|
|
27
|
+
repo: z.string().superRefine((value, context) => {
|
|
28
|
+
try {
|
|
29
|
+
parseOwnerRepository(value);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!(error instanceof InvalidValueError))
|
|
33
|
+
throw error;
|
|
34
|
+
context.addIssue({ code: 'custom', message: `must be in 'owner/repo' form: ${error.message}` });
|
|
35
|
+
}
|
|
36
|
+
}).optional().describe('Target repository, given explicitly as \'owner/repo\''),
|
|
37
|
+
}),
|
|
38
|
+
hasOwnRepo: true,
|
|
39
|
+
positional: [],
|
|
40
|
+
shortFlags: { json: '-j' },
|
|
41
|
+
interactive: false,
|
|
42
|
+
run: async (input, io) => {
|
|
43
|
+
const out = createOutput(false, io);
|
|
44
|
+
const config = requireActiveConfig(out);
|
|
45
|
+
const configPath = getActiveConfigPath();
|
|
46
|
+
const projectName = configPath === undefined ? `${config.host}_${config.owner}_${String(config.project.number)}` : path.parse(configPath).name;
|
|
47
|
+
try {
|
|
48
|
+
const client = createGitHubClient(out, config.host);
|
|
49
|
+
const { items, progress, isLegacy } = await readBoard(client, config, input.repo);
|
|
50
|
+
const statuses = await collectAlertStatuses(client, config);
|
|
51
|
+
const view = { config, projectName, statuses };
|
|
52
|
+
const readiness = isLegacy ? skipBoardReadiness(out) : await readBoardReadiness(out, client, config, items, input.repo, progress);
|
|
53
|
+
if (readiness.mismatches > 0)
|
|
54
|
+
out.warning(mismatchNote(readiness.mismatches));
|
|
55
|
+
const json = readiness.json === undefined ? undefined : (item) => readinessOf(readiness, item);
|
|
56
|
+
out.data(input.json
|
|
57
|
+
? boardShowJson(view, items, json)
|
|
58
|
+
: boardShowMarkdown(view, input.repo, formatBoardOutput(items, readiness.texts), formatStackableChains(readiness.chains)));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof GitHubAPIError)
|
|
62
|
+
return failApi(out, 'read project board', error);
|
|
63
|
+
// Python の `except Exception` と同じ範囲(あらゆる Error)で捕まえる
|
|
64
|
+
if (error instanceof Error && !(error instanceof CommandExit))
|
|
65
|
+
return stopWith(out, `unexpected error: ${error.message}`, 'other');
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
export const BOARD_SHOW_COMMANDS = [boardShowCommand];
|
|
72
|
+
//# sourceMappingURL=board-show.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
|
+
// board sync。ボードの Ready・Blocked・Active・In Review の Issue を判定に合わせて、列と札を直す。
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { homeRepositoryOf } from '../domain/config.js';
|
|
6
|
+
import { loadActiveConfig, listProjectConfigNames, loadConfig, projectsDirectory } from '../infra/config-store.js';
|
|
7
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
8
|
+
import { applyJudgedMoves, judgeBoard, SYNCED_COLUMNS } from './board-judgment.js';
|
|
9
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
10
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
11
|
+
import { NO_ACTIVE_PROJECT, stopWith } from './command-stop.js';
|
|
12
|
+
import { makeClient } from './github-client.js';
|
|
13
|
+
import { createOutput } from './output.js';
|
|
14
|
+
import { pruneArchivedItems, readBoard } from './board-view.js';
|
|
15
|
+
import { failApi } from './project-sync.js';
|
|
16
|
+
function unsupportedWarning(out) {
|
|
17
|
+
out.warning('this GitHub Enterprise Server does not support issue dependencies (blockedBy); no column is moved');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
対象の Issue の前提と着手の跡を読み、判定に合わせて列と札を直す。dryRun は同じ文を予定の行で出し、書かない。
|
|
21
|
+
書き込みの失敗は warning にして続け、失敗した Issue の数を返す
|
|
22
|
+
*/
|
|
23
|
+
async function syncBoard(context, read, isDryRun) {
|
|
24
|
+
const { out, client, config } = context;
|
|
25
|
+
// 着手の跡は一覧に無いので、info と違い、一覧の値だけでは判定しない。Ready で前提 0 件なら動かさないと決まるので読まない
|
|
26
|
+
const judged = await judgeBoard(client, config, read.items, read.progress, {
|
|
27
|
+
columns: SYNCED_COLUMNS,
|
|
28
|
+
withoutRead: (target, known) => (target.item.workflow === 'Ready' && known?.blockedBy === 0 ? 'skip' : undefined),
|
|
29
|
+
});
|
|
30
|
+
if (judged === undefined) {
|
|
31
|
+
unsupportedWarning(out);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
return await applyJudgedMoves(context, judged, isDryRun);
|
|
35
|
+
}
|
|
36
|
+
function availableNames() {
|
|
37
|
+
return listProjectConfigNames().join(', ');
|
|
38
|
+
}
|
|
39
|
+
// --project、次にアクティブ設定。どちらも無く設定が 1 つだけなら、それを使う
|
|
40
|
+
function resolveConfig(out, project) {
|
|
41
|
+
if (project !== undefined) {
|
|
42
|
+
// 一覧は projects/ の *.json の名前なので、一致すれば ../ などの外のパスにならない
|
|
43
|
+
const name = project.endsWith('.json') ? project.slice(0, -'.json'.length) : project;
|
|
44
|
+
return listProjectConfigNames().includes(name) ? loadConfig(path.join(projectsDirectory(), `${name}.json`)) : stopWith(out, `project config not found: ${project}\navailable: ${availableNames()}`, 'project-not-found');
|
|
45
|
+
}
|
|
46
|
+
const active = loadActiveConfig();
|
|
47
|
+
if (active !== undefined)
|
|
48
|
+
return active;
|
|
49
|
+
const names = listProjectConfigNames();
|
|
50
|
+
const [only] = names;
|
|
51
|
+
if (only === undefined)
|
|
52
|
+
return stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
|
|
53
|
+
if (names.length === 1)
|
|
54
|
+
return loadConfig(path.join(projectsDirectory(), `${only}.json`));
|
|
55
|
+
return stopWith(out, hinted `no active project, and ${String(names.length)} project configs exist\nrun: ${commandHint(['board', 'sync'], { project: placeholder('NAME') })}\navailable: ${names.join(', ')}`, 'no-active-project');
|
|
56
|
+
}
|
|
57
|
+
// 窓が途中で切り替わると前後の used を比べられないので、使用量の行を省く
|
|
58
|
+
function reportPoints(out, before, after) {
|
|
59
|
+
if (before === undefined || after === undefined)
|
|
60
|
+
return;
|
|
61
|
+
const used = after.used - before.used;
|
|
62
|
+
if (before.reset === after.reset && used >= 0)
|
|
63
|
+
out.count('GraphQL points used', used);
|
|
64
|
+
out.count('GraphQL points remaining', after.remaining);
|
|
65
|
+
}
|
|
66
|
+
function failureMessage(failures) {
|
|
67
|
+
return failures === 1 ? 'could not write 1 Issue to the board' : `could not write ${String(failures)} Issues to the board`;
|
|
68
|
+
}
|
|
69
|
+
function deleteFailureMessage(failures) {
|
|
70
|
+
return failures === 1 ? 'could not delete 1 archived item from the board' : `could not delete ${String(failures)} archived items from the board`;
|
|
71
|
+
}
|
|
72
|
+
const boardSyncCommand = defineCommand({
|
|
73
|
+
path: ['board', 'sync'],
|
|
74
|
+
description: 'Move the Issues in Ready, Blocked, Active and In Review to the columns and Status values their judgment calls for, and delete the Archived items beyond the latest 20 from the board',
|
|
75
|
+
input: z.strictObject({
|
|
76
|
+
dry_run: z.boolean().default(false).describe('Show the planned moves without writing to the board'),
|
|
77
|
+
project: z.string().optional().describe('Name of the project config under .pecot/config/projects (without .json). Without it, the active project; when none is active and only one config exists, that one'),
|
|
78
|
+
}),
|
|
79
|
+
positional: [],
|
|
80
|
+
interactive: false,
|
|
81
|
+
run: async (input, io) => {
|
|
82
|
+
const out = createOutput(input.dry_run, io);
|
|
83
|
+
const config = resolveConfig(out, input.project);
|
|
84
|
+
const client = makeClient(out, config);
|
|
85
|
+
const before = await client.getGraphqlRateLimit();
|
|
86
|
+
let read;
|
|
87
|
+
try {
|
|
88
|
+
read = await readBoard(client, config, undefined);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (!(error instanceof GitHubAPIError))
|
|
92
|
+
throw error;
|
|
93
|
+
reportPoints(out, before, await client.getGraphqlRateLimit());
|
|
94
|
+
return failApi(out, 'read project board', error);
|
|
95
|
+
}
|
|
96
|
+
if (read.isLegacy)
|
|
97
|
+
unsupportedWarning(out);
|
|
98
|
+
const failures = read.isLegacy ? 0 : await syncBoard({ out, client, config, home: homeRepositoryOf(config) }, read, input.dry_run);
|
|
99
|
+
const pruneFailures = await pruneArchivedItems(out, client, config, read.allItems, input.dry_run);
|
|
100
|
+
reportPoints(out, before, await client.getGraphqlRateLimit());
|
|
101
|
+
if (failures === 0 && pruneFailures === 0)
|
|
102
|
+
return 0;
|
|
103
|
+
if (failures > 0)
|
|
104
|
+
out.error(failureMessage(failures));
|
|
105
|
+
if (pruneFailures > 0)
|
|
106
|
+
out.error(deleteFailureMessage(pruneFailures));
|
|
107
|
+
throw new CommandExit(1, 'partial-failure');
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
export const BOARD_SYNC_COMMANDS = [boardSyncCommand];
|
|
111
|
+
//# sourceMappingURL=board-sync.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { DependabotAlertStatus } from '../domain/dependabot.js';
|
|
3
|
+
import type { BoardItem, BoardProgress } from '../domain/format.js';
|
|
4
|
+
import type { JsonObject } from '../domain/json.js';
|
|
5
|
+
import { JSON_NULL } from '../domain/json-null.js';
|
|
6
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
7
|
+
import type { Output } from './output.js';
|
|
8
|
+
/**
|
|
9
|
+
取得に失敗したリポジトリは、理由の文字列
|
|
10
|
+
*/
|
|
11
|
+
export type AlertStatus = DependabotAlertStatus | string;
|
|
12
|
+
/**
|
|
13
|
+
Archived のアイテムを updatedAt の新しい順に並べ、最新の 20 件を残して、残りをボードから消す。
|
|
14
|
+
消せなかった件数を warning の行に出し、その数を返す
|
|
15
|
+
*/
|
|
16
|
+
export declare function pruneArchivedItems(out: Readonly<Output>, client: Readonly<Pick<GitHubClient, 'deleteProjectItem'>>, config: ProjectConfig, allItems: readonly BoardItem[], isDryRun: boolean): Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
登録リポジトリごとの Dependabot alert の状態(登録の順)。
|
|
19
|
+
1 つの取得の失敗でボードの表示を止めないよう、DependabotAlertError はここで理由の文字列にする
|
|
20
|
+
*/
|
|
21
|
+
export declare function collectAlertStatuses(client: Readonly<GitHubClient>, config: ProjectConfig): Promise<readonly AlertStatus[]>;
|
|
22
|
+
/**
|
|
23
|
+
items を最大 limit 件ずつ並列に処理し、結果を items の順で返す。1 件でも投げたら、その例外で止まる
|
|
24
|
+
*/
|
|
25
|
+
export declare function mapWithLimit<Item, Result>(items: readonly Item[], limit: number, task: (item: Item) => Promise<Result>): Promise<readonly Result[]>;
|
|
26
|
+
export interface BoardShowView {
|
|
27
|
+
readonly config: ProjectConfig;
|
|
28
|
+
readonly projectName: string;
|
|
29
|
+
readonly statuses: readonly AlertStatus[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
アイテムの JSON の readiness を引く。判定の無いアイテムは null
|
|
33
|
+
*/
|
|
34
|
+
export type ReadinessSource = (item: BoardItem) => JsonObject | typeof JSON_NULL;
|
|
35
|
+
/**
|
|
36
|
+
info --json の出力
|
|
37
|
+
*/
|
|
38
|
+
export declare function boardShowJson(view: Readonly<BoardShowView>, items: readonly BoardItem[], readiness?: ReadinessSource): string;
|
|
39
|
+
/**
|
|
40
|
+
info の Markdown の出力
|
|
41
|
+
*/
|
|
42
|
+
export declare function boardShowMarkdown(view: Readonly<BoardShowView>, effectiveRepository: string | undefined, boardOutput: string, chainsSection?: string): string;
|
|
43
|
+
export interface BoardRead {
|
|
44
|
+
readonly allItems: readonly BoardItem[];
|
|
45
|
+
/**
|
|
46
|
+
表示するアイテム(OPEN の Backlog・Pending・Blocked・Ready・Active・In Review。リポジトリの指定があれば絞る)
|
|
47
|
+
*/
|
|
48
|
+
readonly items: readonly BoardItem[];
|
|
49
|
+
/**
|
|
50
|
+
boardItemKey → 着手の判定の軽い入力。前提の無い Issue の個別の読み取りを省く
|
|
51
|
+
*/
|
|
52
|
+
readonly progress: ReadonlyMap<string, BoardProgress>;
|
|
53
|
+
/**
|
|
54
|
+
一覧を足す前のクエリで読み直した(Issue の依存関係に対応しない GHES)
|
|
55
|
+
*/
|
|
56
|
+
readonly isLegacy: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
ボードのアイテムを全部読み、表示するものに絞る
|
|
60
|
+
*/
|
|
61
|
+
export declare function readBoard(client: Readonly<GitHubClient>, config: ProjectConfig, effectiveRepository: string | undefined): Promise<BoardRead>;
|
|
62
|
+
//# sourceMappingURL=board-view.d.ts.map
|