@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,933 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスは利用者が指定する */
|
|
2
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は内部の状態を持つ */
|
|
3
|
+
// `pecot pr` の 4 コマンド(create・read・preflight・cleanup)。cli/commands/pr.py の移植。
|
|
4
|
+
// 途中で抜ける箇所は CommandExit を投げ、defineCommand が終了コードにする。
|
|
5
|
+
import { existsSync, statSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { describeApiError } from '../domain/api-error-detail.js';
|
|
9
|
+
import { extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
10
|
+
import { effectiveReleaseType, findRepository, getDevelopBranch, getFieldId, getOptionId, getReleaseBranch } from '../domain/config.js';
|
|
11
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
12
|
+
import { FrontmatterError } from '../domain/frontmatter.js';
|
|
13
|
+
import { parseRemoteUrl } from '../domain/git-url.js';
|
|
14
|
+
import { isEpicIssue } from '../domain/issue-kind.js';
|
|
15
|
+
import { jsonField } from '../domain/json.js';
|
|
16
|
+
import { appendIssueCloseIfNeeded, collectPreflightWarnings, describePushStatus, extractClosingIssueNumbers, formatPreflightWarning, formatPullRequestMarkdown, formatPullRequestWithReviewsMarkdown, isReleasePullRequest, validatePullRequestContent, } from '../domain/pull-request.js';
|
|
17
|
+
import { parsePythonInteger, pythonStrip } from '../domain/python-format.js';
|
|
18
|
+
import { ReferenceParseError, parsePullRequestReference } from '../domain/reference-parser.js';
|
|
19
|
+
import { AmbiguousRepositoryError, resolveRepository, splitOwnerRepository } from '../domain/repository-resolver.js';
|
|
20
|
+
import { FLAG_MERGE_SLASH_PENDING, FLAG_PECOT_ACTIVE, FLAG_PECOT_QUICK_MODE, FLAG_PECOT_SESSION_TITLE, FLAG_PR_CREATE_SLASH_PENDING, FLAG_WIP_BRANCH_LINKED } from '../domain/state.js';
|
|
21
|
+
import { loadActiveConfig } from '../infra/config-store.js';
|
|
22
|
+
import { parsePullRequestFile } from '../infra/frontmatter-file.js';
|
|
23
|
+
import { gitCurrentBranch, GitCommandError, gitRemoteUrl, gitRunnerFor, gitStdout, gitToplevel, primaryRemoteName, runGit } from '../infra/git.js';
|
|
24
|
+
import { GitHubAPIError, GitHubNotFoundError, isClosedByAnotherRequest, isMissingReferenceError } from '../infra/github/errors.js';
|
|
25
|
+
import { changedFiles, expectedScope, nxProjects, parseTitleScope } from '../infra/nx-scope.js';
|
|
26
|
+
import { isFileNotFound } from '../infra/os-error.js';
|
|
27
|
+
import { outputDirectory, OutputPathReservationError, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
|
|
28
|
+
import { consumeFlag, readFlag, removeFlag } from '../infra/state-store.js';
|
|
29
|
+
import { readTemplateSections, templateFile } from '../infra/template-store.js';
|
|
30
|
+
import { readTextFile } from '../infra/text-file.js';
|
|
31
|
+
import { getCurrentWorktreeName, isWorktreeEnvironment } from '../infra/worktree.js';
|
|
32
|
+
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
33
|
+
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
34
|
+
import { directorySchema } from './directory-option.js';
|
|
35
|
+
import { createGitHubClient } from './github-client.js';
|
|
36
|
+
import { createOutput } from './output.js';
|
|
37
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
38
|
+
import { settle } from './tracker-sync.js';
|
|
39
|
+
const PR_REFERENCE_DESCRIPTION = 'PR reference (`owner/repo/N`, or the short form `N` in the repository of `--repo`, or else of the git remote of the current directory)';
|
|
40
|
+
// 本文の検証の失敗。1(通信・設定・引数)と 2(preflight)と区別する
|
|
41
|
+
const VALIDATION_EXIT_CODE = 3;
|
|
42
|
+
const PREFLIGHT_EXIT_CODE = 2;
|
|
43
|
+
// Python の `{e}` に当たる、例外の文
|
|
44
|
+
function reasonOf(error) {
|
|
45
|
+
return error instanceof Error ? error.message : String(error);
|
|
46
|
+
}
|
|
47
|
+
function templateKindOf(template) {
|
|
48
|
+
return template === 'release' ? 'release' : 'create';
|
|
49
|
+
}
|
|
50
|
+
function isPositive(value) {
|
|
51
|
+
return value !== undefined && value !== 0;
|
|
52
|
+
}
|
|
53
|
+
function primaryRemote(directory) {
|
|
54
|
+
const name = primaryRemoteName(directory);
|
|
55
|
+
if (name === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
const url = gitRemoteUrl(directory, name);
|
|
58
|
+
if (url === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
try {
|
|
61
|
+
return { name, url, location: parseRemoteUrl(url) };
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof InvalidValueError)
|
|
65
|
+
return { name, url, location: undefined };
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// scope を nx のプロジェクトと比べる対象か。release_type が nx、base が develop、remote と作業ツリーが対象に合うときだけ
|
|
70
|
+
function nxScopeTarget(config, owner, repository, base, directory) {
|
|
71
|
+
const configured = findRepository(config, owner, repository);
|
|
72
|
+
if (configured === undefined || effectiveReleaseType(configured) !== 'nx' || (base !== getDevelopBranch(config, owner, repository)))
|
|
73
|
+
return undefined;
|
|
74
|
+
const found = primaryRemote(directory);
|
|
75
|
+
const location = found?.location;
|
|
76
|
+
const isSameRepository = location?.owner.toLowerCase() === owner.toLowerCase() && location.repository.toLowerCase() === repository.toLowerCase();
|
|
77
|
+
if (found === undefined || !isSameRepository)
|
|
78
|
+
return undefined;
|
|
79
|
+
const toplevel = gitToplevel({ cwd: directory });
|
|
80
|
+
return toplevel === undefined || !isRegularFile(path.join(toplevel, 'nx.json')) ? undefined : { toplevel, remote: found.name };
|
|
81
|
+
}
|
|
82
|
+
// Python の Path.is_file() と同じく、stat の失敗は「無い」と扱う
|
|
83
|
+
function isRegularFile(file) {
|
|
84
|
+
try {
|
|
85
|
+
return statSync(file).isFile();
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function expectedTitleScope(target, base, head, out) {
|
|
92
|
+
const projects = nxProjects(target.toplevel);
|
|
93
|
+
const files = projects === undefined ? undefined : changedFiles(target.toplevel, `${target.remote}/${base}`, head);
|
|
94
|
+
if (projects === undefined || files === undefined) {
|
|
95
|
+
out.warning('cannot read nx projects or the diff; skipped the PR title scope check');
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return expectedScope(files, projects);
|
|
99
|
+
}
|
|
100
|
+
function titleScopeErrors(query, out) {
|
|
101
|
+
const { config, owner, repository, title, base, head, directory, template, developBranch, releaseBranch } = query;
|
|
102
|
+
if (isReleasePullRequest(template, base, head, developBranch, releaseBranch))
|
|
103
|
+
return [];
|
|
104
|
+
const target = nxScopeTarget(config, owner, repository, base, directory);
|
|
105
|
+
if (target === undefined)
|
|
106
|
+
return [];
|
|
107
|
+
const expected = expectedTitleScope(target, base, head, out);
|
|
108
|
+
if (expected === undefined || expected.length === 0)
|
|
109
|
+
return [];
|
|
110
|
+
const given = parseTitleScope(title);
|
|
111
|
+
if (given !== undefined && new Set(given).size === new Set(expected).size && given.every(scope => expected.includes(scope)))
|
|
112
|
+
return [];
|
|
113
|
+
const shown = given === undefined ? 'none' : given.join(',');
|
|
114
|
+
return [`PR title scope must be ${expected.join(',')} (given: ${shown}; computed from the tags of the changed nx projects)`];
|
|
115
|
+
}
|
|
116
|
+
// pr create
|
|
117
|
+
function inReviewOperation(issueNumber) {
|
|
118
|
+
return { verb: 'set', target: `Issue #${String(issueNumber)} status to In Review` };
|
|
119
|
+
}
|
|
120
|
+
async function updateIssueStatusToInReview(config, client, location, headBranch, out) {
|
|
121
|
+
const issueNumber = extractIssueNumberFromBranch(headBranch);
|
|
122
|
+
if (issueNumber === undefined)
|
|
123
|
+
return;
|
|
124
|
+
const label = `Issue #${String(issueNumber)}`;
|
|
125
|
+
let itemId;
|
|
126
|
+
try {
|
|
127
|
+
itemId = await client.getItemIdByIssue(config.project.id, location.owner, location.repository, issueNumber);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
out.warning(`board item lookup for ${label} failed: ${reasonOf(error)}`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (itemId === undefined) {
|
|
134
|
+
out.warning(`${label} is not on the board; status not updated`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const optionId = getOptionId(config, 'workflow', 'in_review');
|
|
138
|
+
if (optionId === undefined) {
|
|
139
|
+
out.warning('workflow field has no in_review status; status not updated');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const fieldId = getFieldId(config, 'workflow');
|
|
143
|
+
if (fieldId === undefined) {
|
|
144
|
+
out.warning('workflow field not found; status not updated');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
await client.updateProjectItemField(config.project.id, itemId, fieldId, optionId);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
out.warning(`status update of ${label} failed: ${reasonOf(error)}`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
out.done(inReviewOperation(issueNumber));
|
|
155
|
+
}
|
|
156
|
+
function exitOnUnsetBranch(template, base, head, developBranch, releaseBranch, out) {
|
|
157
|
+
const isRelease = isReleasePullRequest(template, base, head, developBranch, releaseBranch);
|
|
158
|
+
if (isRelease && (releaseBranch === undefined || releaseBranch === '')) {
|
|
159
|
+
stopWith(out, 'release_branch is not set\nset it with: pecot project set-repo owner/repo --release-branch main');
|
|
160
|
+
}
|
|
161
|
+
if (!isRelease && (developBranch === undefined || developBranch === '')) {
|
|
162
|
+
stopWith(out, 'develop_branch is not set\nset it with: pecot project set-repo owner/repo --develop-branch develop');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function resolveHeadBranch(head, directory, out) {
|
|
166
|
+
if (head !== undefined && head !== '')
|
|
167
|
+
return head;
|
|
168
|
+
const current = gitCurrentBranch(directory);
|
|
169
|
+
return current === undefined || current === '' ? stopWith(out, 'cannot determine the head branch') : current;
|
|
170
|
+
}
|
|
171
|
+
async function appendCloseUnlessEpic(config, location, body, issueNumber, out) {
|
|
172
|
+
try {
|
|
173
|
+
const kind = await createGitHubClient(out, config.host).getIssueKind(location.owner, location.repository, issueNumber);
|
|
174
|
+
if (!isEpicIssue(kind))
|
|
175
|
+
return appendIssueCloseIfNeeded(body, issueNumber);
|
|
176
|
+
out.warning(`Issue #${String(issueNumber)} at the end of the branch is an Epic; Closes not added`);
|
|
177
|
+
return body;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof GitHubAPIError)
|
|
181
|
+
return appendIssueCloseIfNeeded(body, issueNumber);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function exitOnValidationErrors(errors, out) {
|
|
186
|
+
if (errors.length === 0)
|
|
187
|
+
return;
|
|
188
|
+
for (const error of errors)
|
|
189
|
+
out.error(error);
|
|
190
|
+
throw new CommandExit(VALIDATION_EXIT_CODE);
|
|
191
|
+
}
|
|
192
|
+
function createOperation(draft) {
|
|
193
|
+
const kind = draft.isDraft ? 'draft PR' : 'PR';
|
|
194
|
+
const suffix = draft.isRelease ? ' (release template)' : '';
|
|
195
|
+
return { verb: 'create', target: `${kind} ${draft.location.owner}/${draft.location.repository} ${draft.head} -> ${draft.base}: ${draft.title}${suffix}` };
|
|
196
|
+
}
|
|
197
|
+
function printPreflightWarnings(out, warnings) {
|
|
198
|
+
for (const warning of warnings)
|
|
199
|
+
out.warning(formatPreflightWarning(warning));
|
|
200
|
+
}
|
|
201
|
+
// git の読み取り。失敗は Python の文字列の印にする
|
|
202
|
+
function getGitStatus(cwd) {
|
|
203
|
+
return gitStdout(['status'], { cwd }) ?? '(git status failed)';
|
|
204
|
+
}
|
|
205
|
+
function getStashList(cwd) {
|
|
206
|
+
const stdout = gitStdout(['stash', 'list'], { cwd });
|
|
207
|
+
return stdout === undefined ? '(git stash list failed)' : pythonStrip(stdout) || '(no stash)';
|
|
208
|
+
}
|
|
209
|
+
function getPushStatus(branch, cwd, remote) {
|
|
210
|
+
const failed = { isPushed: false, message: '(git rev-list failed)' };
|
|
211
|
+
try {
|
|
212
|
+
if (runGit(['rev-parse', '--verify', `${remote}/${branch}`], { cwd }).exitCode !== 0) {
|
|
213
|
+
return { isPushed: false, message: `${remote}/${branch} does not exist (not pushed)` };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
if (isFileNotFound(error))
|
|
218
|
+
return { isPushed: false, message: '(git rev-parse failed)' };
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const ahead = gitStdout(['rev-list', '--count', `${remote}/${branch}..${branch}`], { cwd });
|
|
222
|
+
const behind = ahead === undefined ? undefined : gitStdout(['rev-list', '--count', `${branch}..${remote}/${branch}`], { cwd });
|
|
223
|
+
const aheadCount = ahead === undefined ? undefined : parsePythonInteger(pythonStrip(ahead));
|
|
224
|
+
const behindCount = behind === undefined ? undefined : parsePythonInteger(pythonStrip(behind));
|
|
225
|
+
return aheadCount === undefined || behindCount === undefined ? failed : describePushStatus(remote, branch, aheadCount, behindCount);
|
|
226
|
+
}
|
|
227
|
+
// pr create の早い確認と pr preflight が共有する前提。満たさなければ終了コード 1
|
|
228
|
+
function validatePullRequestContext(directory, out) {
|
|
229
|
+
if (gitToplevel({ cwd: directory }) === undefined)
|
|
230
|
+
stopWith(out, 'not a git repository');
|
|
231
|
+
const found = primaryRemote(directory);
|
|
232
|
+
if (found === undefined)
|
|
233
|
+
return stopWith(out, 'git remote not found');
|
|
234
|
+
const currentBranch = gitCurrentBranch(directory);
|
|
235
|
+
if (currentBranch === undefined)
|
|
236
|
+
return stopWith(out, 'cannot determine the current branch');
|
|
237
|
+
if (found.location === undefined)
|
|
238
|
+
return stopWith(out, 'cannot read repository info from the remote URL\ncheck it with: git remote -v');
|
|
239
|
+
return { remoteUrl: found.url, currentBranch, location: found.location, remoteName: found.name };
|
|
240
|
+
}
|
|
241
|
+
function runPreflightChecksOrExit(directory, out) {
|
|
242
|
+
const context = validatePullRequestContext(directory, out);
|
|
243
|
+
const push = getPushStatus(context.currentBranch, directory, context.remoteName);
|
|
244
|
+
const warnings = collectPreflightWarnings({ gitStatus: getGitStatus(directory), stashList: getStashList(directory), isPushed: push.isPushed, pushMessage: push.message });
|
|
245
|
+
if (warnings.length === 0)
|
|
246
|
+
return;
|
|
247
|
+
out.error('preflight found warnings; fix them before creating a PR');
|
|
248
|
+
printPreflightWarnings(out, warnings);
|
|
249
|
+
throw new CommandExit(PREFLIGHT_EXIT_CODE);
|
|
250
|
+
}
|
|
251
|
+
async function submitPullRequest(config, directory, draft, out) {
|
|
252
|
+
runPreflightChecksOrExit(directory, out);
|
|
253
|
+
const client = createGitHubClient(out, config.host);
|
|
254
|
+
let created;
|
|
255
|
+
try {
|
|
256
|
+
created = await client.createPullRequest(draft.location.owner, draft.location.repository, draft.title, draft.body, draft.head, draft.base, draft.isDraft);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
if (error instanceof GitHubAPIError)
|
|
260
|
+
return stopWith(out, `PR creation failed: ${error.message}`);
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
out.done(createOperation(draft));
|
|
264
|
+
if (!draft.isRelease)
|
|
265
|
+
await updateIssueStatusToInReview(config, client, draft.location, draft.head, out);
|
|
266
|
+
consumeFlag(FLAG_PR_CREATE_SLASH_PENDING);
|
|
267
|
+
const url = jsonField(created, 'html_url');
|
|
268
|
+
if (typeof url !== 'string')
|
|
269
|
+
return stopWith(out, 'PR was created, but the response has no html_url; find it on GitHub');
|
|
270
|
+
out.data(url);
|
|
271
|
+
}
|
|
272
|
+
// 検証して、dry-run なら計画を出し、そうでなければ投稿する。file と -m の両方がここを通る
|
|
273
|
+
async function validateAndSubmit(input, out) {
|
|
274
|
+
const { config, directory, template, location, title, base, head } = input;
|
|
275
|
+
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
276
|
+
const releaseBranch = getReleaseBranch(config, location.owner, location.repository);
|
|
277
|
+
exitOnUnsetBranch(template, base, head, developBranch, releaseBranch, out);
|
|
278
|
+
const requiredSections = readTemplateSections(templateFile('pr', templateKindOf(template)));
|
|
279
|
+
const errors = [
|
|
280
|
+
...validatePullRequestContent({
|
|
281
|
+
body: input.body,
|
|
282
|
+
base,
|
|
283
|
+
developBranch,
|
|
284
|
+
releaseBranch,
|
|
285
|
+
head,
|
|
286
|
+
template,
|
|
287
|
+
skipIssueReferenceCheck: input.noIssueRef,
|
|
288
|
+
screenshot: input.screenshot,
|
|
289
|
+
requiredSections,
|
|
290
|
+
}),
|
|
291
|
+
...titleScopeErrors({ config, owner: location.owner, repository: location.repository, title, base, head, directory, template, developBranch, releaseBranch }, out),
|
|
292
|
+
];
|
|
293
|
+
exitOnValidationErrors(errors, out);
|
|
294
|
+
const isRelease = template === 'release';
|
|
295
|
+
const draft = { location, title, body: input.body, head, base, isDraft: input.isDraft, isRelease };
|
|
296
|
+
if (!input.dryRun) {
|
|
297
|
+
await submitPullRequest(config, directory, draft, out);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
out.planned(createOperation(draft));
|
|
301
|
+
const issueNumber = extractIssueNumberFromBranch(head);
|
|
302
|
+
if (!isRelease && issueNumber !== undefined)
|
|
303
|
+
out.planned(inReviewOperation(issueNumber));
|
|
304
|
+
}
|
|
305
|
+
function requireRepository(value, out) {
|
|
306
|
+
return splitOwnerRepository(value) ?? stopWith(out, `invalid repository format: ${value} (expected: owner/repo)`);
|
|
307
|
+
}
|
|
308
|
+
async function createFromFile(input, directory, out) {
|
|
309
|
+
const config = requireActiveConfigPlain(out);
|
|
310
|
+
let parsed;
|
|
311
|
+
try {
|
|
312
|
+
parsed = parsePullRequestFile(input.file);
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
if (error instanceof FrontmatterError)
|
|
316
|
+
return stopWith(out, error.message);
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
const { frontmatter } = parsed;
|
|
320
|
+
if (frontmatter.repository === '' || !frontmatter.repository.includes('/'))
|
|
321
|
+
return stopWith(out, 'repository is required (e.g. owner/repo)');
|
|
322
|
+
const location = requireRepository(frontmatter.repository, out);
|
|
323
|
+
const head = resolveHeadBranch(frontmatter.head, directory, out);
|
|
324
|
+
let body = parsed.body;
|
|
325
|
+
const issueNumber = extractIssueNumberFromBranch(head);
|
|
326
|
+
if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
|
|
327
|
+
body = await appendCloseUnlessEpic(config, location, body, issueNumber, out);
|
|
328
|
+
}
|
|
329
|
+
await validateAndSubmit({
|
|
330
|
+
config,
|
|
331
|
+
directory,
|
|
332
|
+
template: input.template,
|
|
333
|
+
noIssueRef: input.noIssueRef,
|
|
334
|
+
dryRun: input.dryRun,
|
|
335
|
+
location,
|
|
336
|
+
title: frontmatter.title,
|
|
337
|
+
base: frontmatter.base,
|
|
338
|
+
head,
|
|
339
|
+
isDraft: frontmatter.draft,
|
|
340
|
+
body,
|
|
341
|
+
screenshot: frontmatter.screenshot,
|
|
342
|
+
}, out);
|
|
343
|
+
}
|
|
344
|
+
async function createDirect(input, directory, out) {
|
|
345
|
+
const config = requireActiveConfigPlain(out);
|
|
346
|
+
let location;
|
|
347
|
+
if (input.repository === undefined || input.repository === '') {
|
|
348
|
+
const [only] = config.repositories;
|
|
349
|
+
if (only === undefined || config.repositories.length !== 1)
|
|
350
|
+
return stopWith(out, 'specify the repository (-r owner/repo)');
|
|
351
|
+
location = { owner: only.owner, repository: only.name };
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
location = requireRepository(input.repository, out);
|
|
355
|
+
}
|
|
356
|
+
const head = resolveHeadBranch(input.head, directory, out);
|
|
357
|
+
let body = input.message;
|
|
358
|
+
const issueNumber = extractIssueNumberFromBranch(head);
|
|
359
|
+
if (input.template !== 'release' && !input.noIssueRef && isPositive(issueNumber)) {
|
|
360
|
+
body = appendIssueCloseIfNeeded(body, issueNumber);
|
|
361
|
+
}
|
|
362
|
+
await validateAndSubmit({
|
|
363
|
+
config,
|
|
364
|
+
directory,
|
|
365
|
+
template: input.template,
|
|
366
|
+
noIssueRef: input.noIssueRef,
|
|
367
|
+
dryRun: input.dryRun,
|
|
368
|
+
location,
|
|
369
|
+
title: input.title,
|
|
370
|
+
base: input.base,
|
|
371
|
+
head,
|
|
372
|
+
isDraft: input.isDraft,
|
|
373
|
+
body,
|
|
374
|
+
screenshot: input.screenshot,
|
|
375
|
+
}, out);
|
|
376
|
+
}
|
|
377
|
+
// --prepare
|
|
378
|
+
function addScopeHint(content, config, location, base, directory, out) {
|
|
379
|
+
const target = nxScopeTarget(config, location.owner, location.repository, base, directory);
|
|
380
|
+
if (target === undefined)
|
|
381
|
+
return content;
|
|
382
|
+
const head = gitCurrentBranch(directory);
|
|
383
|
+
const expected = head === undefined || head === '' ? undefined : expectedTitleScope(target, base, head, out);
|
|
384
|
+
if (expected === undefined || expected.length === 0)
|
|
385
|
+
return content;
|
|
386
|
+
const scope = expected.join(',');
|
|
387
|
+
// コメントは閉じの引用符の後ろに置き、YAML の title を "" のままにする
|
|
388
|
+
const hinted = content.replace(/^(title:\s*"[^"]*")/mu, (_matched, title) => `${title} # expected scope: ${scope}`);
|
|
389
|
+
out.done({ verb: 'set', target: `title scope hint to ${scope}` });
|
|
390
|
+
return hinted;
|
|
391
|
+
}
|
|
392
|
+
async function fillClosesInTemplate(content, config, directory, location, out) {
|
|
393
|
+
let target;
|
|
394
|
+
const segments = readFlag(FLAG_PECOT_ACTIVE)?.split('/');
|
|
395
|
+
if (segments?.length === 3) {
|
|
396
|
+
const [activeOwner, activeRepository, digits] = segments;
|
|
397
|
+
const activeNumber = digits !== undefined && /^\p{Nd}+$/u.test(digits) ? parsePythonInteger(digits) : undefined;
|
|
398
|
+
if (activeOwner !== undefined && activeRepository !== undefined && activeNumber !== undefined)
|
|
399
|
+
target = { owner: activeOwner, repository: activeRepository, number: activeNumber };
|
|
400
|
+
}
|
|
401
|
+
if (target === undefined && location !== undefined) {
|
|
402
|
+
const branch = gitCurrentBranch(directory);
|
|
403
|
+
const branchNumber = branch === undefined || branch === '' ? undefined : extractIssueNumberFromBranch(branch);
|
|
404
|
+
if (isPositive(branchNumber))
|
|
405
|
+
target = { owner: location.owner, repository: location.repository, number: branchNumber };
|
|
406
|
+
}
|
|
407
|
+
if (target === undefined || target.owner === '' || target.repository === '')
|
|
408
|
+
return content;
|
|
409
|
+
const label = `Issue #${String(target.number)}`;
|
|
410
|
+
try {
|
|
411
|
+
const kind = await createGitHubClient(out, config?.host).getIssueKind(target.owner, target.repository, target.number);
|
|
412
|
+
if (isEpicIssue(kind)) {
|
|
413
|
+
out.warning(`${label} is an Epic; Closes left empty`);
|
|
414
|
+
return content;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
if (error instanceof GitHubAPIError) {
|
|
419
|
+
out.warning(`kind check of ${label} failed: ${error.message}; fill Closes by hand`);
|
|
420
|
+
return content;
|
|
421
|
+
}
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
const pattern = /^Closes #\s*$/mu;
|
|
425
|
+
if (!pattern.test(content))
|
|
426
|
+
return content;
|
|
427
|
+
out.done({ verb: 'set', target: `Closes to #${String(target.number)}` });
|
|
428
|
+
return content.replace(pattern, () => `Closes #${String(target.number)}`);
|
|
429
|
+
}
|
|
430
|
+
async function prepareTemplate(directory, out, template) {
|
|
431
|
+
const templatePath = templateFile('pr', templateKindOf(template));
|
|
432
|
+
if (!existsSync(templatePath))
|
|
433
|
+
stopWith(out, `template not found: ${templatePath}`);
|
|
434
|
+
let content = readTextFile(templatePath);
|
|
435
|
+
// release テンプレートは、base をテンプレートの既定(main)のままにする
|
|
436
|
+
if (template !== 'release') {
|
|
437
|
+
const location = primaryRemote(directory)?.location;
|
|
438
|
+
const config = loadActiveConfig();
|
|
439
|
+
if (location !== undefined) {
|
|
440
|
+
const developBranch = config === undefined ? undefined : getDevelopBranch(config, location.owner, location.repository);
|
|
441
|
+
if (config !== undefined && developBranch !== undefined && developBranch !== '') {
|
|
442
|
+
content = content.replace(/^base:\s*"[^"]*"/mu, () => `base: "${developBranch}"`);
|
|
443
|
+
out.done({ verb: 'set', target: `base to ${developBranch}` });
|
|
444
|
+
content = addScopeHint(content, config, { owner: location.owner, repository: location.repository }, developBranch, directory, out);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
content = await fillClosesInTemplate(content, config, directory, location, out);
|
|
448
|
+
}
|
|
449
|
+
const prefix = template === 'release' ? 'pr-release' : 'pr-create';
|
|
450
|
+
try {
|
|
451
|
+
withReservedOutputPath(outputDirectory(), timestamp => `${prefix}-${timestamp}.md`, (reserved) => {
|
|
452
|
+
writeFileSync(reserved, content, 'utf8');
|
|
453
|
+
out.data(reserved);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
catch (error) {
|
|
457
|
+
if (error instanceof OutputPathReservationError)
|
|
458
|
+
return stopWith(out, error.message);
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const CreateInputSchema = z.strictObject({
|
|
463
|
+
file: z.string().optional().describe('Path to a Markdown file with front matter'),
|
|
464
|
+
message: z.string().optional().describe('PR body, given directly'),
|
|
465
|
+
title: z.string().optional().describe('PR title (required with -m)'),
|
|
466
|
+
base: z.string().optional().describe('Base branch (required with -m)'),
|
|
467
|
+
head: z.string().optional().describe('Head branch (default: the current branch)'),
|
|
468
|
+
draft: z.boolean().default(false).describe('Create as a draft PR'),
|
|
469
|
+
prepare: z.boolean().default(false).describe('Copy the template to the work directory'),
|
|
470
|
+
dry_run: z.boolean().default(false).describe('Validate only (skip the early preflight check, do not create the PR)'),
|
|
471
|
+
repo: z.string().optional().describe('Repository in owner/repo form (with -m)'),
|
|
472
|
+
no_issue_ref: z.boolean().default(false).describe('Skip the automatic related-Issue setup (extraction from the branch name, adding it to the body, and the validation check)'),
|
|
473
|
+
template: z.string().default('default').describe('PR template kind (default / release)'),
|
|
474
|
+
screenshot: z.string().optional().describe('Reason to omit an image from Summary (with -m)'),
|
|
475
|
+
});
|
|
476
|
+
async function runCreate(input, io) {
|
|
477
|
+
const directory = process.cwd();
|
|
478
|
+
const out = createOutput(input.dry_run, io);
|
|
479
|
+
if (input.template !== 'default' && input.template !== 'release')
|
|
480
|
+
stopWith(out, `--template must be 'default' or 'release' (given: ${input.template})`);
|
|
481
|
+
if (input.prepare) {
|
|
482
|
+
await prepareTemplate(directory, createOutput(false, io), input.template);
|
|
483
|
+
}
|
|
484
|
+
else if (input.file !== undefined) {
|
|
485
|
+
if (input.screenshot !== undefined)
|
|
486
|
+
stopWith(out, '--screenshot is for -m; write the reason in the `screenshot` frontmatter field instead');
|
|
487
|
+
await createFromFile({ file: input.file, template: input.template, noIssueRef: input.no_issue_ref, dryRun: input.dry_run }, directory, out);
|
|
488
|
+
}
|
|
489
|
+
else if (input.message === undefined) {
|
|
490
|
+
stopWith(out, 'missing arguments\nusage:\npecot pr create --prepare\npecot pr create <path>\npecot pr create -m "<body>" -t "<title>" -b <base-branch>');
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
if (input.title === undefined || input.title === '' || input.base === undefined || input.base === '')
|
|
494
|
+
stopWith(out, '-t (title) and -b (base branch) are required with -m');
|
|
495
|
+
await createDirect({
|
|
496
|
+
message: input.message,
|
|
497
|
+
title: input.title,
|
|
498
|
+
base: input.base,
|
|
499
|
+
head: input.head,
|
|
500
|
+
isDraft: input.draft,
|
|
501
|
+
dryRun: input.dry_run,
|
|
502
|
+
repository: input.repo,
|
|
503
|
+
noIssueRef: input.no_issue_ref,
|
|
504
|
+
template: input.template,
|
|
505
|
+
screenshot: pythonStrip(input.screenshot ?? '') || undefined,
|
|
506
|
+
}, directory, out);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
// pr read
|
|
510
|
+
// グローバルの --repo か、いまの git の repository。決められなければ undefined
|
|
511
|
+
function resolveBaseRepository(globalRepository) {
|
|
512
|
+
try {
|
|
513
|
+
return resolveRepository(globalRepository, gitRunnerFor(process.cwd())).repository;
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
if (error instanceof AmbiguousRepositoryError)
|
|
517
|
+
return undefined;
|
|
518
|
+
throw error;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function parseReference(reference, globalRepository, out) {
|
|
522
|
+
try {
|
|
523
|
+
const parsed = parsePullRequestReference(reference, resolveBaseRepository(globalRepository), { repositoryFlag: true });
|
|
524
|
+
return { owner: parsed.repository.owner, repository: parsed.repository.repository, number: parsed.number };
|
|
525
|
+
}
|
|
526
|
+
catch (error) {
|
|
527
|
+
if (error instanceof ReferenceParseError)
|
|
528
|
+
return stopWith(out, error.message, USAGE_EXIT_CODE);
|
|
529
|
+
throw error;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const ReadInputSchema = z.strictObject({
|
|
533
|
+
pr_ref: z.string().describe(PR_REFERENCE_DESCRIPTION),
|
|
534
|
+
json: z.boolean().default(false).describe('Output as JSON'),
|
|
535
|
+
reviews: z.boolean().default(false).describe('Include review details (bodies and line comments)'),
|
|
536
|
+
});
|
|
537
|
+
async function runRead(input, io) {
|
|
538
|
+
const out = createOutput(false, io);
|
|
539
|
+
const config = requireActiveConfigPlain(out);
|
|
540
|
+
const { owner, repository, number } = parseReference(input.pr_ref, input.repo, out);
|
|
541
|
+
try {
|
|
542
|
+
const client = createGitHubClient(out, config.host);
|
|
543
|
+
if (input.reviews) {
|
|
544
|
+
const pr = await client.getPullRequestWithReviews(owner, repository, number);
|
|
545
|
+
out.data(`${input.json ? JSON.stringify(pr, undefined, 2) : formatPullRequestWithReviewsMarkdown(pr, owner, repository)}\n`);
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
const pr = await client.getPullRequestSlim(owner, repository, number);
|
|
549
|
+
out.data(`${input.json ? JSON.stringify(pr, undefined, 2) : formatPullRequestMarkdown(pr)}\n`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
if (error instanceof GitHubAPIError)
|
|
554
|
+
return stopWith(out, error.message);
|
|
555
|
+
throw error;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
// pr preflight
|
|
559
|
+
function hasBranch(branch, cwd) {
|
|
560
|
+
return runGit(['rev-parse', '--verify', branch], { cwd }).exitCode === 0;
|
|
561
|
+
}
|
|
562
|
+
function determineBaseBranch(location, cwd, remote, out) {
|
|
563
|
+
const config = loadActiveConfig();
|
|
564
|
+
if (config === undefined)
|
|
565
|
+
return stopWith(out, 'project config not found\nactivate a project with: pecot project activate <PROJECT>');
|
|
566
|
+
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
567
|
+
if (developBranch === undefined || developBranch === '') {
|
|
568
|
+
return stopWith(out, `develop_branch is not set for ${location.owner}/${location.repository}\nset it with: pecot project set-repo ${location.owner}/${location.repository} --develop-branch develop`);
|
|
569
|
+
}
|
|
570
|
+
const branchName = `${remote}/${developBranch}`;
|
|
571
|
+
return hasBranch(branchName, cwd) ? branchName : stopWith(out, `branch ${branchName} does not exist\ncheck the remote branches with: git branch -r`);
|
|
572
|
+
}
|
|
573
|
+
function readGitignore(cwd) {
|
|
574
|
+
const root = gitToplevel({ cwd });
|
|
575
|
+
if (root === undefined)
|
|
576
|
+
return '(not a git repository)';
|
|
577
|
+
const file = path.join(root, '.gitignore');
|
|
578
|
+
if (!existsSync(file))
|
|
579
|
+
return '(no .gitignore)';
|
|
580
|
+
try {
|
|
581
|
+
return readTextFile(file);
|
|
582
|
+
}
|
|
583
|
+
catch {
|
|
584
|
+
return '(read error)';
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function readGitExclude(cwd) {
|
|
588
|
+
try {
|
|
589
|
+
const common = gitStdout(['rev-parse', '--git-common-dir'], { cwd });
|
|
590
|
+
if (common === undefined)
|
|
591
|
+
return '(read error)';
|
|
592
|
+
const file = path.join(path.resolve(cwd, pythonStrip(common)), 'info', 'exclude');
|
|
593
|
+
return existsSync(file) ? readTextFile(file) : '(no exclude)';
|
|
594
|
+
}
|
|
595
|
+
catch {
|
|
596
|
+
return '(read error)';
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
function getWorktreeInfo(cwd) {
|
|
600
|
+
const listed = gitStdout(['worktree', 'list'], { cwd });
|
|
601
|
+
const lines = [listed === undefined ? '(git worktree list failed)' : pythonStrip(listed), '', `Current directory name: ${path.basename(cwd)}`];
|
|
602
|
+
const gitDirectory = gitStdout(['rev-parse', '--git-dir'], { cwd });
|
|
603
|
+
const commonDirectory = gitDirectory === undefined ? undefined : gitStdout(['rev-parse', '--git-common-dir'], { cwd });
|
|
604
|
+
if (gitDirectory === undefined || commonDirectory === undefined) {
|
|
605
|
+
lines.push('Is worktree environment: (unknown)');
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
const isWorktree = resolveRealPath(path.resolve(cwd, pythonStrip(gitDirectory))) !== resolveRealPath(path.resolve(cwd, pythonStrip(commonDirectory)));
|
|
609
|
+
lines.push(`Is worktree environment: ${isWorktree ? 'true' : 'false'}`);
|
|
610
|
+
}
|
|
611
|
+
return lines.join('\n');
|
|
612
|
+
}
|
|
613
|
+
const PreflightInputSchema = z.strictObject({
|
|
614
|
+
directory: directorySchema,
|
|
615
|
+
});
|
|
616
|
+
function runPreflight(input, io) {
|
|
617
|
+
const out = createOutput(false, io);
|
|
618
|
+
const directory = input.directory;
|
|
619
|
+
const context = validatePullRequestContext(directory, out);
|
|
620
|
+
const baseBranch = determineBaseBranch(context.location, directory, context.remoteName, out);
|
|
621
|
+
const gitStatus = getGitStatus(directory);
|
|
622
|
+
const commits = gitStdout(['log', '--oneline', `${baseBranch}..HEAD`], { cwd: directory });
|
|
623
|
+
const diffSummary = gitStdout(['diff', '--stat', `${baseBranch}...HEAD`], { cwd: directory });
|
|
624
|
+
const push = getPushStatus(context.currentBranch, directory, context.remoteName);
|
|
625
|
+
const stashList = getStashList(directory);
|
|
626
|
+
const sections = [
|
|
627
|
+
['=== Git Remote ===', context.remoteUrl],
|
|
628
|
+
['=== Current Branch ===', context.currentBranch],
|
|
629
|
+
['=== Push Status ===', push.message],
|
|
630
|
+
['=== Base Branch ===', baseBranch],
|
|
631
|
+
['=== Git Status ===', gitStatus],
|
|
632
|
+
['=== .gitignore ===', readGitignore(directory)],
|
|
633
|
+
['=== Git Exclude ===', readGitExclude(directory)],
|
|
634
|
+
[`=== Commits (vs ${baseBranch}) ===`, commits === undefined ? '(git log failed)' : pythonStrip(commits) || '(no commits)'],
|
|
635
|
+
[`=== Diff Summary (vs ${baseBranch}) ===`, diffSummary === undefined ? '(git diff failed)' : pythonStrip(diffSummary) || '(no diff)'],
|
|
636
|
+
['=== Worktree Info ===', getWorktreeInfo(directory)],
|
|
637
|
+
['=== Stash List ===', stashList],
|
|
638
|
+
];
|
|
639
|
+
for (const [index, [heading, content]] of sections.entries()) {
|
|
640
|
+
if (index > 0)
|
|
641
|
+
out.data('\n');
|
|
642
|
+
out.data(`${heading}\n`);
|
|
643
|
+
out.data(`${content}\n`);
|
|
644
|
+
}
|
|
645
|
+
const warnings = collectPreflightWarnings({ gitStatus, stashList, isPushed: push.isPushed, pushMessage: push.message });
|
|
646
|
+
out.count('preflight warnings', warnings.length);
|
|
647
|
+
printPreflightWarnings(out, warnings);
|
|
648
|
+
if (warnings.length > 0)
|
|
649
|
+
throw new CommandExit(PREFLIGHT_EXIT_CODE);
|
|
650
|
+
}
|
|
651
|
+
async function fetchPullRequestForCleanup(config, location, out) {
|
|
652
|
+
try {
|
|
653
|
+
const client = createGitHubClient(out, config.host);
|
|
654
|
+
return { client, pr: await client.getPullRequestSlim(location.owner, location.repository, location.number) };
|
|
655
|
+
}
|
|
656
|
+
catch (error) {
|
|
657
|
+
if (error instanceof GitHubNotFoundError)
|
|
658
|
+
return stopWith(out, `PR not found: ${location.owner}/${location.repository}/${String(location.number)}`);
|
|
659
|
+
if (error instanceof GitHubAPIError)
|
|
660
|
+
return stopWith(out, error.message);
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function collectClosingIssueNumbers(pr) {
|
|
665
|
+
const numbers = new Set(pr.closing_issues.map(issue => issue.number));
|
|
666
|
+
for (const number of extractClosingIssueNumbers(pr.body))
|
|
667
|
+
numbers.add(number);
|
|
668
|
+
const branchNumber = extractIssueNumberFromBranch(pr.head_ref);
|
|
669
|
+
if (isPositive(branchNumber))
|
|
670
|
+
numbers.add(branchNumber);
|
|
671
|
+
return numbers;
|
|
672
|
+
}
|
|
673
|
+
// Epic 保護。Issue Type が Epic か、sub-issue を持つ Issue
|
|
674
|
+
async function findEpicProtectedNumbers(client, location, issueNumbers, out) {
|
|
675
|
+
const protectedNumbers = new Set();
|
|
676
|
+
const ordered = [...issueNumbers].toSorted((a, b) => a - b);
|
|
677
|
+
for (const number of ordered) {
|
|
678
|
+
try {
|
|
679
|
+
if (isEpicIssue(await client.getIssueKind(location.owner, location.repository, number)))
|
|
680
|
+
protectedNumbers.add(number);
|
|
681
|
+
}
|
|
682
|
+
catch (error) {
|
|
683
|
+
if (error instanceof GitHubNotFoundError)
|
|
684
|
+
continue;
|
|
685
|
+
if (!(error instanceof GitHubAPIError))
|
|
686
|
+
throw error;
|
|
687
|
+
out.warning(`kind check of Issue #${String(number)} failed: ${error.message}; not protected`);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return protectedNumbers;
|
|
691
|
+
}
|
|
692
|
+
async function closeRelatedIssues(context, client, location, closing, epicProtected) {
|
|
693
|
+
const { out, isDryRun } = context;
|
|
694
|
+
const protectedOrdered = [...epicProtected].toSorted((a, b) => a - b);
|
|
695
|
+
const closingOrdered = [...closing].toSorted((a, b) => a - b);
|
|
696
|
+
for (const number of protectedOrdered)
|
|
697
|
+
settle(out, { verb: 'skip', target: `closing Issue #${String(number)} (Epic)` });
|
|
698
|
+
for (const number of closingOrdered) {
|
|
699
|
+
const operation = { verb: 'close', target: `Issue #${String(number)}` };
|
|
700
|
+
out.planned(operation);
|
|
701
|
+
if (isDryRun)
|
|
702
|
+
continue;
|
|
703
|
+
try {
|
|
704
|
+
await client.closeIssue(location.owner, location.repository, number);
|
|
705
|
+
out.done(operation);
|
|
706
|
+
}
|
|
707
|
+
catch (error) {
|
|
708
|
+
if (error instanceof GitHubNotFoundError) {
|
|
709
|
+
out.warning(`Issue #${String(number)} not found; skipped`);
|
|
710
|
+
}
|
|
711
|
+
else if (error instanceof GitHubAPIError) {
|
|
712
|
+
if (isClosedByAnotherRequest(error))
|
|
713
|
+
out.done({ verb: 'unchanged', target: `Issue #${String(number)} (already closed)` });
|
|
714
|
+
else
|
|
715
|
+
out.warning(`closing Issue #${String(number)} failed: ${describeApiError(error)}`);
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
throw error;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
// head ブランチを消し、続けて wip ブランチを消す。head が無くても wip は試す
|
|
724
|
+
async function deleteMergedBranch(context, client, location, headBranch) {
|
|
725
|
+
const { out, isDryRun } = context;
|
|
726
|
+
const operation = { verb: 'delete', target: `remote branch ${headBranch}` };
|
|
727
|
+
out.planned(operation);
|
|
728
|
+
if (isDryRun)
|
|
729
|
+
return;
|
|
730
|
+
try {
|
|
731
|
+
await client.deleteBranch(location.owner, location.repository, headBranch);
|
|
732
|
+
out.done(operation);
|
|
733
|
+
}
|
|
734
|
+
catch (error) {
|
|
735
|
+
if (!(error instanceof GitHubAPIError))
|
|
736
|
+
throw error;
|
|
737
|
+
if (!isMissingReferenceError(error)) {
|
|
738
|
+
out.warning(`deleting remote branch ${headBranch} failed: ${describeApiError(error)}`);
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
out.done({ verb: 'unchanged', target: `remote branch ${headBranch} (already deleted)` });
|
|
742
|
+
}
|
|
743
|
+
const wipBranch = `wip/${headBranch}`;
|
|
744
|
+
try {
|
|
745
|
+
await client.deleteBranch(location.owner, location.repository, wipBranch);
|
|
746
|
+
out.done({ verb: 'delete', target: `remote branch ${wipBranch}` });
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
if (!(error instanceof GitHubAPIError))
|
|
750
|
+
throw error;
|
|
751
|
+
if (!isMissingReferenceError(error))
|
|
752
|
+
out.warning(`deleting remote branch ${wipBranch} failed: ${describeApiError(error)}`);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
// 手元と PR の repository が同じなら主の remote 名。違えば警告を出して undefined
|
|
756
|
+
function sameRepositoryRemote(cwd, location, out) {
|
|
757
|
+
const skipped = 'skipped local cleanup';
|
|
758
|
+
try {
|
|
759
|
+
const found = primaryRemote(cwd);
|
|
760
|
+
if (found === undefined) {
|
|
761
|
+
out.warning(`cannot read the remote URL; ${skipped}`);
|
|
762
|
+
return undefined;
|
|
763
|
+
}
|
|
764
|
+
if (found.location === undefined) {
|
|
765
|
+
out.warning(`cannot read the repository from the remote URL; ${skipped}`);
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
if (found.location.owner !== location.owner || found.location.repository !== location.repository) {
|
|
769
|
+
out.warning(`current repository (${found.location.owner}/${found.location.repository}) differs from the PR's (${location.owner}/${location.repository}); ${skipped}`);
|
|
770
|
+
return undefined;
|
|
771
|
+
}
|
|
772
|
+
return found.name;
|
|
773
|
+
}
|
|
774
|
+
catch {
|
|
775
|
+
out.warning(`cannot determine the repository; ${skipped}`);
|
|
776
|
+
return undefined;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
// worktree では worktree 名、そうでなければ develop ブランチ
|
|
780
|
+
function resolveCheckoutTarget(cwd, config, location, out) {
|
|
781
|
+
try {
|
|
782
|
+
if (isWorktreeEnvironment(cwd))
|
|
783
|
+
return getCurrentWorktreeName(cwd) ?? 'main';
|
|
784
|
+
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
785
|
+
if (developBranch !== undefined && developBranch !== '')
|
|
786
|
+
return developBranch;
|
|
787
|
+
out.warning('develop_branch is not set; skipped local cleanup');
|
|
788
|
+
return undefined;
|
|
789
|
+
}
|
|
790
|
+
catch {
|
|
791
|
+
out.warning('cannot determine the worktree; skipped local cleanup');
|
|
792
|
+
return undefined;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
function didRunLocalStep(context, operation, cwd, arguments_, failure) {
|
|
796
|
+
const { out, isDryRun } = context;
|
|
797
|
+
out.planned(operation);
|
|
798
|
+
if (isDryRun)
|
|
799
|
+
return true;
|
|
800
|
+
try {
|
|
801
|
+
runGit(arguments_, { cwd, check: true });
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
if (!(error instanceof GitCommandError) && !isFileNotFound(error))
|
|
805
|
+
throw error;
|
|
806
|
+
out.warning(`${failure} failed: ${reasonOf(error)}`);
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
out.done(operation);
|
|
810
|
+
return true;
|
|
811
|
+
}
|
|
812
|
+
function localCleanupAfterMerge(context, headBranch, config, location) {
|
|
813
|
+
const { out } = context;
|
|
814
|
+
const cwd = process.cwd();
|
|
815
|
+
const remote = sameRepositoryRemote(cwd, location, out);
|
|
816
|
+
if (remote === undefined)
|
|
817
|
+
return;
|
|
818
|
+
const currentBranch = gitCurrentBranch(cwd);
|
|
819
|
+
const checkoutTarget = resolveCheckoutTarget(cwd, config, location, out);
|
|
820
|
+
if (checkoutTarget === undefined)
|
|
821
|
+
return;
|
|
822
|
+
const developBranch = getDevelopBranch(config, location.owner, location.repository);
|
|
823
|
+
if (developBranch === undefined || developBranch === '') {
|
|
824
|
+
out.warning('develop_branch is not set; skipped local cleanup');
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (currentBranch === checkoutTarget) {
|
|
828
|
+
settle(out, { verb: 'unchanged', target: `current branch ${checkoutTarget}` });
|
|
829
|
+
}
|
|
830
|
+
else if (!didRunLocalStep(context, { verb: 'set', target: `current branch to ${checkoutTarget}` }, cwd, ['checkout', checkoutTarget], `checking out ${checkoutTarget}`)) {
|
|
831
|
+
// checkout が失敗したら、pull と branch -D は別のブランチに当たるので止める
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
didRunLocalStep(context, { verb: 'update', target: `${checkoutTarget} from ${remote}/${developBranch}` }, cwd, ['pull', remote, developBranch], `pulling ${developBranch}`);
|
|
835
|
+
if (headBranch === checkoutTarget) {
|
|
836
|
+
settle(out, { verb: 'skip', target: `deleting local branch ${headBranch} (it is the checkout target)` });
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
didRunLocalStep(context, { verb: 'delete', target: `local branch ${headBranch}` }, cwd, ['branch', '-D', headBranch], `deleting local branch ${headBranch}`);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function removeActiveFlags(out) {
|
|
843
|
+
try {
|
|
844
|
+
for (const flag of [FLAG_PECOT_ACTIVE, FLAG_PECOT_SESSION_TITLE, FLAG_PECOT_QUICK_MODE, FLAG_WIP_BRANCH_LINKED])
|
|
845
|
+
removeFlag(flag);
|
|
846
|
+
}
|
|
847
|
+
catch (error) {
|
|
848
|
+
out.warning(`removing flag files failed: ${reasonOf(error)}`);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
const CleanupInputSchema = z.strictObject({
|
|
852
|
+
pr_ref: z.string().describe(PR_REFERENCE_DESCRIPTION),
|
|
853
|
+
dry_run: z.boolean().default(false).describe('Dry-run (do not actually clean up)'),
|
|
854
|
+
delete_branch: z.boolean().default(false).describe('Delete the branch'),
|
|
855
|
+
skip_local_cleanup: z.boolean().default(false).describe('Skip the local branch switch and deletion'),
|
|
856
|
+
});
|
|
857
|
+
async function runCleanup(input, io) {
|
|
858
|
+
const out = createOutput(input.dry_run, io);
|
|
859
|
+
const context = { out, isDryRun: input.dry_run };
|
|
860
|
+
const config = requireActiveConfigPlain(out);
|
|
861
|
+
const reference = parseReference(input.pr_ref, input.repo, out);
|
|
862
|
+
const location = { owner: reference.owner, repository: reference.repository };
|
|
863
|
+
const { client, pr } = await fetchPullRequestForCleanup(config, reference, out);
|
|
864
|
+
if (pr.state !== 'MERGED')
|
|
865
|
+
stopWith(out, `PR #${String(reference.number)} is not merged yet (state: ${pr.state}); merge it with gh pr merge first`);
|
|
866
|
+
const closing = collectClosingIssueNumbers(pr);
|
|
867
|
+
const epicProtected = await findEpicProtectedNumbers(client, location, closing, out);
|
|
868
|
+
for (const number of epicProtected)
|
|
869
|
+
closing.delete(number);
|
|
870
|
+
out.count('Issues to close', closing.size);
|
|
871
|
+
await closeRelatedIssues(context, client, location, closing, epicProtected);
|
|
872
|
+
if (input.delete_branch)
|
|
873
|
+
await deleteMergedBranch(context, client, location, pr.head_ref);
|
|
874
|
+
if (input.skip_local_cleanup)
|
|
875
|
+
return;
|
|
876
|
+
localCleanupAfterMerge(context, pr.head_ref, config, location);
|
|
877
|
+
if (input.dry_run) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
removeActiveFlags(out);
|
|
881
|
+
consumeFlag(FLAG_MERGE_SLASH_PENDING);
|
|
882
|
+
}
|
|
883
|
+
const prCreate = defineCommand({
|
|
884
|
+
path: ['pr', 'create'],
|
|
885
|
+
description: 'Create a PR (pull request)',
|
|
886
|
+
input: CreateInputSchema,
|
|
887
|
+
positional: ['file'],
|
|
888
|
+
shortFlags: { message: '-m', title: '-t', base: '-b', draft: '-d', prepare: '-p', dry_run: '-n', repo: '-r' },
|
|
889
|
+
hasOwnRepo: true,
|
|
890
|
+
interactive: false,
|
|
891
|
+
run: async (input, io) => {
|
|
892
|
+
await runCreate(input, io);
|
|
893
|
+
return 0;
|
|
894
|
+
},
|
|
895
|
+
});
|
|
896
|
+
const prRead = defineCommand({
|
|
897
|
+
path: ['pr', 'read'],
|
|
898
|
+
description: 'Get PR details efficiently (GraphQL, only the needed fields)',
|
|
899
|
+
input: ReadInputSchema,
|
|
900
|
+
positional: ['pr_ref'],
|
|
901
|
+
shortFlags: { json: '-j', reviews: '-r' },
|
|
902
|
+
interactive: false,
|
|
903
|
+
run: async (input, io) => {
|
|
904
|
+
await runRead(input, io);
|
|
905
|
+
return 0;
|
|
906
|
+
},
|
|
907
|
+
});
|
|
908
|
+
const prPreflight = defineCommand({
|
|
909
|
+
path: ['pr', 'preflight'],
|
|
910
|
+
description: 'Show all the information to check before creating a PR',
|
|
911
|
+
input: PreflightInputSchema,
|
|
912
|
+
positional: [],
|
|
913
|
+
shortFlags: { directory: '-D' },
|
|
914
|
+
interactive: false,
|
|
915
|
+
run: (input, io) => {
|
|
916
|
+
runPreflight(input, io);
|
|
917
|
+
return Promise.resolve(0);
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
const prCleanup = defineCommand({
|
|
921
|
+
path: ['pr', 'cleanup'],
|
|
922
|
+
description: 'Clean up after a merged PR (close related Issues, delete branches, local cleanup)',
|
|
923
|
+
input: CleanupInputSchema,
|
|
924
|
+
positional: ['pr_ref'],
|
|
925
|
+
shortFlags: { dry_run: '-n', delete_branch: '-d' },
|
|
926
|
+
interactive: false,
|
|
927
|
+
run: async (input, io) => {
|
|
928
|
+
await runCleanup(input, io);
|
|
929
|
+
return 0;
|
|
930
|
+
},
|
|
931
|
+
});
|
|
932
|
+
export const PR_COMMANDS = [prCleanup, prCreate, prPreflight, prRead];
|
|
933
|
+
//# sourceMappingURL=pr.js.map
|