@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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// PR コマンドの入出力を持たない関数。本文の検証、Closes の抽出と追記、`pr
|
|
1
|
+
// PR コマンドの入出力を持たない関数。本文の検証、Closes の抽出と追記、`pr show` の Markdown の整形、preflight の警告の判定。
|
|
2
2
|
// 引数の型は、infra/github/pulls.ts の返す値が構造として満たす形をここに持つ(domain は infra を import できない)。
|
|
3
|
+
import { hinted, inputHint, inputNameHint } from './command-hint.js';
|
|
3
4
|
import { parsePythonInteger, pythonRightStrip, pythonStrip, splitCodePoints, truncateCodePoints } from './python-format.js';
|
|
4
5
|
import { hasSummaryImage, validateBodyStyle, validateHeadingSummaries, validateSections } from './sections.js';
|
|
5
6
|
// Issue 参照(`#N`、URL 内のフラグメントは除く)。`owner/repo#N` の形も受ける
|
|
@@ -12,10 +13,8 @@ const CLOSING_KEYWORDS_PATTERN = new RegExp(String.raw `(?:close[sd]?|fix(?:e[sd
|
|
|
12
13
|
// stash の件数を数える行の区切り。str.splitlines と同じ。
|
|
13
14
|
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex -- 区切りの制御文字と誤検知
|
|
14
15
|
const LINE_BREAK = /\r\n|[\n\r\v\f\u{1C}-\u{1E}\u{85}\u{2028}\u{2029}]/u;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
+ 'take a screenshot and add it to Summary as ``. '
|
|
18
|
-
+ 'Otherwise, write the reason in the `screenshot` frontmatter field (`--screenshot` with `-m`)';
|
|
16
|
+
const PR_CREATE_PATH = ['pr', 'create'];
|
|
17
|
+
export const SCREENSHOT_MISSING_ERROR = hinted `Summary has no image and \`screenshot\` gives no reason to omit one. If the change alters a screen, Markdown the tool writes for GitHub, or CLI output text, take a screenshot and add it to Summary as \`\`. Otherwise, write the reason in the \`screenshot\` frontmatter field (\`${inputNameHint(PR_CREATE_PATH, 'screenshot')}\` with \`${inputNameHint(PR_CREATE_PATH, 'message')}\`)`;
|
|
19
18
|
/**
|
|
20
19
|
本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
|
|
21
20
|
*/
|
|
@@ -56,7 +55,7 @@ export function validatePullRequestContent(options) {
|
|
|
56
55
|
const errors = [];
|
|
57
56
|
const isRelease = isReleasePullRequest(options.template, base, options.head, developBranch, releaseBranch);
|
|
58
57
|
if (!isRelease && !options.skipIssueReferenceCheck && !hasIssueReference(body)) {
|
|
59
|
-
errors.push(
|
|
58
|
+
errors.push(hinted `PR body has no Issue reference \`#N\` (use \`${inputHint(PR_CREATE_PATH, 'no_issue_ref')}\` for a PR not tied to an Issue)`);
|
|
60
59
|
}
|
|
61
60
|
if (requiredSections.length > 0) {
|
|
62
61
|
const missing = validateSections(body, requiredSections);
|
|
@@ -77,10 +76,60 @@ export function validatePullRequestContent(options) {
|
|
|
77
76
|
errors.push(`release PR base branch must be ${releaseBranch} (given: ${base})`);
|
|
78
77
|
}
|
|
79
78
|
else if (developBranch !== undefined && developBranch !== '' && base !== developBranch) {
|
|
80
|
-
|
|
79
|
+
const { stackedBase } = options;
|
|
80
|
+
const isStacked = stackedBase !== undefined && stackedBase !== '' && stackedBase !== developBranch;
|
|
81
|
+
if (!isStacked)
|
|
82
|
+
errors.push(`base branch must be ${developBranch} (given: ${base})`);
|
|
83
|
+
else if (base !== stackedBase)
|
|
84
|
+
errors.push(`base branch must be ${developBranch} or ${stackedBase} (given: ${base})`);
|
|
81
85
|
}
|
|
82
86
|
return errors;
|
|
83
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
base の記録と下の段の PR の状態から、PR を作る base とスタックへの登録を決める。
|
|
90
|
+
記録の base でも開発ブランチでもない base は、そのまま返して内容の検証で落とす
|
|
91
|
+
*/
|
|
92
|
+
export function decidePullRequestBase(input) {
|
|
93
|
+
const { reading, base, developBranch } = input;
|
|
94
|
+
if (reading.kind === 'malformed')
|
|
95
|
+
return { kind: 'stop', reason: 'malformed', content: reading.content };
|
|
96
|
+
if (reading.kind === 'development')
|
|
97
|
+
return { kind: 'use', base, stackOn: undefined, stackedBase: undefined, isLowerMerged: false };
|
|
98
|
+
const { branch } = reading.record;
|
|
99
|
+
const lower = input.lowerPullRequest;
|
|
100
|
+
if (lower === undefined || lower.state === 'CLOSED')
|
|
101
|
+
return { kind: 'stop', reason: 'no-open-pr', branch };
|
|
102
|
+
const isKnownBase = base === branch || base === developBranch;
|
|
103
|
+
if (lower.state === 'MERGED')
|
|
104
|
+
return { kind: 'use', base: isKnownBase ? developBranch : base, stackOn: undefined, stackedBase: branch, isLowerMerged: true };
|
|
105
|
+
if (base === developBranch)
|
|
106
|
+
return { kind: 'stop', reason: 'lower-open', branch, pullRequest: lower.number, base };
|
|
107
|
+
return { kind: 'use', base, stackOn: base === branch ? lower.number : undefined, stackedBase: branch, isLowerMerged: false };
|
|
108
|
+
}
|
|
109
|
+
const LOWER_STATE_ORDER = ['OPEN', 'MERGED', 'CLOSED'];
|
|
110
|
+
/**
|
|
111
|
+
下の段のブランチを head に持つ PR から、base を決める 1 本を選ぶ。fork でないもののうち、開いている・マージ済み・閉じた の順(同じ状態なら渡した順の先頭)
|
|
112
|
+
*/
|
|
113
|
+
export function pickLowerPullRequest(pullRequests) {
|
|
114
|
+
const own = pullRequests.filter(pullRequest => !pullRequest.isCrossRepository);
|
|
115
|
+
return LOWER_STATE_ORDER.map(state => own.find(pullRequest => pullRequest.state === state)).find(found => found !== undefined);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
止めた理由の文(`error: ` の前置きを含まない)。下の段の PR が無いときは、直し方の行を続ける
|
|
119
|
+
*/
|
|
120
|
+
export function describeBaseStop(stop) {
|
|
121
|
+
switch (stop.reason) {
|
|
122
|
+
case 'malformed': {
|
|
123
|
+
return [`.pecot-base is malformed: ${stop.content}`];
|
|
124
|
+
}
|
|
125
|
+
case 'no-open-pr': {
|
|
126
|
+
return [`base branch ${stop.branch} has no open PR`, `reopen the PR of ${stop.branch}, or create a new one, then run pr create again`];
|
|
127
|
+
}
|
|
128
|
+
case 'lower-open': {
|
|
129
|
+
return [`base branch must be ${stop.branch} while its PR #${String(stop.pullRequest)} is open (given: ${stop.base})`];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
84
133
|
// ISO 8601 の先頭 10 文字(YYYY-MM-DD)。10 文字に満たなければ空
|
|
85
134
|
function datePart(timestamp) {
|
|
86
135
|
return timestamp !== null && splitCodePoints(timestamp).length >= 10 ? truncateCodePoints(timestamp, 10) : '';
|
|
@@ -99,7 +148,7 @@ function referencedIssueLine(issue) {
|
|
|
99
148
|
return ` - #${String(issue.number)}${issue.title === '' ? '' : ` ${issue.title}`}`;
|
|
100
149
|
}
|
|
101
150
|
/**
|
|
102
|
-
`pr
|
|
151
|
+
`pr show` の既定の Markdown
|
|
103
152
|
*/
|
|
104
153
|
export function formatPullRequestMarkdown(pr) {
|
|
105
154
|
const lines = [`## PR #${String(pr.number)} ${pr.title}`, '', metaLine(pr), '', `**Branch:** \`${pr.head_ref}\` → \`${pr.base_ref}\``, ''];
|
|
@@ -157,11 +206,11 @@ export function formatReviewThreadsMarkdown(threads) {
|
|
|
157
206
|
return lines.join('\n');
|
|
158
207
|
}
|
|
159
208
|
/**
|
|
160
|
-
`pr
|
|
209
|
+
`pr show --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
|
|
161
210
|
*/
|
|
162
211
|
export function formatPullRequestWithReviewsMarkdown(pr, owner, repository) {
|
|
163
212
|
const lines = [`## PR #${String(pr.number)} ${pr.title}`, '', metaLine(pr), '', `**Branch:** \`${pr.head_ref}\` → \`${pr.base_ref}\``, ''];
|
|
164
|
-
const detailsLine = (issue) => ` → details:
|
|
213
|
+
const detailsLine = (issue) => ` → details: issue show ${owner}/${repository}/${String(issue.number)}`;
|
|
165
214
|
if (pr.closing_issues.length > 0) {
|
|
166
215
|
lines.push('**Closing Issues:**');
|
|
167
216
|
for (const issue of pr.closing_issues)
|
|
@@ -142,6 +142,50 @@ export declare function planProgression(phases: readonly PlannedPhase[]): Progre
|
|
|
142
142
|
stack の積む先をたどった木の、根から葉までの道を、下から並べて返す。stack の無い根は道を作らないので、1 段だけの道は出ない
|
|
143
143
|
*/
|
|
144
144
|
export declare function stackChains(progressions: ReadonlyMap<string, Progression>): readonly (readonly string[])[];
|
|
145
|
+
/**
|
|
146
|
+
target から前提をたどって届く部分のグラフに findCycle をかけ、輪が target を含むときだけ返す。
|
|
147
|
+
別の Issue の輪に行き当たっただけの Issue には、輪を付けない
|
|
148
|
+
*/
|
|
149
|
+
export declare function cycleThrough(target: string, edges: ReadonlyMap<string, readonly string[]>): readonly string[] | undefined;
|
|
150
|
+
/**
|
|
151
|
+
判定の一覧(Issue のキー → 判定)から、stackChains に渡す進め方を作る。
|
|
152
|
+
stackable は積む先の Issue の上に積み、それ以外は単独として扱う
|
|
153
|
+
*/
|
|
154
|
+
export declare function progressionsFromReadiness(readiness: ReadonlyMap<string, Readiness>): ReadonlyMap<string, Progression>;
|
|
155
|
+
/**
|
|
156
|
+
メッセージに出す Issue の表記。home と同じリポジトリは `#N`、別のリポジトリは `owner/repo#N`。home が無ければ常に `owner/repo#N`
|
|
157
|
+
*/
|
|
158
|
+
export declare function displayReference(reference: IssueReference, home?: RepositoryReference): string;
|
|
159
|
+
/**
|
|
160
|
+
前提 1 件の状態の文。`done`・`closed without merge`・`in review`・`wait: merge — <理由>`、または積めない理由(not started など)
|
|
161
|
+
*/
|
|
162
|
+
export declare function describePrerequisiteState(prerequisite: Readonly<Prerequisite>): string;
|
|
163
|
+
/**
|
|
164
|
+
判定を 1 行の文にする。`startable`・`stackable on #N`・`blocked by #N, #M (<理由>)`。
|
|
165
|
+
blocked by の後には、済んでいない前提をすべて並べる。別のリポジトリの Issue は `owner/repo#N`
|
|
166
|
+
*/
|
|
167
|
+
export declare function describeReadiness(readiness: Readiness, prerequisites: readonly Prerequisite[], targetRepository: RepositoryReference): string;
|
|
168
|
+
/**
|
|
169
|
+
issues の前提と、その pullRequest を state にしたものとして置き換える。一覧に pullRequest が無ければ足す。
|
|
170
|
+
マージの後の読み取りから、マージの前(open)や閉じた後(merged)の判定を作るのに使う
|
|
171
|
+
*/
|
|
172
|
+
export declare function assumePullRequestState(prerequisites: readonly Prerequisite[], issues: readonly IssueReference[], pullRequest: IssuePullRequest, state: 'open' | 'merged'): readonly Prerequisite[];
|
|
173
|
+
/**
|
|
174
|
+
判定の区分か積む先のブランチが違うか。理由と注記の違いは変化としない
|
|
175
|
+
*/
|
|
176
|
+
export declare function hasReadinessChanged(before: Readiness, after: Readiness): boolean;
|
|
177
|
+
/**
|
|
178
|
+
判定の変化の行の文。blocked は理由を付けず、stackable は積む先を付ける
|
|
179
|
+
*/
|
|
180
|
+
export declare function describeReadinessChange(readiness: Readiness, targetRepository: RepositoryReference): string;
|
|
181
|
+
/**
|
|
182
|
+
着手の跡があり、issues のどれかを stack で待つ(その上に積んだ段の)Issue か
|
|
183
|
+
*/
|
|
184
|
+
export declare function isStackedOn(target: IssueFacts, prerequisites: readonly Prerequisite[], issues: readonly IssueReference[]): boolean;
|
|
185
|
+
/**
|
|
186
|
+
読めなかった Issue の表示。列と札は動かさない
|
|
187
|
+
*/
|
|
188
|
+
export declare function describeUnknown(reason: string): string;
|
|
145
189
|
export interface FactsMismatch {
|
|
146
190
|
readonly ref: IssueReference;
|
|
147
191
|
readonly reason: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Issue の着手の可否の判定と、フェーズの進め方(specs/024 の data-model.md の 2〜4)。I/O を持たない純関数だけを置く。
|
|
2
2
|
import { isEpicIssue } from './issue-kind.js';
|
|
3
3
|
import { issueReferenceKey } from './reference-parser.js';
|
|
4
|
-
import { isSameRepository } from './repository-resolver.js';
|
|
4
|
+
import { isSameRepository, repositoryFullName } from './repository-resolver.js';
|
|
5
5
|
export const PENDING_COLUMN = 'Pending';
|
|
6
6
|
export const NEEDS_ATTENTION_LABEL = 'Needs Attention';
|
|
7
7
|
export const TRACKER_TITLE_PREFIX = '[Tracker]';
|
|
@@ -55,12 +55,14 @@ function headsToDevelopment(start, byHead, developmentBranch) {
|
|
|
55
55
|
return reached;
|
|
56
56
|
}
|
|
57
57
|
// 済んでいない前提はすべて PR 中なので、open の PR がちょうど 1 本ある
|
|
58
|
+
// 辿る PR も、対象と同じリポのものだけにする
|
|
58
59
|
function findStackTarget(unfinished, input) {
|
|
60
|
+
const targetRepository = input.target.ref.repository;
|
|
59
61
|
const entries = unfinished.flatMap(({ issue }) => {
|
|
60
62
|
const [pullRequest] = openPullRequests(issue);
|
|
61
63
|
return pullRequest === undefined ? [] : { issue: issue.ref, pullRequest };
|
|
62
64
|
});
|
|
63
|
-
const byHead = new Map([...input.pullRequestsByHead].filter(([, pullRequest]) => isStackBase(pullRequest)));
|
|
65
|
+
const byHead = new Map([...input.pullRequestsByHead].filter(([, pullRequest]) => isStackBase(pullRequest) && isSameRepository(pullRequest.repository, targetRepository)));
|
|
64
66
|
for (const { pullRequest } of entries)
|
|
65
67
|
byHead.set(pullRequest.headRefName, pullRequest);
|
|
66
68
|
for (const start of entries) {
|
|
@@ -99,7 +101,9 @@ export function judgeReadiness(input) {
|
|
|
99
101
|
}
|
|
100
102
|
if (unfinished.length === 0)
|
|
101
103
|
return result('startable', { needsReview: isNeedsReview, attention });
|
|
102
|
-
|
|
104
|
+
// 前提の Issue か、その PR が別のリポにあると、積む先のブランチを対象のリポで引けない
|
|
105
|
+
const otherRepository = unfinished.filter(({ issue }) => !isSameRepository(issue.ref.repository, target.ref.repository)
|
|
106
|
+
|| (isInReview(issue) && openPullRequests(issue).some(pullRequest => !isSameRepository(pullRequest.repository, target.ref.repository))));
|
|
103
107
|
if (otherRepository.length > 0)
|
|
104
108
|
return blocked({ code: 'other-repository', issues: otherRepository.map(({ issue }) => issue.ref) });
|
|
105
109
|
const notInReview = unfinished.filter(({ issue }) => !isStackable(issue));
|
|
@@ -208,6 +212,150 @@ export function stackChains(progressions) {
|
|
|
208
212
|
};
|
|
209
213
|
return roots.flatMap(root => walk(root, [root]));
|
|
210
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
target から前提をたどって届く部分のグラフに findCycle をかけ、輪が target を含むときだけ返す。
|
|
217
|
+
別の Issue の輪に行き当たっただけの Issue には、輪を付けない
|
|
218
|
+
*/
|
|
219
|
+
export function cycleThrough(target, edges) {
|
|
220
|
+
const reached = new Set([target]);
|
|
221
|
+
const pending = [target];
|
|
222
|
+
for (let key = pending.pop(); key !== undefined; key = pending.pop()) {
|
|
223
|
+
const nextKeys = edges.get(key) ?? [];
|
|
224
|
+
for (const next of nextKeys) {
|
|
225
|
+
if (reached.has(next))
|
|
226
|
+
continue;
|
|
227
|
+
reached.add(next);
|
|
228
|
+
pending.push(next);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const subgraph = new Map([...reached].map(key => [key, edges.get(key) ?? []]));
|
|
232
|
+
const cycle = findCycle(subgraph);
|
|
233
|
+
return cycle?.includes(target) === true ? cycle : undefined;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
判定の一覧(Issue のキー → 判定)から、stackChains に渡す進め方を作る。
|
|
237
|
+
stackable は積む先の Issue の上に積み、それ以外は単独として扱う
|
|
238
|
+
*/
|
|
239
|
+
export function progressionsFromReadiness(readiness) {
|
|
240
|
+
return new Map([...readiness].map(([key, judged]) => [
|
|
241
|
+
key,
|
|
242
|
+
judged.kind === 'stackable' && judged.stackOn !== undefined
|
|
243
|
+
? { kind: 'stack', on: issueReferenceKey(judged.stackOn.issue) }
|
|
244
|
+
: { kind: 'alone' },
|
|
245
|
+
]));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
メッセージに出す Issue の表記。home と同じリポジトリは `#N`、別のリポジトリは `owner/repo#N`。home が無ければ常に `owner/repo#N`
|
|
249
|
+
*/
|
|
250
|
+
export function displayReference(reference, home) {
|
|
251
|
+
const number = `#${String(reference.number)}`;
|
|
252
|
+
return home !== undefined && isSameRepository(reference.repository, home) ? number : `${repositoryFullName(reference.repository)}${number}`;
|
|
253
|
+
}
|
|
254
|
+
const NOT_IN_REVIEW_TEXT = new Map([
|
|
255
|
+
['not-started', 'not started'],
|
|
256
|
+
['started-without-pr', 'no PR'],
|
|
257
|
+
['multiple-prs', 'multiple PRs'],
|
|
258
|
+
['fork-pr', 'PR from fork'],
|
|
259
|
+
['pending', 'in Pending'],
|
|
260
|
+
]);
|
|
261
|
+
/**
|
|
262
|
+
前提 1 件の状態の文。`done`・`closed without merge`・`in review`・`wait: merge — <理由>`、または積めない理由(not started など)
|
|
263
|
+
*/
|
|
264
|
+
export function describePrerequisiteState(prerequisite) {
|
|
265
|
+
const { issue, wait, reason } = prerequisite;
|
|
266
|
+
if (isDone(issue))
|
|
267
|
+
return 'done';
|
|
268
|
+
if (issue.state === 'closed')
|
|
269
|
+
return 'closed without merge';
|
|
270
|
+
if (wait === 'merge')
|
|
271
|
+
return reason === undefined ? 'wait: merge' : `wait: merge — ${reason}`;
|
|
272
|
+
const state = notInReviewState(issue);
|
|
273
|
+
return isStackable(issue) ? 'in review' : (NOT_IN_REVIEW_TEXT.get(state) ?? state);
|
|
274
|
+
}
|
|
275
|
+
function describeReason(reason, targetRepository) {
|
|
276
|
+
const show = (reference) => displayReference(reference, targetRepository);
|
|
277
|
+
switch (reason.code) {
|
|
278
|
+
case 'unreadable': {
|
|
279
|
+
return 'unreadable';
|
|
280
|
+
}
|
|
281
|
+
case 'waits-merge': {
|
|
282
|
+
return 'waits for merge';
|
|
283
|
+
}
|
|
284
|
+
case 'diverged': {
|
|
285
|
+
return 'not in one chain';
|
|
286
|
+
}
|
|
287
|
+
case 'closed-unmerged': {
|
|
288
|
+
return `closed without merge: ${reason.issues.map(issue => show(issue)).join(', ')}`;
|
|
289
|
+
}
|
|
290
|
+
case 'other-repository': {
|
|
291
|
+
return `other repository: ${reason.issues.map(issue => show(issue)).join(', ')}`;
|
|
292
|
+
}
|
|
293
|
+
case 'not-in-review': {
|
|
294
|
+
return `not in review: ${reason.issues.map(({ issue, state }) => `${show(issue)} (${NOT_IN_REVIEW_TEXT.get(state) ?? state})`).join(', ')}`;
|
|
295
|
+
}
|
|
296
|
+
case 'cycle': {
|
|
297
|
+
const prefix = `${repositoryFullName(targetRepository).toLowerCase()}#`;
|
|
298
|
+
return `cycle: ${reason.cycle.map(key => (key.startsWith(prefix) ? `#${key.slice(prefix.length)}` : key)).join(' -> ')}`;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
判定を 1 行の文にする。`startable`・`stackable on #N`・`blocked by #N, #M (<理由>)`。
|
|
304
|
+
blocked by の後には、済んでいない前提をすべて並べる。別のリポジトリの Issue は `owner/repo#N`
|
|
305
|
+
*/
|
|
306
|
+
export function describeReadiness(readiness, prerequisites, targetRepository) {
|
|
307
|
+
if (readiness.kind === 'startable')
|
|
308
|
+
return 'startable';
|
|
309
|
+
if (readiness.kind === 'stackable') {
|
|
310
|
+
return readiness.stackOn === undefined ? 'stackable' : `stackable on ${displayReference(readiness.stackOn.issue, targetRepository)}`;
|
|
311
|
+
}
|
|
312
|
+
const unfinished = prerequisites.filter(({ issue }) => !isDone(issue)).map(({ issue }) => displayReference(issue.ref, targetRepository));
|
|
313
|
+
const reason = readiness.reason === undefined ? '' : ` (${describeReason(readiness.reason, targetRepository)})`;
|
|
314
|
+
return `blocked${unfinished.length === 0 ? '' : ` by ${unfinished.join(', ')}`}${reason}`;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
issues の前提と、その pullRequest を state にしたものとして置き換える。一覧に pullRequest が無ければ足す。
|
|
318
|
+
マージの後の読み取りから、マージの前(open)や閉じた後(merged)の判定を作るのに使う
|
|
319
|
+
*/
|
|
320
|
+
export function assumePullRequestState(prerequisites, issues, pullRequest, state) {
|
|
321
|
+
const keys = new Set(issues.map(issue => issueReferenceKey(issue)));
|
|
322
|
+
const assumed = { ...pullRequest, state };
|
|
323
|
+
const isSame = (other) => other.number === pullRequest.number && isSameRepository(other.repository, pullRequest.repository);
|
|
324
|
+
return prerequisites.map((prerequisite) => {
|
|
325
|
+
const { issue } = prerequisite;
|
|
326
|
+
if (!keys.has(issueReferenceKey(issue.ref)))
|
|
327
|
+
return prerequisite;
|
|
328
|
+
const pullRequests = issue.pullRequests.some(other => isSame(other))
|
|
329
|
+
? issue.pullRequests.map(other => (isSame(other) ? assumed : other))
|
|
330
|
+
: [...issue.pullRequests, assumed];
|
|
331
|
+
return { ...prerequisite, issue: { ...issue, state: state === 'open' ? 'open' : 'closed', pullRequests } };
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
判定の区分か積む先のブランチが違うか。理由と注記の違いは変化としない
|
|
336
|
+
*/
|
|
337
|
+
export function hasReadinessChanged(before, after) {
|
|
338
|
+
return before.kind !== after.kind || before.stackOn?.branch !== after.stackOn?.branch;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
判定の変化の行の文。blocked は理由を付けず、stackable は積む先を付ける
|
|
342
|
+
*/
|
|
343
|
+
export function describeReadinessChange(readiness, targetRepository) {
|
|
344
|
+
return readiness.kind === 'blocked' ? 'blocked' : describeReadiness(readiness, [], targetRepository);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
着手の跡があり、issues のどれかを stack で待つ(その上に積んだ段の)Issue か
|
|
348
|
+
*/
|
|
349
|
+
export function isStackedOn(target, prerequisites, issues) {
|
|
350
|
+
const keys = new Set(issues.map(issue => issueReferenceKey(issue)));
|
|
351
|
+
return hasStarted(target) && prerequisites.some(({ issue, wait }) => wait === 'stack' && keys.has(issueReferenceKey(issue.ref)));
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
読めなかった Issue の表示。列と札は動かさない
|
|
355
|
+
*/
|
|
356
|
+
export function describeUnknown(reason) {
|
|
357
|
+
return `unknown (${reason})`;
|
|
358
|
+
}
|
|
211
359
|
const LOWER_STATE = { OPEN: 'open', MERGED: 'merged', CLOSED: 'closed' };
|
|
212
360
|
function toPullRequest(readout) {
|
|
213
361
|
return {
|
|
@@ -220,12 +368,12 @@ function toPullRequest(readout) {
|
|
|
220
368
|
isCrossRepository: readout.isCrossRepository,
|
|
221
369
|
};
|
|
222
370
|
}
|
|
223
|
-
//
|
|
371
|
+
// 積んだ PR は開いている間 Development 欄に載らず、マージ済みの PR はブランチが消えるので、2 つの読み口を合わせる。
|
|
372
|
+
// 同じ PR は 1 本に数え、fork からの PR は、リンクしたブランチの読み口だけ捨てる
|
|
224
373
|
function collectPullRequests(readout) {
|
|
225
374
|
const sources = [
|
|
226
375
|
...readout.linkedBranches.flatMap(branch => branch.pullRequests).filter(pullRequest => !pullRequest.isCrossRepository),
|
|
227
376
|
...readout.closingPullRequests,
|
|
228
|
-
...readout.timelinePullRequests,
|
|
229
377
|
];
|
|
230
378
|
const seen = new Set();
|
|
231
379
|
return sources
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HintedText } from './command-hint.js';
|
|
1
2
|
import { PecotError } from './errors.js';
|
|
2
3
|
import type { RepositoryReference } from './repository-resolver.js';
|
|
3
4
|
/**
|
|
@@ -5,7 +6,8 @@ import type { RepositoryReference } from './repository-resolver.js';
|
|
|
5
6
|
*/
|
|
6
7
|
export declare class ReferenceParseError extends PecotError {
|
|
7
8
|
readonly reference: string;
|
|
8
|
-
|
|
9
|
+
readonly hintedText: HintedText | undefined;
|
|
10
|
+
constructor(message: string | HintedText, reference: string, options?: Readonly<ErrorOptions>);
|
|
9
11
|
}
|
|
10
12
|
export interface IssueReference {
|
|
11
13
|
readonly repository: RepositoryReference;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// `owner/repo/N` 形式を IssueReference にする。短縮形 `N` は基準リポ(baseRepository)で補う。
|
|
4
4
|
// 参照の形式が不正なときの文は、Python の CLI が出していた文に揃える。
|
|
5
|
+
import { formatHinted, globalRepositoryHint, hinted, placeholder } from './command-hint.js';
|
|
5
6
|
import { PecotError, InvalidValueError } from './errors.js';
|
|
6
7
|
import { parsePythonInteger, ValidationFailure } from './python-format.js';
|
|
7
8
|
import { createRepositoryReference, parseOwnerRepository, repositoryFullName } from './repository-resolver.js';
|
|
@@ -10,9 +11,12 @@ import { createRepositoryReference, parseOwnerRepository, repositoryFullName } f
|
|
|
10
11
|
*/
|
|
11
12
|
export class ReferenceParseError extends PecotError {
|
|
12
13
|
reference;
|
|
14
|
+
hintedText;
|
|
15
|
+
// message は CLI の形。出し先の形は hintedText から描き直す
|
|
13
16
|
constructor(message, reference, options) {
|
|
14
|
-
super(message, options);
|
|
17
|
+
super(formatHinted(message, 'cli'), options);
|
|
15
18
|
this.reference = reference;
|
|
19
|
+
this.hintedText = typeof message === 'string' ? undefined : message;
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
@@ -57,7 +61,7 @@ export function parseIssueReference(raw, baseRepository, { repositoryFlag = fals
|
|
|
57
61
|
if (/^\d+$/u.test(raw)) {
|
|
58
62
|
if (baseRepository === undefined) {
|
|
59
63
|
throw new ReferenceParseError(repositoryFlag
|
|
60
|
-
?
|
|
64
|
+
? hinted `the short form 'N' needs a base_repo: pass ${globalRepositoryHint(placeholder('owner/repo'))} or use the full form 'owner/repo/N'`
|
|
61
65
|
: 'the short form \'N\' is not accepted here: use the full form \'owner/repo/N\'', raw);
|
|
62
66
|
}
|
|
63
67
|
return createIssueReference(baseRepository, integerOf(raw));
|
|
@@ -36,14 +36,18 @@ export interface PreflightOptions {
|
|
|
36
36
|
*/
|
|
37
37
|
readonly tagPrefix: string | undefined;
|
|
38
38
|
/**
|
|
39
|
-
ls-remote
|
|
39
|
+
ls-remote と文に使う remote 名。省略すると origin
|
|
40
40
|
*/
|
|
41
41
|
readonly remote?: string | undefined;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
+
base より head が進んでいる commit の数。GitHub の compare で数え、手元の ref は動かさない
|
|
45
|
+
*/
|
|
46
|
+
export type CountCommitsAhead = (base: string, head: string) => Promise<number>;
|
|
47
|
+
/**
|
|
44
48
|
リリース前チェックを実行する。
|
|
45
49
|
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
46
|
-
4. release→develop
|
|
50
|
+
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
47
51
|
*/
|
|
48
|
-
export declare function runPreflight(options: PreflightOptions, git: GitRunner): PreflightResult
|
|
52
|
+
export declare function runPreflight(options: PreflightOptions, git: GitRunner, countAhead: CountCommitsAhead): Promise<PreflightResult>;
|
|
49
53
|
//# sourceMappingURL=release.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// リリース前チェック(preflight)。git は GitRunner を受けて呼ぶ。CHANGELOG は内容(文字列)を受ける。
|
|
2
2
|
import { changelogFileName, changelogNotFoundMessage, extractVersionReleaseNotes, getLatestVersion, validateSemver, VersionNotFoundError } from './changelog.js';
|
|
3
|
-
import { PecotError
|
|
4
|
-
import {
|
|
3
|
+
import { PecotError } from './errors.js';
|
|
4
|
+
import { pythonStrip } from './python-format.js';
|
|
5
5
|
export class ReleaseError extends PecotError {
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
@@ -28,18 +28,12 @@ function determineVersion(options, changelogContent) {
|
|
|
28
28
|
validateSemver(options.version);
|
|
29
29
|
return options.version;
|
|
30
30
|
}
|
|
31
|
-
function countDifference(output) {
|
|
32
|
-
const count = parsePythonInteger(output);
|
|
33
|
-
if (count === undefined)
|
|
34
|
-
throw new InvalidValueError(`invalid literal for int() with base 10: ${pythonStringRepr(output)}`);
|
|
35
|
-
return count;
|
|
36
|
-
}
|
|
37
31
|
/**
|
|
38
32
|
リリース前チェックを実行する。
|
|
39
33
|
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
40
|
-
4. release→develop
|
|
34
|
+
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
41
35
|
*/
|
|
42
|
-
export function runPreflight(options, git) {
|
|
36
|
+
export async function runPreflight(options, git, countAhead) {
|
|
43
37
|
const { changelogContent, developBranch, releaseBranch } = options;
|
|
44
38
|
if (changelogContent === undefined)
|
|
45
39
|
throw new ReleaseError(changelogNotFoundMessage(options.changelogPath));
|
|
@@ -52,8 +46,7 @@ export function runPreflight(options, git) {
|
|
|
52
46
|
const remoteTags = runGit(git, ['ls-remote', '--tags', remote, `refs/tags/${tagName}`]);
|
|
53
47
|
if (remoteTags !== '')
|
|
54
48
|
throw new ReleaseError(`tag already exists on the remote: ${tagName}`);
|
|
55
|
-
|
|
56
|
-
const diffCount = countDifference(runGit(git, ['rev-list', '--count', `${remote}/${releaseBranch}..${remote}/${developBranch}`]));
|
|
49
|
+
const diffCount = await countAhead(releaseBranch, developBranch);
|
|
57
50
|
if (diffCount === 0) {
|
|
58
51
|
throw new ReleaseError(`no difference between ${remote}/${releaseBranch} and ${remote}/${developBranch}: `
|
|
59
52
|
+ 'there is nothing to release');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HintedText } from './command-hint.js';
|
|
1
2
|
import type { RepositoryReference, ResolvedRepository } from './repository-resolver.js';
|
|
2
3
|
export type PolicyMode = 'reject' | 'warn';
|
|
3
4
|
export interface PolicyInput {
|
|
@@ -12,20 +13,25 @@ export interface PolicyInput {
|
|
|
12
13
|
readonly mode: PolicyMode;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
|
-
結果の種類は kind で判別する。stderr
|
|
16
|
+
結果の種類は kind で判別する。stderr は改行を含まない行の並びで、呼ぶ側が出し先の形にして 1 行ずつ出す。
|
|
16
17
|
- proceed は、続行する。adopted は明示値から採用したリポジトリ(--repo が無ければ undefined)。
|
|
17
18
|
- exit は、stderr を出して指定の終了コードで終わる。
|
|
18
19
|
*/
|
|
19
20
|
export type PolicyOutcome = {
|
|
20
21
|
readonly kind: 'proceed';
|
|
21
22
|
readonly adopted: RepositoryReference | undefined;
|
|
22
|
-
readonly stderr: readonly string[];
|
|
23
|
+
readonly stderr: readonly (string | HintedText)[];
|
|
23
24
|
} | {
|
|
24
25
|
readonly kind: 'exit';
|
|
25
26
|
readonly exitCode: 1;
|
|
26
|
-
readonly
|
|
27
|
+
readonly failure: PolicyFailure;
|
|
28
|
+
readonly stderr: readonly (string | HintedText)[];
|
|
27
29
|
};
|
|
28
30
|
/**
|
|
31
|
+
止める原因の名前。commands の FailureKind の一部
|
|
32
|
+
*/
|
|
33
|
+
export type PolicyFailure = 'git-unresolved' | 'invalid-input' | 'repo-mismatch';
|
|
34
|
+
/**
|
|
29
35
|
`--repo` とカレント Git remote の不一致時の方針を判定する
|
|
30
36
|
*/
|
|
31
37
|
export declare function applyRepositoryPolicy(input: PolicyInput): PolicyOutcome;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// `--repo` 不一致方針(FR-009a / FR-009b)の判定。
|
|
2
2
|
//
|
|
3
|
-
// ローカル Git を破壊する操作系(worktree・
|
|
3
|
+
// ローカル Git を破壊する操作系(worktree・session start・branch delete など)は reject にする。
|
|
4
4
|
// GitHub API 側への操作が中心のもの(release など)は warn にする。
|
|
5
5
|
// 判定だけを純粋な関数にする。stderr への出力と終了は、呼ぶ側(commands 層)が行う。
|
|
6
6
|
//
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
// - 不一致で reject は終了コード 1、warn は警告を出して明示値を採用して続行する。
|
|
16
16
|
//
|
|
17
17
|
// 文言は contracts/cli-commands.md の固定文言と一致させる(stderr を e2e で確かめるため)。
|
|
18
|
+
import { globalRepositoryHint, hinted, placeholder } from './command-hint.js';
|
|
18
19
|
import { InvalidValueError } from './errors.js';
|
|
19
20
|
import { pythonStringRepr } from './python-format.js';
|
|
20
21
|
import { parseOwnerRepository, repositoryFullName } from './repository-resolver.js';
|
|
21
|
-
function exitWith(...stderr) {
|
|
22
|
-
return { kind: 'exit', exitCode: 1, stderr };
|
|
22
|
+
function exitWith(failure, ...stderr) {
|
|
23
|
+
return { kind: 'exit', exitCode: 1, failure, stderr };
|
|
23
24
|
}
|
|
24
25
|
function parseExplicit(explicit) {
|
|
25
26
|
try {
|
|
@@ -38,12 +39,12 @@ export function applyRepositoryPolicy(input) {
|
|
|
38
39
|
const { explicit, resolved, mode } = input;
|
|
39
40
|
if (explicit === undefined) {
|
|
40
41
|
return resolved === undefined
|
|
41
|
-
? exitWith('error: the repository is ambiguous',
|
|
42
|
+
? exitWith('git-unresolved', 'error: the repository is ambiguous', hinted ` give ${globalRepositoryHint(placeholder('owner/repo'))}`)
|
|
42
43
|
: { kind: 'proceed', adopted: undefined, stderr: [] };
|
|
43
44
|
}
|
|
44
45
|
const explicitReference = parseExplicit(explicit);
|
|
45
46
|
if (explicitReference === undefined)
|
|
46
|
-
return exitWith(`error:
|
|
47
|
+
return exitWith('invalid-input', hinted `error: ${globalRepositoryHint()} has an invalid form: ${pythonStringRepr(explicit)}`);
|
|
47
48
|
// Git 外 / remote 不在は比較対象が無いので、明示値を採用する
|
|
48
49
|
if (resolved?.source !== 'current-git')
|
|
49
50
|
return { kind: 'proceed', adopted: explicitReference, stderr: [] };
|
|
@@ -54,12 +55,12 @@ export function applyRepositoryPolicy(input) {
|
|
|
54
55
|
const explicitName = repositoryFullName(explicitReference);
|
|
55
56
|
const currentName = repositoryFullName(current);
|
|
56
57
|
if (mode === 'reject') {
|
|
57
|
-
return exitWith(`error:
|
|
58
|
+
return exitWith('repo-mismatch', hinted `error: ${globalRepositoryHint()} ${explicitName} differs from the current Git remote (${currentName})`, ' this command works only on the repository of the current Git remote');
|
|
58
59
|
}
|
|
59
60
|
return {
|
|
60
61
|
kind: 'proceed',
|
|
61
62
|
adopted: explicitReference,
|
|
62
|
-
stderr: [`warning: using
|
|
63
|
+
stderr: [hinted `warning: using ${globalRepositoryHint()} ${explicitName} (current Git remote: ${currentName})`],
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
//# sourceMappingURL=repository-policy.js.map
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
//
|
|
9
9
|
// 検証エラーの文は、Python の CLI の書式に揃える。
|
|
10
10
|
// 表題は元のクラス名(RepoRef・ResolvedRepo)を使う。
|
|
11
|
+
import { formatHinted, globalRepositoryHint, hinted, placeholder } from './command-hint.js';
|
|
11
12
|
import { PecotError, InvalidValueError } from './errors.js';
|
|
12
13
|
import { parseRemoteUrl } from './git-url.js';
|
|
13
14
|
import { pythonStringRepr, ValidationFailure } from './python-format.js';
|
|
@@ -114,6 +115,8 @@ export function resolveRepository(explicit, git) {
|
|
|
114
115
|
if (detected !== undefined) {
|
|
115
116
|
return createResolvedRepository({ repository: detected.repository, source: 'current-git', remoteName: detected.remoteName });
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
+
// 文を出すのは CLI の最上位(src/cli.ts)だけ。ほかの呼び手は捕まえて undefined にする
|
|
119
|
+
const repositoryHint = globalRepositoryHint(placeholder('owner/repo'));
|
|
120
|
+
throw new AmbiguousRepositoryError(formatHinted(hinted `repository is ambiguous: pass ${repositoryHint}`, 'cli'));
|
|
118
121
|
}
|
|
119
122
|
//# sourceMappingURL=repository-resolver.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { PullRequestReadout } from './issue-readout.js';
|
|
2
|
+
import type { BaseReading } from './state.js';
|
|
3
|
+
export interface RestackInput {
|
|
4
|
+
/**
|
|
5
|
+
base の記録。形の誤りは呼び出し側が先に止める
|
|
6
|
+
*/
|
|
7
|
+
readonly reading: Exclude<BaseReading, {
|
|
8
|
+
kind: 'malformed';
|
|
9
|
+
}>;
|
|
10
|
+
readonly developBranch: string;
|
|
11
|
+
/**
|
|
12
|
+
下の段のブランチを head に持つ PR(pickLowerPullRequest で選んだもの)
|
|
13
|
+
*/
|
|
14
|
+
readonly lowerPullRequest: Readonly<PullRequestReadout> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
下の段のブランチの、remote の先頭の SHA。remote に無ければ undefined
|
|
17
|
+
*/
|
|
18
|
+
readonly lowerHead: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
export type RestackDecision = {
|
|
21
|
+
readonly kind: 'not-stacked';
|
|
22
|
+
readonly base: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: 'up-to-date';
|
|
25
|
+
readonly base: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'moved';
|
|
28
|
+
readonly base: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'merged';
|
|
31
|
+
readonly base: string;
|
|
32
|
+
readonly pullRequest: number;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'gone';
|
|
35
|
+
readonly base: string;
|
|
36
|
+
readonly pullRequest: number | undefined;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
載せ直す先を決める。base は、載せ直した後の base のブランチ(merged なら開発ブランチ)
|
|
40
|
+
*/
|
|
41
|
+
export declare function decideRestack(input: Readonly<RestackInput>): RestackDecision;
|
|
42
|
+
/**
|
|
43
|
+
`pr restack --check` の行
|
|
44
|
+
*/
|
|
45
|
+
export declare function describeRestackCheck(branch: string, decision: Exclude<RestackDecision, {
|
|
46
|
+
kind: 'gone';
|
|
47
|
+
}>): string;
|
|
48
|
+
/**
|
|
49
|
+
下の段のブランチが消えていて、マージもされていないときの文(`error: ` の前置きを含まない)
|
|
50
|
+
*/
|
|
51
|
+
export declare function describeGone(decision: Extract<RestackDecision, {
|
|
52
|
+
kind: 'gone';
|
|
53
|
+
}>): string;
|
|
54
|
+
/**
|
|
55
|
+
載せ直しが要るか。下の段が消えていて決められないときは undefined
|
|
56
|
+
*/
|
|
57
|
+
export declare function needsRestack(decision: Readonly<RestackDecision>): boolean | undefined;
|
|
58
|
+
/**
|
|
59
|
+
session show の `- needs restack:` の行。決められないときは undefined
|
|
60
|
+
*/
|
|
61
|
+
export declare function describeNeedsRestack(decision: Readonly<RestackDecision>): string | undefined;
|
|
62
|
+
//# sourceMappingURL=restack.d.ts.map
|