@pecot/workflow-mcp 0.0.0-stage → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +12 -0
- package/cli/dist/commands/github-client.js +23 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +55 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +19 -0
- package/cli/dist/domain/errors.js +31 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-readout.d.ts +107 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +134 -0
- package/cli/dist/domain/pull-request.js +232 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +66 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +49 -0
- package/cli/dist/infra/config-store.js +121 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +74 -0
- package/cli/dist/infra/git.js +133 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +173 -0
- package/cli/dist/infra/github/client.js +576 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +47 -0
- package/cli/dist/infra/github/errors.js +42 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +129 -0
- package/cli/dist/infra/github/issues.js +273 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +45 -0
- package/cli/dist/infra/state-store.js +118 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +139 -0
- package/cli/dist/infra/worktree-links.js +433 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +128 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +181 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +67 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { DependabotAlertStatus } from '../domain/dependabot.js';
|
|
3
|
+
import type { BoardItem } from '../domain/format.js';
|
|
4
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
5
|
+
import type { Output } from './output.js';
|
|
6
|
+
/**
|
|
7
|
+
取得に失敗したリポジトリは、理由の文字列
|
|
8
|
+
*/
|
|
9
|
+
export type AlertStatus = DependabotAlertStatus | string;
|
|
10
|
+
/**
|
|
11
|
+
Archived のアイテムを updatedAt の新しい順に並べ、最新の 20 件を残して、残りをボードから消す。
|
|
12
|
+
消せなかった分は warning にとどめる
|
|
13
|
+
*/
|
|
14
|
+
export declare function pruneArchivedItems(out: Readonly<Output>, client: Readonly<Pick<GitHubClient, 'deleteProjectItem'>>, config: ProjectConfig, allItems: readonly BoardItem[]): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
登録リポジトリごとの Dependabot alert の状態(登録の順)。
|
|
17
|
+
1 つの取得の失敗でボードの表示を止めないよう、DependabotAlertError はここで理由の文字列にする
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectAlertStatuses(client: Readonly<GitHubClient>, config: ProjectConfig): Promise<readonly AlertStatus[]>;
|
|
20
|
+
/**
|
|
21
|
+
items を最大 limit 件ずつ並列に処理し、結果を items の順で返す。1 件でも投げたら、その例外で止まる
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapWithLimit<Item, Result>(items: readonly Item[], limit: number, task: (item: Item) => Promise<Result>): Promise<readonly Result[]>;
|
|
24
|
+
export interface InfoView {
|
|
25
|
+
readonly config: ProjectConfig;
|
|
26
|
+
readonly projectName: string;
|
|
27
|
+
readonly statuses: readonly AlertStatus[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
info --json の出力
|
|
31
|
+
*/
|
|
32
|
+
export declare function infoJson(view: Readonly<InfoView>, items: readonly BoardItem[]): string;
|
|
33
|
+
/**
|
|
34
|
+
info の Markdown の出力
|
|
35
|
+
*/
|
|
36
|
+
export declare function infoMarkdown(view: Readonly<InfoView>, effectiveRepository: string | undefined, boardOutput: string): string;
|
|
37
|
+
export interface BoardRead {
|
|
38
|
+
readonly allItems: readonly BoardItem[];
|
|
39
|
+
/**
|
|
40
|
+
表示するアイテム(OPEN の Backlog・Pending・Blocked・Ready・Active・In Review。リポジトリの指定があれば絞る)
|
|
41
|
+
*/
|
|
42
|
+
readonly items: readonly BoardItem[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
ボードのアイテムを全部読み、表示するものに絞る
|
|
46
|
+
*/
|
|
47
|
+
export declare function readBoard(client: Readonly<GitHubClient>, config: ProjectConfig, effectiveRepository: string | undefined): Promise<BoardRead>;
|
|
48
|
+
//# sourceMappingURL=project-info.d.ts.map
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// project info の表示と、Archived の整理、Dependabot alert の収集。
|
|
2
|
+
import { effectiveReleaseType, workflowFieldName } from '../domain/config.js';
|
|
3
|
+
import { DependabotAlertError, fetchDependabotAlertStatus } from '../domain/dependabot.js';
|
|
4
|
+
import { formatItemsJson, transformItems } from '../domain/format.js';
|
|
5
|
+
import { JSON_NULL } from '../domain/json-null.js';
|
|
6
|
+
import { compareStrings } from '../domain/python-format.js';
|
|
7
|
+
import { createDependabotSource } from '../infra/github/dependabot-source.js';
|
|
8
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
9
|
+
/**
|
|
10
|
+
Archived のうち、ボードに残す件数
|
|
11
|
+
*/
|
|
12
|
+
const ARCHIVED_KEEP = 20;
|
|
13
|
+
/**
|
|
14
|
+
Dependabot alert を並列に取る数の上限(Python の _ALERT_FETCH_MAX_WORKERS と同じ)
|
|
15
|
+
*/
|
|
16
|
+
const ALERT_FETCH_MAX_WORKERS = 8;
|
|
17
|
+
const DISPLAY_STATUSES = new Set(['Backlog', 'Pending', 'Blocked', 'Ready', 'Active', 'In Review']);
|
|
18
|
+
function updatedAtOf(item) {
|
|
19
|
+
return typeof item.updatedAt === 'string' ? item.updatedAt : '';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
Archived のアイテムを updatedAt の新しい順に並べ、最新の 20 件を残して、残りをボードから消す。
|
|
23
|
+
消せなかった分は warning にとどめる
|
|
24
|
+
*/
|
|
25
|
+
export async function pruneArchivedItems(out, client, config, allItems) {
|
|
26
|
+
const archived = allItems.filter(item => item.workflow === 'Archived').toSorted((first, second) => compareStrings(updatedAtOf(second), updatedAtOf(first)));
|
|
27
|
+
if (archived.length <= ARCHIVED_KEEP)
|
|
28
|
+
return;
|
|
29
|
+
const targets = archived.slice(ARCHIVED_KEEP);
|
|
30
|
+
let deleted = 0;
|
|
31
|
+
for (const item of targets) {
|
|
32
|
+
// ID が文字列でないアイテムは、API を呼ばず、失敗として数える
|
|
33
|
+
if (typeof item.id !== 'string')
|
|
34
|
+
continue;
|
|
35
|
+
try {
|
|
36
|
+
await client.deleteProjectItem(config.project.id, item.id);
|
|
37
|
+
deleted += 1;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
// 削除の失敗は数えて続ける
|
|
41
|
+
if (!(error instanceof GitHubAPIError))
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (deleted > 0)
|
|
46
|
+
out.done({ verb: 'delete', target: `${String(deleted)} archived items` });
|
|
47
|
+
const failed = targets.length - deleted;
|
|
48
|
+
if (failed > 0)
|
|
49
|
+
out.warning(`failed to delete ${String(failed)} archived items`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
登録リポジトリごとの Dependabot alert の状態(登録の順)。
|
|
53
|
+
1 つの取得の失敗でボードの表示を止めないよう、DependabotAlertError はここで理由の文字列にする
|
|
54
|
+
*/
|
|
55
|
+
export async function collectAlertStatuses(client, config) {
|
|
56
|
+
const source = createDependabotSource(client);
|
|
57
|
+
return await mapWithLimit(config.repositories, ALERT_FETCH_MAX_WORKERS, async (entry) => {
|
|
58
|
+
try {
|
|
59
|
+
return await fetchDependabotAlertStatus(source, config.host, entry.owner, entry.name);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error instanceof DependabotAlertError)
|
|
63
|
+
return error.message;
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
items を最大 limit 件ずつ並列に処理し、結果を items の順で返す。1 件でも投げたら、その例外で止まる
|
|
70
|
+
*/
|
|
71
|
+
export async function mapWithLimit(items, limit, task) {
|
|
72
|
+
const results = [];
|
|
73
|
+
// 全ての worker が同じ iterator から次の項目を取る
|
|
74
|
+
const pending = items.entries();
|
|
75
|
+
const worker = async () => {
|
|
76
|
+
// eslint-disable-next-line security/detect-object-injection -- index は entries() の添字
|
|
77
|
+
for (const [index, item] of pending)
|
|
78
|
+
results[index] = await task(item);
|
|
79
|
+
};
|
|
80
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
index 番目の取得結果。件数が登録のリポジトリとずれていたら投げる
|
|
85
|
+
*/
|
|
86
|
+
function statusAt(statuses, index) {
|
|
87
|
+
const status = statuses.at(index);
|
|
88
|
+
if (status === undefined)
|
|
89
|
+
throw new RangeError(`no Dependabot alert status for repository #${String(index)}`);
|
|
90
|
+
return status;
|
|
91
|
+
}
|
|
92
|
+
function alertsJson(status) {
|
|
93
|
+
return typeof status === 'string' ? { error: status } : { enabled: status.enabled, open_count: status.openCount, max_severity: status.maxSeverity ?? JSON_NULL, alerts_url: status.alertsUrl };
|
|
94
|
+
}
|
|
95
|
+
function alertsLine(status) {
|
|
96
|
+
if (typeof status === 'string')
|
|
97
|
+
return ` dependabot_alerts: fetch failed (${status})`;
|
|
98
|
+
if (!status.enabled)
|
|
99
|
+
return ' dependabot_alerts: disabled';
|
|
100
|
+
return ` dependabot_alerts: open ${String(status.openCount)}`;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
info --json の出力
|
|
104
|
+
*/
|
|
105
|
+
export function infoJson(view, items) {
|
|
106
|
+
const { config, projectName, statuses } = view;
|
|
107
|
+
const output = {
|
|
108
|
+
project: {
|
|
109
|
+
name: projectName,
|
|
110
|
+
host: config.host,
|
|
111
|
+
owner: config.owner,
|
|
112
|
+
number: config.project.number,
|
|
113
|
+
aggregation_repo: config.aggregation_repo ?? JSON_NULL,
|
|
114
|
+
},
|
|
115
|
+
repositories: config.repositories.map((entry, index) => ({
|
|
116
|
+
full_name: `${entry.owner}/${entry.name}`,
|
|
117
|
+
owner: entry.owner,
|
|
118
|
+
name: entry.name,
|
|
119
|
+
develop_branch: entry.develop_branch ?? JSON_NULL,
|
|
120
|
+
release_branch: entry.release_branch ?? JSON_NULL,
|
|
121
|
+
dependabot_alerts: alertsJson(statusAt(statuses, index)),
|
|
122
|
+
})),
|
|
123
|
+
board: formatItemsJson(items),
|
|
124
|
+
};
|
|
125
|
+
return JSON.stringify(output, undefined, 2);
|
|
126
|
+
}
|
|
127
|
+
function repositoryLines(view) {
|
|
128
|
+
const { config, statuses } = view;
|
|
129
|
+
if (config.repositories.length === 0)
|
|
130
|
+
return ['## Registered repositories', '- none'];
|
|
131
|
+
const lines = ['## Registered repositories'];
|
|
132
|
+
for (const [index, entry] of config.repositories.entries()) {
|
|
133
|
+
const develop = entry.develop_branch === undefined || entry.develop_branch === '' ? [] : [`develop: ${entry.develop_branch}`];
|
|
134
|
+
const release = entry.release_branch === undefined || entry.release_branch === '' ? [] : [`release: ${entry.release_branch}`];
|
|
135
|
+
const branches = [...develop, ...release];
|
|
136
|
+
const fullName = `${entry.owner}/${entry.name}`;
|
|
137
|
+
lines.push(branches.length > 0 ? `- ${fullName} (${branches.join(', ')})` : `- ${fullName}`, ` release_type: ${effectiveReleaseType(entry)}`, alertsLine(statusAt(statuses, index)));
|
|
138
|
+
if (entry.packages !== undefined && entry.packages.length > 0) {
|
|
139
|
+
for (const item of entry.packages)
|
|
140
|
+
lines.push(` package: ${item.name} → ${item.changelog}`);
|
|
141
|
+
}
|
|
142
|
+
else if (entry.changelog_file !== undefined && entry.changelog_file !== '') {
|
|
143
|
+
lines.push(` changelog: ${entry.changelog_file}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return lines;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
info の Markdown の出力
|
|
150
|
+
*/
|
|
151
|
+
export function infoMarkdown(view, effectiveRepository, boardOutput) {
|
|
152
|
+
const { config, projectName } = view;
|
|
153
|
+
const aggregation = config.aggregation_repo === undefined || config.aggregation_repo === '' ? 'none' : `\`${config.aggregation_repo}\``;
|
|
154
|
+
return [
|
|
155
|
+
'# Project info',
|
|
156
|
+
'',
|
|
157
|
+
'## Overview',
|
|
158
|
+
`- Project: ${projectName}`,
|
|
159
|
+
`- Host: ${config.host}`,
|
|
160
|
+
`- Owner: ${config.owner}`,
|
|
161
|
+
`- Roadmap repo: ${aggregation}`,
|
|
162
|
+
'',
|
|
163
|
+
...repositoryLines(view),
|
|
164
|
+
'',
|
|
165
|
+
effectiveRepository === undefined || effectiveRepository === '' ? '## Board status' : `## Board status (filter: ${effectiveRepository})`,
|
|
166
|
+
'',
|
|
167
|
+
boardOutput,
|
|
168
|
+
].join('\n');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
ボードのアイテムを全部読み、表示するものに絞る
|
|
172
|
+
*/
|
|
173
|
+
export async function readBoard(client, config, effectiveRepository) {
|
|
174
|
+
const fieldName = workflowFieldName(config);
|
|
175
|
+
const rawItems = await client.listProjectItems(config.project.id, { workflowFieldName: fieldName });
|
|
176
|
+
const allItems = transformItems(rawItems, fieldName);
|
|
177
|
+
const open = allItems.filter(item => item.content.state === 'OPEN' && typeof item.workflow === 'string' && DISPLAY_STATUSES.has(item.workflow));
|
|
178
|
+
const items = effectiveRepository === undefined || effectiveRepository === '' ? open : open.filter(item => item.content.repository === effectiveRepository);
|
|
179
|
+
return { allItems, items };
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=project-info.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Repository } from '../domain/config.js';
|
|
2
|
+
import type { OptionPlacement } from '../domain/field-options.js';
|
|
3
|
+
import type { JsonObject } from '../domain/json.js';
|
|
4
|
+
import type { JsonValue } from '../domain/python-format.js';
|
|
5
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
6
|
+
import type { GitHubAPIError } from '../infra/github/errors.js';
|
|
7
|
+
import type { ProjectFieldOption } from '../infra/github/projects.js';
|
|
8
|
+
import type { Output } from './output.js';
|
|
9
|
+
/**
|
|
10
|
+
選択肢の定義。isOptional は無くても同期を止めない。placement は足すときの差し込み先の候補(先から使い、無ければ末尾)
|
|
11
|
+
*/
|
|
12
|
+
export interface OptionSpec {
|
|
13
|
+
readonly option: ProjectFieldOption;
|
|
14
|
+
readonly isOptional?: true;
|
|
15
|
+
readonly placement?: readonly OptionPlacement[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
前提を待つ Issue を pecot が置く列
|
|
19
|
+
*/
|
|
20
|
+
export declare const BLOCKED_SPEC: OptionSpec;
|
|
21
|
+
/**
|
|
22
|
+
人の判断を待つ Issue の札。既定の Status の末尾に足す
|
|
23
|
+
*/
|
|
24
|
+
export declare const NEEDS_ATTENTION_SPEC: OptionSpec;
|
|
25
|
+
/**
|
|
26
|
+
既定の Status のフィールド名
|
|
27
|
+
*/
|
|
28
|
+
export declare const STATUS_FIELD_NAME = "Status";
|
|
29
|
+
/**
|
|
30
|
+
workflow フィールドに作る選択肢
|
|
31
|
+
*/
|
|
32
|
+
export declare const WORKFLOW_FIELD_OPTIONS: readonly ProjectFieldOption[];
|
|
33
|
+
export declare const PRIORITY_FIELD_OPTIONS: readonly ProjectFieldOption[];
|
|
34
|
+
export declare const SIZE_FIELD_OPTIONS: readonly ProjectFieldOption[];
|
|
35
|
+
/**
|
|
36
|
+
`could not <action>` に API の失敗の文(と状態コード)を添えて、終了コード 1 で止める
|
|
37
|
+
*/
|
|
38
|
+
export declare function failApi(out: Readonly<Output>, action: string, error: Readonly<GitHubAPIError>): never;
|
|
39
|
+
/**
|
|
40
|
+
Python の str() に当たる文字列。値が無いときは None
|
|
41
|
+
*/
|
|
42
|
+
export declare function textOf(value: JsonValue | undefined): string;
|
|
43
|
+
export declare function isWorkflowField(name: JsonValue | undefined): boolean;
|
|
44
|
+
export declare function hasWorkflowField(fields: readonly JsonValue[]): boolean;
|
|
45
|
+
/**
|
|
46
|
+
プロジェクトの情報から fields.nodes を取る
|
|
47
|
+
*/
|
|
48
|
+
export declare function fieldNodesOf(projectInfo: JsonObject): readonly JsonValue[];
|
|
49
|
+
/**
|
|
50
|
+
タイトルが一致するプロジェクトを一覧から探す。無ければ、選べるタイトルを並べて止める
|
|
51
|
+
*/
|
|
52
|
+
export declare function findProjectByTitle(out: Readonly<Output>, client: Readonly<GitHubClient>, owner: string, name: string): Promise<JsonObject>;
|
|
53
|
+
/**
|
|
54
|
+
workflow フィールドに足りない必須の選択肢(要る順。optional は数えない。名前は大文字と小文字を区別しない)
|
|
55
|
+
*/
|
|
56
|
+
export declare function missingRequiredOptions(field: Readonly<JsonObject>): readonly string[];
|
|
57
|
+
/**
|
|
58
|
+
必須の選択肢が欠けたときの、終了コード 1 の止め方
|
|
59
|
+
*/
|
|
60
|
+
export declare function stopMissingOptions(out: Readonly<Output>, missing: readonly string[]): never;
|
|
61
|
+
/**
|
|
62
|
+
ファイル名に使う slug。小文字にして空白を `-` にし、`a-z0-9-` 以外を落とす
|
|
63
|
+
*/
|
|
64
|
+
export declare function slugify(text: string): string;
|
|
65
|
+
export declare function lastFieldNamed(fields: readonly JsonValue[], name: string): JsonObject | undefined;
|
|
66
|
+
export interface RepositoryParts {
|
|
67
|
+
readonly owner: string;
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly develop_branch?: string | undefined;
|
|
70
|
+
readonly release_branch?: string | undefined;
|
|
71
|
+
readonly changelog_file?: string | undefined;
|
|
72
|
+
readonly packages?: Repository['packages'];
|
|
73
|
+
readonly release_type?: Repository['release_type'];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
リポジトリを、モデルの定義順のキーで作る(保存の JSON のキーの順になる)
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildRepository(parts: Readonly<RepositoryParts>): Repository;
|
|
79
|
+
/**
|
|
80
|
+
GitHub Projects V2 の情報から設定ファイルを作るか更新し、アクティブにする。作った設定ファイルのパスを返す。
|
|
81
|
+
pecot-workflow に合うプロジェクトだけを扱う。suffix はその名前の workflow フィールドを使う。
|
|
82
|
+
skipIfUnchanged は、設定ファイルの内容が同じなら何も書かない
|
|
83
|
+
*/
|
|
84
|
+
export declare function syncProjectConfig(out: Readonly<Output>, client: Readonly<GitHubClient>, target: Readonly<{
|
|
85
|
+
owner: string;
|
|
86
|
+
name: string;
|
|
87
|
+
host: string;
|
|
88
|
+
suffix?: string | undefined;
|
|
89
|
+
skipIfUnchanged?: boolean | undefined;
|
|
90
|
+
}>): Promise<string>;
|
|
91
|
+
//# sourceMappingURL=project-sync.d.ts.map
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// project の各コマンドが共有する部分。失敗の行、フィールドの検証、設定ファイルの同期(Python の project.py の _sync_project_config まわり)。
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parseProjectConfig, serializeProjectConfig } from '../domain/config.js';
|
|
5
|
+
import { isJsonObject, jsonField, parseJsonText } from '../domain/json.js';
|
|
6
|
+
import { pythonRepr } from '../domain/python-format.js';
|
|
7
|
+
import { loadConfig, projectsDirectory, saveConfig, setActiveConfig } from '../infra/config-store.js';
|
|
8
|
+
import { asArray, isTruthy, requireNumber, requireString } from '../infra/github/payload.js';
|
|
9
|
+
import { stopWith } from './command-stop.js';
|
|
10
|
+
const WORKFLOW_FIELD_PREFIX = 'pecot-workflow-';
|
|
11
|
+
/**
|
|
12
|
+
前提を待つ Issue を pecot が置く列
|
|
13
|
+
*/
|
|
14
|
+
export const BLOCKED_SPEC = {
|
|
15
|
+
option: { name: 'Blocked', color: 'GRAY', description: 'Tasks waiting for prerequisite Issues. pecot moves them to Ready once they can start.' },
|
|
16
|
+
isOptional: true,
|
|
17
|
+
placement: [{ after: 'Backlog' }, { before: 'Ready' }],
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
人の判断を待つ Issue の札。既定の Status の末尾に足す
|
|
21
|
+
*/
|
|
22
|
+
export const NEEDS_ATTENTION_SPEC = {
|
|
23
|
+
option: { name: 'Needs Attention', color: 'RED', description: 'Waiting for a human decision or action.' },
|
|
24
|
+
isOptional: true,
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
既定の Status のフィールド名
|
|
28
|
+
*/
|
|
29
|
+
export const STATUS_FIELD_NAME = 'Status';
|
|
30
|
+
/**
|
|
31
|
+
workflow フィールドの選択肢の定義。作る順でもある
|
|
32
|
+
*/
|
|
33
|
+
const WORKFLOW_FIELD_SPECS = [
|
|
34
|
+
{ option: { name: 'Pending', color: 'GRAY', description: 'Items on hold (Epic or Task). Moved here from Ready or Backlog when deprioritized.' } },
|
|
35
|
+
{ option: { name: 'Backlog', color: 'RED', description: 'Items waiting to be planned. Not for direct work - break down into smaller tasks first.' } },
|
|
36
|
+
BLOCKED_SPEC,
|
|
37
|
+
{ option: { name: 'Ready', color: 'GREEN', description: 'Tasks ready for implementation. AI agent picks from here and moves to Active on start.' } },
|
|
38
|
+
{ option: { name: 'Active', color: 'BLUE', description: 'Currently being worked on. One active task per worktree - track progress and updates here.' } },
|
|
39
|
+
{ option: { name: 'In Review', color: 'YELLOW', description: 'Pull request created and waiting for review. Moves to Archived after merge is completed.' } },
|
|
40
|
+
{ option: { name: 'Archived', color: 'PURPLE', description: 'Completed or cancelled items. Moved here after the issue is closed or no longer needed.' } },
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
workflow フィールドに作る選択肢
|
|
44
|
+
*/
|
|
45
|
+
export const WORKFLOW_FIELD_OPTIONS = WORKFLOW_FIELD_SPECS.map(spec => spec.option);
|
|
46
|
+
export const PRIORITY_FIELD_OPTIONS = [
|
|
47
|
+
{ name: 'High', color: 'RED', description: 'Priority: high' },
|
|
48
|
+
{ name: 'Medium', color: 'YELLOW', description: 'Priority: medium' },
|
|
49
|
+
{ name: 'Low', color: 'GREEN', description: 'Priority: low' },
|
|
50
|
+
];
|
|
51
|
+
export const SIZE_FIELD_OPTIONS = [
|
|
52
|
+
{ name: 'XS', color: 'GREEN', description: 'Size: extra small' },
|
|
53
|
+
{ name: 'S', color: 'BLUE', description: 'Size: small' },
|
|
54
|
+
{ name: 'M', color: 'YELLOW', description: 'Size: medium' },
|
|
55
|
+
{ name: 'L', color: 'RED', description: 'Size: large' },
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
`could not <action>` に API の失敗の文(と状態コード)を添えて、終了コード 1 で止める
|
|
59
|
+
*/
|
|
60
|
+
export function failApi(out, action, error) {
|
|
61
|
+
const detail = error.message;
|
|
62
|
+
const status = error.statusCode ?? 0;
|
|
63
|
+
return stopWith(out, status === 0 ? `could not ${action}: ${detail}` : `could not ${action} (status ${String(status)}): ${detail}`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
Python の str() に当たる文字列。値が無いときは None
|
|
67
|
+
*/
|
|
68
|
+
export function textOf(value) {
|
|
69
|
+
if (value === undefined)
|
|
70
|
+
return 'None';
|
|
71
|
+
return typeof value === 'string' ? value : pythonRepr(value);
|
|
72
|
+
}
|
|
73
|
+
export function isWorkflowField(name) {
|
|
74
|
+
return typeof name === 'string' && name.startsWith(WORKFLOW_FIELD_PREFIX);
|
|
75
|
+
}
|
|
76
|
+
export function hasWorkflowField(fields) {
|
|
77
|
+
return fields.some(field => isWorkflowField(jsonField(field, 'name')));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
プロジェクトの情報から fields.nodes を取る
|
|
81
|
+
*/
|
|
82
|
+
export function fieldNodesOf(projectInfo) {
|
|
83
|
+
return asArray(jsonField(jsonField(projectInfo, 'fields'), 'nodes'));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
タイトルが一致するプロジェクトを一覧から探す。無ければ、選べるタイトルを並べて止める
|
|
87
|
+
*/
|
|
88
|
+
export async function findProjectByTitle(out, client, owner, name) {
|
|
89
|
+
const projects = await client.listProjects(owner);
|
|
90
|
+
const found = projects.find(project => jsonField(project, 'title') === name);
|
|
91
|
+
if (found !== undefined)
|
|
92
|
+
return found;
|
|
93
|
+
const titles = projects.map(project => `- ${textOf(jsonField(project, 'title'))}`).join('\n');
|
|
94
|
+
return stopWith(out, `project not found: ${name}\navailable projects:\n${titles}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
workflow フィールドに足りない必須の選択肢(要る順。optional は数えない。名前は大文字と小文字を区別しない)
|
|
98
|
+
*/
|
|
99
|
+
export function missingRequiredOptions(field) {
|
|
100
|
+
const existing = new Set(asArray(field['options']).map(option => lowerName(option)));
|
|
101
|
+
return WORKFLOW_FIELD_SPECS.filter(spec => spec.isOptional !== true && !existing.has(spec.option.name.toLowerCase())).map(spec => spec.option.name);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
必須の選択肢が欠けたときの、終了コード 1 の止め方
|
|
105
|
+
*/
|
|
106
|
+
export function stopMissingOptions(out, missing) {
|
|
107
|
+
return stopWith(out, `pecot-workflow field is missing options: ${missing.join(', ')}\nrequired options: Backlog / Pending / Ready / Active / In Review / Archived`);
|
|
108
|
+
}
|
|
109
|
+
function lowerName(option) {
|
|
110
|
+
const name = jsonField(option, 'name');
|
|
111
|
+
return typeof name === 'string' ? name.toLowerCase() : '';
|
|
112
|
+
}
|
|
113
|
+
// 選択肢を持つ workflow フィールド。suffix があればその名前のもの、無ければ最初の pecot-workflow-*
|
|
114
|
+
function findWorkflowField(fields, suffix) {
|
|
115
|
+
return fields.find((field) => isJsonObject(field) && Object.hasOwn(field, 'options') && (suffix === undefined ? isWorkflowField(field['name']) : field['name'] === `${WORKFLOW_FIELD_PREFIX}${suffix}`));
|
|
116
|
+
}
|
|
117
|
+
async function fetchValidatedFields(out, client, target) {
|
|
118
|
+
const { owner, name, host, number, suffix } = target;
|
|
119
|
+
const projectInfo = await client.getProjectFields(owner, number);
|
|
120
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
121
|
+
return stopWith(out, `could not read project fields: ${name}`);
|
|
122
|
+
const fields = fieldNodesOf(projectInfo);
|
|
123
|
+
const workflowField = findWorkflowField(fields, suffix);
|
|
124
|
+
if (workflowField === undefined) {
|
|
125
|
+
return stopWith(out, `project "${name}" has no pecot-workflow-* field\n`
|
|
126
|
+
+ 'required field: pecot-workflow-<suffix> (Backlog/Pending/Ready/Active/In Review/Archived)\n'
|
|
127
|
+
+ `run: pecot project init --host ${host} --suffix <suffix> ${owner} "${name}"`);
|
|
128
|
+
}
|
|
129
|
+
const missing = missingRequiredOptions(workflowField);
|
|
130
|
+
if (missing.length > 0)
|
|
131
|
+
return stopMissingOptions(out, missing);
|
|
132
|
+
const views = asArray(jsonField(jsonField(projectInfo, 'views'), 'nodes'));
|
|
133
|
+
const viewNumber = jsonField(views.at(0), 'number');
|
|
134
|
+
return { workflowField, fields, viewNumber };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
ファイル名に使う slug。小文字にして空白を `-` にし、`a-z0-9-` 以外を落とす
|
|
138
|
+
*/
|
|
139
|
+
export function slugify(text) {
|
|
140
|
+
return text.toLowerCase().replaceAll(' ', '-').replaceAll(/[^a-z0-9-]/gu, '');
|
|
141
|
+
}
|
|
142
|
+
// urllib.parse.quote(text) と同じ。`/` と `_.-~` は残し、それ以外は %XX にする
|
|
143
|
+
function quote(text) {
|
|
144
|
+
return encodeURIComponent(text)
|
|
145
|
+
.replaceAll(/[!'()*]/gu, character => `%${character.codePointAt(0)?.toString(16).toUpperCase() ?? ''}`)
|
|
146
|
+
.replaceAll('%2F', '/');
|
|
147
|
+
}
|
|
148
|
+
function buildBoardUrl(projectUrl, workflowField, viewNumber) {
|
|
149
|
+
const databaseId = workflowField['databaseId'];
|
|
150
|
+
// 空白入りの値(In Review)を末尾に置く(URL の解析の誤りを避ける)
|
|
151
|
+
const present = new Set(asArray(workflowField['options']).map(option => lowerName(option)));
|
|
152
|
+
const names = WORKFLOW_FIELD_SPECS.filter(spec => spec.isOptional !== true || present.has(spec.option.name.toLowerCase())).map(spec => spec.option.name);
|
|
153
|
+
const plain = names.filter(name => !name.includes(' '));
|
|
154
|
+
const spaced = names.filter(name => name.includes(' '));
|
|
155
|
+
const values = [...plain, ...spaced];
|
|
156
|
+
const statusValues = values.map(value => value.includes(' ') ? `"${value}"` : value).join(',');
|
|
157
|
+
const filterQuery = quote(` ${textOf(workflowField['name'])}:${statusValues}`);
|
|
158
|
+
return isTruthy(databaseId) && isTruthy(viewNumber) ? `${projectUrl}/views/${textOf(viewNumber)}?layout=board&verticalGroupedBy%5BcolumnId%5D=${textOf(databaseId)}&filterQuery=${filterQuery}` : `${projectUrl}?filterQuery=${filterQuery}`;
|
|
159
|
+
}
|
|
160
|
+
function keyEntry(name, isOptional) {
|
|
161
|
+
return { key: name.toLowerCase().replaceAll(' ', '_'), label: name.toLowerCase(), isOptional };
|
|
162
|
+
}
|
|
163
|
+
// 設定ファイルのキーの順(保存の JSON のキーの順になる)。isOptional は選択肢の定義の値を使う
|
|
164
|
+
const WORKFLOW_KEY_ORDER = ['Backlog', 'Pending', 'Blocked', 'Ready', 'Active', 'In Review', 'Archived'];
|
|
165
|
+
const WORKFLOW_KEYS = WORKFLOW_KEY_ORDER.map(name => keyEntry(name, WORKFLOW_FIELD_SPECS.some(spec => spec.option.name === name && spec.isOptional === true)));
|
|
166
|
+
const STATUS_KEYS = [keyEntry('Todo', true), keyEntry(NEEDS_ATTENTION_SPEC.option.name, NEEDS_ATTENTION_SPEC.isOptional === true)];
|
|
167
|
+
const PRIORITY_KEYS = ['High', 'Medium', 'Low'].map(name => keyEntry(name, false));
|
|
168
|
+
const SIZE_KEYS = ['XS', 'S', 'M', 'L'].map(name => keyEntry(name, false));
|
|
169
|
+
// isOptional のキーは、ボードに選択肢が無ければ書かない。それ以外は無ければ空文字列で書く
|
|
170
|
+
function fieldOptionsConfig(field, keys) {
|
|
171
|
+
const idsByName = new Map();
|
|
172
|
+
const optionNodes = asArray(field['options']);
|
|
173
|
+
for (const option of optionNodes) {
|
|
174
|
+
const name = jsonField(option, 'name');
|
|
175
|
+
const id = jsonField(option, 'id');
|
|
176
|
+
if (typeof name === 'string' && typeof id === 'string')
|
|
177
|
+
idsByName.set(name.toLowerCase(), id);
|
|
178
|
+
}
|
|
179
|
+
const entries = keys
|
|
180
|
+
.filter(entry => idsByName.has(entry.label) || !entry.isOptional)
|
|
181
|
+
.map((entry) => [entry.key, idsByName.get(entry.label) ?? '']);
|
|
182
|
+
return { id: requireString(field['id'], 'field.id'), options: Object.fromEntries(entries) };
|
|
183
|
+
}
|
|
184
|
+
// 同じ名前のフィールドが複数あれば、後のものを使う
|
|
185
|
+
export function lastFieldNamed(fields, name) {
|
|
186
|
+
return fields.findLast((field) => isJsonObject(field) && field['name'] === name && Object.hasOwn(field, 'options'));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
リポジトリを、モデルの定義順のキーで作る(保存の JSON のキーの順になる)
|
|
190
|
+
*/
|
|
191
|
+
export function buildRepository(parts) {
|
|
192
|
+
return {
|
|
193
|
+
owner: parts.owner,
|
|
194
|
+
name: parts.name,
|
|
195
|
+
develop_branch: parts.develop_branch,
|
|
196
|
+
release_branch: parts.release_branch,
|
|
197
|
+
changelog_file: parts.changelog_file,
|
|
198
|
+
packages: parts.packages,
|
|
199
|
+
release_type: parts.release_type,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
// 既存の設定の順を先にし、リンクの外れたものを落として、新しいものをリンクの順に足す
|
|
203
|
+
function buildRepositories(linked, existing) {
|
|
204
|
+
const linkedKeys = new Map();
|
|
205
|
+
for (const entry of linked) {
|
|
206
|
+
const key = `${entry.owner}/${entry.name}`;
|
|
207
|
+
if (!linkedKeys.has(key))
|
|
208
|
+
linkedKeys.set(key, entry);
|
|
209
|
+
}
|
|
210
|
+
const previous = new Map(existing.map(repository => [`${repository.owner}/${repository.name}`, repository]));
|
|
211
|
+
const keys = [];
|
|
212
|
+
for (const key of previous.keys()) {
|
|
213
|
+
const entry = linkedKeys.get(key);
|
|
214
|
+
if (entry !== undefined)
|
|
215
|
+
keys.push([key, entry]);
|
|
216
|
+
}
|
|
217
|
+
for (const [key, entry] of linkedKeys) {
|
|
218
|
+
if (!previous.has(key))
|
|
219
|
+
keys.push([key, entry]);
|
|
220
|
+
}
|
|
221
|
+
return keys.map(([key, entry]) => buildRepository({ ...previous.get(key), owner: entry.owner, name: entry.name }));
|
|
222
|
+
}
|
|
223
|
+
function loadExistingConfig(configPath) {
|
|
224
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- 設定ディレクトリ配下のパス
|
|
225
|
+
return existsSync(configPath) ? loadConfig(configPath) : undefined;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
GitHub Projects V2 の情報から設定ファイルを作るか更新し、アクティブにする。作った設定ファイルのパスを返す。
|
|
229
|
+
pecot-workflow に合うプロジェクトだけを扱う。suffix はその名前の workflow フィールドを使う。
|
|
230
|
+
skipIfUnchanged は、設定ファイルの内容が同じなら何も書かない
|
|
231
|
+
*/
|
|
232
|
+
export async function syncProjectConfig(out, client, target) {
|
|
233
|
+
const { owner, name, host, skipIfUnchanged = false } = target;
|
|
234
|
+
const project = await findProjectByTitle(out, client, owner, name);
|
|
235
|
+
const number = requireNumber(project['number'], 'project.number');
|
|
236
|
+
const { workflowField, fields, viewNumber } = await fetchValidatedFields(out, client, { owner, name, host, number, suffix: target.suffix });
|
|
237
|
+
const suffix = textOf(workflowField['name']).slice(WORKFLOW_FIELD_PREFIX.length);
|
|
238
|
+
const configPath = path.join(projectsDirectory(), `${host}_${owner}_${slugify(name)}_${suffix}.json`);
|
|
239
|
+
const existing = loadExistingConfig(configPath);
|
|
240
|
+
const linked = await client.getLinkedRepositories(owner, number);
|
|
241
|
+
const priorityField = lastFieldNamed(fields, 'pecot-priority');
|
|
242
|
+
const sizeField = lastFieldNamed(fields, 'pecot-size');
|
|
243
|
+
const statusField = lastFieldNamed(fields, STATUS_FIELD_NAME);
|
|
244
|
+
const config = {
|
|
245
|
+
host,
|
|
246
|
+
owner,
|
|
247
|
+
workflow_suffix: suffix,
|
|
248
|
+
project: {
|
|
249
|
+
number,
|
|
250
|
+
id: requireString(project['id'], 'project.id'),
|
|
251
|
+
board_url: buildBoardUrl(typeof project['url'] === 'string' ? project['url'] : '', workflowField, viewNumber),
|
|
252
|
+
fields: {
|
|
253
|
+
workflow: fieldOptionsConfig(workflowField, WORKFLOW_KEYS),
|
|
254
|
+
priority: priorityField === undefined ? undefined : fieldOptionsConfig(priorityField, PRIORITY_KEYS),
|
|
255
|
+
size: sizeField === undefined ? undefined : fieldOptionsConfig(sizeField, SIZE_KEYS),
|
|
256
|
+
status: statusField === undefined ? undefined : fieldOptionsConfig(statusField, STATUS_KEYS),
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
repositories: buildRepositories(linked, existing?.repositories ?? []),
|
|
260
|
+
aggregation_repo: existing?.aggregation_repo,
|
|
261
|
+
};
|
|
262
|
+
// 読み直して保存と同じ形にそろえてから比べる
|
|
263
|
+
const normalized = parseProjectConfig(parseJsonText(serializeProjectConfig(config)));
|
|
264
|
+
if (skipIfUnchanged && existing !== undefined && serializeProjectConfig(existing) === serializeProjectConfig(normalized))
|
|
265
|
+
return configPath;
|
|
266
|
+
const verb = existing === undefined ? 'create' : 'update';
|
|
267
|
+
saveConfig(config, configPath);
|
|
268
|
+
out.done({ verb, target: `config file ${configPath}` });
|
|
269
|
+
setActiveConfig(configPath);
|
|
270
|
+
out.done({ verb: 'set', target: `active project to ${path.parse(configPath).name}` });
|
|
271
|
+
return configPath;
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=project-sync.js.map
|