@pecot/workflow-mcp 0.0.0-stage → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +184 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +227 -0
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +59 -0
- package/cli/dist/commands/board-judgment.d.ts +60 -0
- package/cli/dist/commands/board-judgment.js +144 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +57 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +72 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +111 -0
- package/cli/dist/commands/board-view.d.ts +62 -0
- package/cli/dist/commands/board-view.js +191 -0
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +100 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +270 -0
- package/cli/dist/commands/command-definition.d.ts +150 -0
- package/cli/dist/commands/command-definition.js +105 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +21 -0
- package/cli/dist/commands/command-stop.js +31 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +34 -0
- package/cli/dist/commands/failure.d.ts +19 -0
- package/cli/dist/commands/failure.js +59 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +16 -0
- package/cli/dist/commands/github-client.js +33 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +50 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +71 -0
- package/cli/dist/commands/issue-board.js +122 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +215 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +786 -0
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +282 -0
- package/cli/dist/commands/issue-readiness.d.ts +94 -0
- package/cli/dist/commands/issue-readiness.js +218 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +115 -0
- package/cli/dist/commands/issue-shared.d.ts +172 -0
- package/cli/dist/commands/issue-shared.js +426 -0
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +169 -0
- package/cli/dist/commands/issue.d.ts +3 -0
- package/cli/dist/commands/issue.js +13 -0
- package/cli/dist/commands/names.d.ts +42 -0
- package/cli/dist/commands/names.js +78 -0
- package/cli/dist/commands/output.d.ts +90 -0
- package/cli/dist/commands/output.js +194 -0
- package/cli/dist/commands/pr-waiting.d.ts +20 -0
- package/cli/dist/commands/pr-waiting.js +106 -0
- package/cli/dist/commands/pr.d.ts +22 -0
- package/cli/dist/commands/pr.js +852 -0
- package/cli/dist/commands/project-sync.d.ts +92 -0
- package/cli/dist/commands/project-sync.js +282 -0
- package/cli/dist/commands/project.d.ts +6 -0
- package/cli/dist/commands/project.js +714 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +30 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +353 -0
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +34 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +267 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +236 -0
- package/cli/dist/commands/session.d.ts +6 -0
- package/cli/dist/commands/session.js +214 -0
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-security.js +153 -0
- package/cli/dist/commands/tracker-sync.d.ts +65 -0
- package/cli/dist/commands/tracker-sync.js +50 -0
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +18 -0
- package/cli/dist/commands/usage-error.d.ts +51 -0
- package/cli/dist/commands/usage-error.js +78 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +22 -0
- package/cli/dist/commands/work-target.js +82 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +339 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +219 -0
- package/cli/dist/domain/config.js +310 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +24 -0
- package/cli/dist/domain/errors.js +36 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +94 -0
- package/cli/dist/domain/format.js +234 -0
- package/cli/dist/domain/frontmatter.d.ts +137 -0
- package/cli/dist/domain/frontmatter.js +290 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +143 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +201 -0
- package/cli/dist/domain/pull-request.js +281 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +199 -0
- package/cli/dist/domain/readiness.js +391 -0
- package/cli/dist/domain/reference-parser.d.ts +51 -0
- package/cli/dist/domain/reference-parser.js +123 -0
- package/cli/dist/domain/release.d.ts +53 -0
- package/cli/dist/domain/release.js +65 -0
- package/cli/dist/domain/repository-policy.d.ts +38 -0
- package/cli/dist/domain/repository-policy.js +66 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +122 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +59 -0
- package/cli/dist/domain/state.js +95 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +72 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +53 -0
- package/cli/dist/infra/config-store.js +134 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +86 -0
- package/cli/dist/infra/git.js +145 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +178 -0
- package/cli/dist/infra/github/client.js +579 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +65 -0
- package/cli/dist/infra/github/errors.js +64 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +165 -0
- package/cli/dist/infra/github/issues.js +428 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +143 -0
- package/cli/dist/infra/github/projects.js +384 -0
- package/cli/dist/infra/github/pulls.d.ts +104 -0
- package/cli/dist/infra/github/pulls.js +217 -0
- package/cli/dist/infra/github/queries.d.ts +44 -0
- package/cli/dist/infra/github/queries.js +1031 -0
- package/cli/dist/infra/github/readout.d.ts +22 -0
- package/cli/dist/infra/github/readout.js +167 -0
- package/cli/dist/infra/github/repos.d.ts +86 -0
- package/cli/dist/infra/github/repos.js +168 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +54 -0
- package/cli/dist/infra/state-store.js +130 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +142 -0
- package/cli/dist/infra/worktree-links.js +440 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +185 -0
- package/cli/dist/infra/worktree.js +584 -0
- package/cli/dist/mcp/result.d.ts +61 -0
- package/cli/dist/mcp/result.js +96 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +142 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +195 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +74 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// PR コマンドの入出力を持たない関数。本文の検証、Closes の抽出と追記、`pr show` の Markdown の整形、preflight の警告の判定。
|
|
2
|
+
// 引数の型は、infra/github/pulls.ts の返す値が構造として満たす形をここに持つ(domain は infra を import できない)。
|
|
3
|
+
import { hinted, inputHint, inputNameHint } from './command-hint.js';
|
|
4
|
+
import { parsePythonInteger, pythonRightStrip, pythonStrip, splitCodePoints, truncateCodePoints } from './python-format.js';
|
|
5
|
+
import { hasSummaryImage, validateBodyStyle, validateHeadingSummaries, validateSections } from './sections.js';
|
|
6
|
+
// Issue 参照(`#N`、URL 内のフラグメントは除く)。`owner/repo#N` の形も受ける
|
|
7
|
+
const ISSUE_REFERENCE_PATTERN = /(?:^|[^/])#\d+|[\w-]+\/[\w.-]+#\d+/u;
|
|
8
|
+
// Python の `\s`(str.isspace)と同じ空白
|
|
9
|
+
const PYTHON_SPACE = String.raw `[\t\n\v\f\r\u{1C}-\u{20}\u{85}\u{A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}]`;
|
|
10
|
+
// GitHub が認識する close・fix・resolve と、それぞれの -s / -es / -d 付きの形。`owner/repo#N` の形も受ける
|
|
11
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- 固定の文字列から組み立てる
|
|
12
|
+
const CLOSING_KEYWORDS_PATTERN = new RegExp(String.raw `(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)${PYTHON_SPACE}+(?:[\w-]+/[\w.-]+)?#(\p{Nd}+)`, 'giu');
|
|
13
|
+
// stash の件数を数える行の区切り。str.splitlines と同じ。
|
|
14
|
+
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex -- 区切りの制御文字と誤検知
|
|
15
|
+
const LINE_BREAK = /\r\n|[\n\r\v\f\u{1C}-\u{1E}\u{85}\u{2028}\u{2029}]/u;
|
|
16
|
+
const PR_CREATE_PATH = ['pr', 'create'];
|
|
17
|
+
export const SCREENSHOT_MISSING_ERROR = hinted `Summary has no image and \`screenshot\` gives no reason to omit one. If the change alters a screen, Markdown the tool writes for GitHub, or CLI output text, take a screenshot and add it to Summary as \`\`. Otherwise, write the reason in the \`screenshot\` frontmatter field (\`${inputNameHint(PR_CREATE_PATH, 'screenshot')}\` with \`${inputNameHint(PR_CREATE_PATH, 'message')}\`)`;
|
|
18
|
+
/**
|
|
19
|
+
本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
|
|
20
|
+
*/
|
|
21
|
+
export function extractClosingIssueNumbers(body) {
|
|
22
|
+
const numbers = [];
|
|
23
|
+
body.replaceAll(CLOSING_KEYWORDS_PATTERN, (matched, digits) => {
|
|
24
|
+
numbers.push(Number(parsePythonInteger(digits)));
|
|
25
|
+
return matched;
|
|
26
|
+
});
|
|
27
|
+
return [...new Set(numbers)];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
本文にその Issue 番号の参照が無ければ、末尾に `Closes #N` を足す。あればそのまま返す
|
|
31
|
+
*/
|
|
32
|
+
export function appendIssueCloseIfNeeded(body, issueNumber) {
|
|
33
|
+
// URL 内のフラグメントは (^|[^/]) で除く。直後に数字が続くものは否定の先読みで除く
|
|
34
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- Issue 番号は整数
|
|
35
|
+
const pattern = new RegExp(String.raw `(^|[^/])#${String(issueNumber)}(?!\p{Nd})`, 'u');
|
|
36
|
+
return pattern.test(body) ? body : `${pythonRightStrip(body)}\n\nCloses #${String(issueNumber)}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
本文に Issue 参照(`#N` か `owner/repo#N`)があるか
|
|
40
|
+
*/
|
|
41
|
+
export function hasIssueReference(body) {
|
|
42
|
+
return ISSUE_REFERENCE_PATTERN.test(body);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
リリース PR か。release テンプレート、または develop から release への PR
|
|
46
|
+
*/
|
|
47
|
+
export function isReleasePullRequest(template, base, head, developBranch, releaseBranch) {
|
|
48
|
+
return template === 'release' || (releaseBranch !== undefined && releaseBranch !== '' && base === releaseBranch && head === developBranch);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
PR の内容を検証し、エラーの文を返す(無ければ空)。ブランチ設定の欠けは、呼び出し側が先に止める
|
|
52
|
+
*/
|
|
53
|
+
export function validatePullRequestContent(options) {
|
|
54
|
+
const { body, base, developBranch, releaseBranch, requiredSections } = options;
|
|
55
|
+
const errors = [];
|
|
56
|
+
const isRelease = isReleasePullRequest(options.template, base, options.head, developBranch, releaseBranch);
|
|
57
|
+
if (!isRelease && !options.skipIssueReferenceCheck && !hasIssueReference(body)) {
|
|
58
|
+
errors.push(hinted `PR body has no Issue reference \`#N\` (use \`${inputHint(PR_CREATE_PATH, 'no_issue_ref')}\` for a PR not tied to an Issue)`);
|
|
59
|
+
}
|
|
60
|
+
if (requiredSections.length > 0) {
|
|
61
|
+
const missing = validateSections(body, requiredSections);
|
|
62
|
+
if (missing.length > 0)
|
|
63
|
+
errors.push(`missing sections: ${missing.join(', ')}`);
|
|
64
|
+
const summaryErrors = validateHeadingSummaries(body, requiredSections);
|
|
65
|
+
if (summaryErrors.length > 0)
|
|
66
|
+
errors.push(`heading summary rule violations: ${summaryErrors.join(', ')}`);
|
|
67
|
+
}
|
|
68
|
+
const styleErrors = validateBodyStyle(body);
|
|
69
|
+
if (styleErrors.length > 0)
|
|
70
|
+
errors.push(`disallowed syntax: ${styleErrors.join(', ')}`);
|
|
71
|
+
if (!isRelease && (options.screenshot === undefined || options.screenshot === '') && !hasSummaryImage(body)) {
|
|
72
|
+
errors.push(SCREENSHOT_MISSING_ERROR);
|
|
73
|
+
}
|
|
74
|
+
if (isRelease) {
|
|
75
|
+
if (releaseBranch !== undefined && releaseBranch !== '' && base !== releaseBranch)
|
|
76
|
+
errors.push(`release PR base branch must be ${releaseBranch} (given: ${base})`);
|
|
77
|
+
}
|
|
78
|
+
else if (developBranch !== undefined && developBranch !== '' && base !== developBranch) {
|
|
79
|
+
const { stackedBase } = options;
|
|
80
|
+
const isStacked = stackedBase !== undefined && stackedBase !== '' && stackedBase !== developBranch;
|
|
81
|
+
if (!isStacked)
|
|
82
|
+
errors.push(`base branch must be ${developBranch} (given: ${base})`);
|
|
83
|
+
else if (base !== stackedBase)
|
|
84
|
+
errors.push(`base branch must be ${developBranch} or ${stackedBase} (given: ${base})`);
|
|
85
|
+
}
|
|
86
|
+
return errors;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
base の記録と下の段の PR の状態から、PR を作る base とスタックへの登録を決める。
|
|
90
|
+
記録の base でも開発ブランチでもない base は、そのまま返して内容の検証で落とす
|
|
91
|
+
*/
|
|
92
|
+
export function decidePullRequestBase(input) {
|
|
93
|
+
const { reading, base, developBranch } = input;
|
|
94
|
+
if (reading.kind === 'malformed')
|
|
95
|
+
return { kind: 'stop', reason: 'malformed', content: reading.content };
|
|
96
|
+
if (reading.kind === 'development')
|
|
97
|
+
return { kind: 'use', base, stackOn: undefined, stackedBase: undefined, isLowerMerged: false };
|
|
98
|
+
const { branch } = reading.record;
|
|
99
|
+
const lower = input.lowerPullRequest;
|
|
100
|
+
if (lower === undefined || lower.state === 'CLOSED')
|
|
101
|
+
return { kind: 'stop', reason: 'no-open-pr', branch };
|
|
102
|
+
const isKnownBase = base === branch || base === developBranch;
|
|
103
|
+
if (lower.state === 'MERGED')
|
|
104
|
+
return { kind: 'use', base: isKnownBase ? developBranch : base, stackOn: undefined, stackedBase: branch, isLowerMerged: true };
|
|
105
|
+
if (base === developBranch)
|
|
106
|
+
return { kind: 'stop', reason: 'lower-open', branch, pullRequest: lower.number, base };
|
|
107
|
+
return { kind: 'use', base, stackOn: base === branch ? lower.number : undefined, stackedBase: branch, isLowerMerged: false };
|
|
108
|
+
}
|
|
109
|
+
const LOWER_STATE_ORDER = ['OPEN', 'MERGED', 'CLOSED'];
|
|
110
|
+
/**
|
|
111
|
+
下の段のブランチを head に持つ PR から、base を決める 1 本を選ぶ。fork でないもののうち、開いている・マージ済み・閉じた の順(同じ状態なら渡した順の先頭)
|
|
112
|
+
*/
|
|
113
|
+
export function pickLowerPullRequest(pullRequests) {
|
|
114
|
+
const own = pullRequests.filter(pullRequest => !pullRequest.isCrossRepository);
|
|
115
|
+
return LOWER_STATE_ORDER.map(state => own.find(pullRequest => pullRequest.state === state)).find(found => found !== undefined);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
止めた理由の文(`error: ` の前置きを含まない)。下の段の PR が無いときは、直し方の行を続ける
|
|
119
|
+
*/
|
|
120
|
+
export function describeBaseStop(stop) {
|
|
121
|
+
switch (stop.reason) {
|
|
122
|
+
case 'malformed': {
|
|
123
|
+
return [`.pecot-base is malformed: ${stop.content}`];
|
|
124
|
+
}
|
|
125
|
+
case 'no-open-pr': {
|
|
126
|
+
return [`base branch ${stop.branch} has no open PR`, `reopen the PR of ${stop.branch}, or create a new one, then run pr create again`];
|
|
127
|
+
}
|
|
128
|
+
case 'lower-open': {
|
|
129
|
+
return [`base branch must be ${stop.branch} while its PR #${String(stop.pullRequest)} is open (given: ${stop.base})`];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// ISO 8601 の先頭 10 文字(YYYY-MM-DD)。10 文字に満たなければ空
|
|
134
|
+
function datePart(timestamp) {
|
|
135
|
+
return timestamp !== null && splitCodePoints(timestamp).length >= 10 ? truncateCodePoints(timestamp, 10) : '';
|
|
136
|
+
}
|
|
137
|
+
function metaLine(pr) {
|
|
138
|
+
const parts = [`**State:** ${pr.state}`];
|
|
139
|
+
if (pr.is_draft)
|
|
140
|
+
parts.push('**Draft**');
|
|
141
|
+
if (pr.mergeable !== '')
|
|
142
|
+
parts.push(`**Mergeable:** ${pr.mergeable}`);
|
|
143
|
+
if (pr.comments > 0)
|
|
144
|
+
parts.push(`**Comments:** ${String(pr.comments)}`);
|
|
145
|
+
return parts.join(' | ');
|
|
146
|
+
}
|
|
147
|
+
function referencedIssueLine(issue) {
|
|
148
|
+
return ` - #${String(issue.number)}${issue.title === '' ? '' : ` ${issue.title}`}`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
`pr show` の既定の Markdown
|
|
152
|
+
*/
|
|
153
|
+
export function formatPullRequestMarkdown(pr) {
|
|
154
|
+
const lines = [`## PR #${String(pr.number)} ${pr.title}`, '', metaLine(pr), '', `**Branch:** \`${pr.head_ref}\` → \`${pr.base_ref}\``, ''];
|
|
155
|
+
if (pr.closing_issues.length > 0) {
|
|
156
|
+
lines.push('**Closing Issues:**', ...pr.closing_issues.map(issue => ` - #${String(issue.number)} ${issue.title}`), '');
|
|
157
|
+
}
|
|
158
|
+
if (pr.referenced_issues.length > 0) {
|
|
159
|
+
lines.push('**Referenced Issues:**', ...pr.referenced_issues.map(issue => referencedIssueLine(issue)), '');
|
|
160
|
+
}
|
|
161
|
+
if (pr.reviews.length > 0) {
|
|
162
|
+
lines.push('**Reviews:**', ...pr.reviews.map(review => ` - ${review.author ?? 'None'}: ${review.state}`), '');
|
|
163
|
+
}
|
|
164
|
+
lines.push('---', '', pr.body);
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
レビュー本文の節。レビューが無ければ空文字
|
|
169
|
+
*/
|
|
170
|
+
export function formatReviewsMarkdown(reviews) {
|
|
171
|
+
if (reviews.length === 0)
|
|
172
|
+
return '';
|
|
173
|
+
const lines = ['## Reviews', ''];
|
|
174
|
+
for (const review of reviews) {
|
|
175
|
+
const author = review.author === null || review.author === '' ? '(unknown)' : review.author;
|
|
176
|
+
const date = datePart(review.submitted_at);
|
|
177
|
+
lines.push(`### @${author} (${review.state})${date === '' ? '' : ` - ${date}`}`);
|
|
178
|
+
const body = pythonStrip(review.body);
|
|
179
|
+
if (body !== '')
|
|
180
|
+
lines.push('', body);
|
|
181
|
+
lines.push('');
|
|
182
|
+
}
|
|
183
|
+
return lines.join('\n');
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
行コメント(reviewThreads)の節。無ければ空文字
|
|
187
|
+
*/
|
|
188
|
+
export function formatReviewThreadsMarkdown(threads) {
|
|
189
|
+
if (threads.length === 0)
|
|
190
|
+
return '';
|
|
191
|
+
const lines = ['## Line Comments', ''];
|
|
192
|
+
for (const thread of threads) {
|
|
193
|
+
const path = thread.path === null || thread.path === '' ? '(unknown file)' : thread.path;
|
|
194
|
+
const lineInfo = thread.line === null || thread.line === 0 ? '' : `:${String(thread.line)}`;
|
|
195
|
+
lines.push(`### \`${path}${lineInfo}\` [${thread.is_resolved ? 'Resolved' : 'Open'}]`, '');
|
|
196
|
+
for (const comment of thread.comments) {
|
|
197
|
+
const author = comment.author === null || comment.author === '' ? '(unknown)' : comment.author;
|
|
198
|
+
const date = datePart(comment.created_at);
|
|
199
|
+
lines.push(`**@${author}**${date === '' ? '' : ` (${date})`}:`);
|
|
200
|
+
const body = pythonStrip(comment.body);
|
|
201
|
+
if (body !== '')
|
|
202
|
+
lines.push(...body.split('\n').map(line => `> ${line}`));
|
|
203
|
+
lines.push('');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return lines.join('\n');
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
`pr show --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
|
|
210
|
+
*/
|
|
211
|
+
export function formatPullRequestWithReviewsMarkdown(pr, owner, repository) {
|
|
212
|
+
const lines = [`## PR #${String(pr.number)} ${pr.title}`, '', metaLine(pr), '', `**Branch:** \`${pr.head_ref}\` → \`${pr.base_ref}\``, ''];
|
|
213
|
+
const detailsLine = (issue) => ` → details: issue show ${owner}/${repository}/${String(issue.number)}`;
|
|
214
|
+
if (pr.closing_issues.length > 0) {
|
|
215
|
+
lines.push('**Closing Issues:**');
|
|
216
|
+
for (const issue of pr.closing_issues)
|
|
217
|
+
lines.push(` - #${String(issue.number)} ${issue.title}`, detailsLine(issue));
|
|
218
|
+
lines.push('');
|
|
219
|
+
}
|
|
220
|
+
if (pr.referenced_issues.length > 0) {
|
|
221
|
+
lines.push('**Referenced Issues:**');
|
|
222
|
+
for (const issue of pr.referenced_issues)
|
|
223
|
+
lines.push(referencedIssueLine(issue), detailsLine(issue));
|
|
224
|
+
lines.push('');
|
|
225
|
+
}
|
|
226
|
+
lines.push('---', '', pr.body, '');
|
|
227
|
+
const reviews = formatReviewsMarkdown(pr.reviews);
|
|
228
|
+
if (reviews !== '')
|
|
229
|
+
lines.push('---', '', reviews);
|
|
230
|
+
const threads = formatReviewThreadsMarkdown(pr.review_threads);
|
|
231
|
+
if (threads !== '')
|
|
232
|
+
lines.push('---', '', threads);
|
|
233
|
+
return lines.join('\n');
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
`git status` の出力に変更があるか。空・取得失敗の印・「nothing to commit」かつ「working tree clean」は無し
|
|
237
|
+
*/
|
|
238
|
+
export function hasStatusChanges(gitStatus) {
|
|
239
|
+
const stripped = pythonStrip(gitStatus);
|
|
240
|
+
return stripped !== '' && stripped !== '(git status failed)' && !(gitStatus.includes('nothing to commit') && gitStatus.includes('working tree clean'));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
stash の一覧の文字列に、stash の項目があるか(「(no stash)」と取得失敗の印は無し)
|
|
244
|
+
*/
|
|
245
|
+
export function hasStashEntries(stashList) {
|
|
246
|
+
return stashList !== '(no stash)' && !stashList.startsWith('(git stash');
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
ahead と behind のコミット数から、push の状態の文を作る
|
|
250
|
+
*/
|
|
251
|
+
export function describePushStatus(remote, branch, ahead, behind) {
|
|
252
|
+
if (ahead === 0 && behind === 0)
|
|
253
|
+
return { isPushed: true, message: `in sync with ${remote}/${branch}` };
|
|
254
|
+
if (behind === 0)
|
|
255
|
+
return { isPushed: false, message: `${String(ahead)} unpushed commits` };
|
|
256
|
+
if (ahead === 0)
|
|
257
|
+
return { isPushed: true, message: `${remote}/${branch} is ${String(behind)} commits ahead (pull recommended)` };
|
|
258
|
+
return { isPushed: false, message: `diverged: local is ${String(ahead)} commits ahead, ${remote}/${branch} is ${String(behind)} ahead` };
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
警告を、未 push・変更あり・stash ありの順で返す
|
|
262
|
+
*/
|
|
263
|
+
export function collectPreflightWarnings(facts) {
|
|
264
|
+
const warnings = [];
|
|
265
|
+
if (!facts.isPushed)
|
|
266
|
+
warnings.push({ label: 'Push Status', message: facts.pushMessage, fixHint: 'git push' });
|
|
267
|
+
if (hasStatusChanges(facts.gitStatus))
|
|
268
|
+
warnings.push({ label: 'Git Status', message: 'modified or untracked files', fixHint: 'commit' });
|
|
269
|
+
if (hasStashEntries(facts.stashList)) {
|
|
270
|
+
const count = facts.stashList.split(LINE_BREAK).filter(line => pythonStrip(line) !== '').length;
|
|
271
|
+
warnings.push({ label: 'Stash List', message: `${String(count)} stash entries`, fixHint: 'check them' });
|
|
272
|
+
}
|
|
273
|
+
return warnings;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
警告 1 行の文
|
|
277
|
+
*/
|
|
278
|
+
export function formatPreflightWarning(warning) {
|
|
279
|
+
return `${warning.label}: ${warning.message} (fix: ${warning.fixHint})`;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=pull-request.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { InvalidValueError } from './errors.js';
|
|
2
|
+
export type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
|
|
3
|
+
readonly [key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
universal newlines と同じ。`\r\n` と `\r` を `\n` に揃える(Python の text=True・read_text())
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeNewlines(text: string): string;
|
|
9
|
+
/**
|
|
10
|
+
sorted() の str の並べ方に使う比較。UTF-16 の単位順で比べる(BMP 内では Python のコードポイント順と同じ)
|
|
11
|
+
*/
|
|
12
|
+
export declare function compareStrings(a: string, b: string): number;
|
|
13
|
+
/**
|
|
14
|
+
str.rstrip() と同じ
|
|
15
|
+
*/
|
|
16
|
+
export declare function pythonRightStrip(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
文字列をコードポイントに分ける。Python の len・スライスと同じ単位(UTF-16 の単位ではない)
|
|
19
|
+
*/
|
|
20
|
+
export declare function splitCodePoints(text: string): readonly string[];
|
|
21
|
+
/**
|
|
22
|
+
text[:limit] と同じ。コードポイント単位で切る
|
|
23
|
+
*/
|
|
24
|
+
export declare function truncateCodePoints(text: string, limit: number): string;
|
|
25
|
+
/**
|
|
26
|
+
str.strip() と同じ
|
|
27
|
+
*/
|
|
28
|
+
export declare function pythonStrip(text: string): string;
|
|
29
|
+
/**
|
|
30
|
+
repr(str) と同じ。引用符は、' を含み " を含まないときだけ "
|
|
31
|
+
*/
|
|
32
|
+
export declare function pythonStringRepr(text: string): string;
|
|
33
|
+
/**
|
|
34
|
+
repr(float) と同じ。指数表記になるのは、10 進の小数点位置が 16 を超える・-3 未満のとき
|
|
35
|
+
*/
|
|
36
|
+
export declare function pythonFloatRepr(value: number): string;
|
|
37
|
+
export declare function isJsonArray(value: JsonValue | undefined): value is readonly JsonValue[];
|
|
38
|
+
/**
|
|
39
|
+
JSON 値の repr。整数値の数は int、それ以外は float の書式にする
|
|
40
|
+
*/
|
|
41
|
+
export declare function pythonRepr(value: JsonValue): string;
|
|
42
|
+
/**
|
|
43
|
+
type(value).__name__ に当たる名前
|
|
44
|
+
*/
|
|
45
|
+
export declare function pythonTypeName(value: JsonValue | undefined): string;
|
|
46
|
+
/**
|
|
47
|
+
int(text) と同じ。前後の空白・符号・数字の間の `_`・Unicode の 10 進数字を受ける。
|
|
48
|
+
不正なら Python と同じ文の InvalidValueError ではなく undefined を返す(呼び出し側が文言を作る)
|
|
49
|
+
*/
|
|
50
|
+
export declare function parsePythonInteger(text: string): number | undefined;
|
|
51
|
+
export interface HttpStatusFailure {
|
|
52
|
+
readonly statusCode: number;
|
|
53
|
+
/**
|
|
54
|
+
応答の statusText。空ならそのまま空で出す(HTTP/1.1 の空の reason を空のまま出す Python の挙動)
|
|
55
|
+
*/
|
|
56
|
+
readonly statusText: string;
|
|
57
|
+
readonly url: string;
|
|
58
|
+
/**
|
|
59
|
+
Location ヘッダ。リダイレクトの状態(301・302・303・307・308)で、あるときだけ出る
|
|
60
|
+
*/
|
|
61
|
+
readonly location: string | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
2xx 以外の応答に対する、HTTP クライアントの raise_for_status の文
|
|
65
|
+
*/
|
|
66
|
+
export declare function formatHttpStatusError(failure: HttpStatusFailure): string;
|
|
67
|
+
export interface SystemFailure {
|
|
68
|
+
readonly code?: string | undefined;
|
|
69
|
+
readonly path?: string | undefined;
|
|
70
|
+
readonly dest?: string | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
OSError の文(`[Errno 2] No such file or directory: 'x'`)。errno の code が表に無いときは undefined
|
|
74
|
+
*/
|
|
75
|
+
export declare function formatOsError(failure: SystemFailure): string | undefined;
|
|
76
|
+
export interface ValidationIssue {
|
|
77
|
+
/**
|
|
78
|
+
エラーの種類(`missing`・`string_type`・`value_error` など)
|
|
79
|
+
*/
|
|
80
|
+
readonly type: string;
|
|
81
|
+
readonly location: readonly (string | number)[];
|
|
82
|
+
/**
|
|
83
|
+
`Field required` のような本文
|
|
84
|
+
*/
|
|
85
|
+
readonly message: string;
|
|
86
|
+
/**
|
|
87
|
+
エラーになった値。無いこと(undefined)も区別して持つ
|
|
88
|
+
*/
|
|
89
|
+
readonly input: JsonValue | undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
ValidationError の文。表題(モデル名)の後に、エラーごとに 3 行(場所・本文・案内 URL)が続く。
|
|
93
|
+
入力値の repr は、UTF-8 のバイト長が 50 を超えると省略する。
|
|
94
|
+
前 25 バイトと後ろ 24 バイトに収まる文字だけを残し、間を `...` でつなぐ
|
|
95
|
+
*/
|
|
96
|
+
export declare function formatValidationError(title: string, issues: readonly ValidationIssue[]): string;
|
|
97
|
+
/**
|
|
98
|
+
ValidationError に当たる例外。メッセージは formatValidationError の文
|
|
99
|
+
*/
|
|
100
|
+
export declare class ValidationFailure extends InvalidValueError {
|
|
101
|
+
readonly title: string;
|
|
102
|
+
readonly issues: readonly ValidationIssue[];
|
|
103
|
+
constructor(title: string, issues: readonly ValidationIssue[]);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=python-format.d.ts.map
|