@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,43 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側が決める。ここでは存在確認と読み取りだけ */
|
|
2
|
+
// CHANGELOG.md を読む。内容の解釈は domain/changelog.ts にある。
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { CHANGELOG_FALLBACK_FILES, changelogFileName, changelogNotFoundMessage, ChangelogFileNotFoundError, DEFAULT_CHANGELOG_FILE, extractVersionReleaseNotes, getLatestVersion } from '../domain/changelog.js';
|
|
6
|
+
import { readTextFile } from './text-file.js';
|
|
7
|
+
/**
|
|
8
|
+
CHANGELOG ファイルのパスを解決する。存在しない場合もパスだけ返す。
|
|
9
|
+
明示指定(空でない文字列)があればそれ、無ければ CHANGELOG.md → AIST-CHANGELOG.md の順に存在を確かめ、どちらも無ければ CHANGELOG.md。
|
|
10
|
+
明示指定が絶対パスならそのまま返す(pathlib の / と同じ)
|
|
11
|
+
*/
|
|
12
|
+
export function resolveChangelogPath(gitRoot, changelogFile) {
|
|
13
|
+
if (changelogFile !== undefined && changelogFile !== '') {
|
|
14
|
+
return path.isAbsolute(changelogFile) ? changelogFile : path.join(gitRoot, changelogFile);
|
|
15
|
+
}
|
|
16
|
+
const found = CHANGELOG_FALLBACK_FILES.map(candidate => path.join(gitRoot, candidate)).find(candidate => existsSync(candidate));
|
|
17
|
+
return found ?? path.join(gitRoot, DEFAULT_CHANGELOG_FILE);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
ファイルがあれば内容、無ければ undefined
|
|
21
|
+
*/
|
|
22
|
+
export function readChangelogIfExists(changelogPath) {
|
|
23
|
+
return existsSync(changelogPath) ? readTextFile(changelogPath) : undefined;
|
|
24
|
+
}
|
|
25
|
+
function readChangelog(changelogPath) {
|
|
26
|
+
const content = readChangelogIfExists(changelogPath);
|
|
27
|
+
if (content === undefined)
|
|
28
|
+
throw new ChangelogFileNotFoundError(changelogNotFoundMessage(changelogPath));
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
ファイルから最新バージョンを取る。ファイルが無ければ ChangelogFileNotFoundError
|
|
33
|
+
*/
|
|
34
|
+
export function readLatestVersionFromFile(changelogPath) {
|
|
35
|
+
return getLatestVersion(readChangelog(changelogPath), changelogFileName(changelogPath));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
ファイルから指定バージョンのリリースノートを抽出する。ファイルが無ければ ChangelogFileNotFoundError
|
|
39
|
+
*/
|
|
40
|
+
export function extractReleaseNotesFromFile(changelogPath, version) {
|
|
41
|
+
return extractVersionReleaseNotes(readChangelog(changelogPath), version, changelogFileName(changelogPath));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=changelog-file.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
/**
|
|
3
|
+
設定ディレクトリ(`{プロジェクトルート}/.pecot/config`)
|
|
4
|
+
*/
|
|
5
|
+
export declare function configDirectory(): string;
|
|
6
|
+
/**
|
|
7
|
+
プロジェクト設定ディレクトリ(`.pecot/config/projects`)
|
|
8
|
+
*/
|
|
9
|
+
export declare function projectsDirectory(): string;
|
|
10
|
+
/**
|
|
11
|
+
JSON ファイルから設定を読む。無ければ ConfigError、JSON の構文や形が不正なら `invalid config file: {パス}: {詳細}` の ConfigError。
|
|
12
|
+
詳細は、形の不正なら `場所: 本文` を `; ` でつないだもの(Python と同じ)、構文の不正なら JSON パーサーの文(Python の JSONDecodeError の文とは違う)
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadConfig(file: string): ProjectConfig;
|
|
15
|
+
/**
|
|
16
|
+
設定を JSON ファイルに保存する。親ディレクトリが無ければ作る
|
|
17
|
+
*/
|
|
18
|
+
export declare function saveConfig(config: ProjectConfig, file: string): void;
|
|
19
|
+
/**
|
|
20
|
+
.active ファイルが指すアクティブ設定のパス。中身は .active のあるディレクトリ基準の相対パス(絶対パスも可)。
|
|
21
|
+
設定されていない・指す先が無いときは undefined
|
|
22
|
+
*/
|
|
23
|
+
export declare function getActiveConfigPath(): string | undefined;
|
|
24
|
+
export declare function loadActiveConfig(): ProjectConfig | undefined;
|
|
25
|
+
/**
|
|
26
|
+
projects/ にある設定の名前(拡張子 .json を除く。名前順)。ディレクトリが無ければ空
|
|
27
|
+
*/
|
|
28
|
+
export declare function listProjectConfigNames(): readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
アクティブ設定を設定する。.active には .active のあるディレクトリ基準の相対パスを書く。ファイルが無ければ ConfigError
|
|
31
|
+
*/
|
|
32
|
+
export declare function setActiveConfig(file: string): void;
|
|
33
|
+
export interface FindConfigOptions {
|
|
34
|
+
readonly host?: string | undefined;
|
|
35
|
+
readonly owner?: string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
`{host}_{owner}_*.json` の設定ファイルを探す(プロジェクト名ベース)。host と owner の両方が要る。
|
|
39
|
+
複数見つかったら MultipleConfigsError(名前順)
|
|
40
|
+
*/
|
|
41
|
+
export declare function findConfigFile(options: Readonly<FindConfigOptions>): string | undefined;
|
|
42
|
+
export interface ProjectConfigQuery extends FindConfigOptions {
|
|
43
|
+
/**
|
|
44
|
+
リポジトリ名(owner なし)。アクティブ設定の repositories に含まれるかを先に確かめる
|
|
45
|
+
*/
|
|
46
|
+
readonly repository?: string | undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
プロジェクト設定を取得する。引数なしはアクティブ設定。
|
|
50
|
+
repository だけなら、アクティブ設定の repositories にあればそれを返し、無ければ検索する。見つからなければ undefined
|
|
51
|
+
*/
|
|
52
|
+
export declare function getProjectConfig(query?: Readonly<ProjectConfigQuery>): ProjectConfig | undefined;
|
|
53
|
+
//# sourceMappingURL=config-store.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスはプロジェクトルート配下の設定ディレクトリと、呼び出し側が渡す設定ファイル */
|
|
2
|
+
// プロジェクト設定(`.pecot/config/projects/*.json`)の読み書き。モデルと判定は domain/config.ts にある。
|
|
3
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { ConfigError, findRepositoryByName, MultipleConfigsError, parseProjectConfig, serializeProjectConfig, } from '../domain/config.js';
|
|
6
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
7
|
+
import { parseJsonText } from '../domain/json.js';
|
|
8
|
+
import { compareStrings, pythonStrip, ValidationFailure } from '../domain/python-format.js';
|
|
9
|
+
import { isFileNotFound } from './os-error.js';
|
|
10
|
+
import { CONFIG_DIR, projectRoot, resolveRealPath } from './paths.js';
|
|
11
|
+
import { readTextFile } from './text-file.js';
|
|
12
|
+
/**
|
|
13
|
+
設定ディレクトリ(`{プロジェクトルート}/.pecot/config`)
|
|
14
|
+
*/
|
|
15
|
+
export function configDirectory() {
|
|
16
|
+
return path.join(projectRoot(), CONFIG_DIR);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
プロジェクト設定ディレクトリ(`.pecot/config/projects`)
|
|
20
|
+
*/
|
|
21
|
+
export function projectsDirectory() {
|
|
22
|
+
return path.join(configDirectory(), 'projects');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
JSON ファイルから設定を読む。無ければ ConfigError、JSON の構文や形が不正なら `invalid config file: {パス}: {詳細}` の ConfigError。
|
|
26
|
+
詳細は、形の不正なら `場所: 本文` を `; ` でつないだもの(Python と同じ)、構文の不正なら JSON パーサーの文(Python の JSONDecodeError の文とは違う)
|
|
27
|
+
*/
|
|
28
|
+
export function loadConfig(file) {
|
|
29
|
+
if (!existsSync(file))
|
|
30
|
+
throw new ConfigError(`config file not found: ${file}`);
|
|
31
|
+
try {
|
|
32
|
+
return parseProjectConfig(parseJsonText(readTextFile(file)));
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error instanceof ValidationFailure) {
|
|
36
|
+
const detail = error.issues.map(issue => `${issue.location.map(String).join('.')}: ${issue.message}`).join('; ');
|
|
37
|
+
throw new ConfigError(`invalid config file: ${file}: ${detail}`, { cause: error });
|
|
38
|
+
}
|
|
39
|
+
if (error instanceof InvalidValueError)
|
|
40
|
+
throw new ConfigError(`invalid config file: ${file}: ${error.message}`, { cause: error });
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
設定を JSON ファイルに保存する。親ディレクトリが無ければ作る
|
|
46
|
+
*/
|
|
47
|
+
export function saveConfig(config, file) {
|
|
48
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
49
|
+
writeFileSync(file, serializeProjectConfig(config));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
.active ファイルが指すアクティブ設定のパス。中身は .active のあるディレクトリ基準の相対パス(絶対パスも可)。
|
|
53
|
+
設定されていない・指す先が無いときは undefined
|
|
54
|
+
*/
|
|
55
|
+
export function getActiveConfigPath() {
|
|
56
|
+
const activeFile = path.join(projectsDirectory(), '.active');
|
|
57
|
+
if (!existsSync(activeFile))
|
|
58
|
+
return undefined;
|
|
59
|
+
const raw = pythonStrip(readTextFile(activeFile));
|
|
60
|
+
if (raw === '')
|
|
61
|
+
return undefined;
|
|
62
|
+
const configPath = resolveRealPath(path.resolve(path.dirname(activeFile), raw));
|
|
63
|
+
return existsSync(configPath) ? configPath : undefined;
|
|
64
|
+
}
|
|
65
|
+
export function loadActiveConfig() {
|
|
66
|
+
const configPath = getActiveConfigPath();
|
|
67
|
+
return configPath === undefined ? undefined : loadConfig(configPath);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
projects/ にある設定の名前(拡張子 .json を除く。名前順)。ディレクトリが無ければ空
|
|
71
|
+
*/
|
|
72
|
+
export function listProjectConfigNames() {
|
|
73
|
+
try {
|
|
74
|
+
return readdirSync(projectsDirectory()).filter(name => name.endsWith('.json')).map(name => name.slice(0, -'.json'.length)).toSorted(compareStrings);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (isFileNotFound(error))
|
|
78
|
+
return [];
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
アクティブ設定を設定する。.active には .active のあるディレクトリ基準の相対パスを書く。ファイルが無ければ ConfigError
|
|
84
|
+
*/
|
|
85
|
+
export function setActiveConfig(file) {
|
|
86
|
+
if (!existsSync(file))
|
|
87
|
+
throw new ConfigError(`config file not found: ${file}`);
|
|
88
|
+
const activeFile = path.join(projectsDirectory(), '.active');
|
|
89
|
+
mkdirSync(path.dirname(activeFile), { recursive: true });
|
|
90
|
+
const relative = path.relative(path.resolve(path.dirname(activeFile)), path.resolve(file));
|
|
91
|
+
writeFileSync(activeFile, `${relative}\n`);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
`{host}_{owner}_*.json` の設定ファイルを探す(プロジェクト名ベース)。host と owner の両方が要る。
|
|
95
|
+
複数見つかったら MultipleConfigsError(名前順)
|
|
96
|
+
*/
|
|
97
|
+
export function findConfigFile(options) {
|
|
98
|
+
const { host, owner } = options;
|
|
99
|
+
if (host === undefined || host === '' || owner === undefined || owner === '')
|
|
100
|
+
return undefined;
|
|
101
|
+
const directory = projectsDirectory();
|
|
102
|
+
const prefix = `${host}_${owner}_`;
|
|
103
|
+
let names;
|
|
104
|
+
try {
|
|
105
|
+
names = readdirSync(directory);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (isFileNotFound(error))
|
|
109
|
+
return undefined;
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
const matches = names.filter(name => name.startsWith(prefix) && name.endsWith('.json') && name.length >= prefix.length + '.json'.length).toSorted(compareStrings);
|
|
113
|
+
const [only] = matches;
|
|
114
|
+
if (matches.length > 1)
|
|
115
|
+
throw new MultipleConfigsError(matches.map(name => path.join(directory, name)));
|
|
116
|
+
return only === undefined ? undefined : path.join(directory, only);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
プロジェクト設定を取得する。引数なしはアクティブ設定。
|
|
120
|
+
repository だけなら、アクティブ設定の repositories にあればそれを返し、無ければ検索する。見つからなければ undefined
|
|
121
|
+
*/
|
|
122
|
+
export function getProjectConfig(query = {}) {
|
|
123
|
+
const { host, owner, repository } = query;
|
|
124
|
+
if (host === undefined && owner === undefined && repository === undefined)
|
|
125
|
+
return loadActiveConfig();
|
|
126
|
+
if (host === undefined && owner === undefined && repository !== undefined) {
|
|
127
|
+
const active = loadActiveConfig();
|
|
128
|
+
if (active !== undefined && findRepositoryByName(active, repository) !== undefined)
|
|
129
|
+
return active;
|
|
130
|
+
}
|
|
131
|
+
const configPath = findConfigFile({ host, owner });
|
|
132
|
+
return configPath === undefined ? undefined : loadConfig(configPath);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=config-store.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
infra が警告・エラーを伝える受け口。呼ぶ側(commands)が渡す。
|
|
3
|
+
`src/commands/output.ts` の `Output` がそのまま満たす。前置き(`warning:`・`error:`)と字下げは受け口の側が付ける
|
|
4
|
+
*/
|
|
5
|
+
export interface Diagnostics {
|
|
6
|
+
readonly warning: (message: string) => void;
|
|
7
|
+
readonly error: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側が決める。ここは種類を調べるだけ */
|
|
2
|
+
// パスの種類の判定。Python の Path.is_dir() / is_file() と同じく、シンボリックリンクを辿り、読めないパスは偽にする。
|
|
3
|
+
import { statSync } from 'node:fs';
|
|
4
|
+
/**
|
|
5
|
+
ディレクトリか。無い・読めないときは false
|
|
6
|
+
*/
|
|
7
|
+
export function isDirectory(target) {
|
|
8
|
+
try {
|
|
9
|
+
return statSync(target).isDirectory();
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
通常のファイルか。無い・読めないときは false
|
|
17
|
+
*/
|
|
18
|
+
export function isFile(target) {
|
|
19
|
+
try {
|
|
20
|
+
return statSync(target).isFile();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=file-kind.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParsedComment, ParsedIssue, ParsedPullRequest } from '../domain/frontmatter.js';
|
|
2
|
+
/**
|
|
3
|
+
Issue 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseIssueFile(file: string): ParsedIssue;
|
|
6
|
+
/**
|
|
7
|
+
コメント用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseCommentFile(file: string): ParsedComment;
|
|
10
|
+
/**
|
|
11
|
+
PR 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
|
|
12
|
+
*/
|
|
13
|
+
export declare function parsePullRequestFile(file: string): ParsedPullRequest;
|
|
14
|
+
//# sourceMappingURL=frontmatter-file.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側(コマンドの引数)が決める。この層は読むだけ */
|
|
2
|
+
// フロントマター付き Markdown ファイルの読み込み。パースそのものは domain/frontmatter.ts が行う。
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { FrontmatterError, parseCommentContent, parseFrontmatter, parsePullRequestContent } from '../domain/frontmatter.js';
|
|
5
|
+
import { normalizePath } from './paths.js';
|
|
6
|
+
import { readTextFile } from './text-file.js';
|
|
7
|
+
function readFrontmatterFile(file) {
|
|
8
|
+
if (!existsSync(file))
|
|
9
|
+
throw new FrontmatterError(`file not found: ${normalizePath(file)}`);
|
|
10
|
+
return readTextFile(file);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
Issue 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
|
|
14
|
+
*/
|
|
15
|
+
export function parseIssueFile(file) {
|
|
16
|
+
return parseFrontmatter(readFrontmatterFile(file));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
コメント用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
|
|
20
|
+
*/
|
|
21
|
+
export function parseCommentFile(file) {
|
|
22
|
+
return parseCommentContent(readFrontmatterFile(file));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
PR 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
|
|
26
|
+
*/
|
|
27
|
+
export function parsePullRequestFile(file) {
|
|
28
|
+
return parsePullRequestContent(readFrontmatterFile(file));
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=frontmatter-file.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { GitResult, GitRunner } from '../domain/git-runner.js';
|
|
2
|
+
import type { RemoteLocation } from '../domain/git-url.js';
|
|
3
|
+
import { BaseError } from '../domain/errors.js';
|
|
4
|
+
export interface GitOptions {
|
|
5
|
+
/**
|
|
6
|
+
作業ディレクトリ。省略すると呼び出し元の作業ディレクトリ
|
|
7
|
+
*/
|
|
8
|
+
readonly cwd?: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
true なら GIT_* の env を除いて実行する。git のフック内では GIT_DIR 等が設定され、作業ディレクトリの代わりに参照される。
|
|
11
|
+
作業ディレクトリ基準で解決したいときに使う
|
|
12
|
+
*/
|
|
13
|
+
readonly stripGitEnvironment?: boolean | undefined;
|
|
14
|
+
/**
|
|
15
|
+
true なら非 0 終了で GitCommandError を投げる
|
|
16
|
+
*/
|
|
17
|
+
readonly check?: boolean | undefined;
|
|
18
|
+
/**
|
|
19
|
+
足す環境変数。今の環境変数(stripGitEnvironment なら GIT_* を除いたもの)に重ねる
|
|
20
|
+
*/
|
|
21
|
+
readonly env?: Readonly<Record<string, string>> | undefined;
|
|
22
|
+
/**
|
|
23
|
+
時間切れ。過ぎたら止めて、exitCode が GIT_TIMED_OUT の結果を返す
|
|
24
|
+
*/
|
|
25
|
+
readonly timeoutMilliseconds?: number | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
時間切れで止めたときの exitCode
|
|
29
|
+
*/
|
|
30
|
+
export declare const GIT_TIMED_OUT = -2;
|
|
31
|
+
/**
|
|
32
|
+
check 付きの実行が非 0 で終わった(Python の CalledProcessError に当たる)
|
|
33
|
+
*/
|
|
34
|
+
export declare class GitCommandError extends BaseError {
|
|
35
|
+
readonly exitCode: number;
|
|
36
|
+
readonly stdout: string;
|
|
37
|
+
readonly stderr: string;
|
|
38
|
+
constructor(arguments_: readonly string[], result: GitResult);
|
|
39
|
+
}
|
|
40
|
+
export declare const MAX_OUTPUT_BYTES: number;
|
|
41
|
+
/**
|
|
42
|
+
git を実行する。標準出力・標準エラーは改行を \n に揃えた文字列で返す。
|
|
43
|
+
git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
|
|
44
|
+
*/
|
|
45
|
+
export declare function runGit(arguments_: readonly string[], options?: Readonly<GitOptions>): GitResult;
|
|
46
|
+
/**
|
|
47
|
+
cwd を束ねた GitRunner。domain の関数に渡す。非 0 終了は例外にせず結果で返す
|
|
48
|
+
*/
|
|
49
|
+
export declare function gitRunnerFor(cwd?: string, options?: Readonly<Pick<GitOptions, 'stripGitEnvironment'>>): GitRunner;
|
|
50
|
+
/**
|
|
51
|
+
標準出力を削らずに返す。非 0 終了・git が無いときは undefined
|
|
52
|
+
*/
|
|
53
|
+
export declare function gitStdout(arguments_: readonly string[], options?: Readonly<Omit<GitOptions, 'check'>>): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
git リポジトリ(ワークツリー)のルート。git の外・git が無いときは undefined
|
|
56
|
+
*/
|
|
57
|
+
export declare function gitToplevel(options?: Readonly<Pick<GitOptions, 'cwd' | 'stripGitEnvironment'>>): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
remote の URL。remote が無い・git の外なら undefined
|
|
60
|
+
*/
|
|
61
|
+
export declare function gitRemoteUrl(cwd?: string, remote?: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
remote 名の一覧。git の外・git が無いときは undefined
|
|
64
|
+
*/
|
|
65
|
+
export declare function listRemotes(cwd?: string): readonly string[] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
優先順の remote 候補。origin があれば origin だけ、無ければ一覧の順にすべて
|
|
68
|
+
*/
|
|
69
|
+
export declare function preferredRemotes(remotes: readonly string[]): readonly string[];
|
|
70
|
+
/**
|
|
71
|
+
主の remote 名。origin、無ければ最初の remote。remote が無い・git の外なら undefined
|
|
72
|
+
*/
|
|
73
|
+
export declare function primaryRemoteName(cwd?: string): string | undefined;
|
|
74
|
+
/**
|
|
75
|
+
主の remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
76
|
+
*/
|
|
77
|
+
export declare function primaryRemoteRepository(cwd?: string): RemoteLocation | undefined;
|
|
78
|
+
/**
|
|
79
|
+
現在のブランチ名(detached HEAD では `HEAD`)。git の外なら undefined
|
|
80
|
+
*/
|
|
81
|
+
export declare function gitCurrentBranch(cwd?: string): string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
84
|
+
*/
|
|
85
|
+
export declare function remoteRepository(cwd: string | undefined, remote: string): RemoteLocation | undefined;
|
|
86
|
+
//# sourceMappingURL=git.d.ts.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// git コマンド実行の唯一の窓口。git の subprocess 呼び出しはすべて runGit を経由する。
|
|
2
|
+
// 値を返す helper(gitToplevel 等)は、失敗時に undefined を返す。
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { parseRemoteUrl } from '../domain/git-url.js';
|
|
5
|
+
import { BaseError, InvalidValueError } from '../domain/errors.js';
|
|
6
|
+
import { normalizeNewlines, pythonRepr, pythonStrip } from '../domain/python-format.js';
|
|
7
|
+
import { childStdin } from './child-stdin.js';
|
|
8
|
+
import { isFileNotFound, toOsError } from './os-error.js';
|
|
9
|
+
/**
|
|
10
|
+
時間切れで止めたときの exitCode
|
|
11
|
+
*/
|
|
12
|
+
export const GIT_TIMED_OUT = -2;
|
|
13
|
+
function isTimedOut(error) {
|
|
14
|
+
return error !== undefined && 'code' in error && error.code === 'ETIMEDOUT';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
check 付きの実行が非 0 で終わった(Python の CalledProcessError に当たる)
|
|
18
|
+
*/
|
|
19
|
+
export class GitCommandError extends BaseError {
|
|
20
|
+
exitCode;
|
|
21
|
+
stdout;
|
|
22
|
+
stderr;
|
|
23
|
+
constructor(arguments_, result) {
|
|
24
|
+
super(`Command ${pythonRepr(['git', ...arguments_])} returned non-zero exit status ${String(result.exitCode)}.`);
|
|
25
|
+
this.exitCode = result.exitCode;
|
|
26
|
+
this.stdout = result.stdout;
|
|
27
|
+
this.stderr = result.stderr;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// 出力が大きい git(log・diff 等)でも切れないようにする
|
|
31
|
+
export const MAX_OUTPUT_BYTES = 1024 * 1024 * 1024;
|
|
32
|
+
function withoutGitVariables() {
|
|
33
|
+
// interface-env: none
|
|
34
|
+
return Object.fromEntries(Object.entries(process.env).filter((entry) => entry[1] !== undefined && !entry[0].startsWith('GIT_')));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
git を実行する。標準出力・標準エラーは改行を \n に揃えた文字列で返す。
|
|
38
|
+
git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
|
|
39
|
+
*/
|
|
40
|
+
export function runGit(arguments_, options = {}) {
|
|
41
|
+
// interface-env: none
|
|
42
|
+
const base = options.stripGitEnvironment === true ? withoutGitVariables() : (options.env === undefined ? undefined : process.env);
|
|
43
|
+
const result = spawnSync('git', [...arguments_], {
|
|
44
|
+
cwd: options.cwd,
|
|
45
|
+
env: base === undefined ? undefined : { ...base, ...options.env },
|
|
46
|
+
encoding: 'utf8',
|
|
47
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
48
|
+
stdio: [childStdin(), 'pipe', 'pipe'],
|
|
49
|
+
...(options.timeoutMilliseconds !== undefined && { timeout: options.timeoutMilliseconds, killSignal: 'SIGKILL' }),
|
|
50
|
+
});
|
|
51
|
+
if (isTimedOut(result.error))
|
|
52
|
+
return { exitCode: GIT_TIMED_OUT, stdout: normalizeNewlines(result.stdout), stderr: normalizeNewlines(result.stderr) };
|
|
53
|
+
if (result.error !== undefined) {
|
|
54
|
+
// spawnSync の ENOENT は path が `git` で入る。cwd が無いときも同じ ENOENT になる
|
|
55
|
+
throw toOsError(result.error);
|
|
56
|
+
}
|
|
57
|
+
const gitResult = { exitCode: result.status ?? -1, stdout: normalizeNewlines(result.stdout), stderr: normalizeNewlines(result.stderr) };
|
|
58
|
+
if (options.check === true && gitResult.exitCode !== 0)
|
|
59
|
+
throw new GitCommandError(arguments_, gitResult);
|
|
60
|
+
return gitResult;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
cwd を束ねた GitRunner。domain の関数に渡す。非 0 終了は例外にせず結果で返す
|
|
64
|
+
*/
|
|
65
|
+
export function gitRunnerFor(cwd, options = {}) {
|
|
66
|
+
return arguments_ => runGit(arguments_, { cwd, stripGitEnvironment: options.stripGitEnvironment });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
標準出力を削らずに返す。非 0 終了・git が無いときは undefined
|
|
70
|
+
*/
|
|
71
|
+
export function gitStdout(arguments_, options = {}) {
|
|
72
|
+
try {
|
|
73
|
+
return runGit(arguments_, { ...options, check: true }).stdout;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof GitCommandError || isFileNotFound(error))
|
|
77
|
+
return undefined;
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function runForValue(arguments_, options) {
|
|
82
|
+
const stdout = gitStdout(arguments_, options);
|
|
83
|
+
return stdout === undefined ? undefined : pythonStrip(stdout);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
git リポジトリ(ワークツリー)のルート。git の外・git が無いときは undefined
|
|
87
|
+
*/
|
|
88
|
+
export function gitToplevel(options = {}) {
|
|
89
|
+
return runForValue(['rev-parse', '--show-toplevel'], options);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
remote の URL。remote が無い・git の外なら undefined
|
|
93
|
+
*/
|
|
94
|
+
export function gitRemoteUrl(cwd, remote = 'origin') {
|
|
95
|
+
return runForValue(['remote', 'get-url', remote], { cwd });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
remote 名の一覧。git の外・git が無いときは undefined
|
|
99
|
+
*/
|
|
100
|
+
export function listRemotes(cwd) {
|
|
101
|
+
const output = runForValue(['remote'], { cwd });
|
|
102
|
+
return output === undefined ? undefined : output.split('\n').map(line => pythonStrip(line)).filter(line => line !== '');
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
優先順の remote 候補。origin があれば origin だけ、無ければ一覧の順にすべて
|
|
106
|
+
*/
|
|
107
|
+
export function preferredRemotes(remotes) {
|
|
108
|
+
return remotes.includes('origin') ? ['origin'] : remotes;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
主の remote 名。origin、無ければ最初の remote。remote が無い・git の外なら undefined
|
|
112
|
+
*/
|
|
113
|
+
export function primaryRemoteName(cwd) {
|
|
114
|
+
return preferredRemotes(listRemotes(cwd) ?? [])[0];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
主の remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
118
|
+
*/
|
|
119
|
+
export function primaryRemoteRepository(cwd) {
|
|
120
|
+
const name = primaryRemoteName(cwd);
|
|
121
|
+
return name === undefined ? undefined : remoteRepository(cwd, name);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
現在のブランチ名(detached HEAD では `HEAD`)。git の外なら undefined
|
|
125
|
+
*/
|
|
126
|
+
export function gitCurrentBranch(cwd) {
|
|
127
|
+
return runForValue(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
131
|
+
*/
|
|
132
|
+
export function remoteRepository(cwd, remote) {
|
|
133
|
+
const url = gitRemoteUrl(cwd, remote);
|
|
134
|
+
if (url === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
try {
|
|
137
|
+
return parseRemoteUrl(url);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error instanceof InvalidValueError)
|
|
141
|
+
return undefined;
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { JsonObject } from '../../domain/json.js';
|
|
2
|
+
import type { JsonValue } from '../../domain/python-format.js';
|
|
3
|
+
/**
|
|
4
|
+
str(value) と同じ。文字列はそのまま、それ以外は repr
|
|
5
|
+
*/
|
|
6
|
+
export declare function pythonString(value: JsonValue): string;
|
|
7
|
+
/**
|
|
8
|
+
環境変数の値。無ければ undefined。
|
|
9
|
+
|
|
10
|
+
名前が実行時に決まるので、環境変数の名前を添字で直接書く形では読めない。
|
|
11
|
+
名前の元は、hosts.json の env_var、ホストから作る `PECOT_GITHUB_<HOST>_TOKEN`、ROOT_ENV_VAR_MAP。
|
|
12
|
+
環境変数の宣言の確認(.githooks/tests/test_nx_env_inputs.py)は、この読み方を検出できない。
|
|
13
|
+
宣言できない代わりに、テストが結果をトークンの値に依存させない。
|
|
14
|
+
テストは token を明示して渡すか、トークンの変数を自分で設定する。
|
|
15
|
+
トークンの変数を外す隔離は tests/_helpers/environment.ts の useIsolatedEnvironment が行う。
|
|
16
|
+
*/
|
|
17
|
+
export declare function environmentValue(name: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
ホスト設定をロードする(キャッシュ付き)。
|
|
20
|
+
設定ディレクトリの hosts.json を読む。ファイルが無ければ空の設定。
|
|
21
|
+
最上位が JSON のオブジェクトでないときは、空の設定として扱う
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadHostsConfig(): JsonObject;
|
|
24
|
+
/**
|
|
25
|
+
ホスト設定のキャッシュを捨てる(テスト用)
|
|
26
|
+
*/
|
|
27
|
+
export declare function clearHostsConfigCache(): void;
|
|
28
|
+
/**
|
|
29
|
+
ホストの設定(env_var・token_url・description・scopes)。無い、または空のオブジェクトなら undefined
|
|
30
|
+
*/
|
|
31
|
+
export declare function getHostConfig(host: string): JsonObject | undefined;
|
|
32
|
+
/**
|
|
33
|
+
hosts.json に定義が無いときの既定の環境変数名。hosts.json.sample・.env.sample と同じ名前。
|
|
34
|
+
hosts.json はリポに含まれないため、Actions などの新しい checkout ではこの名前を使う
|
|
35
|
+
*/
|
|
36
|
+
export declare const DEFAULT_ENV_VAR_MAP: ReadonlyMap<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
ホストに対応する環境変数名。hosts.json の定義、既定の対応、`PECOT_GITHUB_<HOST>_TOKEN`(ドットはアンダースコア)の順に使う
|
|
39
|
+
*/
|
|
40
|
+
export declare function getEnvironmentVariableName(host: string): string;
|
|
41
|
+
export declare const ROOT_ENV_VAR_MAP: ReadonlyMap<string, string>;
|
|
42
|
+
/**
|
|
43
|
+
環境変数ファイルを読み、実行中の環境に設定する。Python の load_env_file と同じく環境を書き換える。
|
|
44
|
+
KEY=VALUE 形式で、空行と # で始まる行は飛ばす。既にある環境変数は上書きしない
|
|
45
|
+
*/
|
|
46
|
+
export declare function loadEnvironmentFile(file: string): void;
|
|
47
|
+
/**
|
|
48
|
+
トークンの取得先 URL(hosts.json の token_url、無ければ設定画面の URL)
|
|
49
|
+
*/
|
|
50
|
+
export declare function tokenUrlFor(host: string): string;
|
|
51
|
+
/**
|
|
52
|
+
hosts.json の scopes。無い、または配列でないときは空
|
|
53
|
+
*/
|
|
54
|
+
export declare function scopesFor(host: string): readonly string[];
|
|
55
|
+
/**
|
|
56
|
+
認証用の .env を生成または更新して、そのパスを返す。
|
|
57
|
+
無ければ新規作成する。あるときは、ホストの環境変数名が書かれていない場合だけ追記する
|
|
58
|
+
*/
|
|
59
|
+
export declare function ensureEnvironmentFile(host: string): string;
|
|
60
|
+
//# sourceMappingURL=auth.d.ts.map
|