@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,6 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { BoardMove, LabelValue, MissingValue, MovableColumn } from '../domain/board-move.js';
|
|
1
3
|
import type { ProjectConfig } from '../domain/config.js';
|
|
4
|
+
import type { IssueReference } from '../domain/reference-parser.js';
|
|
5
|
+
import type { RepositoryReference } from '../domain/repository-resolver.js';
|
|
2
6
|
import type { JsonObject } from '../domain/json.js';
|
|
3
7
|
import type { GitHubClient } from '../infra/github/index.js';
|
|
8
|
+
import type { Output } from './output.js';
|
|
4
9
|
export interface BoardItem {
|
|
5
10
|
readonly itemId: string;
|
|
6
11
|
readonly issueNodeId: string;
|
|
@@ -15,6 +20,10 @@ Issue をボードへ追加し、項目 ID と Issue の node id を返す。
|
|
|
15
20
|
*/
|
|
16
21
|
export declare function addIssueToBoard(client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, issueNodeId: string | undefined): Promise<BoardItem>;
|
|
17
22
|
/**
|
|
23
|
+
設定の workflow に、その status のオプションがあるか
|
|
24
|
+
*/
|
|
25
|
+
export declare function isStatusConfigured(config: ProjectConfig, status: string): boolean;
|
|
26
|
+
/**
|
|
18
27
|
カスタムフィールドを 1 つ設定する。設定したら true。
|
|
19
28
|
設定に無いフィールド・オプションは何もせず false。更新に失敗したら GitHubAPIError
|
|
20
29
|
*/
|
|
@@ -35,4 +44,56 @@ export interface PutOnBoardOptions {
|
|
|
35
44
|
途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。失敗したら GitHubAPIError
|
|
36
45
|
*/
|
|
37
46
|
export declare function putOnBoard(client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, priority: string | undefined, options: Readonly<PutOnBoardOptions>): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
列と札の行(moved: と set: Status of)に出した値。issue は行の表示の参照、reason は列を動かす理由の文。書いていない側は undefined
|
|
49
|
+
*/
|
|
50
|
+
export interface BoardMoveLine {
|
|
51
|
+
readonly issue: string;
|
|
52
|
+
readonly column: {
|
|
53
|
+
readonly from: string;
|
|
54
|
+
readonly to: MovableColumn;
|
|
55
|
+
} | undefined;
|
|
56
|
+
readonly label: LabelValue | undefined;
|
|
57
|
+
readonly reason: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync と pr create の data が使う
|
|
61
|
+
*/
|
|
62
|
+
export declare const BOARD_MOVE_JSON: z.ZodObject<{
|
|
63
|
+
issue: z.ZodString;
|
|
64
|
+
from: z.ZodOptional<z.ZodString>;
|
|
65
|
+
to: z.ZodOptional<z.ZodString>;
|
|
66
|
+
label: z.ZodOptional<z.ZodString>;
|
|
67
|
+
reason: z.ZodString;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
export declare function moveJson({ issue, column, label, reason }: Readonly<BoardMoveLine>): z.input<typeof BOARD_MOVE_JSON>;
|
|
70
|
+
export interface AppliedMove {
|
|
71
|
+
/**
|
|
72
|
+
実際に動いた先の列。動かなかったら undefined
|
|
73
|
+
*/
|
|
74
|
+
readonly column: MovableColumn | undefined;
|
|
75
|
+
readonly missing: readonly MissingValue[];
|
|
76
|
+
/**
|
|
77
|
+
書き込みに失敗した。列だけ書けて札で失敗したときも真
|
|
78
|
+
*/
|
|
79
|
+
readonly hasFailed: boolean;
|
|
80
|
+
/**
|
|
81
|
+
書けた列と札。どちらも書かなかったら undefined
|
|
82
|
+
*/
|
|
83
|
+
readonly written: BoardMoveLine | undefined;
|
|
84
|
+
}
|
|
85
|
+
interface MoveTarget {
|
|
86
|
+
readonly ref: IssueReference;
|
|
87
|
+
readonly home: RepositoryReference | undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
decideBoardMove の結果をボードに書く。書き込みの失敗は warning にして続ける(元の列のまま)。
|
|
91
|
+
text は列を動かす理由の判定の文。board sync と issue block / unblock が使う
|
|
92
|
+
*/
|
|
93
|
+
export declare function applyBoardMove(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, itemId: string, target: MoveTarget, move: Readonly<BoardMove>, text: string): Promise<AppliedMove>;
|
|
94
|
+
/**
|
|
95
|
+
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)。予定の列と札を返し、どちらも無ければ undefined
|
|
96
|
+
*/
|
|
97
|
+
export declare function planBoardMove(out: Readonly<Output>, target: MoveTarget, move: Readonly<BoardMove>, text: string): BoardMoveLine | undefined;
|
|
98
|
+
export {};
|
|
38
99
|
//# sourceMappingURL=issue-board.d.ts.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
|
-
// Issue
|
|
2
|
+
// Issue の作成・ボードへの追加・フィールドの設定と、判定に応じた列と札の書き込み(applyBoardMove)。cli/core/issue_board.py の移植に applyBoardMove を足した。
|
|
3
3
|
// 失敗は GitHubAPIError で呼び出し側に返す。表示と終了コードは呼び出し側が決める。
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { COLUMN_CONFIG_KEYS, LABEL_CONFIG_KEYS } from '../domain/board-move.js';
|
|
4
6
|
import { getFieldId, getOptionId } from '../domain/config.js';
|
|
7
|
+
import { displayReference } from '../domain/readiness.js';
|
|
8
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
5
9
|
// 作ったボード項目の Status(Tracker はここから始める)
|
|
6
10
|
const BOARD_STATUS = 'backlog';
|
|
7
11
|
/**
|
|
@@ -20,6 +24,14 @@ export async function addIssueToBoard(client, config, owner, repository, issueNu
|
|
|
20
24
|
return { itemId, issueNodeId: nodeId };
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
27
|
+
設定の workflow に、その status のオプションがあるか
|
|
28
|
+
*/
|
|
29
|
+
export function isStatusConfigured(config, status) {
|
|
30
|
+
const fieldId = getFieldId(config, 'workflow');
|
|
31
|
+
const optionId = getOptionId(config, 'workflow', status);
|
|
32
|
+
return fieldId !== undefined && fieldId !== '' && optionId !== undefined && optionId !== '';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
23
35
|
カスタムフィールドを 1 つ設定する。設定したら true。
|
|
24
36
|
設定に無いフィールド・オプションは何もせず false。更新に失敗したら GitHubAPIError
|
|
25
37
|
*/
|
|
@@ -59,4 +71,76 @@ export async function putOnBoard(client, config, owner, repository, issueNumber,
|
|
|
59
71
|
await setIssueField(client, config, itemId, fieldName, option);
|
|
60
72
|
}
|
|
61
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync と pr create の data が使う
|
|
76
|
+
*/
|
|
77
|
+
export const BOARD_MOVE_JSON = z.strictObject({
|
|
78
|
+
issue: z.string().describe('Issue as shown in the moved line (#N, or owner/repo#N outside the home repository)'),
|
|
79
|
+
from: z.string().optional().describe('Column before the move (omitted when only the Status changed)'),
|
|
80
|
+
to: z.string().optional().describe('Column after the move (omitted when only the Status changed)'),
|
|
81
|
+
label: z.string().optional().describe('Status value set (omitted when the Status did not change)'),
|
|
82
|
+
reason: z.string().describe('Readiness that decided the move'),
|
|
83
|
+
});
|
|
84
|
+
export function moveJson({ issue, column, label, reason }) {
|
|
85
|
+
return {
|
|
86
|
+
issue,
|
|
87
|
+
...column !== undefined && { from: column.from, to: column.to },
|
|
88
|
+
...label !== undefined && { label },
|
|
89
|
+
reason,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function moveOperation(name, column, text) {
|
|
93
|
+
return { verb: 'move', target: `${name} ${column.from} -> ${column.to} (${text})` };
|
|
94
|
+
}
|
|
95
|
+
function labelOperation(name, label) {
|
|
96
|
+
return { verb: 'set', target: `Status of ${name} to ${label}` };
|
|
97
|
+
}
|
|
98
|
+
function warnConflict(out, name, target, conflict) {
|
|
99
|
+
const blockers = conflict.issues.map(issue => displayReference(issue, target.home));
|
|
100
|
+
out.warning(`${name} is in ${conflict.column} but blocked${blockers.length > 0 ? ` by ${blockers.join(', ')}` : ''}`);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
decideBoardMove の結果をボードに書く。書き込みの失敗は warning にして続ける(元の列のまま)。
|
|
104
|
+
text は列を動かす理由の判定の文。board sync と issue block / unblock が使う
|
|
105
|
+
*/
|
|
106
|
+
export async function applyBoardMove(out, client, config, itemId, target, move, text) {
|
|
107
|
+
const name = displayReference(target.ref, target.home);
|
|
108
|
+
if (move.conflict !== undefined)
|
|
109
|
+
warnConflict(out, name, target, move.conflict);
|
|
110
|
+
let column;
|
|
111
|
+
let label;
|
|
112
|
+
let hasFailed = false;
|
|
113
|
+
try {
|
|
114
|
+
if (move.column !== undefined && await setIssueField(client, config, itemId, 'workflow', COLUMN_CONFIG_KEYS[move.column.to])) {
|
|
115
|
+
column = { from: move.column.from, to: move.column.to };
|
|
116
|
+
out.done(moveOperation(name, move.column, text));
|
|
117
|
+
}
|
|
118
|
+
if (move.label !== undefined && await setIssueField(client, config, itemId, 'status', LABEL_CONFIG_KEYS[move.label])) {
|
|
119
|
+
label = move.label;
|
|
120
|
+
out.done(labelOperation(name, move.label));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (!(error instanceof GitHubAPIError))
|
|
125
|
+
throw error;
|
|
126
|
+
out.warning(`could not move ${name}: ${error.message}`);
|
|
127
|
+
hasFailed = true;
|
|
128
|
+
}
|
|
129
|
+
const written = column === undefined && label === undefined ? undefined : { issue: name, column, label, reason: text };
|
|
130
|
+
return { column: column?.to, missing: move.missing, hasFailed, written };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)。予定の列と札を返し、どちらも無ければ undefined
|
|
134
|
+
*/
|
|
135
|
+
export function planBoardMove(out, target, move, text) {
|
|
136
|
+
const name = displayReference(target.ref, target.home);
|
|
137
|
+
if (move.conflict !== undefined)
|
|
138
|
+
warnConflict(out, name, target, move.conflict);
|
|
139
|
+
if (move.column !== undefined)
|
|
140
|
+
out.planned(moveOperation(name, move.column, text));
|
|
141
|
+
if (move.label !== undefined)
|
|
142
|
+
out.planned(labelOperation(name, move.label));
|
|
143
|
+
const column = move.column === undefined ? undefined : { from: move.column.from, to: move.column.to };
|
|
144
|
+
return column === undefined && move.label === undefined ? undefined : { issue: name, column, label: move.label, reason: text };
|
|
145
|
+
}
|
|
62
146
|
//# sourceMappingURL=issue-board.js.map
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable security/detect-non-literal-fs-filename -- パスは利用者の引数とテンプレートの置き場で決まる */
|
|
3
3
|
// issue comment。cli/commands/issue.py の issue_comment とその内部関数の移植。
|
|
4
4
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
import { isRepositoryInProject } from '../domain/config.js';
|
|
7
8
|
import { FrontmatterError, setFrontmatterValue } from '../domain/frontmatter.js';
|
|
@@ -14,23 +15,37 @@ import { OutputPathReservationError, outputDirectory, withReservedOutputPath } f
|
|
|
14
15
|
import { readTextFile } from '../infra/text-file.js';
|
|
15
16
|
import { templateFile } from '../infra/template-store.js';
|
|
16
17
|
import { defineCommand, CommandExit } from './command-definition.js';
|
|
18
|
+
import { commandHint, hinted, inputNameHint, placeholder } from './command-hint.js';
|
|
17
19
|
import { stopWith, requireActiveConfigPlain } from './command-stop.js';
|
|
20
|
+
import { kindOfFailure } from './failure.js';
|
|
18
21
|
import { createGitHubClient } from './github-client.js';
|
|
19
22
|
import { COMMENT_VALIDATION_EXIT_CODE, hasReportedTemplateViolations, issuePath, parseIssueReferenceOrExit, runWithExit, } from './issue-shared.js';
|
|
20
|
-
import { createOutput } from './output.js';
|
|
23
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
21
24
|
const TEMPLATE_SCHEMA = z.enum(['plan', 'merge-diff', 'review-findings', 'review-resolution', 'precede-notify']);
|
|
22
25
|
const TEMPLATE_CHOICES = TEMPLATE_SCHEMA.options.join(' / ');
|
|
23
26
|
// PR へのコメントは GitHub が /pull/ の形で html_url を返すので、両方受ける
|
|
24
27
|
const COMMENT_URL_PATTERN = /^https?:\/\/(?<host>[^/]+)\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/(?:issues|pull)\/(?<number>\d+)#issuecomment-(?<id>\d+)$/u;
|
|
28
|
+
const ISSUE_COMMENT_OUTPUT = z.strictObject({
|
|
29
|
+
issue: z.string().optional().describe('Issue commented on (owner/repo/N; omitted with prepare)'),
|
|
30
|
+
commentUrl: z.string().optional().describe('URL of the comment created or updated (omitted on dry_run, with prepare, or when GitHub returned no URL)'),
|
|
31
|
+
change: z.enum(['created', 'updated']).optional().describe('Whether the comment was created or updated (omitted with prepare)'),
|
|
32
|
+
file: z.string().optional().describe('Absolute path of the file written: the template copied with prepare, or the file whose comment_url was written back after posting from it (omitted otherwise)'),
|
|
33
|
+
dryRun: DRY_RUN_FIELD,
|
|
34
|
+
});
|
|
25
35
|
function htmlUrlOf(comment, fallback) {
|
|
26
36
|
const url = jsonField(comment, 'html_url');
|
|
27
37
|
return typeof url === 'string' ? url : fallback;
|
|
28
38
|
}
|
|
29
39
|
// テンプレートをコピーして、そのパスを標準出力に出す。issue_ref が渡されていれば、コピーの issue_ref に入れる
|
|
30
|
-
function prepareTemplate(output, template, issueReference) {
|
|
40
|
+
function prepareTemplate(output, template, issueReference, isDryRun) {
|
|
31
41
|
const templatePath = templateFile('comment', template);
|
|
32
42
|
if (!existsSync(templatePath)) {
|
|
33
|
-
stopWith(output, `template not found: ${templatePath}
|
|
43
|
+
stopWith(output, `template not found: ${templatePath}`, 'other');
|
|
44
|
+
}
|
|
45
|
+
if (isDryRun) {
|
|
46
|
+
output.result({});
|
|
47
|
+
output.planned({ verb: 'create', target: `comment template ${template} in ${outputDirectory()}` });
|
|
48
|
+
return;
|
|
34
49
|
}
|
|
35
50
|
let content = readTextFile(templatePath);
|
|
36
51
|
if (issueReference !== undefined && issueReference !== '') {
|
|
@@ -39,36 +54,38 @@ function prepareTemplate(output, template, issueReference) {
|
|
|
39
54
|
try {
|
|
40
55
|
withReservedOutputPath(outputDirectory(), timestamp => `comment-${template}-${timestamp}.md`, (reserved) => {
|
|
41
56
|
writeFileSync(reserved, content, 'utf8');
|
|
57
|
+
output.result({ file: path.resolve(reserved) });
|
|
42
58
|
output.data(reserved);
|
|
43
59
|
});
|
|
44
60
|
}
|
|
45
61
|
catch (error) {
|
|
46
62
|
if (!(error instanceof OutputPathReservationError))
|
|
47
63
|
throw error;
|
|
48
|
-
stopWith(output, error.message);
|
|
64
|
+
stopWith(output, error.message, 'other');
|
|
49
65
|
}
|
|
50
66
|
}
|
|
51
67
|
// comment_url からコメントの id を取る。issue_ref と別の Issue を指していたら終了コード 1
|
|
52
68
|
function commentIdFor(output, commentUrl, host, target) {
|
|
53
69
|
const groups = COMMENT_URL_PATTERN.exec(pythonStrip(commentUrl))?.groups;
|
|
54
70
|
if (groups === undefined) {
|
|
55
|
-
return stopWith(output, `comment_url has the wrong form: ${commentUrl}\nexpected: https://<host>/<owner>/<repo>/{issues|pull}/<number>#issuecomment-<id
|
|
71
|
+
return stopWith(output, `comment_url has the wrong form: ${commentUrl}\nexpected: https://<host>/<owner>/<repo>/{issues|pull}/<number>#issuecomment-<id>`, 'invalid-input');
|
|
56
72
|
}
|
|
57
73
|
const { host: urlHost = '', owner = '', repo: urlRepository = '', number = '', id = '' } = groups;
|
|
58
74
|
if (urlHost.toLowerCase() !== host.toLowerCase()) {
|
|
59
|
-
return stopWith(output, `the host of comment_url (${urlHost}) differs from the configured host (${host})
|
|
75
|
+
return stopWith(output, `the host of comment_url (${urlHost}) differs from the configured host (${host})`, 'invalid-input');
|
|
60
76
|
}
|
|
61
77
|
const isSameIssue = owner.toLowerCase() === target.owner.toLowerCase()
|
|
62
78
|
&& urlRepository.toLowerCase() === target.repository.toLowerCase()
|
|
63
79
|
&& Number(number) === target.number;
|
|
64
80
|
const message = `comment_url (${owner}/${urlRepository}/${number}) points to a different Issue than issue_ref (${target.owner}/${target.repository}/${String(target.number)})`;
|
|
65
|
-
return isSameIssue ? Number(id) : stopWith(output, message);
|
|
81
|
+
return isSameIssue ? Number(id) : stopWith(output, message, 'invalid-input');
|
|
66
82
|
}
|
|
67
83
|
// 次に同じファイルを渡したとき更新になるよう、URL を書き戻す。できなければ warning だけ出す
|
|
68
84
|
function writeBackCommentUrl(output, file, commentUrl) {
|
|
69
85
|
try {
|
|
70
86
|
const content = readTextFile(file);
|
|
71
87
|
writeFileSync(file, setFrontmatterValue(content, 'comment_url', commentUrl), 'utf8');
|
|
88
|
+
output.result({ file: path.resolve(file) });
|
|
72
89
|
}
|
|
73
90
|
catch (error) {
|
|
74
91
|
const converted = toOsError(error, file);
|
|
@@ -89,9 +106,10 @@ async function createComment(output, client, target, body) {
|
|
|
89
106
|
catch (error) {
|
|
90
107
|
if (!(error instanceof GitHubAPIError))
|
|
91
108
|
throw error;
|
|
92
|
-
return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}
|
|
109
|
+
return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
|
|
93
110
|
}
|
|
94
111
|
const createdUrl = htmlUrlOf(comment, '');
|
|
112
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: 'created', ...createdUrl !== '' && { commentUrl: createdUrl } });
|
|
95
113
|
output.done({ verb: 'create', target: `comment on ${display}` });
|
|
96
114
|
output.data(createdUrl);
|
|
97
115
|
return createdUrl;
|
|
@@ -106,12 +124,14 @@ async function updateComment(output, client, target, commentId, commentUrl, body
|
|
|
106
124
|
catch (error) {
|
|
107
125
|
if (!(error instanceof GitHubAPIError))
|
|
108
126
|
throw error;
|
|
109
|
-
return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}
|
|
127
|
+
return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
|
|
110
128
|
}
|
|
129
|
+
const updatedUrl = htmlUrlOf(comment, commentUrl);
|
|
130
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: 'updated', commentUrl: updatedUrl });
|
|
111
131
|
output.done({ verb: 'update', target: `comment on ${display}` });
|
|
112
|
-
output.data(
|
|
132
|
+
output.data(updatedUrl);
|
|
113
133
|
}
|
|
114
|
-
async function postFromFile(output, config, repository, file) {
|
|
134
|
+
async function postFromFile(output, config, repository, file, isDryRun) {
|
|
115
135
|
let parsed;
|
|
116
136
|
try {
|
|
117
137
|
parsed = parseCommentFile(file);
|
|
@@ -119,15 +139,15 @@ async function postFromFile(output, config, repository, file) {
|
|
|
119
139
|
catch (error) {
|
|
120
140
|
if (!(error instanceof FrontmatterError))
|
|
121
141
|
throw error;
|
|
122
|
-
return stopWith(output, error.message);
|
|
142
|
+
return stopWith(output, error.message, 'content-invalid');
|
|
123
143
|
}
|
|
124
144
|
const { frontmatter, body } = parsed;
|
|
125
145
|
const target = parseIssueReferenceOrExit(output, repository, frontmatter.issue_ref);
|
|
126
146
|
if (frontmatter.template === undefined) {
|
|
127
|
-
return stopWith(output, `specify template in the frontmatter (${TEMPLATE_CHOICES})
|
|
147
|
+
return stopWith(output, `specify template in the frontmatter (${TEMPLATE_CHOICES})`, 'content-invalid');
|
|
128
148
|
}
|
|
129
149
|
if (hasReportedTemplateViolations(output, body, templateFile('comment', frontmatter.template)))
|
|
130
|
-
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE);
|
|
150
|
+
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
|
|
131
151
|
// comment_url は、issue_ref と同じ Issue のコメントに限る
|
|
132
152
|
const commentUrl = frontmatter.comment_url;
|
|
133
153
|
const hasCommentUrl = commentUrl !== undefined && commentUrl !== '';
|
|
@@ -136,6 +156,14 @@ async function postFromFile(output, config, repository, file) {
|
|
|
136
156
|
if (!await isRepositoryInProject(config, target.owner, target.repository, client)) {
|
|
137
157
|
output.warning(`${target.owner}/${target.repository} is not in the project`);
|
|
138
158
|
}
|
|
159
|
+
if (isDryRun) {
|
|
160
|
+
const display = issuePath(target.owner, target.repository, target.number);
|
|
161
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: hasCommentUrl ? 'updated' : 'created' });
|
|
162
|
+
output.planned({ verb: hasCommentUrl ? 'update' : 'create', target: `comment on ${display}` });
|
|
163
|
+
if (!hasCommentUrl)
|
|
164
|
+
output.planned({ verb: 'set', target: `comment_url in ${file}` });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
139
167
|
if (hasCommentUrl) {
|
|
140
168
|
await updateComment(output, client, target, commentId, commentUrl, body);
|
|
141
169
|
return;
|
|
@@ -144,51 +172,59 @@ async function postFromFile(output, config, repository, file) {
|
|
|
144
172
|
if (createdUrl !== '')
|
|
145
173
|
writeBackCommentUrl(output, file, createdUrl);
|
|
146
174
|
}
|
|
147
|
-
async function postDirect(output, config, repository, issueReference, message, template) {
|
|
175
|
+
async function postDirect(output, config, repository, issueReference, message, template, isDryRun) {
|
|
148
176
|
const target = parseIssueReferenceOrExit(output, repository, issueReference);
|
|
149
177
|
if (hasReportedTemplateViolations(output, message, templateFile('comment', template)))
|
|
150
|
-
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE);
|
|
178
|
+
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
|
|
179
|
+
if (isDryRun) {
|
|
180
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: 'created' });
|
|
181
|
+
output.planned({ verb: 'create', target: `comment on ${issuePath(target.owner, target.repository, target.number)}` });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
151
184
|
await createComment(output, createGitHubClient(output, config.host), target, message);
|
|
152
185
|
}
|
|
186
|
+
const COMMENT_PATH = ['issue', 'comment'];
|
|
153
187
|
const ISSUE_COMMENT = defineCommand({
|
|
154
|
-
path:
|
|
188
|
+
path: COMMENT_PATH,
|
|
155
189
|
description: 'Post a comment on an Issue',
|
|
156
190
|
input: z.object({
|
|
157
191
|
file: z.string().optional().describe('Path of a Markdown file with frontmatter'),
|
|
158
192
|
message: z.string().optional().describe('Comment body'),
|
|
159
|
-
|
|
193
|
+
issue_ref: z.string().optional().describe('Issue reference (owner/repo/123 form, required with -m)'),
|
|
160
194
|
prepare: z.boolean().default(false).describe('Copy a template to the work directory'),
|
|
161
195
|
template: TEMPLATE_SCHEMA.optional().describe('Template type (required with --prepare and -m; plan/merge-diff/review-findings/review-resolution/precede-notify)'),
|
|
196
|
+
dry_run: z.boolean().default(false).describe('Show what would be posted or written without changing anything'),
|
|
162
197
|
}),
|
|
198
|
+
output: ISSUE_COMMENT_OUTPUT,
|
|
163
199
|
positional: ['file'],
|
|
164
|
-
shortFlags: { message: '-m',
|
|
200
|
+
shortFlags: { message: '-m', issue_ref: '-i', prepare: '-p', template: '-t', dry_run: '-n' },
|
|
165
201
|
interactive: false,
|
|
166
202
|
run: async (input, io) => {
|
|
167
|
-
const output = createOutput(
|
|
203
|
+
const output = createOutput(input.dry_run, io);
|
|
168
204
|
return await runWithExit(async () => {
|
|
169
|
-
const { file, message, issue, prepare, template } = input;
|
|
205
|
+
const { file, message, issue_ref: issue, prepare, template } = input;
|
|
170
206
|
if (template === undefined && (prepare || (message !== undefined && file === undefined))) {
|
|
171
|
-
stopWith(output, `specify a template with
|
|
207
|
+
stopWith(output, hinted `specify a template with ${inputNameHint(COMMENT_PATH, 'template')} (${TEMPLATE_CHOICES})`, 'invalid-input');
|
|
172
208
|
}
|
|
173
209
|
if (prepare && template !== undefined) {
|
|
174
|
-
prepareTemplate(output, template, issue);
|
|
210
|
+
prepareTemplate(output, template, issue, input.dry_run);
|
|
175
211
|
return;
|
|
176
212
|
}
|
|
177
213
|
if (file !== undefined) {
|
|
178
|
-
await postFromFile(output, requireActiveConfigPlain(output), input.repo, file);
|
|
214
|
+
await postFromFile(output, requireActiveConfigPlain(output), input.repo, file, input.dry_run);
|
|
179
215
|
return;
|
|
180
216
|
}
|
|
181
217
|
if (message !== undefined && template !== undefined) {
|
|
182
218
|
if (issue === undefined || issue === '') {
|
|
183
|
-
stopWith(output, '
|
|
219
|
+
stopWith(output, hinted `${inputNameHint(COMMENT_PATH, 'issue_ref')} (Issue reference) is required with ${inputNameHint(COMMENT_PATH, 'message')}`, 'invalid-input');
|
|
184
220
|
}
|
|
185
|
-
await postDirect(output, requireActiveConfigPlain(output), input.repo, issue, message, template);
|
|
221
|
+
await postDirect(output, requireActiveConfigPlain(output), input.repo, issue, message, template, input.dry_run);
|
|
186
222
|
return;
|
|
187
223
|
}
|
|
188
|
-
stopWith(output,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
224
|
+
stopWith(output, hinted `missing arguments
|
|
225
|
+
direct posting: ${commandHint(COMMENT_PATH, { message: placeholder('MESSAGE'), template: placeholder('template'), issue_ref: 'owner/repo/123' })}
|
|
226
|
+
prepare a template: ${commandHint(COMMENT_PATH, { prepare: true, template: placeholder('template') })}
|
|
227
|
+
from a file: ${commandHint(COMMENT_PATH, { file: placeholder('path') })}`, 'invalid-input');
|
|
192
228
|
});
|
|
193
229
|
},
|
|
194
230
|
});
|