@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,264 @@
|
|
|
1
|
+
// YAML フロントマター付き Markdown のパーサー。文字列を受けて、検証済みのフロントマターと本文を返す。
|
|
2
|
+
// ファイルを読む関数は infra/frontmatter-file.ts が持つ。
|
|
3
|
+
//
|
|
4
|
+
// 検証のエラー文は、Python の CLI が出していた書式(` - 項目: 本文`)に合わせる。
|
|
5
|
+
// 型の変換("2" → 2、"yes" → true、空文字列 → 未指定)も Python の CLI と同じ。
|
|
6
|
+
// 値が無いこと(null・未指定・空文字列)は、読んだ後はどれも undefined になる。
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { convertToInteger, PRIORITIES, SIZES, WORKFLOW_STATUSES } from './config.js';
|
|
9
|
+
import { PecotError } from './errors.js';
|
|
10
|
+
import { normalizeNewlines, parsePythonInteger, pythonStrip, pythonStringRepr } from './python-format.js';
|
|
11
|
+
import { parseYamlDocument } from './yaml-document.js';
|
|
12
|
+
export class FrontmatterError extends PecotError {
|
|
13
|
+
}
|
|
14
|
+
// 検証のエラー文
|
|
15
|
+
const REQUIRED_MESSAGE = 'Field required';
|
|
16
|
+
const STRING_MESSAGE = 'Input should be a valid string';
|
|
17
|
+
const LIST_MESSAGE = 'Input should be a valid list';
|
|
18
|
+
const PARALLEL_MESSAGE = 'String should match pattern \'^[a-z]$\'';
|
|
19
|
+
function quotedChoices(values) {
|
|
20
|
+
const quoted = values.map(value => pythonStringRepr(String(value)));
|
|
21
|
+
const last = quoted.at(-1);
|
|
22
|
+
return last === undefined || quoted.length <= 1 ? quoted.join('') : `${quoted.slice(0, -1).join(', ')} or ${last}`;
|
|
23
|
+
}
|
|
24
|
+
function choiceMessage(issue) {
|
|
25
|
+
return issue.input === undefined ? REQUIRED_MESSAGE : `Input should be ${quotedChoices(issue.values ?? [])}`;
|
|
26
|
+
}
|
|
27
|
+
function stringMessage(issue) {
|
|
28
|
+
return issue.input === undefined ? REQUIRED_MESSAGE : STRING_MESSAGE;
|
|
29
|
+
}
|
|
30
|
+
function listMessage(issue) {
|
|
31
|
+
return issue.input === undefined ? REQUIRED_MESSAGE : LIST_MESSAGE;
|
|
32
|
+
}
|
|
33
|
+
function integerMessage(input) {
|
|
34
|
+
if (typeof input === 'string')
|
|
35
|
+
return 'Input should be a valid integer, unable to parse string as an integer';
|
|
36
|
+
if (typeof input !== 'number')
|
|
37
|
+
return 'Input should be a valid integer';
|
|
38
|
+
if (!Number.isFinite(input))
|
|
39
|
+
return 'Input should be a finite number';
|
|
40
|
+
return 'Input should be a valid integer, got a number with a fractional part';
|
|
41
|
+
}
|
|
42
|
+
// 2 の 63 乗。これ以上の数は、真偽値の変換で整数として扱われない
|
|
43
|
+
const INTEGER_LIMIT = 2 ** 63;
|
|
44
|
+
function booleanMessage(input) {
|
|
45
|
+
const isParsable = typeof input === 'string' || (typeof input === 'number' && Number.isSafeInteger(input) && Math.abs(input) < INTEGER_LIMIT);
|
|
46
|
+
return isParsable ? 'Input should be a valid boolean, unable to interpret input' : 'Input should be a valid boolean';
|
|
47
|
+
}
|
|
48
|
+
// 型の変換
|
|
49
|
+
function emptyStringToUndefined(value) {
|
|
50
|
+
return value === '' ? undefined : value;
|
|
51
|
+
}
|
|
52
|
+
const TRUE_STRINGS = new Set(['1', 'on', 't', 'true', 'y', 'yes']);
|
|
53
|
+
const FALSE_STRINGS = new Set(['0', 'off', 'f', 'false', 'n', 'no']);
|
|
54
|
+
// bool の lax な変換。文字列は大文字小文字を区別せず(前後の空白は落とさない)、数は 0 と 1 だけを受ける
|
|
55
|
+
function convertToBoolean(value) {
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
const lowered = value.toLowerCase();
|
|
58
|
+
if (TRUE_STRINGS.has(lowered))
|
|
59
|
+
return true;
|
|
60
|
+
if (FALSE_STRINGS.has(lowered))
|
|
61
|
+
return false;
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
if (value === 1)
|
|
65
|
+
return true;
|
|
66
|
+
if (value === 0)
|
|
67
|
+
return false;
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
// 文字列なら前後の空白を落とし、空なら未指定にする(Python の OptionalText)。文字列以外はそのまま
|
|
71
|
+
function normalizeOptionalText(value) {
|
|
72
|
+
return typeof value === 'string' ? emptyStringToUndefined(pythonStrip(value)) : value;
|
|
73
|
+
}
|
|
74
|
+
// parent_epic の入力の正規化。未指定・空文字 → 未指定、数字だけの文字列 → 整数、それ以外の文字列 → 前後の空白を落とした文字列
|
|
75
|
+
function normalizeParentEpic(value) {
|
|
76
|
+
if (value === null || emptyStringToUndefined(value) === undefined)
|
|
77
|
+
return undefined;
|
|
78
|
+
if (typeof value === 'boolean')
|
|
79
|
+
return value ? 1 : 0;
|
|
80
|
+
if (typeof value !== 'string')
|
|
81
|
+
return value;
|
|
82
|
+
const stripped = pythonStrip(value);
|
|
83
|
+
return /^\p{Nd}+$/u.test(stripped) ? parsePythonInteger(stripped) : stripped;
|
|
84
|
+
}
|
|
85
|
+
// スキーマ
|
|
86
|
+
const IntegerSchema = z.number({ error: issue => integerMessage(issue.input) }).refine(Number.isSafeInteger, { error: issue => integerMessage(issue.input) });
|
|
87
|
+
const IssueTypeSchema = z.enum(['task', 'bug', 'epic', 'tracker'], { error: choiceMessage });
|
|
88
|
+
const WorkflowStatusSchema = z.enum(WORKFLOW_STATUSES, { error: choiceMessage });
|
|
89
|
+
const IssueFrontmatterSchema = z.object({
|
|
90
|
+
title: z.string({ error: stringMessage }),
|
|
91
|
+
type: IssueTypeSchema,
|
|
92
|
+
template: z.preprocess(emptyStringToUndefined, z.enum(['task', 'bug', 'epic', 'tracker', 'task-implement'], { error: choiceMessage }).nullish().transform(value => value ?? undefined)),
|
|
93
|
+
repository: z.string({ error: stringMessage }),
|
|
94
|
+
status: WorkflowStatusSchema,
|
|
95
|
+
priority: z.preprocess(emptyStringToUndefined, z.enum(PRIORITIES, { error: choiceMessage }).nullish().transform(value => value ?? undefined)),
|
|
96
|
+
size: z.preprocess(emptyStringToUndefined, z.enum(SIZES, { error: choiceMessage }).nullish().transform(value => value ?? undefined)),
|
|
97
|
+
labels: z.array(z.string({ error: STRING_MESSAGE }), { error: listMessage }).readonly().prefault([]),
|
|
98
|
+
parent_epic: z.preprocess(normalizeParentEpic, z.unknown().transform((value, context) => {
|
|
99
|
+
// 「整数 | 文字列」のどちらでもない値は、枝ごとの誤り(`parent_epic.int`・`parent_epic.str`)を 2 行で返す
|
|
100
|
+
if (value === undefined || typeof value === 'string' || (typeof value === 'number' && Number.isSafeInteger(value)))
|
|
101
|
+
return value;
|
|
102
|
+
context.issues.push({ code: 'custom', message: integerMessage(value), input: value, path: ['int'] }, { code: 'custom', message: STRING_MESSAGE, input: value, path: ['str'] });
|
|
103
|
+
return z.NEVER;
|
|
104
|
+
})),
|
|
105
|
+
order: z.preprocess(value => convertToInteger(emptyStringToUndefined(value)), IntegerSchema.nullish().transform(value => value ?? undefined)),
|
|
106
|
+
parallel: z.preprocess(emptyStringToUndefined, z.string({ error: STRING_MESSAGE }).regex(/^[a-z]$/u, { error: PARALLEL_MESSAGE }).nullish().transform(value => value ?? undefined)),
|
|
107
|
+
}).readonly();
|
|
108
|
+
const CommentFrontmatterSchema = z.object({
|
|
109
|
+
issue_ref: z.string({ error: stringMessage }),
|
|
110
|
+
template: z.enum(['plan', 'merge-diff', 'review-findings', 'review-resolution', 'precede-notify'], { error: choiceMessage }).nullish().transform(value => value ?? undefined),
|
|
111
|
+
comment_url: z.string({ error: STRING_MESSAGE }).nullish().transform(value => value ?? undefined),
|
|
112
|
+
}).readonly();
|
|
113
|
+
const PullRequestFrontmatterSchema = z.object({
|
|
114
|
+
title: z.string({ error: stringMessage }),
|
|
115
|
+
repository: z.string({ error: stringMessage }),
|
|
116
|
+
base: z.string({ error: stringMessage }),
|
|
117
|
+
head: z.string({ error: STRING_MESSAGE }).nullish().transform(value => value ?? undefined),
|
|
118
|
+
draft: z.preprocess(convertToBoolean, z.boolean({ error: issue => booleanMessage(issue.input) })).prefault(false),
|
|
119
|
+
screenshot: z.preprocess(normalizeOptionalText, z.string({ error: stringMessage }).nullish().transform(value => value ?? undefined)),
|
|
120
|
+
}).readonly();
|
|
121
|
+
function issueLine(issue) {
|
|
122
|
+
return ` - ${issue.path.map(String).join('.')}: ${issue.message}`;
|
|
123
|
+
}
|
|
124
|
+
function validationError(lines) {
|
|
125
|
+
return new FrontmatterError(`validation error:\n${lines.join('\n')}`);
|
|
126
|
+
}
|
|
127
|
+
function fieldErrors(issues) {
|
|
128
|
+
return validationError(issues.map(issue => issueLine(issue)));
|
|
129
|
+
}
|
|
130
|
+
// parent_epic と order の相互検証。項目の誤りが無いときだけ行う
|
|
131
|
+
function checkOrderWithParentEpic(frontmatter) {
|
|
132
|
+
const { parent_epic: parentEpic, order, parallel } = frontmatter;
|
|
133
|
+
let message;
|
|
134
|
+
if (parentEpic !== undefined && order === undefined)
|
|
135
|
+
message = 'order is required when parent_epic is set';
|
|
136
|
+
else if (parentEpic === undefined && order !== undefined)
|
|
137
|
+
message = 'parent_epic is required when order is set';
|
|
138
|
+
else if (order !== undefined && order <= 0)
|
|
139
|
+
message = `order must be an integer of 1 or more: ${String(order)}`;
|
|
140
|
+
else if (parallel !== undefined && order === undefined)
|
|
141
|
+
message = 'order is required when parallel is set';
|
|
142
|
+
if (message !== undefined)
|
|
143
|
+
throw validationError([` - : Value error, ${message}`]);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
値から Issue のフロントマターを作る。不正なら FrontmatterError
|
|
147
|
+
*/
|
|
148
|
+
export function validateIssueFrontmatter(data) {
|
|
149
|
+
const result = IssueFrontmatterSchema.safeParse(data);
|
|
150
|
+
if (!result.success)
|
|
151
|
+
throw fieldErrors(result.error.issues);
|
|
152
|
+
checkOrderWithParentEpic(result.data);
|
|
153
|
+
return result.data;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
値からコメントのフロントマターを作る。不正なら FrontmatterError
|
|
157
|
+
*/
|
|
158
|
+
export function validateCommentFrontmatter(data) {
|
|
159
|
+
const result = CommentFrontmatterSchema.safeParse(data);
|
|
160
|
+
if (!result.success)
|
|
161
|
+
throw fieldErrors(result.error.issues);
|
|
162
|
+
return result.data;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
値から PR のフロントマターを作る。不正なら FrontmatterError
|
|
166
|
+
*/
|
|
167
|
+
export function validatePullRequestFrontmatter(data) {
|
|
168
|
+
const result = PullRequestFrontmatterSchema.safeParse(data);
|
|
169
|
+
if (!result.success)
|
|
170
|
+
throw fieldErrors(result.error.issues);
|
|
171
|
+
return result.data;
|
|
172
|
+
}
|
|
173
|
+
// パーサー関数
|
|
174
|
+
// ^---\n で始まり、\n---\n で終わる
|
|
175
|
+
// 先頭の空白の連続と、本文の最短一致が、空白を取り合う。入力はフロントマター付きの Markdown 1 ファイルで、
|
|
176
|
+
// Python の同名の正規表現と同じ範囲を取るため、この形を保つ。
|
|
177
|
+
// eslint-disable-next-line regexp/no-super-linear-backtracking -- 空白の連続が長い入力でだけ遅くなる。取る範囲を Python と揃えるため書き換えない
|
|
178
|
+
const FRONTMATTER_PATTERN = /^---\s*\n(.*?)\n---\s*/dsu;
|
|
179
|
+
// 本文先頭のガイドコメント(`--prepare` 雛形の「読者:/書き方:/フィールド:」ブロック)。
|
|
180
|
+
// 前後の空白・空行ごと 1 ブロックだけ食う。本文途中のコメントは対象外。
|
|
181
|
+
const LEADING_HTML_COMMENT_PATTERN = /^\s*<!--.*?-->\s*/su;
|
|
182
|
+
/**
|
|
183
|
+
本文先頭の HTML コメントブロックを 1 つだけ除去する。
|
|
184
|
+
`--prepare` が配る雛形は、冒頭に書き方ガイドの HTML コメントを持つ。
|
|
185
|
+
利用者が消し忘れたまま投稿しても GitHub 本文に残らないよう、パース時に取り除く(#958 F-02)。
|
|
186
|
+
本文途中の `<details>` 等の HTML には触れない
|
|
187
|
+
*/
|
|
188
|
+
export function stripLeadingHtmlComment(body) {
|
|
189
|
+
return body.replace(LEADING_HTML_COMMENT_PATTERN, '');
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
フロントマターを落とした本文を返す(不正・不在なら原文をそのまま返す)。
|
|
193
|
+
パース前の素朴な走査(プレースホルダ検証など)で本文だけを対象にするための寛容なヘルパで、検証はしない
|
|
194
|
+
*/
|
|
195
|
+
export function stripFrontmatter(content) {
|
|
196
|
+
const match = FRONTMATTER_PATTERN.exec(content);
|
|
197
|
+
return match === null ? content : content.slice(match[0].length);
|
|
198
|
+
}
|
|
199
|
+
function isMapping(data) {
|
|
200
|
+
return typeof data === 'object' && data !== null && Object.getPrototypeOf(data) === Object.prototype;
|
|
201
|
+
}
|
|
202
|
+
// フロントマターの YAML を読み、本文と分ける。フロントマターの検証はしない
|
|
203
|
+
function splitFrontmatter(content) {
|
|
204
|
+
if (!content.startsWith('---'))
|
|
205
|
+
throw new FrontmatterError('frontmatter not found (does not start with ---)');
|
|
206
|
+
const match = FRONTMATTER_PATTERN.exec(content);
|
|
207
|
+
if (match === null)
|
|
208
|
+
throw new FrontmatterError('frontmatter is not closed (missing closing ---)');
|
|
209
|
+
const rest = pythonStrip(content.slice(match[0].length));
|
|
210
|
+
const body = pythonStrip(stripLeadingHtmlComment(rest));
|
|
211
|
+
let data;
|
|
212
|
+
try {
|
|
213
|
+
// 改行は \r\n・\r も \n と同じ行区切りとして読む(YAML ライブラリは末尾の \r を値に含める)
|
|
214
|
+
data = parseYamlDocument(normalizeNewlines(match[1] ?? ''));
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw new FrontmatterError(`failed to parse YAML: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
218
|
+
}
|
|
219
|
+
if (!isMapping(data))
|
|
220
|
+
throw new FrontmatterError('frontmatter must be a mapping (key: value)');
|
|
221
|
+
return { data, body };
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
文字列から Issue のフロントマターをパースする。不正なら FrontmatterError
|
|
225
|
+
*/
|
|
226
|
+
export function parseFrontmatter(content) {
|
|
227
|
+
const { data, body } = splitFrontmatter(content);
|
|
228
|
+
return { frontmatter: validateIssueFrontmatter(data), body };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
文字列からコメントのフロントマターをパースする。不正なら FrontmatterError
|
|
232
|
+
*/
|
|
233
|
+
export function parseCommentContent(content) {
|
|
234
|
+
const { data, body } = splitFrontmatter(content);
|
|
235
|
+
return { frontmatter: validateCommentFrontmatter(data), body };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
文字列から PR のフロントマターをパースする。不正なら FrontmatterError
|
|
239
|
+
*/
|
|
240
|
+
export function parsePullRequestContent(content) {
|
|
241
|
+
const { data, body } = splitFrontmatter(content);
|
|
242
|
+
return { frontmatter: validatePullRequestFrontmatter(data), body };
|
|
243
|
+
}
|
|
244
|
+
// `key` の直後に空白を挟んで `:` が続く行か(Python の `^key\s*:`)
|
|
245
|
+
function isKeyLine(line, key) {
|
|
246
|
+
return line.startsWith(key) && /^\s*:/u.test(line.slice(key.length));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
フロントマターに `key: "value"` の 1 行を足す。同じキーの行があれば置き換えるだけで、足さない。
|
|
250
|
+
フロントマターが無ければ FrontmatterError
|
|
251
|
+
*/
|
|
252
|
+
export function setFrontmatterValue(content, key, value) {
|
|
253
|
+
const match = FRONTMATTER_PATTERN.exec(content);
|
|
254
|
+
const span = match?.indices?.[1];
|
|
255
|
+
if (match === null || span === undefined)
|
|
256
|
+
throw new FrontmatterError('frontmatter not found');
|
|
257
|
+
const lines = (match[1] ?? '').split('\n');
|
|
258
|
+
const entry = `${key}: "${value}"`;
|
|
259
|
+
const replaced = lines.map(line => isKeyLine(line, key) ? entry : line);
|
|
260
|
+
if (lines.every(line => !isKeyLine(line, key)))
|
|
261
|
+
replaced.push(entry);
|
|
262
|
+
return content.slice(0, span[0]) + replaced.join('\n') + content.slice(span[1]);
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=frontmatter.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface GitResult {
|
|
2
|
+
readonly exitCode: number;
|
|
3
|
+
readonly stdout: string;
|
|
4
|
+
readonly stderr: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
git を実行する。非 0 終了でも例外にせず結果を返す。git の起動に失敗したときは例外を投げる。
|
|
8
|
+
*/
|
|
9
|
+
export type GitRunner = (arguments_: readonly string[]) => GitResult;
|
|
10
|
+
//# sourceMappingURL=git-runner.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InvalidValueError } from './errors.js';
|
|
2
|
+
export declare class RemoteUrlFormatError extends InvalidValueError {
|
|
3
|
+
}
|
|
4
|
+
export interface RemoteLocation {
|
|
5
|
+
readonly host: string;
|
|
6
|
+
readonly owner: string;
|
|
7
|
+
readonly repository: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
リモート URL を分ける。前後の空白は除く。
|
|
11
|
+
対応する形式は次の 3 つ。
|
|
12
|
+
- 形式 1: `https://host/owner/repo[.git]`。
|
|
13
|
+
- 形式 2: `git@host:owner/repo[.git]`。
|
|
14
|
+
- 形式 3: `ssh://[user@]host[:port]/owner/repo[.git][/]`。
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseRemoteUrl(url: string): RemoteLocation;
|
|
17
|
+
//# sourceMappingURL=git-url.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Git リモート URL の解析。HTTPS / SSH 形式から (host, owner, repository) を取り出す。
|
|
2
|
+
import { InvalidValueError } from './errors.js';
|
|
3
|
+
import { pythonStrip } from './python-format.js';
|
|
4
|
+
export class RemoteUrlFormatError extends InvalidValueError {
|
|
5
|
+
}
|
|
6
|
+
const HTTPS_URL_PATTERN = /^https?:\/\/([^/]+)\/([^/]+)\/([^/]+?)(?:\.git)?$/u;
|
|
7
|
+
const SSH_URL_PATTERN = /^git@([^:]+):([^/]+)\/([^/]+?)(?:\.git)?$/u;
|
|
8
|
+
const USERINFO_PATTERN = /^([a-z][a-z0-9+.-]*:\/\/)[^/]*@/iu;
|
|
9
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- 入力はリモート URL 1 本で、バックトラックの幅は URL の長さに収まる
|
|
10
|
+
const SSH_SCHEME_URL_PATTERN = /^ssh:\/\/(?:[^@/]+@)?([^/:@]+)(?::\p{Nd}+)?\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/u;
|
|
11
|
+
/**
|
|
12
|
+
リモート URL を分ける。前後の空白は除く。
|
|
13
|
+
対応する形式は次の 3 つ。
|
|
14
|
+
- 形式 1: `https://host/owner/repo[.git]`。
|
|
15
|
+
- 形式 2: `git@host:owner/repo[.git]`。
|
|
16
|
+
- 形式 3: `ssh://[user@]host[:port]/owner/repo[.git][/]`。
|
|
17
|
+
*/
|
|
18
|
+
export function parseRemoteUrl(url) {
|
|
19
|
+
const trimmed = pythonStrip(url);
|
|
20
|
+
for (const pattern of [HTTPS_URL_PATTERN, SSH_URL_PATTERN, SSH_SCHEME_URL_PATTERN]) {
|
|
21
|
+
const [, host, owner, repository] = pattern.exec(trimmed) ?? [];
|
|
22
|
+
if (host !== undefined && owner !== undefined && repository !== undefined) {
|
|
23
|
+
// https://user:token@host/... の userinfo は host に含めない
|
|
24
|
+
return { host: host.slice(host.lastIndexOf('@') + 1), owner, repository };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// エラー文に認証情報(userinfo)を出さない
|
|
28
|
+
throw new RemoteUrlFormatError(`unexpected remote URL format: ${trimmed.replace(USERINFO_PATTERN, '$1')}`);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=git-url.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const EPIC_TYPE_NAME = "Epic";
|
|
2
|
+
/**
|
|
3
|
+
Issue 種別の取得結果。キー名は Python の CLI が返していた辞書と同じ
|
|
4
|
+
*/
|
|
5
|
+
export interface IssueKind {
|
|
6
|
+
readonly issue_type?: string | null | undefined;
|
|
7
|
+
readonly sub_issues_total?: number | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
Issue Type=Epic、または subIssues.totalCount > 0 を Epic とみなす。
|
|
11
|
+
1. issue_type が `Epic` なら true(大文字小文字は区別しない)。
|
|
12
|
+
2. issue_type が空・未設定で sub_issues_total > 0 なら true(Issue Type が無かった頃のフォールバック)。
|
|
13
|
+
3. それ以外は false。
|
|
14
|
+
*/
|
|
15
|
+
export declare function isEpicIssue(issueKind: IssueKind): boolean;
|
|
16
|
+
//# sourceMappingURL=issue-kind.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Issue 種別判定(GitHub の Issue 種別の取得結果に対する純関数)。
|
|
2
|
+
import { pythonStrip } from './python-format.js';
|
|
3
|
+
export const EPIC_TYPE_NAME = 'Epic';
|
|
4
|
+
/**
|
|
5
|
+
Issue Type=Epic、または subIssues.totalCount > 0 を Epic とみなす。
|
|
6
|
+
1. issue_type が `Epic` なら true(大文字小文字は区別しない)。
|
|
7
|
+
2. issue_type が空・未設定で sub_issues_total > 0 なら true(Issue Type が無かった頃のフォールバック)。
|
|
8
|
+
3. それ以外は false。
|
|
9
|
+
*/
|
|
10
|
+
export function isEpicIssue(issueKind) {
|
|
11
|
+
const issueType = pythonStrip(issueKind.issue_type ?? '');
|
|
12
|
+
const isEpicType = issueType.toLowerCase() === EPIC_TYPE_NAME.toLowerCase();
|
|
13
|
+
const isFallback = issueType === '' && (issueKind.sub_issues_total ?? 0) > 0;
|
|
14
|
+
return isEpicType || isFallback;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=issue-kind.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { RepositoryReference } from './repository-resolver.js';
|
|
2
|
+
/**
|
|
3
|
+
GitHub の PR の状態。GraphQL の PullRequestState の値そのまま
|
|
4
|
+
*/
|
|
5
|
+
export type PullRequestStateReadout = 'OPEN' | 'CLOSED' | 'MERGED';
|
|
6
|
+
/**
|
|
7
|
+
Issue の状態。GraphQL の IssueState の値そのまま
|
|
8
|
+
*/
|
|
9
|
+
export type IssueStateReadout = 'OPEN' | 'CLOSED';
|
|
10
|
+
export interface PullRequestReadout {
|
|
11
|
+
/**
|
|
12
|
+
PR のあるリポ(base 側)
|
|
13
|
+
*/
|
|
14
|
+
readonly repository: RepositoryReference;
|
|
15
|
+
readonly number: number;
|
|
16
|
+
readonly state: PullRequestStateReadout;
|
|
17
|
+
readonly headRefName: string;
|
|
18
|
+
readonly baseRefName: string;
|
|
19
|
+
readonly isDraft: boolean;
|
|
20
|
+
readonly isCrossRepository: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
ボードの単一選択のフィールドの値 1 つ。設定のプロジェクトに絞った後の値
|
|
24
|
+
*/
|
|
25
|
+
export interface ProjectFieldValueReadout {
|
|
26
|
+
readonly fieldId: string;
|
|
27
|
+
readonly fieldName: string;
|
|
28
|
+
readonly optionId: string;
|
|
29
|
+
readonly optionName: string;
|
|
30
|
+
}
|
|
31
|
+
export interface LinkedBranchReadout {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/**
|
|
34
|
+
このブランチを head に持つ PR
|
|
35
|
+
*/
|
|
36
|
+
readonly pullRequests: readonly PullRequestReadout[];
|
|
37
|
+
}
|
|
38
|
+
export interface IssueReadout {
|
|
39
|
+
/**
|
|
40
|
+
GraphQL の node ID
|
|
41
|
+
*/
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly repository: RepositoryReference;
|
|
44
|
+
readonly number: number;
|
|
45
|
+
readonly state: IssueStateReadout;
|
|
46
|
+
readonly title: string;
|
|
47
|
+
/**
|
|
48
|
+
Issue Type の名前。無い、または issueType に対応しない GHES では null
|
|
49
|
+
*/
|
|
50
|
+
readonly issueType: string | null;
|
|
51
|
+
readonly subIssuesTotal: number;
|
|
52
|
+
/**
|
|
53
|
+
設定のプロジェクトのアイテムの値。ボードに無ければ空
|
|
54
|
+
*/
|
|
55
|
+
readonly projectFieldValues: readonly ProjectFieldValueReadout[];
|
|
56
|
+
readonly linkedBranches: readonly LinkedBranchReadout[];
|
|
57
|
+
/**
|
|
58
|
+
closedByPullRequestsReferences(includeClosedPrs: true) の PR
|
|
59
|
+
*/
|
|
60
|
+
readonly closingPullRequests: readonly PullRequestReadout[];
|
|
61
|
+
/**
|
|
62
|
+
timelineItems の PR。ConnectedEvent のうち後で外されていないものと、CrossReferencedEvent のうち閉じる参照か、head が `/<Issue 番号>` で終わるもの
|
|
63
|
+
*/
|
|
64
|
+
readonly timelinePullRequests: readonly PullRequestReadout[];
|
|
65
|
+
}
|
|
66
|
+
export interface TargetIssueReadout extends IssueReadout {
|
|
67
|
+
readonly body: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
blockedBy の読み取り結果。読めない部分があるときは read-failed。
|
|
71
|
+
読めない部分とは、blockedBy の null の node・エラー・件数不足と、対象と前提の Issue の connection の取りこぼし
|
|
72
|
+
*/
|
|
73
|
+
export type BlockedByReadout = {
|
|
74
|
+
readonly kind: 'ok';
|
|
75
|
+
readonly issues: readonly IssueReadout[];
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'read-failed';
|
|
78
|
+
readonly reason: string;
|
|
79
|
+
};
|
|
80
|
+
export interface IssuePrerequisitesReadout {
|
|
81
|
+
readonly issue: TargetIssueReadout;
|
|
82
|
+
readonly blockedBy: BlockedByReadout;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
ボードのフィールド名。getIssuePrerequisites が値を取る 2 つ
|
|
86
|
+
*/
|
|
87
|
+
export interface PrerequisiteFieldNames {
|
|
88
|
+
/**
|
|
89
|
+
進行の欄のフィールド名
|
|
90
|
+
*/
|
|
91
|
+
readonly columnFieldName: string;
|
|
92
|
+
/**
|
|
93
|
+
札のフィールド名
|
|
94
|
+
*/
|
|
95
|
+
readonly labelFieldName: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
head のブランチ名で引いた PR。新しい順
|
|
99
|
+
*/
|
|
100
|
+
export interface PullRequestsByHeadReadout {
|
|
101
|
+
readonly pullRequests: readonly PullRequestReadout[];
|
|
102
|
+
/**
|
|
103
|
+
先頭の件数に収まらず、続きがあるか
|
|
104
|
+
*/
|
|
105
|
+
readonly hasNextPage: boolean;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=issue-readout.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { JsonValue } from './python-format.js';
|
|
2
|
+
export type JsonObject = Readonly<Record<string, JsonValue>>;
|
|
3
|
+
/**
|
|
4
|
+
配列でも null でもないオブジェクトか
|
|
5
|
+
*/
|
|
6
|
+
export declare function isJsonObject(value: JsonValue | undefined): value is JsonObject;
|
|
7
|
+
/**
|
|
8
|
+
オブジェクトの自身のキーの値。オブジェクトでない、またはキーが無ければ undefined。
|
|
9
|
+
キーに prototype の名前が来ても、継承した値は返さない
|
|
10
|
+
*/
|
|
11
|
+
export declare function jsonField(value: JsonValue | undefined, key: string): JsonValue | undefined;
|
|
12
|
+
/**
|
|
13
|
+
JSON 文字列を読む。構文が不正なら undefined
|
|
14
|
+
*/
|
|
15
|
+
export declare function tryParseJsonText(text: string): JsonValue | undefined;
|
|
16
|
+
/**
|
|
17
|
+
JSON 文字列を読む。不正なら InvalidValueError。
|
|
18
|
+
文言は JSON パーサーのもので、Python の JSONDecodeError の文とは違う
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseJsonText(text: string): JsonValue;
|
|
21
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// JSON の値を読む補助。型の絞り込み、フィールドの読み取り、JSON 文字列の読み込みの置き場。
|
|
2
|
+
// 同じ補助を各所に書かないよう、domain と infra はここから import する。
|
|
3
|
+
import { InvalidValueError } from './errors.js';
|
|
4
|
+
import { isJsonArray } from './python-format.js';
|
|
5
|
+
/**
|
|
6
|
+
配列でも null でもないオブジェクトか
|
|
7
|
+
*/
|
|
8
|
+
export function isJsonObject(value) {
|
|
9
|
+
return typeof value === 'object' && value !== null && !isJsonArray(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
オブジェクトの自身のキーの値。オブジェクトでない、またはキーが無ければ undefined。
|
|
13
|
+
キーに prototype の名前が来ても、継承した値は返さない
|
|
14
|
+
*/
|
|
15
|
+
export function jsonField(value, key) {
|
|
16
|
+
return isJsonObject(value) ? new Map(Object.entries(value)).get(key) : undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
JSON 文字列を読む。構文が不正なら undefined
|
|
20
|
+
*/
|
|
21
|
+
export function tryParseJsonText(text) {
|
|
22
|
+
try {
|
|
23
|
+
// eslint-disable-next-line no-restricted-syntax -- JSON.parse の結果は定義上 JsonValue
|
|
24
|
+
return JSON.parse(text);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof SyntaxError)
|
|
28
|
+
return undefined;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
JSON 文字列を読む。不正なら InvalidValueError。
|
|
34
|
+
文言は JSON パーサーのもので、Python の JSONDecodeError の文とは違う
|
|
35
|
+
*/
|
|
36
|
+
export function parseJsonText(text) {
|
|
37
|
+
try {
|
|
38
|
+
// eslint-disable-next-line no-restricted-syntax -- JSON.parse の結果は定義上 JsonValue
|
|
39
|
+
return JSON.parse(text);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof SyntaxError)
|
|
43
|
+
throw new InvalidValueError(error.message, { cause: error });
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IssueReference } from './reference-parser.js';
|
|
2
|
+
import type { RepositoryReference } from './repository-resolver.js';
|
|
3
|
+
export declare const WAITS_FOR_MERGE_HEADING = "## Waits for merge";
|
|
4
|
+
export interface WaitsForMergeLine {
|
|
5
|
+
readonly ref: IssueReference;
|
|
6
|
+
readonly reason: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
absent は節が無いこと。malformed は節が読めないこと(呼ぶ側は前提をすべて merge として扱う)
|
|
10
|
+
*/
|
|
11
|
+
export type WaitsForMergeReadout = {
|
|
12
|
+
readonly kind: 'absent';
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'ok';
|
|
15
|
+
readonly lines: readonly WaitsForMergeLine[];
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'malformed';
|
|
18
|
+
readonly reason: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
本文から `## Waits for merge` の節を読む。repository は `#N` の参照が指すリポ(本文のある Issue のリポ)
|
|
22
|
+
*/
|
|
23
|
+
export declare function readWaitsForMerge(body: string, repository: RepositoryReference): WaitsForMergeReadout;
|
|
24
|
+
/**
|
|
25
|
+
前提の行を足す。同じ参照の行があれば理由を書き換える。節の外は変えない。節が読めないときは InvalidValueError
|
|
26
|
+
*/
|
|
27
|
+
export declare function upsertWaitsForMerge(body: string, repository: RepositoryReference, reference: IssueReference, reason: string): string;
|
|
28
|
+
/**
|
|
29
|
+
前提の行を外す。参照が無ければ本文をそのまま返す。行が無くなれば節ごと消す。節が読めないときは InvalidValueError
|
|
30
|
+
*/
|
|
31
|
+
export declare function removeWaitsForMerge(body: string, repository: RepositoryReference, reference: IssueReference): string;
|
|
32
|
+
//# sourceMappingURL=prerequisites.d.ts.map
|