@pecot/workflow-mcp 5.0.0 → 7.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 +1 -1
- package/README.md +27 -22
- package/cli/dist/cli.js +6 -1
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +69 -0
- package/cli/dist/commands/board-judgment.d.ts +69 -0
- package/cli/dist/commands/board-judgment.js +150 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +65 -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 +75 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +120 -0
- package/cli/dist/commands/board-view.d.ts +151 -0
- package/cli/dist/commands/board-view.js +293 -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 +111 -0
- package/cli/dist/commands/command-binding.js +4 -0
- package/cli/dist/commands/command-definition.d.ts +39 -8
- package/cli/dist/commands/command-definition.js +20 -7
- package/cli/dist/commands/command-help.js +2 -2
- 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 +5 -3
- package/cli/dist/commands/command-stop.js +7 -6
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +35 -0
- package/cli/dist/commands/failure.d.ts +6 -0
- package/cli/dist/commands/failure.js +29 -3
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +13 -3
- package/cli/dist/commands/help.js +8 -13
- package/cli/dist/commands/issue-board.d.ts +61 -0
- package/cli/dist/commands/issue-board.js +85 -1
- package/cli/dist/commands/issue-comment.js +66 -30
- package/cli/dist/commands/issue-create.js +632 -92
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +310 -0
- package/cli/dist/commands/issue-readiness.d.ts +122 -0
- package/cli/dist/commands/issue-readiness.js +253 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +130 -0
- package/cli/dist/commands/issue-shared.d.ts +33 -20
- package/cli/dist/commands/issue-shared.js +84 -76
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +239 -0
- package/cli/dist/commands/issue.d.ts +0 -1
- package/cli/dist/commands/issue.js +6 -8
- package/cli/dist/commands/names.d.ts +33 -0
- package/cli/dist/commands/names.js +63 -0
- package/cli/dist/commands/output.d.ts +32 -4
- package/cli/dist/commands/output.js +28 -8
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +230 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +233 -0
- package/cli/dist/commands/pr-waiting.d.ts +59 -0
- package/cli/dist/commands/pr-waiting.js +143 -0
- package/cli/dist/commands/pr.d.ts +23 -0
- package/cli/dist/commands/pr.js +378 -366
- package/cli/dist/commands/project-sync.d.ts +12 -3
- package/cli/dist/commands/project-sync.js +23 -13
- package/cli/dist/commands/project.d.ts +3 -2
- package/cli/dist/commands/project.js +371 -177
- package/cli/dist/commands/registry.js +15 -10
- package/cli/dist/commands/release.d.ts +2 -2
- package/cli/dist/commands/release.js +118 -130
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-match.js +9 -3
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +383 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +252 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +186 -32
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
- package/cli/dist/commands/tracker-sync.d.ts +37 -0
- package/cli/dist/commands/tracker-sync.js +18 -6
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +20 -0
- package/cli/dist/commands/usage-error.d.ts +4 -0
- package/cli/dist/commands/usage-error.js +6 -0
- package/cli/dist/commands/work-target.d.ts +20 -3
- package/cli/dist/commands/work-target.js +49 -6
- package/cli/dist/commands/worktree.js +103 -33
- 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.js +1 -1
- 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 +4 -0
- package/cli/dist/domain/config.js +11 -1
- package/cli/dist/domain/dependabot.js +1 -1
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/format.d.ts +51 -4
- package/cli/dist/domain/format.js +72 -6
- package/cli/dist/domain/frontmatter.d.ts +18 -3
- package/cli/dist/domain/frontmatter.js +38 -12
- 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 +36 -4
- package/cli/dist/domain/pull-request.d.ts +71 -4
- package/cli/dist/domain/pull-request.js +59 -10
- package/cli/dist/domain/readiness.d.ts +44 -0
- package/cli/dist/domain/readiness.js +153 -5
- package/cli/dist/domain/reference-parser.d.ts +3 -1
- package/cli/dist/domain/reference-parser.js +6 -2
- package/cli/dist/domain/release.d.ts +7 -3
- package/cli/dist/domain/release.js +5 -12
- package/cli/dist/domain/repository-policy.d.ts +9 -3
- package/cli/dist/domain/repository-policy.js +8 -7
- package/cli/dist/domain/repository-resolver.js +4 -1
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/security-alerts.js +1 -1
- package/cli/dist/domain/state.d.ts +69 -0
- package/cli/dist/domain/state.js +67 -1
- package/cli/dist/domain/work-start.d.ts +30 -0
- package/cli/dist/domain/work-start.js +42 -0
- package/cli/dist/infra/authored-notes.d.ts +1 -1
- package/cli/dist/infra/authored-notes.js +10 -4
- package/cli/dist/infra/config-store.d.ts +4 -0
- package/cli/dist/infra/config-store.js +13 -0
- package/cli/dist/infra/git.d.ts +76 -0
- package/cli/dist/infra/git.js +123 -1
- package/cli/dist/infra/github/client.d.ts +5 -0
- package/cli/dist/infra/github/client.js +10 -7
- package/cli/dist/infra/github/errors.d.ts +18 -0
- package/cli/dist/infra/github/errors.js +22 -0
- package/cli/dist/infra/github/issues.d.ts +39 -3
- package/cli/dist/infra/github/issues.js +178 -23
- package/cli/dist/infra/github/projects.d.ts +35 -0
- package/cli/dist/infra/github/projects.js +89 -8
- package/cli/dist/infra/github/pulls.d.ts +105 -2
- package/cli/dist/infra/github/pulls.js +172 -5
- package/cli/dist/infra/github/queries.d.ts +15 -4
- package/cli/dist/infra/github/queries.js +203 -40
- package/cli/dist/infra/github/readout.d.ts +5 -1
- package/cli/dist/infra/github/readout.js +11 -33
- package/cli/dist/infra/github/repos.d.ts +18 -0
- package/cli/dist/infra/github/repos.js +31 -0
- package/cli/dist/infra/nx-scope.d.ts +1 -1
- package/cli/dist/infra/nx-scope.js +1 -1
- package/cli/dist/infra/state-store.d.ts +10 -1
- package/cli/dist/infra/state-store.js +14 -2
- package/cli/dist/infra/worktree-links.d.ts +3 -0
- package/cli/dist/infra/worktree-links.js +8 -1
- package/cli/dist/infra/worktree.d.ts +12 -1
- package/cli/dist/infra/worktree.js +40 -23
- package/cli/dist/mcp/result.d.ts +82 -7
- package/cli/dist/mcp/result.js +139 -19
- package/cli/dist/mcp/server.d.ts +2 -2
- package/cli/dist/mcp/server.js +57 -10
- package/cli/templates/comment/plan.md +14 -0
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task-implement.md +13 -6
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/cli/dist/commands/dependabot.d.ts +0 -3
- package/cli/dist/commands/issue-project.d.ts +0 -3
- package/cli/dist/commands/issue-project.js +0 -176
- package/cli/dist/commands/issue-quick.d.ts +0 -3
- package/cli/dist/commands/issue-quick.js +0 -126
- package/cli/dist/commands/issue-read.d.ts +0 -3
- package/cli/dist/commands/issue-read.js +0 -80
- package/cli/dist/commands/project-info.d.ts +0 -48
- package/cli/dist/commands/project-info.js +0 -181
- package/cli/dist/commands/repository.d.ts +0 -5
- package/cli/dist/commands/repository.js +0 -265
- package/cli/dist/commands/security.d.ts +0 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// 積んだブランチを載せ直す先の判断と、その表示。git と GitHub の読み取りは commands が行う。
|
|
2
|
+
/**
|
|
3
|
+
載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
|
|
4
|
+
*/
|
|
5
|
+
export function decideRestack(input) {
|
|
6
|
+
const { reading, developBranch, lowerPullRequest, lowerHead } = input;
|
|
7
|
+
if (reading.kind === 'development')
|
|
8
|
+
return { kind: 'not-stacked', base: developBranch };
|
|
9
|
+
const { branch, sha } = reading.record;
|
|
10
|
+
if (lowerPullRequest?.state === 'MERGED')
|
|
11
|
+
return { kind: 'merged', base: developBranch, pullRequest: lowerPullRequest.number };
|
|
12
|
+
if (lowerHead === undefined)
|
|
13
|
+
return { kind: 'gone', base: branch, pullRequest: lowerPullRequest?.number };
|
|
14
|
+
return { kind: lowerHead === sha ? 'up-to-date' : 'moved', base: branch };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
`pr restack --check` の行
|
|
18
|
+
*/
|
|
19
|
+
export function describeRestackCheck(branch, decision) {
|
|
20
|
+
switch (decision.kind) {
|
|
21
|
+
case 'not-stacked':
|
|
22
|
+
case 'up-to-date': {
|
|
23
|
+
return `up to date: ${branch} on ${decision.base}`;
|
|
24
|
+
}
|
|
25
|
+
case 'moved': {
|
|
26
|
+
return `needs restack: ${branch} on ${decision.base} (base moved)`;
|
|
27
|
+
}
|
|
28
|
+
case 'merged': {
|
|
29
|
+
return `needs restack: ${branch} onto ${decision.base} (base #${String(decision.pullRequest)} merged)`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
下の段のブランチが消えていて、マージもされていないときの文(`error: ` の前置きを含まない)
|
|
35
|
+
*/
|
|
36
|
+
export function describeGone(decision) {
|
|
37
|
+
const pullRequest = decision.pullRequest === undefined ? 'it has no merged PR' : `PR #${String(decision.pullRequest)} was not merged`;
|
|
38
|
+
return `base branch ${decision.base} is gone and ${pullRequest}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
載せ直しが要るか。下の段が消えていて決められないときは undefined
|
|
42
|
+
*/
|
|
43
|
+
export function needsRestack(decision) {
|
|
44
|
+
return decision.kind === 'gone' ? undefined : decision.kind === 'moved' || decision.kind === 'merged';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
session show の `- needs restack:` の行。決められないときは undefined
|
|
48
|
+
*/
|
|
49
|
+
export function describeNeedsRestack(decision) {
|
|
50
|
+
const needed = needsRestack(decision);
|
|
51
|
+
return needed === undefined ? undefined : `- needs restack: ${needed ? 'yes' : 'no'}`;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=restack.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// security alert の種類と、種類ごとの open の alert の取得、code scanning・secret scanning の状態判定。`release
|
|
1
|
+
// security alert の種類と、種類ごとの open の alert の取得、code scanning・secret scanning の状態判定。`release check` と `tracker sync security` が使う。
|
|
2
2
|
// 取得は ScanAlertSource と DependabotSource に任せる。
|
|
3
3
|
import { describeApiError } from './api-error-detail.js';
|
|
4
4
|
import { PecotError } from './errors.js';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { IssueReference } from './reference-parser.js';
|
|
1
2
|
export declare const FLAG_PECOT_ACTIVE = ".pecot-active";
|
|
2
3
|
export declare const FLAG_PECOT_SESSION_TITLE = ".pecot-session-title";
|
|
4
|
+
export declare const FLAG_PECOT_BASE = ".pecot-base";
|
|
5
|
+
export declare const FLAG_PECOT_RESTACK = ".pecot-restack";
|
|
3
6
|
export declare const FLAG_PECOT_QUICK_MODE = ".pecot-quick-mode";
|
|
4
7
|
export declare const FLAG_WIP_BRANCH_LINKED = ".wip-branch-linked";
|
|
5
8
|
export declare const FLAG_PR_CREATE_SLASH_PENDING = "pr-create-slash-pending";
|
|
@@ -26,4 +29,70 @@ export interface WorkTarget {
|
|
|
26
29
|
作業対象として書く内容(.pecot-active と .pecot-session-title)を決める。参照の末尾が整数でなければ InvalidValueError
|
|
27
30
|
*/
|
|
28
31
|
export declare function planWorkTarget(issueReference: string, title: string): WorkTarget;
|
|
32
|
+
export interface BaseRecord {
|
|
33
|
+
readonly branch: string;
|
|
34
|
+
readonly sha: string;
|
|
35
|
+
/**
|
|
36
|
+
積んだ先の Issue。開発ブランチから着手したときは undefined
|
|
37
|
+
*/
|
|
38
|
+
readonly stackedOn: IssueReference | undefined;
|
|
39
|
+
}
|
|
40
|
+
export type BaseReading = {
|
|
41
|
+
readonly kind: 'development';
|
|
42
|
+
readonly record: BaseRecord | undefined;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: 'stacked';
|
|
45
|
+
readonly record: BaseRecord;
|
|
46
|
+
readonly stackedOn: IssueReference;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'malformed';
|
|
49
|
+
readonly content: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
.pecot-base の 1 行。`<branch> <sha>` に、積んだときは ` <owner/repo#N>` を続ける
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatBaseRecord(record: Readonly<BaseRecord>): string;
|
|
55
|
+
/**
|
|
56
|
+
.pecot-base の内容を読む。ファイルが無いのは、この機能の前に着手したものも含めて、開発ブランチから着手したものとして扱う。
|
|
57
|
+
形が誤っていれば malformed
|
|
58
|
+
*/
|
|
59
|
+
export declare function interpretBaseRecord(content: string | undefined): BaseReading;
|
|
60
|
+
export interface RestackProgress {
|
|
61
|
+
readonly remote: string;
|
|
62
|
+
/**
|
|
63
|
+
載せ直しているブランチ。rebase の途中は HEAD が detached なので、ここから読む
|
|
64
|
+
*/
|
|
65
|
+
readonly branch: string;
|
|
66
|
+
/**
|
|
67
|
+
載せ直す前のブランチの先頭。remote にだけある変更が見つかったときに、ここへ戻す
|
|
68
|
+
*/
|
|
69
|
+
readonly originalSha: string;
|
|
70
|
+
readonly ontoBranch: string;
|
|
71
|
+
readonly ontoSha: string;
|
|
72
|
+
/**
|
|
73
|
+
push の `--force-with-lease` に渡す、fetch した時点の remote の SHA。remote にブランチが無ければ undefined
|
|
74
|
+
*/
|
|
75
|
+
readonly leaseSha: string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
載せ直した後も積んだ記録を保つなら、積んだ先の Issue。開発ブランチへ載せ直すなら undefined
|
|
78
|
+
*/
|
|
79
|
+
readonly stackedOn: IssueReference | undefined;
|
|
80
|
+
}
|
|
81
|
+
export type RestackProgressReading = {
|
|
82
|
+
readonly kind: 'none';
|
|
83
|
+
} | {
|
|
84
|
+
readonly kind: 'progress';
|
|
85
|
+
readonly progress: RestackProgress;
|
|
86
|
+
} | {
|
|
87
|
+
readonly kind: 'malformed';
|
|
88
|
+
readonly content: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
.pecot-restack の 1 行。`<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N>` で、無い項目は `-`
|
|
92
|
+
*/
|
|
93
|
+
export declare function formatRestackProgress(progress: Readonly<RestackProgress>): string;
|
|
94
|
+
/**
|
|
95
|
+
.pecot-restack の内容を読む。ファイルが無ければ none、形が誤っていれば malformed
|
|
96
|
+
*/
|
|
97
|
+
export declare function interpretRestackProgress(content: string | undefined): RestackProgressReading;
|
|
29
98
|
//# sourceMappingURL=state.d.ts.map
|
package/cli/dist/domain/state.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
// フック状態の規則(フラグ名・セッション名・作業ディレクトリ名)。ファイルの読み書きは infra/state-store.ts が行う。
|
|
2
2
|
import { InvalidValueError } from './errors.js';
|
|
3
3
|
import { parsePythonInteger, pythonRightStrip, pythonStrip, pythonStringRepr, truncateCodePoints } from './python-format.js';
|
|
4
|
+
import { createIssueReference, issueReferenceToString } from './reference-parser.js';
|
|
5
|
+
import { createRepositoryReference } from './repository-resolver.js';
|
|
4
6
|
// フラグファイル名
|
|
5
7
|
export const FLAG_PECOT_ACTIVE = '.pecot-active';
|
|
6
8
|
// セッション名(hooks の session-title.sh が Claude Code の sessionTitle に流す)。.pecot-active と同じタイミングで書く
|
|
7
9
|
export const FLAG_PECOT_SESSION_TITLE = '.pecot-session-title';
|
|
10
|
+
// 着手のときに選んだ base(ブランチ・位置・積んだ先の Issue)。session start が書き、session finish が消す
|
|
11
|
+
export const FLAG_PECOT_BASE = '.pecot-base';
|
|
12
|
+
// 衝突で止まった載せ直しの途中の記録。pr restack が書き、続行か取りやめで消す
|
|
13
|
+
export const FLAG_PECOT_RESTACK = '.pecot-restack';
|
|
8
14
|
export const FLAG_PECOT_QUICK_MODE = '.pecot-quick-mode';
|
|
9
15
|
export const FLAG_WIP_BRANCH_LINKED = '.wip-branch-linked';
|
|
10
16
|
// スラッシュコマンド起点の外部反映免除フラグ。
|
|
11
17
|
// 設置は hooks の create-slash-flag.sh が行う。
|
|
12
|
-
// 確認は mcp-handlers/pecot-post-ask.sh(merge は core/external-post-check.sh)が行う。
|
|
18
|
+
// 確認は mcp-handlers/pecot-post-ask.sh(merge は pr_merge も。gh pr merge は core/external-post-check.sh)が行う。
|
|
13
19
|
// MCP ツールが実投稿成功時に削除する。
|
|
14
20
|
export const FLAG_PR_CREATE_SLASH_PENDING = 'pr-create-slash-pending';
|
|
15
21
|
export const FLAG_ISSUE_CREATE_SLASH_PENDING = 'issue-create-slash-pending';
|
|
@@ -53,4 +59,64 @@ export function planWorkTarget(issueReference, title) {
|
|
|
53
59
|
throw new InvalidValueError(`invalid literal for int() with base 10: ${pythonStringRepr(text)}`);
|
|
54
60
|
return { active: issueReference, sessionTitle: formatSessionTitle(number, title) };
|
|
55
61
|
}
|
|
62
|
+
// ブランチ名に空白は入らないので、空白で区切る
|
|
63
|
+
const BASE_SHA_PATTERN = /^(?:[\da-f]{40}|[\da-f]{64})$/u;
|
|
64
|
+
const BASE_ISSUE_PATTERN = /^([^\s#/]+)\/([^\s#/]+)#(\d+)$/u;
|
|
65
|
+
/**
|
|
66
|
+
.pecot-base の 1 行。`<branch> <sha>` に、積んだときは ` <owner/repo#N>` を続ける
|
|
67
|
+
*/
|
|
68
|
+
export function formatBaseRecord(record) {
|
|
69
|
+
const fields = [record.branch, record.sha];
|
|
70
|
+
if (record.stackedOn !== undefined)
|
|
71
|
+
fields.push(issueReferenceToString(record.stackedOn));
|
|
72
|
+
return fields.join(' ');
|
|
73
|
+
}
|
|
74
|
+
function parseStackedOn(text) {
|
|
75
|
+
const match = BASE_ISSUE_PATTERN.exec(text);
|
|
76
|
+
const [, owner, repository, digits] = match ?? [];
|
|
77
|
+
if (owner === undefined || repository === undefined || digits === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
const number = Number(digits);
|
|
80
|
+
return number > 0 ? createIssueReference(createRepositoryReference(owner, repository), number) : undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
.pecot-base の内容を読む。ファイルが無いのは、この機能の前に着手したものも含めて、開発ブランチから着手したものとして扱う。
|
|
84
|
+
形が誤っていれば malformed
|
|
85
|
+
*/
|
|
86
|
+
export function interpretBaseRecord(content) {
|
|
87
|
+
if (content === undefined)
|
|
88
|
+
return { kind: 'development', record: undefined };
|
|
89
|
+
const [branch, sha, issue, ...rest] = content.split(' ');
|
|
90
|
+
if (branch === undefined || branch === '' || sha === undefined || !BASE_SHA_PATTERN.test(sha) || rest.length > 0)
|
|
91
|
+
return { kind: 'malformed', content };
|
|
92
|
+
if (issue === undefined)
|
|
93
|
+
return { kind: 'development', record: { branch, sha, stackedOn: undefined } };
|
|
94
|
+
const stackedOn = parseStackedOn(issue);
|
|
95
|
+
return stackedOn === undefined ? { kind: 'malformed', content } : { kind: 'stacked', record: { branch, sha, stackedOn }, stackedOn };
|
|
96
|
+
}
|
|
97
|
+
const ABSENT = '-';
|
|
98
|
+
/**
|
|
99
|
+
.pecot-restack の 1 行。`<remote> <branch> <originalSha> <ontoBranch> <ontoSha> <leaseSha> <owner/repo#N>` で、無い項目は `-`
|
|
100
|
+
*/
|
|
101
|
+
export function formatRestackProgress(progress) {
|
|
102
|
+
const stackedOn = progress.stackedOn === undefined ? ABSENT : issueReferenceToString(progress.stackedOn);
|
|
103
|
+
return [progress.remote, progress.branch, progress.originalSha, progress.ontoBranch, progress.ontoSha, progress.leaseSha ?? ABSENT, stackedOn].join(' ');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
.pecot-restack の内容を読む。ファイルが無ければ none、形が誤っていれば malformed
|
|
107
|
+
*/
|
|
108
|
+
export function interpretRestackProgress(content) {
|
|
109
|
+
if (content === undefined)
|
|
110
|
+
return { kind: 'none' };
|
|
111
|
+
const malformed = { kind: 'malformed', content };
|
|
112
|
+
const [remote, branch, originalSha, ontoBranch, ontoSha, lease, issue, ...rest] = content.split(' ');
|
|
113
|
+
if (remote === undefined || branch === undefined || originalSha === undefined || ontoBranch === undefined || ontoSha === undefined || lease === undefined || issue === undefined || rest.length > 0 || [remote, branch, ontoBranch].includes('') || !BASE_SHA_PATTERN.test(ontoSha) || !BASE_SHA_PATTERN.test(originalSha))
|
|
114
|
+
return malformed;
|
|
115
|
+
if (lease !== ABSENT && !BASE_SHA_PATTERN.test(lease))
|
|
116
|
+
return malformed;
|
|
117
|
+
const stackedOn = issue === ABSENT ? undefined : parseStackedOn(issue);
|
|
118
|
+
if (issue !== ABSENT && stackedOn === undefined)
|
|
119
|
+
return malformed;
|
|
120
|
+
return { kind: 'progress', progress: { remote, branch, originalSha, ontoBranch, ontoSha, leaseSha: lease === ABSENT ? undefined : lease, stackedOn } };
|
|
121
|
+
}
|
|
56
122
|
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HintedText } from './command-hint.js';
|
|
2
|
+
import type { PullRequestReadout } from './issue-readout.js';
|
|
3
|
+
import type { Prerequisite, Readiness } from './readiness.js';
|
|
4
|
+
import type { IssueReference } from './reference-parser.js';
|
|
5
|
+
export type StartDecision = {
|
|
6
|
+
readonly kind: 'start';
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'stack';
|
|
9
|
+
readonly branch: string;
|
|
10
|
+
readonly issue: IssueReference;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'blocked';
|
|
13
|
+
readonly message: HintedText;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
判定から着手の仕方を決める。stackable は積む先のブランチから、blocked は止める。
|
|
17
|
+
startable と、判定を持たない Epic・Tracker(undefined)は、今までどおり
|
|
18
|
+
*/
|
|
19
|
+
export declare function decideStart(readiness: Readiness | undefined, prerequisites: readonly Prerequisite[], target: IssueReference): StartDecision;
|
|
20
|
+
/**
|
|
21
|
+
--base が、判定で選んだ積む先と違うときの文。stackable のときだけ比べる
|
|
22
|
+
*/
|
|
23
|
+
export declare function describeBaseMismatch(base: string | undefined, decision: Exclude<StartDecision, {
|
|
24
|
+
kind: 'blocked';
|
|
25
|
+
}>, target: IssueReference): HintedText | undefined;
|
|
26
|
+
/**
|
|
27
|
+
session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
|
|
28
|
+
*/
|
|
29
|
+
export declare function describeStackBase(branch: string, issue: IssueReference, pullRequest: Readonly<PullRequestReadout> | undefined | 'unknown'): string;
|
|
30
|
+
//# sourceMappingURL=work-start.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// 着手の判定から、base の選び方・止める文・積んだ先の表示を決める。I/O を持たない。
|
|
2
|
+
import { commandHint, hinted, inputHint, joinHinted } from './command-hint.js';
|
|
3
|
+
import { describePrerequisiteState, describeReadiness, displayReference, isDone } from './readiness.js';
|
|
4
|
+
import { issueReferenceToCliReference } from './reference-parser.js';
|
|
5
|
+
function blockedMessage(target, readiness, prerequisites) {
|
|
6
|
+
const home = target.repository;
|
|
7
|
+
const unfinished = prerequisites.filter(({ issue }) => !isDone(issue));
|
|
8
|
+
const subject = issueReferenceToCliReference(target);
|
|
9
|
+
const waitsMerge = readiness.reason?.code === 'waits-merge' ? readiness.reason.issues : [];
|
|
10
|
+
return joinHinted([
|
|
11
|
+
`${displayReference(target, home)} is ${describeReadiness(readiness, prerequisites, home)}`,
|
|
12
|
+
...unfinished.map(prerequisite => `- ${displayReference(prerequisite.issue.ref, home)}: ${describePrerequisiteState(prerequisite)}`),
|
|
13
|
+
...unfinished.map(({ issue }) => hinted `to remove the prerequisite: ${commandHint(['issue', 'unblock'], { issue_ref: subject, by: issueReferenceToCliReference(issue.ref) })}`),
|
|
14
|
+
...waitsMerge.map(({ issue }) => hinted `to stack on it instead of waiting for merge: ${commandHint(['issue', 'block'], { issue_ref: subject, by: issueReferenceToCliReference(issue), wait: 'stack' })}`),
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
判定から着手の仕方を決める。stackable は積む先のブランチから、blocked は止める。
|
|
19
|
+
startable と、判定を持たない Epic・Tracker(undefined)は、今までどおり
|
|
20
|
+
*/
|
|
21
|
+
export function decideStart(readiness, prerequisites, target) {
|
|
22
|
+
if (readiness?.kind === 'blocked')
|
|
23
|
+
return { kind: 'blocked', message: blockedMessage(target, readiness, prerequisites) };
|
|
24
|
+
if (readiness?.kind === 'stackable' && readiness.stackOn !== undefined)
|
|
25
|
+
return { kind: 'stack', branch: readiness.stackOn.branch, issue: readiness.stackOn.issue };
|
|
26
|
+
return { kind: 'start' };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
--base が、判定で選んだ積む先と違うときの文。stackable のときだけ比べる
|
|
30
|
+
*/
|
|
31
|
+
export function describeBaseMismatch(base, decision, target) {
|
|
32
|
+
const isDifferent = base !== undefined && base !== '' && decision.kind === 'stack' && base !== decision.branch;
|
|
33
|
+
return isDifferent ? hinted `${inputHint(['session', 'start'], 'base', base)} differs from the base chosen by readiness: ${decision.branch} (stacked on ${displayReference(decision.issue, target.repository)})` : undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
|
|
37
|
+
*/
|
|
38
|
+
export function describeStackBase(branch, issue, pullRequest) {
|
|
39
|
+
const pr = pullRequest === 'unknown' ? 'PR unknown' : (pullRequest === undefined ? 'no PR' : `PR #${String(pullRequest.number)} ${pullRequest.state}`);
|
|
40
|
+
return `- base: ${branch} (#${String(issue.number)}, ${pr})`;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=work-start.js.map
|
|
@@ -30,7 +30,7 @@ export type NotesResult = {
|
|
|
30
30
|
readonly reason: string;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
ID(`PW-
|
|
33
|
+
ID(`PW-SESSION-START`)の項目の details・constraints・examples・default_notes を読む。
|
|
34
34
|
ファイルが無い・YAML として読めない・項目が無い・欄の形が違うときは、場所と理由を持つ unreadable を返す
|
|
35
35
|
*/
|
|
36
36
|
export declare function readAuthoredNotes(id: string, root?: string): NotesResult;
|
|
@@ -12,11 +12,16 @@ const DEPENDENCY_SCHEMA = z.object({ requires: z.record(z.string(), NAMES_SCHEMA
|
|
|
12
12
|
const CONSTRAINT_SCHEMA = z.union([CONFLICTS_SCHEMA, DEPENDENCY_SCHEMA]);
|
|
13
13
|
const EXAMPLE_SCHEMA = z.object({ run: z.string(), note: z.string() });
|
|
14
14
|
const FILE_SCHEMA = z.object({ entries: z.record(z.string(), z.unknown()) });
|
|
15
|
-
const
|
|
15
|
+
const PROSE_SHAPE = {
|
|
16
16
|
details: NAMES_SCHEMA,
|
|
17
|
-
constraints: z.array(CONSTRAINT_SCHEMA),
|
|
18
17
|
examples: z.array(EXAMPLE_SCHEMA),
|
|
19
18
|
default_notes: z.record(z.string(), z.string()),
|
|
19
|
+
};
|
|
20
|
+
// help は --help に出す英語の文。日本語で書いた定義書では、同じ名前の 3 つの欄の代わりに読む
|
|
21
|
+
const ENTRY_SCHEMA = z.object({
|
|
22
|
+
...PROSE_SHAPE,
|
|
23
|
+
constraints: z.array(CONSTRAINT_SCHEMA),
|
|
24
|
+
help: z.object(PROSE_SHAPE).optional(),
|
|
20
25
|
});
|
|
21
26
|
/**
|
|
22
27
|
authored.yaml の置き場所。pluginRoot() の下の interface/
|
|
@@ -31,7 +36,7 @@ function isMissingFile(error) {
|
|
|
31
36
|
return error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
32
37
|
}
|
|
33
38
|
/**
|
|
34
|
-
ID(`PW-
|
|
39
|
+
ID(`PW-SESSION-START`)の項目の details・constraints・examples・default_notes を読む。
|
|
35
40
|
ファイルが無い・YAML として読めない・項目が無い・欄の形が違うときは、場所と理由を持つ unreadable を返す
|
|
36
41
|
*/
|
|
37
42
|
export function readAuthoredNotes(id, root = pluginRoot()) {
|
|
@@ -60,7 +65,8 @@ export function readAuthoredNotes(id, root = pluginRoot()) {
|
|
|
60
65
|
const parsed = ENTRY_SCHEMA.safeParse(entry);
|
|
61
66
|
if (!parsed.success)
|
|
62
67
|
return unreadable(file, `the fields of ${id} have the wrong shape`);
|
|
63
|
-
const {
|
|
68
|
+
const { constraints } = parsed.data;
|
|
69
|
+
const { details, examples, default_notes: defaultNotes } = parsed.data.help ?? parsed.data;
|
|
64
70
|
return { kind: 'read', notes: { details, constraints, examples, defaultNotes: new Map(Object.entries(defaultNotes)) } };
|
|
65
71
|
}
|
|
66
72
|
//# sourceMappingURL=authored-notes.js.map
|
|
@@ -23,6 +23,10 @@ export declare function saveConfig(config: ProjectConfig, file: string): void;
|
|
|
23
23
|
export declare function getActiveConfigPath(): string | undefined;
|
|
24
24
|
export declare function loadActiveConfig(): ProjectConfig | undefined;
|
|
25
25
|
/**
|
|
26
|
+
projects/ にある設定の名前(拡張子 .json を除く。名前順)。ディレクトリが無ければ空
|
|
27
|
+
*/
|
|
28
|
+
export declare function listProjectConfigNames(): readonly string[];
|
|
29
|
+
/**
|
|
26
30
|
アクティブ設定を設定する。.active には .active のあるディレクトリ基準の相対パスを書く。ファイルが無ければ ConfigError
|
|
27
31
|
*/
|
|
28
32
|
export declare function setActiveConfig(file: string): void;
|
|
@@ -67,6 +67,19 @@ export function loadActiveConfig() {
|
|
|
67
67
|
return configPath === undefined ? undefined : loadConfig(configPath);
|
|
68
68
|
}
|
|
69
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
|
+
/**
|
|
70
83
|
アクティブ設定を設定する。.active には .active のあるディレクトリ基準の相対パスを書く。ファイルが無ければ ConfigError
|
|
71
84
|
*/
|
|
72
85
|
export function setActiveConfig(file) {
|
package/cli/dist/infra/git.d.ts
CHANGED
|
@@ -15,8 +15,20 @@ export interface GitOptions {
|
|
|
15
15
|
true なら非 0 終了で GitCommandError を投げる
|
|
16
16
|
*/
|
|
17
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;
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
28
|
+
時間切れで止めたときの exitCode
|
|
29
|
+
*/
|
|
30
|
+
export declare const GIT_TIMED_OUT = -2;
|
|
31
|
+
/**
|
|
20
32
|
check 付きの実行が非 0 で終わった(Python の CalledProcessError に当たる)
|
|
21
33
|
*/
|
|
22
34
|
export declare class GitCommandError extends BaseError {
|
|
@@ -71,4 +83,68 @@ export declare function gitCurrentBranch(cwd?: string): string | undefined;
|
|
|
71
83
|
指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
|
|
72
84
|
*/
|
|
73
85
|
export declare function remoteRepository(cwd: string | undefined, remote: string): RemoteLocation | undefined;
|
|
86
|
+
export declare const NON_INTERACTIVE_GIT: Readonly<Record<string, string>>;
|
|
87
|
+
export interface FetchResult {
|
|
88
|
+
readonly succeeded: boolean;
|
|
89
|
+
readonly stderr: string;
|
|
90
|
+
}
|
|
91
|
+
export type PushResult = {
|
|
92
|
+
readonly pushed: true;
|
|
93
|
+
} | {
|
|
94
|
+
readonly pushed: false;
|
|
95
|
+
readonly stderr: string;
|
|
96
|
+
};
|
|
97
|
+
export type RebaseOutcome = 'done' | 'conflict';
|
|
98
|
+
/**
|
|
99
|
+
`git fetch <remote>`。失敗・時間切れは succeeded が false
|
|
100
|
+
*/
|
|
101
|
+
export declare function fetchRemote(cwd: string, remote: string): FetchResult;
|
|
102
|
+
/**
|
|
103
|
+
ref の指すコミットの SHA。無ければ undefined
|
|
104
|
+
*/
|
|
105
|
+
export declare function resolveCommit(cwd: string, reference: string): string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
2 つの ref の merge-base の SHA。共通の祖先が無ければ undefined
|
|
108
|
+
*/
|
|
109
|
+
export declare function mergeBase(cwd: string, a: string, b: string): string | undefined;
|
|
110
|
+
/**
|
|
111
|
+
`git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
|
|
112
|
+
*/
|
|
113
|
+
export declare function rebaseOnto(cwd: string, newBase: string, oldBase: string): RebaseOutcome;
|
|
114
|
+
/**
|
|
115
|
+
衝突を解いた後の `git rebase --continue`。コミットの文の編集は開かない
|
|
116
|
+
*/
|
|
117
|
+
export declare function continueRebase(cwd: string): RebaseOutcome;
|
|
118
|
+
export declare function abortRebase(cwd: string): void;
|
|
119
|
+
/**
|
|
120
|
+
rebase の途中か。worktree では .git がファイルなので、git に場所を尋ねる
|
|
121
|
+
*/
|
|
122
|
+
export declare function isRebaseInProgress(cwd: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
衝突が残っているファイルの一覧
|
|
125
|
+
*/
|
|
126
|
+
export declare function conflictedFiles(cwd: string): readonly string[];
|
|
127
|
+
/**
|
|
128
|
+
remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
|
|
129
|
+
*/
|
|
130
|
+
export declare function remoteOnlyChanges(cwd: string, local: string, remoteBranch: string, excluded: readonly string[]): readonly string[];
|
|
131
|
+
/**
|
|
132
|
+
2 つの ref の木が同じか
|
|
133
|
+
*/
|
|
134
|
+
export declare function hasSameTree(cwd: string, a: string, b: string): boolean;
|
|
135
|
+
export declare function resetHardTo(cwd: string, reference: string): void;
|
|
136
|
+
/**
|
|
137
|
+
remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか失敗したら stderr を返す
|
|
138
|
+
*/
|
|
139
|
+
export declare function pushWithLease(cwd: string, remote: string, branch: string, expectedSha: string): PushResult;
|
|
140
|
+
export type RemoteHead = {
|
|
141
|
+
readonly isReachable: true;
|
|
142
|
+
readonly sha: string | undefined;
|
|
143
|
+
} | {
|
|
144
|
+
readonly isReachable: false;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
|
|
148
|
+
*/
|
|
149
|
+
export declare function remoteBranchHead(cwd: string, remote: string, branch: string): RemoteHead;
|
|
74
150
|
//# sourceMappingURL=git.d.ts.map
|
package/cli/dist/infra/git.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
// git コマンド実行の唯一の窓口。git の subprocess 呼び出しはすべて runGit を経由する。
|
|
2
2
|
// 値を返す helper(gitToplevel 等)は、失敗時に undefined を返す。
|
|
3
3
|
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
4
6
|
import { parseRemoteUrl } from '../domain/git-url.js';
|
|
5
7
|
import { BaseError, InvalidValueError } from '../domain/errors.js';
|
|
6
8
|
import { normalizeNewlines, pythonRepr, pythonStrip } from '../domain/python-format.js';
|
|
7
9
|
import { childStdin } from './child-stdin.js';
|
|
8
10
|
import { isFileNotFound, toOsError } from './os-error.js';
|
|
9
11
|
/**
|
|
12
|
+
時間切れで止めたときの exitCode
|
|
13
|
+
*/
|
|
14
|
+
export const GIT_TIMED_OUT = -2;
|
|
15
|
+
function isTimedOut(error) {
|
|
16
|
+
return error !== undefined && 'code' in error && error.code === 'ETIMEDOUT';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
10
19
|
check 付きの実行が非 0 で終わった(Python の CalledProcessError に当たる)
|
|
11
20
|
*/
|
|
12
21
|
export class GitCommandError extends BaseError {
|
|
@@ -31,13 +40,18 @@ git を実行する。標準出力・標準エラーは改行を \n に揃えた
|
|
|
31
40
|
git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
|
|
32
41
|
*/
|
|
33
42
|
export function runGit(arguments_, options = {}) {
|
|
43
|
+
// interface-env: none
|
|
44
|
+
const base = options.stripGitEnvironment === true ? withoutGitVariables() : (options.env === undefined ? undefined : process.env);
|
|
34
45
|
const result = spawnSync('git', [...arguments_], {
|
|
35
46
|
cwd: options.cwd,
|
|
36
|
-
env:
|
|
47
|
+
env: base === undefined ? undefined : { ...base, ...options.env },
|
|
37
48
|
encoding: 'utf8',
|
|
38
49
|
maxBuffer: MAX_OUTPUT_BYTES,
|
|
39
50
|
stdio: [childStdin(), 'pipe', 'pipe'],
|
|
51
|
+
...(options.timeoutMilliseconds !== undefined && { timeout: options.timeoutMilliseconds, killSignal: 'SIGKILL' }),
|
|
40
52
|
});
|
|
53
|
+
if (isTimedOut(result.error))
|
|
54
|
+
return { exitCode: GIT_TIMED_OUT, stdout: normalizeNewlines(result.stdout), stderr: normalizeNewlines(result.stderr) };
|
|
41
55
|
if (result.error !== undefined) {
|
|
42
56
|
// spawnSync の ENOENT は path が `git` で入る。cwd が無いときも同じ ENOENT になる
|
|
43
57
|
throw toOsError(result.error);
|
|
@@ -130,4 +144,112 @@ export function remoteRepository(cwd, remote) {
|
|
|
130
144
|
throw error;
|
|
131
145
|
}
|
|
132
146
|
}
|
|
147
|
+
// 端末で尋ねさせない。ssh は GIT_SSH_COMMAND で BatchMode にすると利用者の GIT_SSH と core.sshCommand を上書きするので、askpass を失敗させる
|
|
148
|
+
export const NON_INTERACTIVE_GIT = { GIT_TERMINAL_PROMPT: '0', SSH_ASKPASS: 'false', SSH_ASKPASS_REQUIRE: 'force' };
|
|
149
|
+
// fetch・push は、認証の入力を待たずに、この時間で諦める
|
|
150
|
+
const REMOTE_TIMEOUT_MILLISECONDS = 60_000;
|
|
151
|
+
const PEEL_TO_COMMIT = '^{commit}';
|
|
152
|
+
/**
|
|
153
|
+
`git fetch <remote>`。失敗・時間切れは succeeded が false
|
|
154
|
+
*/
|
|
155
|
+
export function fetchRemote(cwd, remote) {
|
|
156
|
+
const result = runGit(['fetch', remote], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS });
|
|
157
|
+
return { succeeded: result.exitCode === 0, stderr: result.stderr };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
ref の指すコミットの SHA。無ければ undefined
|
|
161
|
+
*/
|
|
162
|
+
export function resolveCommit(cwd, reference) {
|
|
163
|
+
return runForValue(['rev-parse', '--verify', '--quiet', `${reference}${PEEL_TO_COMMIT}`], { cwd });
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
2 つの ref の merge-base の SHA。共通の祖先が無ければ undefined
|
|
167
|
+
*/
|
|
168
|
+
export function mergeBase(cwd, a, b) {
|
|
169
|
+
return runForValue(['merge-base', a, b], { cwd });
|
|
170
|
+
}
|
|
171
|
+
// 失敗の後に rebase の途中なら衝突、ほかの失敗は GitCommandError
|
|
172
|
+
function rebaseOutcome(cwd, arguments_, environment) {
|
|
173
|
+
const result = runGit(arguments_, { cwd, env: environment });
|
|
174
|
+
if (result.exitCode === 0)
|
|
175
|
+
return 'done';
|
|
176
|
+
if (isRebaseInProgress(cwd))
|
|
177
|
+
return 'conflict';
|
|
178
|
+
throw new GitCommandError(arguments_, result);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
`git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
|
|
182
|
+
*/
|
|
183
|
+
export function rebaseOnto(cwd, newBase, oldBase) {
|
|
184
|
+
const arguments_ = ['rebase', '--no-update-refs', '--onto', newBase, oldBase];
|
|
185
|
+
// 既に途中なら git は始めずに失敗する。その失敗を衝突と読まない
|
|
186
|
+
if (isRebaseInProgress(cwd))
|
|
187
|
+
throw new GitCommandError(arguments_, runGit(arguments_, { cwd }));
|
|
188
|
+
return rebaseOutcome(cwd, arguments_);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
衝突を解いた後の `git rebase --continue`。コミットの文の編集は開かない
|
|
192
|
+
*/
|
|
193
|
+
export function continueRebase(cwd) {
|
|
194
|
+
return rebaseOutcome(cwd, ['rebase', '--continue'], { ...NON_INTERACTIVE_GIT, GIT_EDITOR: 'true' });
|
|
195
|
+
}
|
|
196
|
+
export function abortRebase(cwd) {
|
|
197
|
+
runGit(['rebase', '--abort'], { cwd, check: true });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
rebase の途中か。worktree では .git がファイルなので、git に場所を尋ねる
|
|
201
|
+
*/
|
|
202
|
+
export function isRebaseInProgress(cwd) {
|
|
203
|
+
const output = runGit(['rev-parse', '--git-path', 'rebase-merge', '--git-path', 'rebase-apply'], { cwd, check: true }).stdout;
|
|
204
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- git が返した git ディレクトリの中のパス
|
|
205
|
+
return output.split('\n').filter(line => line !== '').some(line => existsSync(path.resolve(cwd, line)));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
衝突が残っているファイルの一覧
|
|
209
|
+
*/
|
|
210
|
+
export function conflictedFiles(cwd) {
|
|
211
|
+
return runGit(['diff', '--name-only', '--diff-filter=U'], { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
|
|
215
|
+
*/
|
|
216
|
+
export function remoteOnlyChanges(cwd, local, remoteBranch, excluded) {
|
|
217
|
+
const arguments_ = ['rev-list', '--right-only', '--cherry-pick', '--no-merges', `${local}...${remoteBranch}`, ...excluded.map(reference => `^${reference}`), '--'];
|
|
218
|
+
return runGit(arguments_, { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
2 つの ref の木が同じか
|
|
222
|
+
*/
|
|
223
|
+
export function hasSameTree(cwd, a, b) {
|
|
224
|
+
const arguments_ = ['diff', '--quiet', a, b, '--'];
|
|
225
|
+
const result = runGit(arguments_, { cwd });
|
|
226
|
+
if (result.exitCode === 0)
|
|
227
|
+
return true;
|
|
228
|
+
if (result.exitCode === 1)
|
|
229
|
+
return false;
|
|
230
|
+
throw new GitCommandError(arguments_, result);
|
|
231
|
+
}
|
|
232
|
+
export function resetHardTo(cwd, reference) {
|
|
233
|
+
runGit(['reset', '--quiet', '--hard', reference], { cwd, check: true });
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか失敗したら stderr を返す
|
|
237
|
+
*/
|
|
238
|
+
export function pushWithLease(cwd, remote, branch, expectedSha) {
|
|
239
|
+
const result = runGit(['push', `--force-with-lease=${branch}:${expectedSha}`, remote, branch], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS });
|
|
240
|
+
return result.exitCode === 0 ? { pushed: true } : { pushed: false, stderr: result.stderr };
|
|
241
|
+
}
|
|
242
|
+
// ls-remote は、ref が無いと終了コード 2 を返す
|
|
243
|
+
const LS_REMOTE_NOT_FOUND = 2;
|
|
244
|
+
const LS_REMOTE_TIMEOUT_MILLISECONDS = 10_000;
|
|
245
|
+
/**
|
|
246
|
+
remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
|
|
247
|
+
*/
|
|
248
|
+
export function remoteBranchHead(cwd, remote, branch) {
|
|
249
|
+
const listed = runGit(['ls-remote', '--exit-code', remote, `refs/heads/${branch}`], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: LS_REMOTE_TIMEOUT_MILLISECONDS });
|
|
250
|
+
if (listed.exitCode === LS_REMOTE_NOT_FOUND)
|
|
251
|
+
return { isReachable: true, sha: undefined };
|
|
252
|
+
const [sha] = listed.exitCode === 0 ? listed.stdout.split(/\s/u, 1) : [];
|
|
253
|
+
return sha === undefined || sha === '' ? { isReachable: false } : { isReachable: true, sha };
|
|
254
|
+
}
|
|
133
255
|
//# sourceMappingURL=git.js.map
|
|
@@ -20,7 +20,12 @@ export interface RestRequestOptions {
|
|
|
20
20
|
JSON の本文
|
|
21
21
|
*/
|
|
22
22
|
readonly json?: JsonValue | undefined;
|
|
23
|
+
/**
|
|
24
|
+
X-GitHub-Api-Version の値。省略すると DEFAULT_API_VERSION
|
|
25
|
+
*/
|
|
26
|
+
readonly apiVersion?: string | undefined;
|
|
23
27
|
}
|
|
28
|
+
export declare const DEFAULT_API_VERSION = "2022-11-28";
|
|
24
29
|
/**
|
|
25
30
|
送信の失敗(接続できない・時間切れ)。Python の httpx の例外に当たり、PecotError ではない
|
|
26
31
|
*/
|