@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,107 @@
|
|
|
1
|
+
// CHANGELOG.md の検証ロジック。Keep a Changelog 形式とセマンティックバージョニングに準拠する。
|
|
2
|
+
// ファイルは読まない。内容(文字列)を受けて値を返す。ファイルを読む側は infra/changelog-file.ts にある。
|
|
3
|
+
// Python の re と同じ判定にする(\d は Unicode の 10 進数字、\s は str.isspace、$ は末尾の改行 1 つの前でも合う)。
|
|
4
|
+
import { PecotError, BaseError } from './errors.js';
|
|
5
|
+
import { pythonStrip, splitCodePoints } from './python-format.js';
|
|
6
|
+
export class ChangelogError extends PecotError {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
セマンティックバージョニング形式(X.Y.Z)に準拠していない
|
|
10
|
+
*/
|
|
11
|
+
export class InvalidVersionError extends ChangelogError {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
CHANGELOG.md にバージョン情報が存在しない
|
|
15
|
+
*/
|
|
16
|
+
export class VersionNotFoundError extends ChangelogError {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
CHANGELOG.md が存在しない。Python の FileNotFoundError に当たるので、PecotError ではない
|
|
20
|
+
*/
|
|
21
|
+
export class ChangelogFileNotFoundError extends BaseError {
|
|
22
|
+
}
|
|
23
|
+
export const DEFAULT_CHANGELOG_FILE = 'CHANGELOG.md';
|
|
24
|
+
export const CHANGELOG_FALLBACK_FILES = ['CHANGELOG.md', 'AIST-CHANGELOG.md'];
|
|
25
|
+
// X.Y.Z 形式。先頭に `v` は付けない
|
|
26
|
+
const SEMVER_PATTERN = /^\p{Nd}+\.\p{Nd}+\.\p{Nd}+\n?$/u;
|
|
27
|
+
// バージョン行の見出し記号と空白より後ろを見る。行の形は `## [X.Y.Z] - YYYY-MM-DD`。
|
|
28
|
+
const VERSION_PATTERN = /^\[(\p{Nd}+\.\p{Nd}+\.\p{Nd}+)\]/u;
|
|
29
|
+
// str.splitlines() の区切り。U+001C〜U+001E も含む。量指定子は無く、unsafe-regex は誤検知。
|
|
30
|
+
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex -- 区切りの制御文字と誤検知
|
|
31
|
+
const LINE_BREAK = /[\n\r\v\f\u{1C}-\u{1E}\u{85}\u{2028}\u{2029}]/u;
|
|
32
|
+
function splitLines(content) {
|
|
33
|
+
// 改行コードの \r\n は区切り 1 つと数えるため、先に \n へ揃える
|
|
34
|
+
const lines = content.replaceAll('\r\n', '\n').split(LINE_BREAK);
|
|
35
|
+
if (lines.at(-1) === '')
|
|
36
|
+
lines.pop();
|
|
37
|
+
return lines;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
`##` + 空白 1 つ以上で始まる行の、空白の後ろを返す。そうでなければ undefined。
|
|
41
|
+
空白は Python の `\s`(str.isspace)と同じ。pythonStrip で先頭の空白を落として確かめる
|
|
42
|
+
*/
|
|
43
|
+
function headingRest(line) {
|
|
44
|
+
if (!line.startsWith('##'))
|
|
45
|
+
return undefined;
|
|
46
|
+
const body = line.slice(2);
|
|
47
|
+
return body === '' || pythonStrip(splitCodePoints(body)[0] ?? '') !== '' ? undefined : pythonStrip(body);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
パス末尾のファイル名。エラー文に、実際に探したファイルの名前を出すために使う
|
|
51
|
+
*/
|
|
52
|
+
export function changelogFileName(changelogPath) {
|
|
53
|
+
return changelogPath.slice(changelogPath.lastIndexOf('/') + 1);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
CHANGELOG が無いときの文
|
|
57
|
+
*/
|
|
58
|
+
export function changelogNotFoundMessage(changelogPath) {
|
|
59
|
+
return `${changelogFileName(changelogPath)} not found: ${changelogPath}`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
セマンティックバージョニング形式を検証する。形式違反は InvalidVersionError
|
|
63
|
+
*/
|
|
64
|
+
export function validateSemver(version) {
|
|
65
|
+
if (!SEMVER_PATTERN.test(version)) {
|
|
66
|
+
throw new InvalidVersionError(`invalid version format: ${version}\n`
|
|
67
|
+
+ 'use semantic versioning (X.Y.Z)');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
## [X.Y.Z] 形式の最初のバージョンを返す。Unreleased は飛ばす。無ければ VersionNotFoundError。
|
|
72
|
+
fileName は、エラー文に出す CHANGELOG のファイル名
|
|
73
|
+
*/
|
|
74
|
+
export function getLatestVersion(content, fileName = DEFAULT_CHANGELOG_FILE) {
|
|
75
|
+
for (const line of splitLines(content)) {
|
|
76
|
+
const version = VERSION_PATTERN.exec(headingRest(line) ?? '')?.[1];
|
|
77
|
+
if (version !== undefined)
|
|
78
|
+
return version;
|
|
79
|
+
}
|
|
80
|
+
throw new VersionNotFoundError(`no version found in ${fileName}\n`
|
|
81
|
+
+ 'for a first release, specify the version manually');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
## [X.Y.Z] の次の行から次の `## ` セクションまでの内容を返す。無ければ VersionNotFoundError。
|
|
85
|
+
fileName は、エラー文に出す CHANGELOG のファイル名
|
|
86
|
+
*/
|
|
87
|
+
export function extractVersionReleaseNotes(content, version, fileName = DEFAULT_CHANGELOG_FILE) {
|
|
88
|
+
const heading = `[${version}]`;
|
|
89
|
+
let isInVersion = false;
|
|
90
|
+
const versionLines = [];
|
|
91
|
+
for (const line of splitLines(content)) {
|
|
92
|
+
if (headingRest(line)?.startsWith(heading) === true) {
|
|
93
|
+
isInVersion = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!isInVersion)
|
|
97
|
+
continue;
|
|
98
|
+
// 次の ## セクションが来たら終了
|
|
99
|
+
if (line.startsWith('## '))
|
|
100
|
+
break;
|
|
101
|
+
versionLines.push(line);
|
|
102
|
+
}
|
|
103
|
+
if (!isInVersion)
|
|
104
|
+
throw new VersionNotFoundError(`version not found in ${fileName}: ${version}`);
|
|
105
|
+
return pythonStrip(versionLines.join('\n'));
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=changelog.js.map
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PecotError } from './errors.js';
|
|
3
|
+
import type { JsonValue } from './python-format.js';
|
|
4
|
+
import type { RepositoryReference } from './repository-resolver.js';
|
|
5
|
+
declare const WorkflowStatusSchema: z.ZodEnum<{
|
|
6
|
+
active: "active";
|
|
7
|
+
archived: "archived";
|
|
8
|
+
backlog: "backlog";
|
|
9
|
+
blocked: "blocked";
|
|
10
|
+
in_review: "in_review";
|
|
11
|
+
pending: "pending";
|
|
12
|
+
ready: "ready";
|
|
13
|
+
}>;
|
|
14
|
+
export type WorkflowStatus = z.infer<typeof WorkflowStatusSchema>;
|
|
15
|
+
export declare const WORKFLOW_STATUSES: readonly WorkflowStatus[];
|
|
16
|
+
declare const PrioritySchema: z.ZodEnum<{
|
|
17
|
+
high: "high";
|
|
18
|
+
low: "low";
|
|
19
|
+
medium: "medium";
|
|
20
|
+
}>;
|
|
21
|
+
export type Priority = z.infer<typeof PrioritySchema>;
|
|
22
|
+
export declare const PRIORITIES: readonly Priority[];
|
|
23
|
+
declare const SizeSchema: z.ZodEnum<{
|
|
24
|
+
l: "l";
|
|
25
|
+
m: "m";
|
|
26
|
+
s: "s";
|
|
27
|
+
xs: "xs";
|
|
28
|
+
}>;
|
|
29
|
+
export type Size = z.infer<typeof SizeSchema>;
|
|
30
|
+
export declare const SIZES: readonly Size[];
|
|
31
|
+
export declare function convertToInteger(value: unknown): unknown;
|
|
32
|
+
declare const FieldOptionsSchema: z.ZodReadonly<z.ZodObject<{
|
|
33
|
+
id: z.ZodString;
|
|
34
|
+
options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
35
|
+
}, z.core.$strip>>;
|
|
36
|
+
declare const PackageSchema: z.ZodReadonly<z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
changelog: z.ZodString;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
declare const ReleaseTypeSchema: z.ZodEnum<{
|
|
41
|
+
multi: "multi";
|
|
42
|
+
nx: "nx";
|
|
43
|
+
single: "single";
|
|
44
|
+
}>;
|
|
45
|
+
export type ReleaseType = z.infer<typeof ReleaseTypeSchema>;
|
|
46
|
+
/**
|
|
47
|
+
release_type の取れる値(single・multi・nx)
|
|
48
|
+
*/
|
|
49
|
+
export declare const RELEASE_TYPES: readonly ReleaseType[];
|
|
50
|
+
declare const RepositorySchema: z.ZodReadonly<z.ZodObject<{
|
|
51
|
+
owner: z.ZodString;
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
develop_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
54
|
+
release_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
55
|
+
changelog_file: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
56
|
+
packages: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
57
|
+
name: z.ZodString;
|
|
58
|
+
changelog: z.ZodString;
|
|
59
|
+
}, z.core.$strip>>>>>>, z.ZodTransform<readonly Readonly<{
|
|
60
|
+
name: string;
|
|
61
|
+
changelog: string;
|
|
62
|
+
}>[] | undefined, readonly Readonly<{
|
|
63
|
+
name: string;
|
|
64
|
+
changelog: string;
|
|
65
|
+
}>[] | null | undefined>>;
|
|
66
|
+
release_type: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
67
|
+
multi: "multi";
|
|
68
|
+
nx: "nx";
|
|
69
|
+
single: "single";
|
|
70
|
+
}>>>, z.ZodTransform<"multi" | "nx" | "single" | undefined, "multi" | "nx" | "single" | null | undefined>>;
|
|
71
|
+
}, z.core.$strip>>;
|
|
72
|
+
declare const ProjectConfigSchema: z.ZodReadonly<z.ZodObject<{
|
|
73
|
+
host: z.ZodString;
|
|
74
|
+
owner: z.ZodString;
|
|
75
|
+
workflow_suffix: z.ZodString;
|
|
76
|
+
project: z.ZodReadonly<z.ZodObject<{
|
|
77
|
+
number: z.ZodPreprocess<z.ZodInt, unknown>;
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
board_url: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
80
|
+
fields: z.ZodReadonly<z.ZodObject<{
|
|
81
|
+
workflow: z.ZodReadonly<z.ZodObject<{
|
|
82
|
+
id: z.ZodString;
|
|
83
|
+
options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
84
|
+
}, z.core.$strip>>;
|
|
85
|
+
priority: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
86
|
+
id: z.ZodString;
|
|
87
|
+
options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
88
|
+
}, z.core.$strip>>>>, z.ZodTransform<Readonly<{
|
|
89
|
+
id: string;
|
|
90
|
+
options: Readonly<Record<string, string>>;
|
|
91
|
+
}> | undefined, Readonly<{
|
|
92
|
+
id: string;
|
|
93
|
+
options: Readonly<Record<string, string>>;
|
|
94
|
+
}> | null | undefined>>;
|
|
95
|
+
size: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
96
|
+
id: z.ZodString;
|
|
97
|
+
options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
98
|
+
}, z.core.$strip>>>>, z.ZodTransform<Readonly<{
|
|
99
|
+
id: string;
|
|
100
|
+
options: Readonly<Record<string, string>>;
|
|
101
|
+
}> | undefined, Readonly<{
|
|
102
|
+
id: string;
|
|
103
|
+
options: Readonly<Record<string, string>>;
|
|
104
|
+
}> | null | undefined>>;
|
|
105
|
+
status: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
|
|
106
|
+
id: z.ZodString;
|
|
107
|
+
options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
108
|
+
}, z.core.$strip>>>>, z.ZodTransform<Readonly<{
|
|
109
|
+
id: string;
|
|
110
|
+
options: Readonly<Record<string, string>>;
|
|
111
|
+
}> | undefined, Readonly<{
|
|
112
|
+
id: string;
|
|
113
|
+
options: Readonly<Record<string, string>>;
|
|
114
|
+
}> | null | undefined>>;
|
|
115
|
+
}, z.core.$strip>>;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
repositories: z.ZodDefault<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
118
|
+
owner: z.ZodString;
|
|
119
|
+
name: z.ZodString;
|
|
120
|
+
develop_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
121
|
+
release_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
122
|
+
changelog_file: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
123
|
+
packages: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
|
|
124
|
+
name: z.ZodString;
|
|
125
|
+
changelog: z.ZodString;
|
|
126
|
+
}, z.core.$strip>>>>>>, z.ZodTransform<readonly Readonly<{
|
|
127
|
+
name: string;
|
|
128
|
+
changelog: string;
|
|
129
|
+
}>[] | undefined, readonly Readonly<{
|
|
130
|
+
name: string;
|
|
131
|
+
changelog: string;
|
|
132
|
+
}>[] | null | undefined>>;
|
|
133
|
+
release_type: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
134
|
+
multi: "multi";
|
|
135
|
+
nx: "nx";
|
|
136
|
+
single: "single";
|
|
137
|
+
}>>>, z.ZodTransform<"multi" | "nx" | "single" | undefined, "multi" | "nx" | "single" | null | undefined>>;
|
|
138
|
+
}, z.core.$strip>>>>>;
|
|
139
|
+
aggregation_repo: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
|
|
140
|
+
}, z.core.$strip>>;
|
|
141
|
+
export type FieldOptions = z.infer<typeof FieldOptionsSchema>;
|
|
142
|
+
export type Package = z.infer<typeof PackageSchema>;
|
|
143
|
+
export type Repository = z.infer<typeof RepositorySchema>;
|
|
144
|
+
export type ProjectConfig = z.infer<typeof ProjectConfigSchema>;
|
|
145
|
+
/**
|
|
146
|
+
プロジェクトにリンクされたリポジトリ。判定の問い合わせ先(GitHub)の実体は infra が持つ
|
|
147
|
+
*/
|
|
148
|
+
export interface LinkedRepository {
|
|
149
|
+
readonly owner: string;
|
|
150
|
+
readonly name: string;
|
|
151
|
+
}
|
|
152
|
+
export interface RepositoryMembership {
|
|
153
|
+
readonly linkedRepositories: (owner: string, projectNumber: number) => Promise<readonly LinkedRepository[]>;
|
|
154
|
+
}
|
|
155
|
+
export declare class ConfigError extends PecotError {
|
|
156
|
+
}
|
|
157
|
+
export declare class MultipleConfigsError extends ConfigError {
|
|
158
|
+
readonly files: readonly string[];
|
|
159
|
+
constructor(files: readonly string[]);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
JSON の値からプロジェクト設定を作る。形が不正なら ValidationFailure(表題は ProjectConfig)
|
|
163
|
+
*/
|
|
164
|
+
export declare function parseProjectConfig(data: JsonValue): ProjectConfig;
|
|
165
|
+
/**
|
|
166
|
+
パッケージ 1 件を作る。NAME の形が不正なら ValidationFailure(表題は Package)。保存より前の検証で使う
|
|
167
|
+
*/
|
|
168
|
+
export declare function parsePackage(data: JsonValue): Package;
|
|
169
|
+
/**
|
|
170
|
+
設定ファイルの中身。2 スペースのインデントで、末尾に改行を置く。
|
|
171
|
+
値の無い項目は出さず、非 ASCII の文字はそのまま出す。
|
|
172
|
+
キーの順はモデルの定義順
|
|
173
|
+
*/
|
|
174
|
+
export declare function serializeProjectConfig(config: ProjectConfig): string;
|
|
175
|
+
export declare function workflowFieldName(config: ProjectConfig): string;
|
|
176
|
+
export declare function getFieldId(config: ProjectConfig, fieldName: string): string | undefined;
|
|
177
|
+
export declare function getOptionId(config: ProjectConfig, fieldName: string, optionName: string): string | undefined;
|
|
178
|
+
export declare function findRepository(config: ProjectConfig, owner: string, name: string): Repository | undefined;
|
|
179
|
+
/**
|
|
180
|
+
owner を指定せずに名前だけで探す(アクティブ設定内の検索用)
|
|
181
|
+
*/
|
|
182
|
+
export declare function findRepositoryByName(config: ProjectConfig, name: string): Repository | undefined;
|
|
183
|
+
/**
|
|
184
|
+
設定の repositories の 1 件の `owner/name`
|
|
185
|
+
*/
|
|
186
|
+
export declare function configuredRepositoryFullName(repository: Repository): string;
|
|
187
|
+
export declare function findPackage(repository: Repository, name: string): Package | undefined;
|
|
188
|
+
/**
|
|
189
|
+
release_type が未指定なら、packages の有無から決める(あれば multi、無ければ single)
|
|
190
|
+
*/
|
|
191
|
+
export declare function effectiveReleaseType(repository: Repository): ReleaseType;
|
|
192
|
+
export declare function getDevelopBranch(config: ProjectConfig, owner: string, name: string): string | undefined;
|
|
193
|
+
export declare function getReleaseBranch(config: ProjectConfig, owner: string, name: string): string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
aggregation_repo を RepositoryReference にする(未設定なら undefined)
|
|
196
|
+
*/
|
|
197
|
+
export declare function aggregationRepositoryReference(config: ProjectConfig): RepositoryReference | undefined;
|
|
198
|
+
/**
|
|
199
|
+
リポジトリがプロジェクトにリンクされているか。リンクの一覧は membership に問い合わせる
|
|
200
|
+
*/
|
|
201
|
+
export declare function isRepositoryInProject(config: ProjectConfig, owner: string, name: string, membership: RepositoryMembership): Promise<boolean>;
|
|
202
|
+
/**
|
|
203
|
+
aggregation_repo を差し替えたコピー。undefined なら外す。値の形式は検証しない(呼び出し側が先に検証する)
|
|
204
|
+
*/
|
|
205
|
+
export declare function withAggregationRepository(config: ProjectConfig, value: string | undefined): ProjectConfig;
|
|
206
|
+
/**
|
|
207
|
+
リポジトリを末尾に足したコピー
|
|
208
|
+
*/
|
|
209
|
+
export declare function withRepositoryAppended(config: ProjectConfig, repository: Repository): ProjectConfig;
|
|
210
|
+
/**
|
|
211
|
+
同じ owner と name のリポジトリのうち、最初の 1 件を差し替えたコピー(find_repository と同じ)。無ければ元のまま
|
|
212
|
+
*/
|
|
213
|
+
export declare function withRepositoryReplaced(config: ProjectConfig, repository: Repository): ProjectConfig;
|
|
214
|
+
export {};
|
|
215
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// プロジェクト設定(.pecot/config/projects/*.json)のモデルと判定。ファイルの読み書きは infra/config-store.ts が行う。
|
|
2
|
+
//
|
|
3
|
+
// モデルは zod の schema で表す。読んだ値は読み取り専用(凍結)で、更新はコピーを作る。
|
|
4
|
+
// 検証エラーは、Python の CLI が出していた書式(表題は元のクラス名)の ValidationFailure にして投げる。
|
|
5
|
+
// 値が無いこと(null・未指定)は、読んだ後はどちらも undefined になり、保存では出さない。
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { PecotError } from './errors.js';
|
|
8
|
+
import { isJsonObject, jsonField } from './json.js';
|
|
9
|
+
import { isJsonArray, pythonRepr, pythonStrip, pythonStringRepr, ValidationFailure } from './python-format.js';
|
|
10
|
+
import { parseOwnerRepository } from './repository-resolver.js';
|
|
11
|
+
const WorkflowStatusSchema = z.enum(['backlog', 'pending', 'blocked', 'ready', 'active', 'in_review', 'archived']);
|
|
12
|
+
export const WORKFLOW_STATUSES = WorkflowStatusSchema.options;
|
|
13
|
+
const PrioritySchema = z.enum(['high', 'medium', 'low']);
|
|
14
|
+
export const PRIORITIES = PrioritySchema.options;
|
|
15
|
+
const SizeSchema = z.enum(['xs', 's', 'm', 'l']);
|
|
16
|
+
export const SIZES = SizeSchema.options;
|
|
17
|
+
const NAME_PATTERN = /^[\w.-]+$/u;
|
|
18
|
+
// zod が issue に入れる pattern(`/source/flags`)→ Python の文に出す正規表現の文字列
|
|
19
|
+
const PYTHON_PATTERN_TEXTS = new Map([[String(NAME_PATTERN), '^[A-Za-z0-9_.-]+$']]);
|
|
20
|
+
const AGGREGATION_REPOSITORY_PATTERN = /^[\w.-]+\/[\w.-]+$/u;
|
|
21
|
+
/**
|
|
22
|
+
オブジェクトの schema。型が違うときの issue の message に、元のクラス名を入れる
|
|
23
|
+
*/
|
|
24
|
+
function model(name, shape) {
|
|
25
|
+
return z.object(shape, { error: () => name });
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
`X | None = None` に当たる文字列。null と未指定は、どちらも undefined にする
|
|
29
|
+
*/
|
|
30
|
+
const optionalString = z.string().nullish().transform(value => value ?? undefined);
|
|
31
|
+
// int の lax な変換。bool は 0・1、前後の空白・符号・数字の間の `_`・小数部が 0 だけの文字列は整数にする。
|
|
32
|
+
// 変換できない値はそのまま渡し、z.int() が型の誤りにする。
|
|
33
|
+
export function convertToInteger(value) {
|
|
34
|
+
if (typeof value === 'boolean')
|
|
35
|
+
return value ? 1 : 0;
|
|
36
|
+
if (typeof value !== 'string')
|
|
37
|
+
return value;
|
|
38
|
+
const text = pythonStrip(value);
|
|
39
|
+
const isUnderscoreSeparatedDigits = text.replace(/^[+-]/u, '').split('_').every(group => /^\d+$/u.test(group));
|
|
40
|
+
if (isUnderscoreSeparatedDigits)
|
|
41
|
+
return Number(text.replaceAll('_', ''));
|
|
42
|
+
if (/^[+-]?\d+\.0+$/u.test(text))
|
|
43
|
+
return Number(text.slice(0, text.indexOf('.'))) + 0; // -0 を 0 にする
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
const laxInteger = z.preprocess(convertToInteger, z.int());
|
|
47
|
+
const FieldOptionsSchema = model('FieldOptions', {
|
|
48
|
+
id: z.string(),
|
|
49
|
+
options: z.record(z.string(), z.string()).readonly(),
|
|
50
|
+
}).readonly();
|
|
51
|
+
const ProjectFieldsSchema = model('ProjectFields', {
|
|
52
|
+
workflow: FieldOptionsSchema,
|
|
53
|
+
priority: FieldOptionsSchema.nullish().transform(value => value ?? undefined),
|
|
54
|
+
size: FieldOptionsSchema.nullish().transform(value => value ?? undefined),
|
|
55
|
+
status: FieldOptionsSchema.nullish().transform(value => value ?? undefined),
|
|
56
|
+
}).readonly();
|
|
57
|
+
const ProjectSchema = model('Project', {
|
|
58
|
+
number: laxInteger,
|
|
59
|
+
id: z.string(),
|
|
60
|
+
board_url: optionalString,
|
|
61
|
+
fields: ProjectFieldsSchema,
|
|
62
|
+
}).readonly();
|
|
63
|
+
const PackageSchema = model('Package', {
|
|
64
|
+
name: z.string().min(1, { abort: true }).regex(NAME_PATTERN),
|
|
65
|
+
changelog: z.string().min(1),
|
|
66
|
+
}).readonly();
|
|
67
|
+
const ReleaseTypeSchema = z.enum(['single', 'multi', 'nx']);
|
|
68
|
+
/**
|
|
69
|
+
release_type の取れる値(single・multi・nx)
|
|
70
|
+
*/
|
|
71
|
+
export const RELEASE_TYPES = ReleaseTypeSchema.options;
|
|
72
|
+
const RepositorySchema = model('Repository', {
|
|
73
|
+
owner: z.string(),
|
|
74
|
+
name: z.string(),
|
|
75
|
+
develop_branch: optionalString,
|
|
76
|
+
release_branch: optionalString,
|
|
77
|
+
changelog_file: optionalString,
|
|
78
|
+
packages: z.array(PackageSchema).readonly().nullish().transform(value => value ?? undefined),
|
|
79
|
+
release_type: ReleaseTypeSchema.nullish().transform(value => value ?? undefined),
|
|
80
|
+
}).superRefine((repository, context) => {
|
|
81
|
+
// monorepo 構成(packages あり)では CHANGELOG は package ごとに管理するので、リポ全体の changelog_file は意味を持たない
|
|
82
|
+
const hasPackages = repository.packages !== undefined && repository.packages.length > 0;
|
|
83
|
+
if (hasPackages && repository.changelog_file !== undefined && repository.changelog_file !== '') {
|
|
84
|
+
context.addIssue({
|
|
85
|
+
code: 'custom',
|
|
86
|
+
message: 'Value error, changelog_file and packages cannot be set together; in a monorepo, use packages[].changelog instead',
|
|
87
|
+
params: { type: 'value_error' },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}).readonly();
|
|
91
|
+
const ProjectConfigSchema = model('ProjectConfig', {
|
|
92
|
+
host: z.string(),
|
|
93
|
+
owner: z.string(),
|
|
94
|
+
workflow_suffix: z.string(),
|
|
95
|
+
project: ProjectSchema,
|
|
96
|
+
repositories: z.array(RepositorySchema).readonly().default([]),
|
|
97
|
+
aggregation_repo: z.string().superRefine((value, context) => {
|
|
98
|
+
if (!AGGREGATION_REPOSITORY_PATTERN.test(value)) {
|
|
99
|
+
context.addIssue({
|
|
100
|
+
code: 'custom',
|
|
101
|
+
message: `Value error, aggregation_repo must be in 'owner/repo' form: ${pythonStringRepr(value)}`,
|
|
102
|
+
params: { type: 'value_error' },
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}).nullish().transform(value => value ?? undefined),
|
|
106
|
+
}).readonly();
|
|
107
|
+
export class ConfigError extends PecotError {
|
|
108
|
+
}
|
|
109
|
+
export class MultipleConfigsError extends ConfigError {
|
|
110
|
+
files;
|
|
111
|
+
constructor(files) {
|
|
112
|
+
const names = files.map(file => file.slice(file.lastIndexOf('/') + 1));
|
|
113
|
+
super(`multiple config files found: ${pythonRepr(names)}`);
|
|
114
|
+
this.files = files;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// 検証エラーの変換
|
|
118
|
+
function valueAt(root, location) {
|
|
119
|
+
let current = root;
|
|
120
|
+
for (const key of location) {
|
|
121
|
+
if (isJsonArray(current))
|
|
122
|
+
current = current[Number(key)];
|
|
123
|
+
else if (isJsonObject(current))
|
|
124
|
+
current = jsonField(current, String(key));
|
|
125
|
+
else
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
return current;
|
|
129
|
+
}
|
|
130
|
+
function quotedChoices(values) {
|
|
131
|
+
const quoted = values.map(value => pythonStringRepr(String(value)));
|
|
132
|
+
const last = quoted.at(-1);
|
|
133
|
+
return last === undefined || quoted.length <= 1 ? quoted.join('') : `${quoted.slice(0, -1).join(', ')} or ${last}`;
|
|
134
|
+
}
|
|
135
|
+
function integerIssue(input) {
|
|
136
|
+
if (typeof input === 'string')
|
|
137
|
+
return { type: 'int_parsing', message: 'Input should be a valid integer, unable to parse string as an integer' };
|
|
138
|
+
if (typeof input !== 'number')
|
|
139
|
+
return { type: 'int_type', message: 'Input should be a valid integer' };
|
|
140
|
+
if (!Number.isFinite(input))
|
|
141
|
+
return { type: 'finite_number', message: 'Input should be a finite number' };
|
|
142
|
+
return { type: 'int_from_float', message: 'Input should be a valid integer, got a number with a fractional part' };
|
|
143
|
+
}
|
|
144
|
+
function invalidTypeIssue(expected, modelName, location, input) {
|
|
145
|
+
if (input === undefined)
|
|
146
|
+
return { type: 'missing', location, message: 'Field required', input: undefined };
|
|
147
|
+
if (expected === 'string')
|
|
148
|
+
return { type: 'string_type', location, message: 'Input should be a valid string', input };
|
|
149
|
+
if (expected === 'int' || expected === 'number')
|
|
150
|
+
return { ...integerIssue(input), location, input };
|
|
151
|
+
if (expected === 'array')
|
|
152
|
+
return { type: 'list_type', location, message: 'Input should be a valid list', input };
|
|
153
|
+
if (expected === 'record')
|
|
154
|
+
return { type: 'dict_type', location, message: 'Input should be a valid dictionary', input };
|
|
155
|
+
return { type: 'model_type', location, message: `Input should be a valid dictionary or instance of ${modelName}`, input };
|
|
156
|
+
}
|
|
157
|
+
function toValidationIssue(issue, root) {
|
|
158
|
+
const location = issue.path.map(key => typeof key === 'symbol' ? String(key) : key);
|
|
159
|
+
const input = valueAt(root, location);
|
|
160
|
+
if (issue.code === 'invalid_type') {
|
|
161
|
+
// 値が無いときの input は、その項目を持つはずの親(Python の入力辞書)
|
|
162
|
+
const base = invalidTypeIssue(issue.expected, issue.message, location, input);
|
|
163
|
+
return base.type === 'missing' ? { ...base, input: valueAt(root, location.slice(0, -1)) } : base;
|
|
164
|
+
}
|
|
165
|
+
if (issue.code === 'invalid_value')
|
|
166
|
+
return { type: 'literal_error', location, message: `Input should be ${quotedChoices(issue.values ?? [])}`, input };
|
|
167
|
+
if (issue.code === 'too_small') {
|
|
168
|
+
const minimum = Number(issue.minimum);
|
|
169
|
+
return { type: 'string_too_short', location, message: `String should have at least ${String(minimum)} character${minimum === 1 ? '' : 's'}`, input };
|
|
170
|
+
}
|
|
171
|
+
if (issue.code === 'invalid_format') {
|
|
172
|
+
// Python の文には、Python 側の正規表現の書き方(lint が書き換える前の形)がそのまま入る
|
|
173
|
+
const pattern = PYTHON_PATTERN_TEXTS.get(String(issue.pattern)) ?? String(issue.pattern);
|
|
174
|
+
return { type: 'string_pattern_mismatch', location, message: `String should match pattern ${pythonStringRepr(pattern)}`, input };
|
|
175
|
+
}
|
|
176
|
+
return { type: 'value_error', location, message: issue.message, input };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
JSON の値からプロジェクト設定を作る。形が不正なら ValidationFailure(表題は ProjectConfig)
|
|
180
|
+
*/
|
|
181
|
+
export function parseProjectConfig(data) {
|
|
182
|
+
const result = ProjectConfigSchema.safeParse(data);
|
|
183
|
+
if (!result.success)
|
|
184
|
+
throw new ValidationFailure('ProjectConfig', result.error.issues.map(issue => toValidationIssue(issue, data)));
|
|
185
|
+
return result.data;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
パッケージ 1 件を作る。NAME の形が不正なら ValidationFailure(表題は Package)。保存より前の検証で使う
|
|
189
|
+
*/
|
|
190
|
+
export function parsePackage(data) {
|
|
191
|
+
const result = PackageSchema.safeParse(data);
|
|
192
|
+
if (!result.success)
|
|
193
|
+
throw new ValidationFailure('Package', result.error.issues.map(issue => toValidationIssue(issue, data)));
|
|
194
|
+
return result.data;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
設定ファイルの中身。2 スペースのインデントで、末尾に改行を置く。
|
|
198
|
+
値の無い項目は出さず、非 ASCII の文字はそのまま出す。
|
|
199
|
+
キーの順はモデルの定義順
|
|
200
|
+
*/
|
|
201
|
+
export function serializeProjectConfig(config) {
|
|
202
|
+
return `${JSON.stringify(config, undefined, 2)}\n`;
|
|
203
|
+
}
|
|
204
|
+
// 検索
|
|
205
|
+
export function workflowFieldName(config) {
|
|
206
|
+
return `pecot-workflow-${config.workflow_suffix}`;
|
|
207
|
+
}
|
|
208
|
+
function fieldOf(config, fieldName) {
|
|
209
|
+
switch (fieldName) {
|
|
210
|
+
case 'workflow': {
|
|
211
|
+
return config.project.fields.workflow;
|
|
212
|
+
}
|
|
213
|
+
case 'priority': {
|
|
214
|
+
return config.project.fields.priority;
|
|
215
|
+
}
|
|
216
|
+
case 'size': {
|
|
217
|
+
return config.project.fields.size;
|
|
218
|
+
}
|
|
219
|
+
case 'status': {
|
|
220
|
+
return config.project.fields.status;
|
|
221
|
+
}
|
|
222
|
+
default: {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export function getFieldId(config, fieldName) {
|
|
228
|
+
return fieldOf(config, fieldName)?.id;
|
|
229
|
+
}
|
|
230
|
+
export function getOptionId(config, fieldName, optionName) {
|
|
231
|
+
const options = fieldOf(config, fieldName)?.options;
|
|
232
|
+
return options === undefined ? undefined : new Map(Object.entries(options)).get(optionName);
|
|
233
|
+
}
|
|
234
|
+
export function findRepository(config, owner, name) {
|
|
235
|
+
return config.repositories.find(repository => repository.owner === owner && repository.name === name);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
owner を指定せずに名前だけで探す(アクティブ設定内の検索用)
|
|
239
|
+
*/
|
|
240
|
+
export function findRepositoryByName(config, name) {
|
|
241
|
+
return config.repositories.find(repository => repository.name === name);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
設定の repositories の 1 件の `owner/name`
|
|
245
|
+
*/
|
|
246
|
+
export function configuredRepositoryFullName(repository) {
|
|
247
|
+
return `${repository.owner}/${repository.name}`;
|
|
248
|
+
}
|
|
249
|
+
export function findPackage(repository, name) {
|
|
250
|
+
return repository.packages?.find(item => item.name === name);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
release_type が未指定なら、packages の有無から決める(あれば multi、無ければ single)
|
|
254
|
+
*/
|
|
255
|
+
export function effectiveReleaseType(repository) {
|
|
256
|
+
if (repository.release_type !== undefined)
|
|
257
|
+
return repository.release_type;
|
|
258
|
+
return repository.packages !== undefined && repository.packages.length > 0 ? 'multi' : 'single';
|
|
259
|
+
}
|
|
260
|
+
export function getDevelopBranch(config, owner, name) {
|
|
261
|
+
return findRepository(config, owner, name)?.develop_branch;
|
|
262
|
+
}
|
|
263
|
+
export function getReleaseBranch(config, owner, name) {
|
|
264
|
+
return findRepository(config, owner, name)?.release_branch;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
aggregation_repo を RepositoryReference にする(未設定なら undefined)
|
|
268
|
+
*/
|
|
269
|
+
export function aggregationRepositoryReference(config) {
|
|
270
|
+
return config.aggregation_repo === undefined || config.aggregation_repo === '' ? undefined : parseOwnerRepository(config.aggregation_repo);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
リポジトリがプロジェクトにリンクされているか。リンクの一覧は membership に問い合わせる
|
|
274
|
+
*/
|
|
275
|
+
export async function isRepositoryInProject(config, owner, name, membership) {
|
|
276
|
+
const linked = await membership.linkedRepositories(config.owner, config.project.number);
|
|
277
|
+
return linked.some(repository => repository.owner === owner && repository.name === name);
|
|
278
|
+
}
|
|
279
|
+
// 更新(コピーを作る)
|
|
280
|
+
/**
|
|
281
|
+
aggregation_repo を差し替えたコピー。undefined なら外す。値の形式は検証しない(呼び出し側が先に検証する)
|
|
282
|
+
*/
|
|
283
|
+
export function withAggregationRepository(config, value) {
|
|
284
|
+
return Object.freeze({ ...config, aggregation_repo: value });
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
リポジトリを末尾に足したコピー
|
|
288
|
+
*/
|
|
289
|
+
export function withRepositoryAppended(config, repository) {
|
|
290
|
+
return Object.freeze({ ...config, repositories: Object.freeze([...config.repositories, repository]) });
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
同じ owner と name のリポジトリのうち、最初の 1 件を差し替えたコピー(find_repository と同じ)。無ければ元のまま
|
|
294
|
+
*/
|
|
295
|
+
export function withRepositoryReplaced(config, repository) {
|
|
296
|
+
const index = config.repositories.findIndex(item => item.owner === repository.owner && item.name === repository.name);
|
|
297
|
+
const replaced = config.repositories.map((item, position) => position === index ? repository : item);
|
|
298
|
+
return Object.freeze({ ...config, repositories: Object.freeze(replaced) });
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=config.js.map
|