@pecot/workflow-mcp 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +80 -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 +59 -0
- package/cli/dist/commands/board-judgment.d.ts +60 -0
- package/cli/dist/commands/board-judgment.js +144 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +57 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +72 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +111 -0
- package/cli/dist/commands/{project-info.d.ts → board-view.d.ts} +21 -7
- package/cli/dist/commands/{project-info.js → board-view.js} +22 -12
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +100 -0
- package/cli/dist/commands/command-binding.js +4 -0
- package/cli/dist/commands/command-definition.d.ts +20 -6
- package/cli/dist/commands/command-definition.js +11 -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 +34 -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 +33 -0
- package/cli/dist/commands/issue-board.js +61 -1
- package/cli/dist/commands/issue-comment.js +47 -28
- package/cli/dist/commands/issue-create.js +548 -91
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +282 -0
- package/cli/dist/commands/issue-readiness.d.ts +94 -0
- package/cli/dist/commands/issue-readiness.js +218 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +115 -0
- package/cli/dist/commands/issue-shared.d.ts +32 -19
- package/cli/dist/commands/issue-shared.js +82 -75
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +169 -0
- package/cli/dist/commands/issue.d.ts +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 +62 -0
- package/cli/dist/commands/output.d.ts +14 -2
- package/cli/dist/commands/output.js +14 -7
- package/cli/dist/commands/pr-waiting.d.ts +20 -0
- package/cli/dist/commands/pr-waiting.js +106 -0
- package/cli/dist/commands/pr.d.ts +19 -0
- package/cli/dist/commands/pr.js +242 -323
- package/cli/dist/commands/project-sync.d.ts +2 -1
- package/cli/dist/commands/project-sync.js +18 -9
- package/cli/dist/commands/project.d.ts +3 -2
- package/cli/dist/commands/project.js +212 -175
- package/cli/dist/commands/registry.js +13 -10
- package/cli/dist/commands/release.d.ts +2 -2
- package/cli/dist/commands/release.js +53 -114
- 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 +3 -2
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +267 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/{repository.js → session-start.js} +99 -128
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +82 -29
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +57 -66
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/{security.js → tracker-sync-security.js} +50 -61
- package/cli/dist/commands/tracker-sync.d.ts +7 -0
- package/cli/dist/commands/tracker-sync.js +3 -6
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +18 -0
- package/cli/dist/commands/usage-error.d.ts +4 -0
- package/cli/dist/commands/usage-error.js +6 -0
- package/cli/dist/commands/work-target.d.ts +12 -3
- package/cli/dist/commands/work-target.js +46 -5
- package/cli/dist/commands/worktree.js +32 -28
- 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 -0
- 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 +27 -0
- package/cli/dist/domain/readiness.js +114 -3
- 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/security-alerts.js +1 -1
- package/cli/dist/domain/state.d.ts +30 -0
- package/cli/dist/domain/state.js +39 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -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 +12 -0
- package/cli/dist/infra/git.js +13 -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 +24 -0
- package/cli/dist/infra/github/pulls.js +56 -0
- package/cli/dist/infra/github/queries.d.ts +12 -4
- package/cli/dist/infra/github/queries.js +156 -8
- package/cli/dist/infra/github/readout.d.ts +5 -1
- package/cli/dist/infra/github/readout.js +11 -0
- 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 +34 -6
- package/cli/dist/mcp/result.js +62 -18
- package/cli/dist/mcp/server.d.ts +2 -2
- package/cli/dist/mcp/server.js +24 -10
- package/cli/templates/comment/plan.md +14 -0
- package/cli/templates/issue/bug.md +1 -1
- package/cli/templates/issue/task-implement.md +13 -6
- package/cli/templates/issue/task.md +1 -1
- 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/repository.d.ts +0 -5
- package/cli/dist/commands/security.d.ts +0 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// 案内(domain/command-hint.ts)の再 export と、定義の登録。出し先は CommandIo の surface で決まり、無ければ CLI の形。
|
|
2
|
+
import { registerHintCommands } from '../domain/command-hint.js';
|
|
3
|
+
export { commandHint, globalRepositoryHint, hinted, hintedTextOf, inputHint, inputNameHint, joinHinted, placeholder } from '../domain/command-hint.js';
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- zod の型
|
|
5
|
+
export function registerCommandHints(definitions) {
|
|
6
|
+
registerHintCommands(definitions.map(definition => ({
|
|
7
|
+
path: definition.path,
|
|
8
|
+
positional: definition.positional,
|
|
9
|
+
inputs: Object.keys(definition.input.shape),
|
|
10
|
+
hasOwnRepo: definition.hasOwnRepo,
|
|
11
|
+
})));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=command-hint.js.map
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { HintedText } from './command-hint.js';
|
|
3
|
+
import type { FailureKind } from './failure-kind.js';
|
|
2
4
|
import type { Output } from './output.js';
|
|
3
5
|
/**
|
|
4
6
|
アクティブなプロジェクトが無いときの案内
|
|
5
7
|
*/
|
|
6
|
-
export declare const NO_ACTIVE_PROJECT
|
|
8
|
+
export declare const NO_ACTIVE_PROJECT: HintedText;
|
|
7
9
|
/**
|
|
8
|
-
error
|
|
10
|
+
error の行を出して、原因の名前と指定の終了コード(既定は 1)で止める
|
|
9
11
|
*/
|
|
10
|
-
export declare function stopWith(out: Readonly<Output>, message: string, code?: number): never;
|
|
12
|
+
export declare function stopWith(out: Readonly<Output>, message: string | HintedText, kind: FailureKind, code?: number): never;
|
|
11
13
|
/**
|
|
12
14
|
アクティブなプロジェクトの設定を読む。無ければ案内付きの NO_ACTIVE_PROJECT を error の行にして止める
|
|
13
15
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
2
2
|
import { CommandExit } from './command-definition.js';
|
|
3
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
3
4
|
/**
|
|
4
5
|
アクティブなプロジェクトが無いときの、案内を添えない文
|
|
5
6
|
*/
|
|
@@ -7,24 +8,24 @@ const NO_ACTIVE_PROJECT_PLAIN = 'no active project';
|
|
|
7
8
|
/**
|
|
8
9
|
アクティブなプロジェクトが無いときの案内
|
|
9
10
|
*/
|
|
10
|
-
export const NO_ACTIVE_PROJECT =
|
|
11
|
+
export const NO_ACTIVE_PROJECT = hinted `no active project\nrun: ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`;
|
|
11
12
|
/**
|
|
12
|
-
error
|
|
13
|
+
error の行を出して、原因の名前と指定の終了コード(既定は 1)で止める
|
|
13
14
|
*/
|
|
14
|
-
export function stopWith(out, message, code = 1) {
|
|
15
|
+
export function stopWith(out, message, kind, code = 1) {
|
|
15
16
|
out.error(message);
|
|
16
|
-
throw new CommandExit(code);
|
|
17
|
+
throw new CommandExit(code, kind);
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
アクティブなプロジェクトの設定を読む。無ければ案内付きの NO_ACTIVE_PROJECT を error の行にして止める
|
|
20
21
|
*/
|
|
21
22
|
export function requireActiveConfig(out) {
|
|
22
|
-
return loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT);
|
|
23
|
+
return loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
requireActiveConfig の、案内を添えない形。無ければ NO_ACTIVE_PROJECT_PLAIN を error の行にして止める
|
|
26
27
|
*/
|
|
27
28
|
export function requireActiveConfigPlain(out) {
|
|
28
|
-
return loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT_PLAIN);
|
|
29
|
+
return loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT_PLAIN, 'no-active-project');
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=command-stop.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const FAILURE_KINDS: readonly ['invalid-input', 'aborted', 'github-auth', 'github-not-found', 'github-rate-limit', 'github-api', 'config-invalid', 'project-root-not-found', 'session-directory-unresolved', 'no-active-project', 'project-not-found', 'not-initialized', 'already-exists', 'repo-not-in-project', 'repo-setting-missing', 'repo-mismatch', 'git-unresolved', 'not-on-board', 'status-not-configured', 'guard-blocked', 'not-ready', 'dependency-rejected', 'dependency-unreadable', 'order-conflict', 'content-invalid', 'preflight-failed', 'pr-state', 'partial-failure', 'other'];
|
|
2
|
+
export type FailureKind = typeof FAILURE_KINDS[number];
|
|
3
|
+
//# sourceMappingURL=failure-kind.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// 失敗の原因の名前。MCP の結果の kind に入る。定義書の exit_status[].kind の集合と一致させる(tests/failure-kinds-definition.test.ts)。
|
|
2
|
+
// eslint-disable-next-line no-restricted-syntax -- 配列から型を作るための as const
|
|
3
|
+
export const FAILURE_KINDS = [
|
|
4
|
+
'invalid-input',
|
|
5
|
+
'aborted',
|
|
6
|
+
'github-auth',
|
|
7
|
+
'github-not-found',
|
|
8
|
+
'github-rate-limit',
|
|
9
|
+
'github-api',
|
|
10
|
+
'config-invalid',
|
|
11
|
+
'project-root-not-found',
|
|
12
|
+
'session-directory-unresolved',
|
|
13
|
+
'no-active-project',
|
|
14
|
+
'project-not-found',
|
|
15
|
+
'not-initialized',
|
|
16
|
+
'already-exists',
|
|
17
|
+
'repo-not-in-project',
|
|
18
|
+
'repo-setting-missing',
|
|
19
|
+
'repo-mismatch',
|
|
20
|
+
'git-unresolved',
|
|
21
|
+
'not-on-board',
|
|
22
|
+
'status-not-configured',
|
|
23
|
+
'guard-blocked',
|
|
24
|
+
'not-ready',
|
|
25
|
+
'dependency-rejected',
|
|
26
|
+
'dependency-unreadable',
|
|
27
|
+
'order-conflict',
|
|
28
|
+
'content-invalid',
|
|
29
|
+
'preflight-failed',
|
|
30
|
+
'pr-state',
|
|
31
|
+
'partial-failure',
|
|
32
|
+
'other',
|
|
33
|
+
];
|
|
34
|
+
//# sourceMappingURL=failure-kind.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FailureKind } from './failure-kind.js';
|
|
1
2
|
import type { CommandIo } from './registry.js';
|
|
2
3
|
export declare const FAILURE_EXIT_CODE = 1;
|
|
3
4
|
/**
|
|
@@ -5,6 +6,11 @@ export declare const FAILURE_EXIT_CODE = 1;
|
|
|
5
6
|
*/
|
|
6
7
|
export declare function isReportableFailure(error: unknown): error is Error;
|
|
7
8
|
export declare function reportFailure(error: Readonly<Error>, io: CommandIo): void;
|
|
9
|
+
export declare const KIND_BY_CLASS: readonly (readonly [abstract new (...arguments_: never[]) => unknown, FailureKind])[];
|
|
10
|
+
/**
|
|
11
|
+
例外のクラスから失敗の原因の名前を決める。表に無いものは other
|
|
12
|
+
*/
|
|
13
|
+
export declare function kindOfFailure(error: unknown): FailureKind;
|
|
8
14
|
/**
|
|
9
15
|
コマンドの実行で捕まえた例外を、終了コードにする。CLI の runCli と MCP のツールの呼び出しが共有する。
|
|
10
16
|
使い方の誤りは枠付きで stderr に出して 2。確認の中止は Aborted. で 1。報告できる失敗は error の行で 1。それ以外は伝える
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// コマンドが捕まえなかった例外を、最上位で `error: <message>` の行と終了コード 1 にする(Python の PecotError の網と同じ)。
|
|
2
2
|
// 値の誤り(InvalidValueError)と OS のエラーも同じ行にする。上のどれでもない例外はプログラムの誤りなので、伝える。
|
|
3
|
-
import {
|
|
3
|
+
import { ConfigError } from '../domain/config.js';
|
|
4
|
+
import { PecotError, InvalidValueError, ProjectRootNotFoundError } from '../domain/errors.js';
|
|
5
|
+
import { DependenciesUnsupportedError, GitHubAPIError, GitHubAuthError, GitHubNotFoundError, GitHubRateLimitError } from '../infra/github/errors.js';
|
|
4
6
|
import { OsError } from '../infra/os-error.js';
|
|
7
|
+
import { hintedTextOf } from './command-hint.js';
|
|
5
8
|
import { AbortedError, createOutput, reportAborted } from './output.js';
|
|
6
9
|
import { formatUsageError, USAGE_EXIT_CODE, UsageError } from './usage-error.js';
|
|
7
10
|
export const FAILURE_EXIT_CODE = 1;
|
|
@@ -12,7 +15,26 @@ export function isReportableFailure(error) {
|
|
|
12
15
|
return error instanceof PecotError || error instanceof InvalidValueError || error instanceof OsError;
|
|
13
16
|
}
|
|
14
17
|
export function reportFailure(error, io) {
|
|
15
|
-
createOutput(false, io).error(error.message);
|
|
18
|
+
createOutput(false, io).error(hintedTextOf(error) ?? error.message);
|
|
19
|
+
}
|
|
20
|
+
// 子クラスを親より先に並べる
|
|
21
|
+
export const KIND_BY_CLASS = [
|
|
22
|
+
[UsageError, 'invalid-input'],
|
|
23
|
+
[InvalidValueError, 'invalid-input'],
|
|
24
|
+
[AbortedError, 'aborted'],
|
|
25
|
+
[GitHubAuthError, 'github-auth'],
|
|
26
|
+
[GitHubNotFoundError, 'github-not-found'],
|
|
27
|
+
[GitHubRateLimitError, 'github-rate-limit'],
|
|
28
|
+
[DependenciesUnsupportedError, 'dependency-rejected'],
|
|
29
|
+
[GitHubAPIError, 'github-api'],
|
|
30
|
+
[ConfigError, 'config-invalid'],
|
|
31
|
+
[ProjectRootNotFoundError, 'project-root-not-found'],
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
例外のクラスから失敗の原因の名前を決める。表に無いものは other
|
|
35
|
+
*/
|
|
36
|
+
export function kindOfFailure(error) {
|
|
37
|
+
return KIND_BY_CLASS.find(([type]) => error instanceof type)?.[1] ?? 'other';
|
|
16
38
|
}
|
|
17
39
|
/**
|
|
18
40
|
コマンドの実行で捕まえた例外を、終了コードにする。CLI の runCli と MCP のツールの呼び出しが共有する。
|
|
@@ -20,13 +42,17 @@ export function reportFailure(error, io) {
|
|
|
20
42
|
*/
|
|
21
43
|
export function exitCodeOfFailure(error, io, width) {
|
|
22
44
|
if (error instanceof UsageError) {
|
|
45
|
+
io.failureKind?.(kindOfFailure(error));
|
|
23
46
|
io.stderr(formatUsageError(error, width));
|
|
24
47
|
return USAGE_EXIT_CODE;
|
|
25
48
|
}
|
|
26
|
-
if (error instanceof AbortedError)
|
|
49
|
+
if (error instanceof AbortedError) {
|
|
50
|
+
io.failureKind?.(kindOfFailure(error));
|
|
27
51
|
return reportAborted(io);
|
|
52
|
+
}
|
|
28
53
|
if (!isReportableFailure(error))
|
|
29
54
|
throw error;
|
|
55
|
+
io.failureKind?.(kindOfFailure(error));
|
|
30
56
|
reportFailure(error, io);
|
|
31
57
|
return FAILURE_EXIT_CODE;
|
|
32
58
|
}
|
|
@@ -6,7 +6,11 @@ host 向けのクライアントを作る。host が undefined なら既定の
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function createGitHubClient(out: Readonly<Output>, host: string | undefined): GitHubClient;
|
|
8
8
|
/**
|
|
9
|
-
|
|
9
|
+
GitHub の失敗(GitHubAPIError と、接続の失敗の TransportFailure)なら、その文を返す。それ以外は投げ直す
|
|
10
10
|
*/
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function apiFailureMessage(error: unknown): string;
|
|
12
|
+
/**
|
|
13
|
+
クライアントを作る。認証などの失敗は error の行にして終了コード 1 で止める
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeClient(out: Readonly<Output>, config: Readonly<ProjectConfig>): GitHubClient;
|
|
12
16
|
//# sourceMappingURL=github-client.d.ts.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { TransportFailure } from '../infra/github/client.js';
|
|
1
2
|
import { GitHubClient } from '../infra/github/index.js';
|
|
2
3
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
4
|
+
import { stopWith } from './command-stop.js';
|
|
5
|
+
import { kindOfFailure } from './failure.js';
|
|
3
6
|
/**
|
|
4
7
|
host 向けのクライアントを作る。host が undefined なら既定のホスト。トークンが無いときは GitHubAuthError を投げる
|
|
5
8
|
*/
|
|
@@ -7,7 +10,15 @@ export function createGitHubClient(out, host) {
|
|
|
7
10
|
return new GitHubClient({ host, diagnostics: out });
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
|
-
|
|
13
|
+
GitHub の失敗(GitHubAPIError と、接続の失敗の TransportFailure)なら、その文を返す。それ以外は投げ直す
|
|
14
|
+
*/
|
|
15
|
+
export function apiFailureMessage(error) {
|
|
16
|
+
if (error instanceof GitHubAPIError || error instanceof TransportFailure)
|
|
17
|
+
return error.message;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
クライアントを作る。認証などの失敗は error の行にして終了コード 1 で止める
|
|
11
22
|
*/
|
|
12
23
|
export function makeClient(out, config) {
|
|
13
24
|
try {
|
|
@@ -16,8 +27,7 @@ export function makeClient(out, config) {
|
|
|
16
27
|
catch (error) {
|
|
17
28
|
if (!(error instanceof GitHubAPIError))
|
|
18
29
|
throw error;
|
|
19
|
-
out.
|
|
20
|
-
return undefined;
|
|
30
|
+
return stopWith(out, error.message, kindOfFailure(error));
|
|
21
31
|
}
|
|
22
32
|
}
|
|
23
33
|
//# sourceMappingURL=github-client.js.map
|
|
@@ -2,17 +2,11 @@
|
|
|
2
2
|
// ルートとグループの説明。枠を使わず、コマンドごとの --help と同じ「見出し + 字下げした 2 列」の書式で出す(help-layout.ts)。
|
|
3
3
|
// 節は Usage、説明、Options、Commands の順。中身の無い節は出さない。
|
|
4
4
|
import { definitionSection, HELP_OPTION, helpWidth, paragraph, usageLines } from './help-layout.js';
|
|
5
|
+
import { COMMAND_GROUPS } from './names.js';
|
|
5
6
|
export const PROGRAM_DESCRIPTION = 'pecot-workflow CLI - work tracking on GitHub Projects';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
['pr', 'Work with PRs'],
|
|
10
|
-
['session', 'Manage the session'],
|
|
11
|
-
['release', 'Work with releases'],
|
|
12
|
-
['security', 'Put security alerts into a Tracker'],
|
|
13
|
-
['dependabot', 'Put Dependabot PRs waiting for a human decision into a Tracker'],
|
|
14
|
-
['worktree', 'Work with worktrees'],
|
|
15
|
-
]);
|
|
7
|
+
function groupHelp(name) {
|
|
8
|
+
return COMMAND_GROUPS.find(group => group.name === name)?.help ?? '';
|
|
9
|
+
}
|
|
16
10
|
const ROOT_OPTIONS = [
|
|
17
11
|
{ name: '-v, --version', description: 'Show the version' },
|
|
18
12
|
{ name: '--repo <owner/repo>', description: 'Target repository, given explicitly as \'owner/repo\'' },
|
|
@@ -21,7 +15,8 @@ const ROOT_OPTIONS = [
|
|
|
21
15
|
];
|
|
22
16
|
const ROOT_FOOTER = 'Run \'pecot COMMAND --help\' for the arguments and options of a command.';
|
|
23
17
|
/**
|
|
24
|
-
path
|
|
18
|
+
path の直下のコマンドとグループを、コマンドを先にして登録順で並べる。
|
|
19
|
+
コマンドはどれも 2 語なので、ルートにはグループだけ、グループの下にはコマンドだけが並ぶ
|
|
25
20
|
*/
|
|
26
21
|
function entriesOf(path, commands) {
|
|
27
22
|
const level = path.length;
|
|
@@ -31,7 +26,7 @@ function entriesOf(path, commands) {
|
|
|
31
26
|
.map(command => command.path.slice(level, level + 1).join(''));
|
|
32
27
|
return [
|
|
33
28
|
...direct.map(command => ({ name: command.path.slice(level, level + 1).join(''), description: command.description })),
|
|
34
|
-
...[...new Set(groups)].map(name => ({ name, description:
|
|
29
|
+
...[...new Set(groups)].map(name => ({ name, description: groupHelp(name) })),
|
|
35
30
|
];
|
|
36
31
|
}
|
|
37
32
|
/**
|
|
@@ -41,7 +36,7 @@ path のグループ(空ならルート)の説明。Usage、説明、Options
|
|
|
41
36
|
export function helpText(path, commands, columns = 80) {
|
|
42
37
|
const width = helpWidth(columns);
|
|
43
38
|
const isRoot = path.length === 0;
|
|
44
|
-
const description = isRoot ? PROGRAM_DESCRIPTION :
|
|
39
|
+
const description = isRoot ? PROGRAM_DESCRIPTION : groupHelp(path.slice(0, 1).join(''));
|
|
45
40
|
const entries = entriesOf(path, commands);
|
|
46
41
|
const sections = [
|
|
47
42
|
usageLines(['pecot', ...path, '[OPTIONS] COMMAND [ARGS]...'].join(' '), width),
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type { BoardMove, MissingValue, MovableColumn } from '../domain/board-move.js';
|
|
1
2
|
import type { ProjectConfig } from '../domain/config.js';
|
|
3
|
+
import type { IssueReference } from '../domain/reference-parser.js';
|
|
4
|
+
import type { RepositoryReference } from '../domain/repository-resolver.js';
|
|
2
5
|
import type { JsonObject } from '../domain/json.js';
|
|
3
6
|
import type { GitHubClient } from '../infra/github/index.js';
|
|
7
|
+
import type { Output } from './output.js';
|
|
4
8
|
export interface BoardItem {
|
|
5
9
|
readonly itemId: string;
|
|
6
10
|
readonly issueNodeId: string;
|
|
@@ -15,6 +19,10 @@ Issue をボードへ追加し、項目 ID と Issue の node id を返す。
|
|
|
15
19
|
*/
|
|
16
20
|
export declare function addIssueToBoard(client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, issueNodeId: string | undefined): Promise<BoardItem>;
|
|
17
21
|
/**
|
|
22
|
+
設定の workflow に、その status のオプションがあるか
|
|
23
|
+
*/
|
|
24
|
+
export declare function isStatusConfigured(config: ProjectConfig, status: string): boolean;
|
|
25
|
+
/**
|
|
18
26
|
カスタムフィールドを 1 つ設定する。設定したら true。
|
|
19
27
|
設定に無いフィールド・オプションは何もせず false。更新に失敗したら GitHubAPIError
|
|
20
28
|
*/
|
|
@@ -35,4 +43,29 @@ export interface PutOnBoardOptions {
|
|
|
35
43
|
途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。失敗したら GitHubAPIError
|
|
36
44
|
*/
|
|
37
45
|
export declare function putOnBoard(client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, priority: string | undefined, options: Readonly<PutOnBoardOptions>): Promise<void>;
|
|
46
|
+
export interface AppliedMove {
|
|
47
|
+
/**
|
|
48
|
+
実際に動いた先の列。動かなかったら undefined
|
|
49
|
+
*/
|
|
50
|
+
readonly column: MovableColumn | undefined;
|
|
51
|
+
readonly missing: readonly MissingValue[];
|
|
52
|
+
/**
|
|
53
|
+
書き込みに失敗した。列だけ書けて札で失敗したときも真
|
|
54
|
+
*/
|
|
55
|
+
readonly hasFailed: boolean;
|
|
56
|
+
}
|
|
57
|
+
interface MoveTarget {
|
|
58
|
+
readonly ref: IssueReference;
|
|
59
|
+
readonly home: RepositoryReference | undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
decideBoardMove の結果をボードに書く。書き込みの失敗は warning にして続ける(元の列のまま)。
|
|
63
|
+
text は列を動かす理由の判定の文。board sync と issue block / unblock が使う
|
|
64
|
+
*/
|
|
65
|
+
export declare function applyBoardMove(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, itemId: string, target: MoveTarget, move: Readonly<BoardMove>, text: string): Promise<AppliedMove>;
|
|
66
|
+
/**
|
|
67
|
+
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)
|
|
68
|
+
*/
|
|
69
|
+
export declare function planBoardMove(out: Readonly<Output>, target: MoveTarget, move: Readonly<BoardMove>, text: string): void;
|
|
70
|
+
export {};
|
|
38
71
|
//# sourceMappingURL=issue-board.d.ts.map
|
|
@@ -1,7 +1,10 @@
|
|
|
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 { COLUMN_CONFIG_KEYS, LABEL_CONFIG_KEYS } from '../domain/board-move.js';
|
|
4
5
|
import { getFieldId, getOptionId } from '../domain/config.js';
|
|
6
|
+
import { displayReference } from '../domain/readiness.js';
|
|
7
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
5
8
|
// 作ったボード項目の Status(Tracker はここから始める)
|
|
6
9
|
const BOARD_STATUS = 'backlog';
|
|
7
10
|
/**
|
|
@@ -20,6 +23,14 @@ export async function addIssueToBoard(client, config, owner, repository, issueNu
|
|
|
20
23
|
return { itemId, issueNodeId: nodeId };
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
26
|
+
設定の workflow に、その status のオプションがあるか
|
|
27
|
+
*/
|
|
28
|
+
export function isStatusConfigured(config, status) {
|
|
29
|
+
const fieldId = getFieldId(config, 'workflow');
|
|
30
|
+
const optionId = getOptionId(config, 'workflow', status);
|
|
31
|
+
return fieldId !== undefined && fieldId !== '' && optionId !== undefined && optionId !== '';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
23
34
|
カスタムフィールドを 1 つ設定する。設定したら true。
|
|
24
35
|
設定に無いフィールド・オプションは何もせず false。更新に失敗したら GitHubAPIError
|
|
25
36
|
*/
|
|
@@ -59,4 +70,53 @@ export async function putOnBoard(client, config, owner, repository, issueNumber,
|
|
|
59
70
|
await setIssueField(client, config, itemId, fieldName, option);
|
|
60
71
|
}
|
|
61
72
|
}
|
|
73
|
+
function moveOperation(name, column, text) {
|
|
74
|
+
return { verb: 'move', target: `${name} ${column.from} -> ${column.to} (${text})` };
|
|
75
|
+
}
|
|
76
|
+
function labelOperation(name, label) {
|
|
77
|
+
return { verb: 'set', target: `Status of ${name} to ${label}` };
|
|
78
|
+
}
|
|
79
|
+
function warnConflict(out, name, target, conflict) {
|
|
80
|
+
const blockers = conflict.issues.map(issue => displayReference(issue, target.home));
|
|
81
|
+
out.warning(`${name} is in ${conflict.column} but blocked${blockers.length > 0 ? ` by ${blockers.join(', ')}` : ''}`);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
decideBoardMove の結果をボードに書く。書き込みの失敗は warning にして続ける(元の列のまま)。
|
|
85
|
+
text は列を動かす理由の判定の文。board sync と issue block / unblock が使う
|
|
86
|
+
*/
|
|
87
|
+
export async function applyBoardMove(out, client, config, itemId, target, move, text) {
|
|
88
|
+
const name = displayReference(target.ref, target.home);
|
|
89
|
+
if (move.conflict !== undefined)
|
|
90
|
+
warnConflict(out, name, target, move.conflict);
|
|
91
|
+
let moved;
|
|
92
|
+
let hasFailed = false;
|
|
93
|
+
try {
|
|
94
|
+
if (move.column !== undefined && await setIssueField(client, config, itemId, 'workflow', COLUMN_CONFIG_KEYS[move.column.to])) {
|
|
95
|
+
moved = move.column.to;
|
|
96
|
+
out.done(moveOperation(name, move.column, text));
|
|
97
|
+
}
|
|
98
|
+
if (move.label !== undefined && await setIssueField(client, config, itemId, 'status', LABEL_CONFIG_KEYS[move.label])) {
|
|
99
|
+
out.done(labelOperation(name, move.label));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (!(error instanceof GitHubAPIError))
|
|
104
|
+
throw error;
|
|
105
|
+
out.warning(`could not move ${name}: ${error.message}`);
|
|
106
|
+
hasFailed = true;
|
|
107
|
+
}
|
|
108
|
+
return { column: moved, missing: move.missing, hasFailed };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)
|
|
112
|
+
*/
|
|
113
|
+
export function planBoardMove(out, target, move, text) {
|
|
114
|
+
const name = displayReference(target.ref, target.home);
|
|
115
|
+
if (move.conflict !== undefined)
|
|
116
|
+
warnConflict(out, name, target, move.conflict);
|
|
117
|
+
if (move.column !== undefined)
|
|
118
|
+
out.planned(moveOperation(name, move.column, text));
|
|
119
|
+
if (move.label !== undefined)
|
|
120
|
+
out.planned(labelOperation(name, move.label));
|
|
121
|
+
}
|
|
62
122
|
//# sourceMappingURL=issue-board.js.map
|
|
@@ -14,7 +14,9 @@ import { OutputPathReservationError, outputDirectory, withReservedOutputPath } f
|
|
|
14
14
|
import { readTextFile } from '../infra/text-file.js';
|
|
15
15
|
import { templateFile } from '../infra/template-store.js';
|
|
16
16
|
import { defineCommand, CommandExit } from './command-definition.js';
|
|
17
|
+
import { commandHint, hinted, inputNameHint, placeholder } from './command-hint.js';
|
|
17
18
|
import { stopWith, requireActiveConfigPlain } from './command-stop.js';
|
|
19
|
+
import { kindOfFailure } from './failure.js';
|
|
18
20
|
import { createGitHubClient } from './github-client.js';
|
|
19
21
|
import { COMMENT_VALIDATION_EXIT_CODE, hasReportedTemplateViolations, issuePath, parseIssueReferenceOrExit, runWithExit, } from './issue-shared.js';
|
|
20
22
|
import { createOutput } from './output.js';
|
|
@@ -27,10 +29,14 @@ function htmlUrlOf(comment, fallback) {
|
|
|
27
29
|
return typeof url === 'string' ? url : fallback;
|
|
28
30
|
}
|
|
29
31
|
// テンプレートをコピーして、そのパスを標準出力に出す。issue_ref が渡されていれば、コピーの issue_ref に入れる
|
|
30
|
-
function prepareTemplate(output, template, issueReference) {
|
|
32
|
+
function prepareTemplate(output, template, issueReference, isDryRun) {
|
|
31
33
|
const templatePath = templateFile('comment', template);
|
|
32
34
|
if (!existsSync(templatePath)) {
|
|
33
|
-
stopWith(output, `template not found: ${templatePath}
|
|
35
|
+
stopWith(output, `template not found: ${templatePath}`, 'other');
|
|
36
|
+
}
|
|
37
|
+
if (isDryRun) {
|
|
38
|
+
output.planned({ verb: 'create', target: `comment template ${template} in ${outputDirectory()}` });
|
|
39
|
+
return;
|
|
34
40
|
}
|
|
35
41
|
let content = readTextFile(templatePath);
|
|
36
42
|
if (issueReference !== undefined && issueReference !== '') {
|
|
@@ -45,24 +51,24 @@ function prepareTemplate(output, template, issueReference) {
|
|
|
45
51
|
catch (error) {
|
|
46
52
|
if (!(error instanceof OutputPathReservationError))
|
|
47
53
|
throw error;
|
|
48
|
-
stopWith(output, error.message);
|
|
54
|
+
stopWith(output, error.message, 'other');
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
// comment_url からコメントの id を取る。issue_ref と別の Issue を指していたら終了コード 1
|
|
52
58
|
function commentIdFor(output, commentUrl, host, target) {
|
|
53
59
|
const groups = COMMENT_URL_PATTERN.exec(pythonStrip(commentUrl))?.groups;
|
|
54
60
|
if (groups === undefined) {
|
|
55
|
-
return stopWith(output, `comment_url has the wrong form: ${commentUrl}\nexpected: https://<host>/<owner>/<repo>/{issues|pull}/<number>#issuecomment-<id
|
|
61
|
+
return stopWith(output, `comment_url has the wrong form: ${commentUrl}\nexpected: https://<host>/<owner>/<repo>/{issues|pull}/<number>#issuecomment-<id>`, 'invalid-input');
|
|
56
62
|
}
|
|
57
63
|
const { host: urlHost = '', owner = '', repo: urlRepository = '', number = '', id = '' } = groups;
|
|
58
64
|
if (urlHost.toLowerCase() !== host.toLowerCase()) {
|
|
59
|
-
return stopWith(output, `the host of comment_url (${urlHost}) differs from the configured host (${host})
|
|
65
|
+
return stopWith(output, `the host of comment_url (${urlHost}) differs from the configured host (${host})`, 'invalid-input');
|
|
60
66
|
}
|
|
61
67
|
const isSameIssue = owner.toLowerCase() === target.owner.toLowerCase()
|
|
62
68
|
&& urlRepository.toLowerCase() === target.repository.toLowerCase()
|
|
63
69
|
&& Number(number) === target.number;
|
|
64
70
|
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);
|
|
71
|
+
return isSameIssue ? Number(id) : stopWith(output, message, 'invalid-input');
|
|
66
72
|
}
|
|
67
73
|
// 次に同じファイルを渡したとき更新になるよう、URL を書き戻す。できなければ warning だけ出す
|
|
68
74
|
function writeBackCommentUrl(output, file, commentUrl) {
|
|
@@ -89,7 +95,7 @@ async function createComment(output, client, target, body) {
|
|
|
89
95
|
catch (error) {
|
|
90
96
|
if (!(error instanceof GitHubAPIError))
|
|
91
97
|
throw error;
|
|
92
|
-
return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}
|
|
98
|
+
return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
|
|
93
99
|
}
|
|
94
100
|
const createdUrl = htmlUrlOf(comment, '');
|
|
95
101
|
output.done({ verb: 'create', target: `comment on ${display}` });
|
|
@@ -106,12 +112,12 @@ async function updateComment(output, client, target, commentId, commentUrl, body
|
|
|
106
112
|
catch (error) {
|
|
107
113
|
if (!(error instanceof GitHubAPIError))
|
|
108
114
|
throw error;
|
|
109
|
-
return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}
|
|
115
|
+
return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
|
|
110
116
|
}
|
|
111
117
|
output.done({ verb: 'update', target: `comment on ${display}` });
|
|
112
118
|
output.data(htmlUrlOf(comment, commentUrl));
|
|
113
119
|
}
|
|
114
|
-
async function postFromFile(output, config, repository, file) {
|
|
120
|
+
async function postFromFile(output, config, repository, file, isDryRun) {
|
|
115
121
|
let parsed;
|
|
116
122
|
try {
|
|
117
123
|
parsed = parseCommentFile(file);
|
|
@@ -119,15 +125,15 @@ async function postFromFile(output, config, repository, file) {
|
|
|
119
125
|
catch (error) {
|
|
120
126
|
if (!(error instanceof FrontmatterError))
|
|
121
127
|
throw error;
|
|
122
|
-
return stopWith(output, error.message);
|
|
128
|
+
return stopWith(output, error.message, 'content-invalid');
|
|
123
129
|
}
|
|
124
130
|
const { frontmatter, body } = parsed;
|
|
125
131
|
const target = parseIssueReferenceOrExit(output, repository, frontmatter.issue_ref);
|
|
126
132
|
if (frontmatter.template === undefined) {
|
|
127
|
-
return stopWith(output, `specify template in the frontmatter (${TEMPLATE_CHOICES})
|
|
133
|
+
return stopWith(output, `specify template in the frontmatter (${TEMPLATE_CHOICES})`, 'content-invalid');
|
|
128
134
|
}
|
|
129
135
|
if (hasReportedTemplateViolations(output, body, templateFile('comment', frontmatter.template)))
|
|
130
|
-
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE);
|
|
136
|
+
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
|
|
131
137
|
// comment_url は、issue_ref と同じ Issue のコメントに限る
|
|
132
138
|
const commentUrl = frontmatter.comment_url;
|
|
133
139
|
const hasCommentUrl = commentUrl !== undefined && commentUrl !== '';
|
|
@@ -136,6 +142,13 @@ async function postFromFile(output, config, repository, file) {
|
|
|
136
142
|
if (!await isRepositoryInProject(config, target.owner, target.repository, client)) {
|
|
137
143
|
output.warning(`${target.owner}/${target.repository} is not in the project`);
|
|
138
144
|
}
|
|
145
|
+
if (isDryRun) {
|
|
146
|
+
const display = issuePath(target.owner, target.repository, target.number);
|
|
147
|
+
output.planned({ verb: hasCommentUrl ? 'update' : 'create', target: `comment on ${display}` });
|
|
148
|
+
if (!hasCommentUrl)
|
|
149
|
+
output.planned({ verb: 'set', target: `comment_url in ${file}` });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
139
152
|
if (hasCommentUrl) {
|
|
140
153
|
await updateComment(output, client, target, commentId, commentUrl, body);
|
|
141
154
|
return;
|
|
@@ -144,51 +157,57 @@ async function postFromFile(output, config, repository, file) {
|
|
|
144
157
|
if (createdUrl !== '')
|
|
145
158
|
writeBackCommentUrl(output, file, createdUrl);
|
|
146
159
|
}
|
|
147
|
-
async function postDirect(output, config, repository, issueReference, message, template) {
|
|
160
|
+
async function postDirect(output, config, repository, issueReference, message, template, isDryRun) {
|
|
148
161
|
const target = parseIssueReferenceOrExit(output, repository, issueReference);
|
|
149
162
|
if (hasReportedTemplateViolations(output, message, templateFile('comment', template)))
|
|
150
|
-
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE);
|
|
163
|
+
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
|
|
164
|
+
if (isDryRun) {
|
|
165
|
+
output.planned({ verb: 'create', target: `comment on ${issuePath(target.owner, target.repository, target.number)}` });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
151
168
|
await createComment(output, createGitHubClient(output, config.host), target, message);
|
|
152
169
|
}
|
|
170
|
+
const COMMENT_PATH = ['issue', 'comment'];
|
|
153
171
|
const ISSUE_COMMENT = defineCommand({
|
|
154
|
-
path:
|
|
172
|
+
path: COMMENT_PATH,
|
|
155
173
|
description: 'Post a comment on an Issue',
|
|
156
174
|
input: z.object({
|
|
157
175
|
file: z.string().optional().describe('Path of a Markdown file with frontmatter'),
|
|
158
176
|
message: z.string().optional().describe('Comment body'),
|
|
159
|
-
|
|
177
|
+
issue_ref: z.string().optional().describe('Issue reference (owner/repo/123 form, required with -m)'),
|
|
160
178
|
prepare: z.boolean().default(false).describe('Copy a template to the work directory'),
|
|
161
179
|
template: TEMPLATE_SCHEMA.optional().describe('Template type (required with --prepare and -m; plan/merge-diff/review-findings/review-resolution/precede-notify)'),
|
|
180
|
+
dry_run: z.boolean().default(false).describe('Show what would be posted or written without changing anything'),
|
|
162
181
|
}),
|
|
163
182
|
positional: ['file'],
|
|
164
|
-
shortFlags: { message: '-m',
|
|
183
|
+
shortFlags: { message: '-m', issue_ref: '-i', prepare: '-p', template: '-t', dry_run: '-n' },
|
|
165
184
|
interactive: false,
|
|
166
185
|
run: async (input, io) => {
|
|
167
|
-
const output = createOutput(
|
|
186
|
+
const output = createOutput(input.dry_run, io);
|
|
168
187
|
return await runWithExit(async () => {
|
|
169
|
-
const { file, message, issue, prepare, template } = input;
|
|
188
|
+
const { file, message, issue_ref: issue, prepare, template } = input;
|
|
170
189
|
if (template === undefined && (prepare || (message !== undefined && file === undefined))) {
|
|
171
|
-
stopWith(output, `specify a template with
|
|
190
|
+
stopWith(output, hinted `specify a template with ${inputNameHint(COMMENT_PATH, 'template')} (${TEMPLATE_CHOICES})`, 'invalid-input');
|
|
172
191
|
}
|
|
173
192
|
if (prepare && template !== undefined) {
|
|
174
|
-
prepareTemplate(output, template, issue);
|
|
193
|
+
prepareTemplate(output, template, issue, input.dry_run);
|
|
175
194
|
return;
|
|
176
195
|
}
|
|
177
196
|
if (file !== undefined) {
|
|
178
|
-
await postFromFile(output, requireActiveConfigPlain(output), input.repo, file);
|
|
197
|
+
await postFromFile(output, requireActiveConfigPlain(output), input.repo, file, input.dry_run);
|
|
179
198
|
return;
|
|
180
199
|
}
|
|
181
200
|
if (message !== undefined && template !== undefined) {
|
|
182
201
|
if (issue === undefined || issue === '') {
|
|
183
|
-
stopWith(output, '
|
|
202
|
+
stopWith(output, hinted `${inputNameHint(COMMENT_PATH, 'issue_ref')} (Issue reference) is required with ${inputNameHint(COMMENT_PATH, 'message')}`, 'invalid-input');
|
|
184
203
|
}
|
|
185
|
-
await postDirect(output, requireActiveConfigPlain(output), input.repo, issue, message, template);
|
|
204
|
+
await postDirect(output, requireActiveConfigPlain(output), input.repo, issue, message, template, input.dry_run);
|
|
186
205
|
return;
|
|
187
206
|
}
|
|
188
|
-
stopWith(output,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
207
|
+
stopWith(output, hinted `missing arguments
|
|
208
|
+
direct posting: ${commandHint(COMMENT_PATH, { message: placeholder('MESSAGE'), template: placeholder('template'), issue_ref: 'owner/repo/123' })}
|
|
209
|
+
prepare a template: ${commandHint(COMMENT_PATH, { prepare: true, template: placeholder('template') })}
|
|
210
|
+
from a file: ${commandHint(COMMENT_PATH, { file: placeholder('path') })}`, 'invalid-input');
|
|
192
211
|
});
|
|
193
212
|
},
|
|
194
213
|
});
|