@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,514 @@
|
|
|
1
|
+
// テンプレート由来の必須セクション抽出・検証。
|
|
2
|
+
//
|
|
3
|
+
// `--prepare` が配る雛形の見出し構成を基準に、投稿本文が雛形どおりに編集されているかを判定する。
|
|
4
|
+
// issue / comment / pr の 3 コマンドが同じ厳しさで検証するよう、抽出器と検証器をここに集約する(#958 F-03)。
|
|
5
|
+
// テンプレートのファイルを読む関数は infra/template-store.ts が持つ。
|
|
6
|
+
//
|
|
7
|
+
// 正規表現は Python の CLI のものを写している。違いが出やすい点は次のとおり。
|
|
8
|
+
// - 行頭と行末の区切りは `\n` だけにする。JS の m フラグは `\r` や U+2028 でも区切る
|
|
9
|
+
// - `.` が `\r` や U+2028 を含むかは、s フラグで揃える
|
|
10
|
+
// - 文字数と位置はコードポイントで数える(絵文字で数がずれない)
|
|
11
|
+
import { stripLeadingHtmlComment } from './frontmatter.js';
|
|
12
|
+
import { pythonStrip, splitCodePoints } from './python-format.js';
|
|
13
|
+
// 見出しの em-dash 一行サマリの上限文字数
|
|
14
|
+
export const SUMMARY_MAX_CHARS = 50;
|
|
15
|
+
// 折りたたみの開閉部分(<summary>)に許す唯一の形。文言を揃え、開閉部分を右寄せにする
|
|
16
|
+
// (GitHub は style / class を除去するため、残る align 属性で寄せる)。テンプレ名ごとに検証を掛ける
|
|
17
|
+
export const PLAN_FOLD_SUMMARY = '<summary align="right">詳細はこちら</summary>';
|
|
18
|
+
export const FOLD_SUMMARY_BY_TEMPLATE = new Map([['plan', PLAN_FOLD_SUMMARY]]);
|
|
19
|
+
/**
|
|
20
|
+
テンプレに無い `##` / `###` 見出しを拒否するテンプレ名と、拒否したときに添える案内文。
|
|
21
|
+
テンプレごとに閉じた見出しの集合を持たせる。
|
|
22
|
+
Python の `issue.py` の `_report_template_violations` は、この Map にテンプレ名があるときだけ 2 つの検証を掛ける。
|
|
23
|
+
掛ける検証は validateFoldBalance と validateClosedHeadings。コマンドを移すときは同じ条件にする
|
|
24
|
+
*/
|
|
25
|
+
export const CLOSED_HEADINGS_BY_TEMPLATE = new Map([['plan', 'put content that fits no other heading under ### Notes']]);
|
|
26
|
+
// 検証エラー文。テンプレの規約ブロックとの対応をテンプレートの単体テストが固定する
|
|
27
|
+
export const CHECKBOX_ERROR = 'checkbox syntax (- [ ] / 1. [ ]) is not allowed';
|
|
28
|
+
export const HORIZONTAL_RULE_ERROR = 'horizontal rules are not allowed';
|
|
29
|
+
export const EMOJI_ERROR = 'emoji are not allowed';
|
|
30
|
+
export const SOFT_BREAK_ERROR = 'a paragraph is broken across lines: GitHub shows line breaks as written, so write each paragraph on one line and separate paragraphs with a blank line';
|
|
31
|
+
export const SUMMARY_NOT_JAPANESE_ERROR = 'the summary must be written in Japanese';
|
|
32
|
+
export const SUMMARY_MULTI_SENTENCE_ERROR = 'the summary must be one sentence';
|
|
33
|
+
// GitHub が Markdown 描画時にサニタイズせず通す HTML タグのうち、投稿本文で実際に使うもの。
|
|
34
|
+
// この一覧に無いタグ形状の <...> は未編集プレースホルダ扱い(`<T>` のような型・メタ表記はバッククォートで囲んで書く)。
|
|
35
|
+
const ALLOWED_HTML_TAGS = new Set([
|
|
36
|
+
'a', 'b', 'blockquote', 'br', 'code', 'details', 'div', 'em', 'i', 'img', 'kbd', 'li', 'ol', 'p', 'pre', 'span',
|
|
37
|
+
'strong', 'sub', 'summary', 'sup', 'table', 'td', 'th', 'tr', 'ul',
|
|
38
|
+
]);
|
|
39
|
+
const HTML_COMMENT_PATTERN = /<!--.*?-->/gsu;
|
|
40
|
+
const CHECKBOX_PATTERN = /^\s*(?:[*+-]|\p{Nd}+[).])\s+\[[ X]\](?:\s|$)/iu;
|
|
41
|
+
// 水平線(thematic break)。setext 見出しの下線 `---` も同じ形で弾く(テンプレは ATX 見出しのみ)。
|
|
42
|
+
// CommonMark は区切りにタブも許す
|
|
43
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- 行ごとに当てる。繰り返す群は同じ記号 1 文字と空白だけで、再試行は行の長さに比例して増えない
|
|
44
|
+
const THEMATIC_BREAK_PATTERN = /^ {0,3}([*_-])(?:[\t ]*\1){2,}[\t ]*$/u;
|
|
45
|
+
// 引用(`>`)とリストマーカーの接頭辞。剥がした残りにも水平線・タスクリスト判定を当てる
|
|
46
|
+
const BLOCKQUOTE_PREFIX_PATTERN = /^[\t ]*>[\t ]?/u;
|
|
47
|
+
const LIST_MARKER_PREFIX_PATTERN = /^[\t ]*(?:[*+-]|\p{Nd}+[).])[\t ]+/u;
|
|
48
|
+
// 絵文字ショートコード(`:white_check_mark:` 等)。英字を含むものだけ(`10:30:00` は通す)
|
|
49
|
+
const EMOJI_SHORTCODE_PATTERN = /:[-\d+_]*[a-z][-\d+_a-z]*:/u;
|
|
50
|
+
// サマリの日本語判定: ひらがな・カタカナ・CJK 統合漢字・々・半角カナ
|
|
51
|
+
const JAPANESE_CHARACTER_RANGES = [
|
|
52
|
+
[0x30_40, 0x30_9F], [0x30_A0, 0x30_FF], [0x4E_00, 0x9F_FF], [0x30_05, 0x30_05], [0xFF_66, 0xFF_9F],
|
|
53
|
+
];
|
|
54
|
+
const HEADING_PATTERN = /^(#{2,6})\s/u;
|
|
55
|
+
// `<...>` トークン。改行を跨がせない(閉じ忘れで本文全体を飲み込むのを防ぐ)
|
|
56
|
+
const TOKEN_PATTERN = /<[^\n<>]+>/gu;
|
|
57
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- `<...>` 1 トークンに当てる。トークンは改行・山括弧を含まない
|
|
58
|
+
const HTML_TAG_PATTERN = /^<\/?([A-Za-z][\dA-Za-z-]*)(?:\s[^<>]*)?\/?>$/u;
|
|
59
|
+
const AUTOLINK_URI_PATTERN = /^<[A-Za-z][\d+.A-Za-z-]*:\/\/[^\s<>]*>$/u;
|
|
60
|
+
const AUTOLINK_EMAIL_PATTERN = /^<[^\s<>@]+@[^\s<>]+>$/u;
|
|
61
|
+
// Emoji_Presentation=Yes の BMP 文字。
|
|
62
|
+
// 出典: Unicode 15.1 emoji-data.txt(Date: 2023-02-01)の Emoji_Presentation 行のうち U+1F000 未満。
|
|
63
|
+
// `⚠` `✓` `★` `→` `✗` は Emoji_Presentation=No なので含めない(U+FE0F を伴えば絵文字扱い)
|
|
64
|
+
const EMOJI_PRESENTATION_BMP_RANGES = [
|
|
65
|
+
[0x23_1A, 0x23_1B], [0x23_E9, 0x23_EC], [0x23_F0, 0x23_F0], [0x23_F3, 0x23_F3], [0x25_FD, 0x25_FE],
|
|
66
|
+
[0x26_14, 0x26_15], [0x26_48, 0x26_53], [0x26_7F, 0x26_7F], [0x26_93, 0x26_93], [0x26_A1, 0x26_A1],
|
|
67
|
+
[0x26_AA, 0x26_AB], [0x26_BD, 0x26_BE], [0x26_C4, 0x26_C5], [0x26_CE, 0x26_CE], [0x26_D4, 0x26_D4],
|
|
68
|
+
[0x26_EA, 0x26_EA], [0x26_F2, 0x26_F3], [0x26_F5, 0x26_F5], [0x26_FA, 0x26_FA], [0x26_FD, 0x26_FD],
|
|
69
|
+
[0x27_05, 0x27_05], [0x27_0A, 0x27_0B], [0x27_28, 0x27_28], [0x27_4C, 0x27_4C], [0x27_4E, 0x27_4E],
|
|
70
|
+
[0x27_53, 0x27_55], [0x27_57, 0x27_57], [0x27_95, 0x27_97], [0x27_B0, 0x27_B0], [0x27_BF, 0x27_BF],
|
|
71
|
+
[0x2B_1B, 0x2B_1C], [0x2B_50, 0x2B_50], [0x2B_55, 0x2B_55], [0x32_97, 0x32_97], [0x32_99, 0x32_99],
|
|
72
|
+
];
|
|
73
|
+
// 絵文字面(Mahjong / Domino / Playing Cards から Symbols and Pictographs Extended-A まで)。
|
|
74
|
+
// この範囲にある非絵文字ブロック(Enclosed Alphanumeric Supplement 等)も意図して弾く。
|
|
75
|
+
// 本文で使う場面が無く、範囲指定を単純に保つため。
|
|
76
|
+
const EMOJI_PLANE_FIRST = 0x1_F0_00;
|
|
77
|
+
const EMOJI_PLANE_LAST = 0x1_FA_FF;
|
|
78
|
+
// 異体字セレクタ 16(直前の文字を絵文字表示にする)
|
|
79
|
+
const EMOJI_VARIATION_SELECTOR = 0xFE_0F;
|
|
80
|
+
// 文の区切り。半角 `.` は `v1.2` のような表記があるため含めない
|
|
81
|
+
const SENTENCE_END_CHARACTERS = new Set(splitCodePoints('。!?!?'));
|
|
82
|
+
// 1 文判定の前にサマリ末尾から除く閉じ括弧類(`「完了。」` を 1 文として扱う)
|
|
83
|
+
const CLOSING_BRACKETS = new Set(splitCodePoints('」』)】〕〉》]}"\'”’)]}'));
|
|
84
|
+
// 抽出
|
|
85
|
+
// `##`〜`######` の後に空白が続き、その後に文字が 1 つ以上ある行を見出しとして読む
|
|
86
|
+
// (空白だけが続く行は、空白が 2 文字以上のときだけ名前が空の見出しになる)
|
|
87
|
+
function parseTemplateHeading(line) {
|
|
88
|
+
const level = /^#*/u.exec(line)?.[0].length ?? 0;
|
|
89
|
+
if (level < 2 || level > 6)
|
|
90
|
+
return undefined;
|
|
91
|
+
const afterHashes = line.slice(level);
|
|
92
|
+
const text = afterHashes.trimStart();
|
|
93
|
+
const whitespaceLength = afterHashes.length - text.length;
|
|
94
|
+
return whitespaceLength === 0 || (text === '' && whitespaceLength < 2) ? undefined : { level, name: pythonStrip(text) };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
テンプレートの内容から見出しセクションを抽出する(レベル情報付き)。
|
|
98
|
+
フロントマター(先頭の `---` と次の `---` の間)と、その後ろの先頭の HTML コメント(書き方ガイド)は読み飛ばし、`##`〜`######` で始まる行を拾う
|
|
99
|
+
*/
|
|
100
|
+
export function extractSectionsFromTemplate(template) {
|
|
101
|
+
let body = template;
|
|
102
|
+
if (template.startsWith('---')) {
|
|
103
|
+
const second = template.indexOf('---', 3);
|
|
104
|
+
if (second !== -1)
|
|
105
|
+
body = template.slice(second + 3);
|
|
106
|
+
}
|
|
107
|
+
body = stripLeadingHtmlComment(body);
|
|
108
|
+
const sections = [];
|
|
109
|
+
for (const line of body.split('\n')) {
|
|
110
|
+
const heading = parseTemplateHeading(line);
|
|
111
|
+
if (heading !== undefined)
|
|
112
|
+
sections.push(heading);
|
|
113
|
+
}
|
|
114
|
+
return sections;
|
|
115
|
+
}
|
|
116
|
+
// 見出しの検索
|
|
117
|
+
function escapeRegularExpression(text) {
|
|
118
|
+
return text.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw `\$&`);
|
|
119
|
+
}
|
|
120
|
+
// 本文の中で、行頭から始まる見出しを探す。`^` は直前が改行か本文の先頭の位置
|
|
121
|
+
function findHeading(body, pattern) {
|
|
122
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- 見出しの文字列は escape 済み
|
|
123
|
+
return new RegExp(String.raw `(?<![^\n])${pattern}`, 'u').exec(body);
|
|
124
|
+
}
|
|
125
|
+
function findEmDashHeading(body, prefix, base) {
|
|
126
|
+
return findHeading(body, String.raw `${escapeRegularExpression(prefix)}\s+${escapeRegularExpression(base)}\s+—\s+(\S[^\n]*)`);
|
|
127
|
+
}
|
|
128
|
+
const EM_DASH_SEPARATOR = ' — ';
|
|
129
|
+
function baseOf(name) {
|
|
130
|
+
return name.split(EM_DASH_SEPARATOR, 1)[0] ?? name;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
必須セクションの存在を確認する(見出しレベルも検証)。不足している見出しの表記を返す(例: `### Done — <summary>`)。
|
|
134
|
+
em-dash 付きの見出しは「ベース名 + em-dash + サマリ」の形があるかだけを見る。
|
|
135
|
+
サマリの規則(文字数・日本語・1 文)は validateHeadingSummaries が、未編集の `<...>` の残存は validateBodyStyle が見る(#962)。
|
|
136
|
+
それ以外の見出しはセクション名の前方一致をチェックする
|
|
137
|
+
*/
|
|
138
|
+
export function validateSections(body, requiredSections) {
|
|
139
|
+
const missing = [];
|
|
140
|
+
for (const { level, name } of requiredSections) {
|
|
141
|
+
const prefix = '#'.repeat(level);
|
|
142
|
+
// em-dash 付きのテンプレ見出しは「ベース名 + em-dash + サマリ」を要求
|
|
143
|
+
if (name.includes(EM_DASH_SEPARATOR)) {
|
|
144
|
+
const base = baseOf(name);
|
|
145
|
+
if (findEmDashHeading(body, prefix, base) === null)
|
|
146
|
+
missing.push(`${prefix} ${base} — <summary>`);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
// それ以外は前方一致チェック(セクション名で始まればよい)
|
|
150
|
+
if (findHeading(body, String.raw `${escapeRegularExpression(prefix)}\s+${escapeRegularExpression(name)}`) === null)
|
|
151
|
+
missing.push(`${prefix} ${name}`);
|
|
152
|
+
}
|
|
153
|
+
return missing;
|
|
154
|
+
}
|
|
155
|
+
function isJapaneseCharacter(character) {
|
|
156
|
+
const code = character.codePointAt(0) ?? 0;
|
|
157
|
+
return JAPANESE_CHARACTER_RANGES.some(([first, last]) => code >= first && code <= last);
|
|
158
|
+
}
|
|
159
|
+
// em-dash サマリの規則違反(文字数・日本語・1 文)を返す
|
|
160
|
+
function summaryErrors(summary) {
|
|
161
|
+
const errors = [];
|
|
162
|
+
const characters = splitCodePoints(summary);
|
|
163
|
+
if (characters.length > SUMMARY_MAX_CHARS)
|
|
164
|
+
errors.push(`the summary is ${String(characters.length)} characters (limit: ${String(SUMMARY_MAX_CHARS)})`);
|
|
165
|
+
if (characters.every(character => !isJapaneseCharacter(character)))
|
|
166
|
+
errors.push(SUMMARY_NOT_JAPANESE_ERROR);
|
|
167
|
+
let end = characters.length;
|
|
168
|
+
while (end > 0 && CLOSING_BRACKETS.has(characters[end - 1] ?? ''))
|
|
169
|
+
end -= 1;
|
|
170
|
+
if (characters.slice(0, Math.max(end - 1, 0)).some(character => SENTENCE_END_CHARACTERS.has(character)))
|
|
171
|
+
errors.push(SUMMARY_MULTI_SENTENCE_ERROR);
|
|
172
|
+
return errors;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
em-dash 見出しのサマリが規則を満たすか確認し、違反の表記を返す。
|
|
176
|
+
規則は文字数・日本語・1 文である
|
|
177
|
+
(例: `## Verified — the summary must be written in Japanese`)。
|
|
178
|
+
見出し自体が無いものは validateSections が不足として返すため、ここでは扱わない
|
|
179
|
+
*/
|
|
180
|
+
export function validateHeadingSummaries(body, requiredSections) {
|
|
181
|
+
const errors = [];
|
|
182
|
+
for (const { level, name } of requiredSections) {
|
|
183
|
+
if (!name.includes(EM_DASH_SEPARATOR))
|
|
184
|
+
continue;
|
|
185
|
+
const prefix = '#'.repeat(level);
|
|
186
|
+
const base = baseOf(name);
|
|
187
|
+
const found = findEmDashHeading(body, prefix, base);
|
|
188
|
+
if (found === null)
|
|
189
|
+
continue;
|
|
190
|
+
const summary = pythonStrip(found[1] ?? '');
|
|
191
|
+
errors.push(...summaryErrors(summary).map(message => `${prefix} ${base} — ${message}`));
|
|
192
|
+
}
|
|
193
|
+
return errors;
|
|
194
|
+
}
|
|
195
|
+
// マスク
|
|
196
|
+
function isClosingFence(line, character, length) {
|
|
197
|
+
const trimmed = line.replace(/^[\t ]+/u, '').replace(/[\t ]+$/u, '');
|
|
198
|
+
const characters = splitCodePoints(trimmed);
|
|
199
|
+
return characters.length >= length && characters.every(item => item === character);
|
|
200
|
+
}
|
|
201
|
+
// 行頭の空白(スペース・タブ)の後に、同じ文字(` か ~)が 3 つ以上続く行を、開始フェンスとして読む
|
|
202
|
+
function parseOpeningFence(line) {
|
|
203
|
+
const rest = line.replace(/^[\t ]+/u, '');
|
|
204
|
+
const character = rest.charAt(0);
|
|
205
|
+
if (character !== '`' && character !== '~')
|
|
206
|
+
return undefined;
|
|
207
|
+
let length = 0;
|
|
208
|
+
while (rest.charAt(length) === character)
|
|
209
|
+
length += 1;
|
|
210
|
+
return length < 3 ? undefined : { character, length, info: rest.slice(length) };
|
|
211
|
+
}
|
|
212
|
+
// フェンスコードブロックの中身を空行に置き換える。
|
|
213
|
+
// 開始フェンスはリスト配下のインデントを許し、閉じフェンスは開始と同じ文字で同じ長さ以上のものを探す(インデントは問わない)
|
|
214
|
+
function maskFencedCode(body) {
|
|
215
|
+
const lines = [];
|
|
216
|
+
let fenceCharacter = '';
|
|
217
|
+
let fenceLength = 0;
|
|
218
|
+
for (const line of body.split('\n')) {
|
|
219
|
+
if (fenceCharacter === '') {
|
|
220
|
+
const fence = parseOpeningFence(line);
|
|
221
|
+
// バッククォートのフェンスは info string にバッククォートを含められない(その形はインラインコードのラン)
|
|
222
|
+
if (fence !== undefined && !(fence.character === '`' && fence.info.includes('`'))) {
|
|
223
|
+
fenceCharacter = fence.character;
|
|
224
|
+
fenceLength = fence.length;
|
|
225
|
+
lines.push('');
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
lines.push(line);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
lines.push('');
|
|
232
|
+
if (!isClosingFence(line, fenceCharacter, fenceLength)) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
fenceCharacter = '';
|
|
236
|
+
fenceLength = 0;
|
|
237
|
+
}
|
|
238
|
+
return { lines, hasUnclosedFence: fenceCharacter !== '' };
|
|
239
|
+
}
|
|
240
|
+
// from 以降で最初のバッククォートの連続を探す
|
|
241
|
+
function findBacktickRun(line, from) {
|
|
242
|
+
const start = line.indexOf('`', from);
|
|
243
|
+
if (start === -1)
|
|
244
|
+
return undefined;
|
|
245
|
+
let end = start;
|
|
246
|
+
while (line.charAt(end) === '`')
|
|
247
|
+
end += 1;
|
|
248
|
+
return { start, end };
|
|
249
|
+
}
|
|
250
|
+
// opener と同じ長さのバッククォートの連続を、opener の後ろから探す
|
|
251
|
+
function findCloser(line, opener) {
|
|
252
|
+
const runLength = opener.end - opener.start;
|
|
253
|
+
let candidate = findBacktickRun(line, opener.end);
|
|
254
|
+
while (candidate !== undefined && candidate.end - candidate.start !== runLength)
|
|
255
|
+
candidate = findBacktickRun(line, candidate.end);
|
|
256
|
+
return candidate;
|
|
257
|
+
}
|
|
258
|
+
// インラインコードスパンを同じ長さの fill(既定は空白)へ置換する。
|
|
259
|
+
// CommonMark のバッククォート・ラン規則(同じ長さのランで閉じる)に従い、`` `- [ ]` `` や二重バッククォートのスパンを検証対象から外す。
|
|
260
|
+
// 閉じランが同一行に無い場合は暴走を避けてマスクしない
|
|
261
|
+
function maskInlineCode(line, fill = ' ') {
|
|
262
|
+
let result = '';
|
|
263
|
+
let position = 0;
|
|
264
|
+
for (;;) {
|
|
265
|
+
const opener = findBacktickRun(line, position);
|
|
266
|
+
if (opener === undefined)
|
|
267
|
+
return result + line.slice(position);
|
|
268
|
+
const closer = findCloser(line, opener);
|
|
269
|
+
if (closer === undefined) {
|
|
270
|
+
result += line.slice(position, opener.end);
|
|
271
|
+
position = opener.end;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
result += line.slice(position, opener.start) + fill.repeat(closer.end - opener.start);
|
|
275
|
+
position = closer.end;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// フェンス・インラインコード・HTML コメントの中身を消した行リストを返す。
|
|
279
|
+
// フェンス内の行は空文字になり、インラインコードと HTML コメントは同じ長さの fill になる(改行は残す)。
|
|
280
|
+
// 水平線の判定だけ fill に '`' を使う(`**`x`**` の外側の `**` を空白にすると水平線に見えるため)
|
|
281
|
+
function maskedLines(body, fill = ' ') {
|
|
282
|
+
const { lines, hasUnclosedFence } = maskFencedCode(body);
|
|
283
|
+
const masked = lines.map(line => maskInlineCode(line, fill)).join('\n')
|
|
284
|
+
.replaceAll(HTML_COMMENT_PATTERN, comment => comment.replaceAll(/[^\n]/g, () => fill));
|
|
285
|
+
return { lines: masked.split('\n'), hasUnclosedFence };
|
|
286
|
+
}
|
|
287
|
+
// 行の中の `<...>` トークンを、出てくる順に返す
|
|
288
|
+
function tokensIn(line) {
|
|
289
|
+
const tokens = Array.from(line.matchAll(TOKEN_PATTERN), match => ({ text: match[0], index: match.index }));
|
|
290
|
+
return tokens;
|
|
291
|
+
}
|
|
292
|
+
function isHorizontalRuleTag(token) {
|
|
293
|
+
const tag = HTML_TAG_PATTERN.exec(token);
|
|
294
|
+
return tag !== null && (tag[1] ?? '').toLowerCase() === 'hr';
|
|
295
|
+
}
|
|
296
|
+
// 行頭の引用 `>` とリストマーカーを 1 段ずつ剥がした行を、元の行から順に返す。
|
|
297
|
+
// `> ---`・`- ***`・`> - [ ] x` のように引用・リストの中に置いた水平線とタスクリストも GitHub は描画するため、剥がした各段で判定する。
|
|
298
|
+
// `- - -` のように剥がすと崩れる形があるため、剥がす前の行も残す
|
|
299
|
+
function containerVariants(line) {
|
|
300
|
+
const variants = [line];
|
|
301
|
+
let current = line;
|
|
302
|
+
for (;;) {
|
|
303
|
+
const match = BLOCKQUOTE_PREFIX_PATTERN.exec(current) ?? LIST_MARKER_PREFIX_PATTERN.exec(current);
|
|
304
|
+
if (match === null)
|
|
305
|
+
return variants;
|
|
306
|
+
current = current.slice(match[0].length);
|
|
307
|
+
variants.push(current);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function hasCheckbox(line) {
|
|
311
|
+
return containerVariants(line).some(variant => CHECKBOX_PATTERN.test(variant));
|
|
312
|
+
}
|
|
313
|
+
// 水平線の行か、`<hr>` タグを含むか
|
|
314
|
+
function hasHorizontalRule(line) {
|
|
315
|
+
return containerVariants(line).some(variant => THEMATIC_BREAK_PATTERN.test(variant)) || tokensIn(line).some(token => isHorizontalRuleTag(token.text));
|
|
316
|
+
}
|
|
317
|
+
function isEmojiPresentationBmp(code) {
|
|
318
|
+
return EMOJI_PRESENTATION_BMP_RANGES.some(([first, last]) => code >= first && code <= last);
|
|
319
|
+
}
|
|
320
|
+
// 絵文字面の文字・Emoji_Presentation の BMP 文字・U+FE0F 付きの文字・ショートコードを含むか
|
|
321
|
+
function hasEmoji(line) {
|
|
322
|
+
if (EMOJI_SHORTCODE_PATTERN.test(line))
|
|
323
|
+
return true;
|
|
324
|
+
return splitCodePoints(line).some((character, index) => {
|
|
325
|
+
const code = character.codePointAt(0) ?? 0;
|
|
326
|
+
return (code >= EMOJI_PLANE_FIRST && code <= EMOJI_PLANE_LAST) || isEmojiPresentationBmp(code) || (code === EMOJI_VARIATION_SELECTOR && index > 0);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
// `<...>` トークンが正当な記法(HTML タグ / autolink / 比較表記)か
|
|
330
|
+
function isAllowedToken(token) {
|
|
331
|
+
// `<hr>` は水平線規則(hasHorizontalRule)が担当するため、ここでは許可扱い
|
|
332
|
+
if (isHorizontalRuleTag(token))
|
|
333
|
+
return true;
|
|
334
|
+
// `<0.0.0>` `<1s>` のような比較・バージョン表現は候補から外す
|
|
335
|
+
const head = String.fromCodePoint(token.codePointAt(1) ?? 0);
|
|
336
|
+
if (!(head === '/' || head === '!' || /^\p{L}$/u.test(head)))
|
|
337
|
+
return true;
|
|
338
|
+
const tag = HTML_TAG_PATTERN.exec(token);
|
|
339
|
+
const isAllowedTag = tag !== null && ALLOWED_HTML_TAGS.has((tag[1] ?? '').toLowerCase());
|
|
340
|
+
return isAllowedTag || AUTOLINK_URI_PATTERN.test(token) || AUTOLINK_EMAIL_PATTERN.test(token);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
投稿本文に使えない記法が残っていないかを判定する(#962)。
|
|
344
|
+
チェックボックス記法・水平線・絵文字・未編集プレースホルダ `<...>` を検出し、エラーメッセージを返す(問題がなければ空)。
|
|
345
|
+
コードフェンス・インラインコード・HTML コメントの中身は対象外(型・比較・メタ表記はバッククォートで囲めば通る)
|
|
346
|
+
*/
|
|
347
|
+
// 段落の続きと見なさない行の頭(見出し・リスト・表・引用・HTML タグ・画像・字下げ)
|
|
348
|
+
const NON_PARAGRAPH_LINE_PATTERN = /^(?:#{1,6}\s|\s*(?:[-*+]|\d+[.)])\s|\s*\||\s*>|\s*<|\s*!\[|\s{2,}\S)/;
|
|
349
|
+
// 引用の行頭(`>` の段を剥がして、引用の中の段落も同じく判定する)と、GitHub の引用の種類の行(`[!WARNING]`)
|
|
350
|
+
const QUOTE_PREFIX_PATTERN = /^\s*>\s?/;
|
|
351
|
+
const ALERT_MARKER_PATTERN = /^\[![A-Z]+\]\s*$/;
|
|
352
|
+
function isParagraphLine(line) {
|
|
353
|
+
return line.trim() !== '' && !NON_PARAGRAPH_LINE_PATTERN.test(line);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
行頭の `>` の段数と、剥がした後の本文
|
|
357
|
+
*/
|
|
358
|
+
function quoteLevelAndText(line) {
|
|
359
|
+
let level = 0;
|
|
360
|
+
let rest = line;
|
|
361
|
+
for (let match = QUOTE_PREFIX_PATTERN.exec(rest); match !== null; match = QUOTE_PREFIX_PATTERN.exec(rest)) {
|
|
362
|
+
level += 1;
|
|
363
|
+
rest = rest.slice(match[0].length);
|
|
364
|
+
}
|
|
365
|
+
return [level, rest];
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
同じ段の引用(段数 0 は地の文)の中で、地の文の行が続いているか
|
|
369
|
+
*/
|
|
370
|
+
function isContinuedParagraph(previous, line) {
|
|
371
|
+
const [previousLevel, previousText] = quoteLevelAndText(previous);
|
|
372
|
+
const [level, text] = quoteLevelAndText(line);
|
|
373
|
+
return previousLevel === level && !ALERT_MARKER_PATTERN.test(previousText.trim()) && isParagraphLine(previousText) && isParagraphLine(text);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
地の文の行を 2 行続けた段落があるか。
|
|
377
|
+
行の種類はマスク済みの行で判定し、行末の明示の改行(空白 2 つか `\\`)は元の行で判定する(インラインコードは空白に置き換わるため、マスク済みの行末では取り違える)
|
|
378
|
+
*/
|
|
379
|
+
function hasSoftBreak(maskedLines, originalLines) {
|
|
380
|
+
return maskedLines.some((line, index) => {
|
|
381
|
+
const previous = maskedLines[index - 1];
|
|
382
|
+
const originalPrevious = originalLines[index - 1] ?? '';
|
|
383
|
+
return previous !== undefined && isContinuedParagraph(previous, line) && !originalPrevious.endsWith(' ') && !originalPrevious.endsWith('\\');
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
export function validateBodyStyle(body) {
|
|
387
|
+
const { lines, hasUnclosedFence } = maskedLines(body);
|
|
388
|
+
// 何も言わずに通すとフェンス以降が丸ごと未検証になる(検証バイパス)
|
|
389
|
+
if (hasUnclosedFence)
|
|
390
|
+
return ['code fence is not closed'];
|
|
391
|
+
const errors = [];
|
|
392
|
+
const ruleLines = maskedLines(body, '`').lines;
|
|
393
|
+
const lineRules = [
|
|
394
|
+
[CHECKBOX_ERROR, hasCheckbox, lines],
|
|
395
|
+
[HORIZONTAL_RULE_ERROR, hasHorizontalRule, ruleLines],
|
|
396
|
+
[EMOJI_ERROR, hasEmoji, lines],
|
|
397
|
+
];
|
|
398
|
+
for (const [message, matches, target] of lineRules) {
|
|
399
|
+
if (target.some(line => matches(line)))
|
|
400
|
+
errors.push(message);
|
|
401
|
+
}
|
|
402
|
+
if (hasSoftBreak(lines, body.split('\n')))
|
|
403
|
+
errors.push(SOFT_BREAK_ERROR);
|
|
404
|
+
const seen = new Set();
|
|
405
|
+
for (const line of lines) {
|
|
406
|
+
const heading = HEADING_PATTERN.exec(line);
|
|
407
|
+
for (const { text: token } of tokensIn(line)) {
|
|
408
|
+
if (isAllowedToken(token))
|
|
409
|
+
continue;
|
|
410
|
+
const message = heading === null ? `unedited placeholder ${token} remains` : `unedited placeholder ${token} remains in the ${heading[1] ?? ''} heading`;
|
|
411
|
+
if (seen.has(message))
|
|
412
|
+
continue;
|
|
413
|
+
seen.add(message);
|
|
414
|
+
errors.push(message);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return errors;
|
|
418
|
+
}
|
|
419
|
+
// 折りたたみ
|
|
420
|
+
/**
|
|
421
|
+
折りたたみ(`<details>`)の開閉が対応しているかを判定する。
|
|
422
|
+
コードフェンス・インラインコード・HTML コメントの中の `<details>` は折りたたみとして扱わない。
|
|
423
|
+
閉じられていない開きタグ、開きの無い閉じタグをエラーにする。折りたたみの外の文字数は見ない。
|
|
424
|
+
未閉じのコードフェンスは空リストを返す(validateBodyStyle が別に出す)
|
|
425
|
+
*/
|
|
426
|
+
export function validateFoldBalance(body) {
|
|
427
|
+
const { lines, hasUnclosedFence } = maskedLines(body);
|
|
428
|
+
if (hasUnclosedFence)
|
|
429
|
+
return [];
|
|
430
|
+
let depth = 0;
|
|
431
|
+
for (const maskedLine of lines) {
|
|
432
|
+
for (const match of tokensIn(maskedLine)) {
|
|
433
|
+
const tag = HTML_TAG_PATTERN.exec(match.text);
|
|
434
|
+
if (tag === null || (tag[1] ?? '').toLowerCase() !== 'details')
|
|
435
|
+
continue;
|
|
436
|
+
depth += match.text.startsWith('</') ? -1 : 1;
|
|
437
|
+
if (depth < 0)
|
|
438
|
+
return ['<details> has no matching opening tag'];
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return depth === 0 ? [] : ['<details> is not closed'];
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
テンプレに無い `##` / `###` 見出しが本文に無いかを判定する。
|
|
445
|
+
`(level, 名前)` の組で比べる。名前は em-dash の前の部分で、サマリは見ない。
|
|
446
|
+
コードフェンス・インラインコード・HTML コメントの中の見出しは対象外で、`<details>` の中の見出しは対象にする。
|
|
447
|
+
h1 と h4 以下は縛らない。テンプレに無い見出しの表記を返す(例: `## Context`)。同じ見出しは 1 回だけ返す
|
|
448
|
+
*/
|
|
449
|
+
export function validateClosedHeadings(body, requiredSections) {
|
|
450
|
+
const allowed = new Set(requiredSections.map(({ level, name }) => `${String(level)}\0${pythonStrip(baseOf(name))}`));
|
|
451
|
+
const { lines, hasUnclosedFence } = maskedLines(body);
|
|
452
|
+
if (hasUnclosedFence)
|
|
453
|
+
return [];
|
|
454
|
+
const extra = [];
|
|
455
|
+
for (const line of lines) {
|
|
456
|
+
const heading = parseTemplateHeading(line);
|
|
457
|
+
if (heading === undefined || heading.level > 3)
|
|
458
|
+
continue;
|
|
459
|
+
const name = pythonStrip(baseOf(heading.name));
|
|
460
|
+
if (allowed.has(`${String(heading.level)}\0${name}`))
|
|
461
|
+
continue;
|
|
462
|
+
const label = `${'#'.repeat(heading.level)} ${name}`;
|
|
463
|
+
if (!extra.includes(label))
|
|
464
|
+
extra.push(label);
|
|
465
|
+
}
|
|
466
|
+
return extra;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
折りたたみの開閉部分(`<summary>`)が全て expected の形かを判定する。
|
|
470
|
+
コードフェンス・インラインコード・HTML コメントの中の `<summary>` は対象外。
|
|
471
|
+
開きタグの位置から expected と一字一句一致するかを見るため、属性・文言・閉じタグのどれが違っても違反になる
|
|
472
|
+
*/
|
|
473
|
+
export function validateFoldSummaries(body, expected) {
|
|
474
|
+
const { lines, hasUnclosedFence } = maskedLines(body);
|
|
475
|
+
if (hasUnclosedFence)
|
|
476
|
+
return [];
|
|
477
|
+
const errors = [];
|
|
478
|
+
for (const maskedLine of lines) {
|
|
479
|
+
for (const match of tokensIn(maskedLine)) {
|
|
480
|
+
const token = match.text;
|
|
481
|
+
const tag = HTML_TAG_PATTERN.exec(token);
|
|
482
|
+
if (tag === null || (tag[1] ?? '').toLowerCase() !== 'summary' || token.startsWith('</') || maskedLine.startsWith(expected, match.index))
|
|
483
|
+
continue;
|
|
484
|
+
const message = `${pythonStrip(maskedLine)} must be ${expected}`;
|
|
485
|
+
if (!errors.includes(message))
|
|
486
|
+
errors.push(message);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return errors;
|
|
490
|
+
}
|
|
491
|
+
const SUMMARY_HEADING_PATTERN = /^ {0,3}##\s+Summary(?:\s|$)/u;
|
|
492
|
+
const LEVEL_1_OR_2_HEADING_PATTERN = /^ {0,3}#{1,2}(?:\s|$)/u;
|
|
493
|
+
const IMAGE_ALT = String.raw `(?:[^[\]]|\[[^[\]]*\])*`;
|
|
494
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- 固定の文字列から組み立てる。代替文は角括弧の入れ子 1 段までで、再試行は入力の長さに比例して増えない
|
|
495
|
+
const IMAGE_PATTERN = new RegExp(String.raw `!\[${IMAGE_ALT}\]\([^)]+\)|!\[${IMAGE_ALT}\]\[[^\]]*\]|<img(?![\p{L}\p{N}_])`, 'iu');
|
|
496
|
+
/**
|
|
497
|
+
Summary 節に画像の参照(Markdown 記法か `<img`)があるか。フェンス・インラインコード・HTML コメントの中は数えない。
|
|
498
|
+
記法は網羅しない。取りこぼしは screenshot の理由で避けられる
|
|
499
|
+
*/
|
|
500
|
+
export function hasSummaryImage(body) {
|
|
501
|
+
const { lines } = maskedLines(body);
|
|
502
|
+
const start = lines.findIndex(line => SUMMARY_HEADING_PATTERN.test(line));
|
|
503
|
+
if (start === -1)
|
|
504
|
+
return false;
|
|
505
|
+
const section = [];
|
|
506
|
+
const following = lines.slice(start + 1);
|
|
507
|
+
for (const line of following) {
|
|
508
|
+
if (LEVEL_1_OR_2_HEADING_PATTERN.test(line))
|
|
509
|
+
break;
|
|
510
|
+
section.push(line);
|
|
511
|
+
}
|
|
512
|
+
return IMAGE_PATTERN.test(section.join('\n'));
|
|
513
|
+
}
|
|
514
|
+
//# sourceMappingURL=sections.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JsonValue } from './python-format.js';
|
|
2
|
+
/**
|
|
3
|
+
一覧を取る種類。Dependabot は dependabot-source.ts の取得元が受け持つ
|
|
4
|
+
*/
|
|
5
|
+
export type ScanKind = 'code-scanning' | 'secret-scanning';
|
|
6
|
+
/**
|
|
7
|
+
kind で判別する。ok は取れた alert そのもの(件数と番号は domain が数える)。unconfirmed は一覧を読めず無効とも確かめられない(権限不足など)。failure は API エラー、network は応答なし
|
|
8
|
+
*/
|
|
9
|
+
export type ScanListResult = {
|
|
10
|
+
readonly kind: 'ok';
|
|
11
|
+
readonly alerts: readonly JsonValue[];
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'disabled';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'unconfirmed';
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'failure';
|
|
18
|
+
readonly message: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'network';
|
|
21
|
+
readonly message: string;
|
|
22
|
+
};
|
|
23
|
+
export interface ScanAlertSource {
|
|
24
|
+
/**
|
|
25
|
+
open な alert を全件取る
|
|
26
|
+
*/
|
|
27
|
+
readonly listOpenAlerts: (kind: ScanKind, owner: string, repository: string) => Promise<ScanListResult>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=security-alerts-source.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// code scanning と secret scanning の alert の取得元の型。domain/security-alerts.ts が使い、GitHub を使う実体は infra/github/security-alerts-source.ts に置く。
|
|
2
|
+
// 「無効」「解析なし」の見分けは取得元が済ませる。結果は判別共用体(kind)で返すので、domain のテストはメモリ上の実装で書ける。
|
|
3
|
+
export {};
|
|
4
|
+
//# sourceMappingURL=security-alerts-source.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { DependabotSource } from './dependabot-source.js';
|
|
2
|
+
import { PecotError } from './errors.js';
|
|
3
|
+
import type { JsonValue } from './python-format.js';
|
|
4
|
+
import type { ScanAlertSource, ScanKind } from './security-alerts-source.js';
|
|
5
|
+
export type AlertKind = 'dependabot' | ScanKind;
|
|
6
|
+
/**
|
|
7
|
+
種類の並び。Tracker の見出しと行の並びはこの順
|
|
8
|
+
*/
|
|
9
|
+
export declare const ALERT_KINDS: readonly AlertKind[];
|
|
10
|
+
/**
|
|
11
|
+
Tracker の見出しとエラー文に出す種類の表示名
|
|
12
|
+
*/
|
|
13
|
+
export declare function kindLabel(kind: AlertKind): string;
|
|
14
|
+
/**
|
|
15
|
+
security alert の状態を判定できない
|
|
16
|
+
*/
|
|
17
|
+
export declare class SecurityAlertError extends PecotError {
|
|
18
|
+
}
|
|
19
|
+
export interface ScanAlertStatus {
|
|
20
|
+
readonly enabled: boolean;
|
|
21
|
+
/**
|
|
22
|
+
open の alert 件数(無効なら 0)
|
|
23
|
+
*/
|
|
24
|
+
readonly openCount: number;
|
|
25
|
+
/**
|
|
26
|
+
alert 一覧の Web URL
|
|
27
|
+
*/
|
|
28
|
+
readonly alertsUrl: string;
|
|
29
|
+
/**
|
|
30
|
+
open の alert 番号(昇順)
|
|
31
|
+
*/
|
|
32
|
+
readonly openNumbers: readonly number[];
|
|
33
|
+
}
|
|
34
|
+
export interface AlertSources {
|
|
35
|
+
readonly scan: ScanAlertSource;
|
|
36
|
+
readonly dependabot: DependabotSource;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
種類ごとの open の alert(API の応答そのもの)を取る。機能が無効のリポは undefined。
|
|
40
|
+
一覧を取得できず無効とも言えないとき(API エラー・通信エラー・権限不足)は SecurityAlertError
|
|
41
|
+
*/
|
|
42
|
+
export declare function listOpenAlerts(sources: AlertSources, kind: AlertKind, owner: string, repository: string): Promise<readonly JsonValue[] | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
code scanning の open の alert 数を取る(既定ブランチが対象)。状態を判定できなければ SecurityAlertError
|
|
45
|
+
*/
|
|
46
|
+
export declare function fetchCodeScanningStatus(source: ScanAlertSource, host: string, owner: string, repository: string): Promise<ScanAlertStatus>;
|
|
47
|
+
/**
|
|
48
|
+
secret scanning の open の alert 数を取る(値は取得しない)。
|
|
49
|
+
権限不足などで無効と確かめられないときも SecurityAlertError
|
|
50
|
+
*/
|
|
51
|
+
export declare function fetchSecretScanningStatus(source: ScanAlertSource, host: string, owner: string, repository: string): Promise<ScanAlertStatus>;
|
|
52
|
+
//# sourceMappingURL=security-alerts.d.ts.map
|