@pecot/workflow-mcp 0.0.0-stage → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +184 -2
  4. package/bin/pecot-workflow-mcp.mjs +10 -0
  5. package/cli/dist/cli.d.ts +26 -0
  6. package/cli/dist/cli.js +227 -0
  7. package/cli/dist/commands/board-add.d.ts +3 -0
  8. package/cli/dist/commands/board-add.js +59 -0
  9. package/cli/dist/commands/board-judgment.d.ts +60 -0
  10. package/cli/dist/commands/board-judgment.js +144 -0
  11. package/cli/dist/commands/board-move.d.ts +3 -0
  12. package/cli/dist/commands/board-move.js +57 -0
  13. package/cli/dist/commands/board-readiness.d.ts +34 -0
  14. package/cli/dist/commands/board-readiness.js +108 -0
  15. package/cli/dist/commands/board-show.d.ts +3 -0
  16. package/cli/dist/commands/board-show.js +72 -0
  17. package/cli/dist/commands/board-sync.d.ts +3 -0
  18. package/cli/dist/commands/board-sync.js +111 -0
  19. package/cli/dist/commands/board-view.d.ts +62 -0
  20. package/cli/dist/commands/board-view.js +191 -0
  21. package/cli/dist/commands/board.d.ts +3 -0
  22. package/cli/dist/commands/board.js +12 -0
  23. package/cli/dist/commands/branch.d.ts +3 -0
  24. package/cli/dist/commands/branch.js +100 -0
  25. package/cli/dist/commands/cell-table.d.ts +3 -0
  26. package/cli/dist/commands/cell-table.js +495 -0
  27. package/cli/dist/commands/command-binding.d.ts +26 -0
  28. package/cli/dist/commands/command-binding.js +270 -0
  29. package/cli/dist/commands/command-definition.d.ts +150 -0
  30. package/cli/dist/commands/command-definition.js +105 -0
  31. package/cli/dist/commands/command-help.d.ts +8 -0
  32. package/cli/dist/commands/command-help.js +173 -0
  33. package/cli/dist/commands/command-hint.d.ts +5 -0
  34. package/cli/dist/commands/command-hint.js +13 -0
  35. package/cli/dist/commands/command-stop.d.ts +21 -0
  36. package/cli/dist/commands/command-stop.js +31 -0
  37. package/cli/dist/commands/directory-option.d.ts +7 -0
  38. package/cli/dist/commands/directory-option.js +48 -0
  39. package/cli/dist/commands/failure-kind.d.ts +3 -0
  40. package/cli/dist/commands/failure-kind.js +34 -0
  41. package/cli/dist/commands/failure.d.ts +19 -0
  42. package/cli/dist/commands/failure.js +59 -0
  43. package/cli/dist/commands/fuzzy.d.ts +7 -0
  44. package/cli/dist/commands/fuzzy.js +79 -0
  45. package/cli/dist/commands/github-client.d.ts +16 -0
  46. package/cli/dist/commands/github-client.js +33 -0
  47. package/cli/dist/commands/global-options.d.ts +25 -0
  48. package/cli/dist/commands/global-options.js +83 -0
  49. package/cli/dist/commands/help-layout.d.ts +40 -0
  50. package/cli/dist/commands/help-layout.js +117 -0
  51. package/cli/dist/commands/help.d.ts +8 -0
  52. package/cli/dist/commands/help.js +50 -0
  53. package/cli/dist/commands/input-schema.d.ts +14 -0
  54. package/cli/dist/commands/input-schema.js +56 -0
  55. package/cli/dist/commands/issue-board.d.ts +71 -0
  56. package/cli/dist/commands/issue-board.js +122 -0
  57. package/cli/dist/commands/issue-comment.d.ts +3 -0
  58. package/cli/dist/commands/issue-comment.js +215 -0
  59. package/cli/dist/commands/issue-create.d.ts +3 -0
  60. package/cli/dist/commands/issue-create.js +786 -0
  61. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  62. package/cli/dist/commands/issue-dependency.js +282 -0
  63. package/cli/dist/commands/issue-readiness.d.ts +94 -0
  64. package/cli/dist/commands/issue-readiness.js +218 -0
  65. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  66. package/cli/dist/commands/issue-reopen.js +115 -0
  67. package/cli/dist/commands/issue-shared.d.ts +172 -0
  68. package/cli/dist/commands/issue-shared.js +426 -0
  69. package/cli/dist/commands/issue-show.d.ts +3 -0
  70. package/cli/dist/commands/issue-show.js +169 -0
  71. package/cli/dist/commands/issue.d.ts +3 -0
  72. package/cli/dist/commands/issue.js +13 -0
  73. package/cli/dist/commands/names.d.ts +42 -0
  74. package/cli/dist/commands/names.js +78 -0
  75. package/cli/dist/commands/output.d.ts +90 -0
  76. package/cli/dist/commands/output.js +194 -0
  77. package/cli/dist/commands/pr-waiting.d.ts +20 -0
  78. package/cli/dist/commands/pr-waiting.js +106 -0
  79. package/cli/dist/commands/pr.d.ts +22 -0
  80. package/cli/dist/commands/pr.js +852 -0
  81. package/cli/dist/commands/project-sync.d.ts +92 -0
  82. package/cli/dist/commands/project-sync.js +282 -0
  83. package/cli/dist/commands/project.d.ts +6 -0
  84. package/cli/dist/commands/project.js +714 -0
  85. package/cli/dist/commands/registry.d.ts +6 -0
  86. package/cli/dist/commands/registry.js +30 -0
  87. package/cli/dist/commands/release.d.ts +10 -0
  88. package/cli/dist/commands/release.js +353 -0
  89. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  90. package/cli/dist/commands/renamed-commands.js +53 -0
  91. package/cli/dist/commands/repository-display.d.ts +3 -0
  92. package/cli/dist/commands/repository-display.js +7 -0
  93. package/cli/dist/commands/repository-match.d.ts +14 -0
  94. package/cli/dist/commands/repository-match.js +34 -0
  95. package/cli/dist/commands/rich-panel.d.ts +22 -0
  96. package/cli/dist/commands/rich-panel.js +295 -0
  97. package/cli/dist/commands/session-finish.d.ts +3 -0
  98. package/cli/dist/commands/session-finish.js +267 -0
  99. package/cli/dist/commands/session-start.d.ts +3 -0
  100. package/cli/dist/commands/session-start.js +236 -0
  101. package/cli/dist/commands/session.d.ts +6 -0
  102. package/cli/dist/commands/session.js +214 -0
  103. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  104. package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
  105. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  106. package/cli/dist/commands/tracker-sync-security.js +153 -0
  107. package/cli/dist/commands/tracker-sync.d.ts +65 -0
  108. package/cli/dist/commands/tracker-sync.js +50 -0
  109. package/cli/dist/commands/tracker.d.ts +3 -0
  110. package/cli/dist/commands/tracker.js +18 -0
  111. package/cli/dist/commands/usage-error.d.ts +51 -0
  112. package/cli/dist/commands/usage-error.js +78 -0
  113. package/cli/dist/commands/value-types.d.ts +46 -0
  114. package/cli/dist/commands/value-types.js +94 -0
  115. package/cli/dist/commands/work-target.d.ts +22 -0
  116. package/cli/dist/commands/work-target.js +82 -0
  117. package/cli/dist/commands/worktree.d.ts +3 -0
  118. package/cli/dist/commands/worktree.js +339 -0
  119. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  120. package/cli/dist/domain/api-error-detail.js +25 -0
  121. package/cli/dist/domain/batch-plan.d.ts +73 -0
  122. package/cli/dist/domain/batch-plan.js +114 -0
  123. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  124. package/cli/dist/domain/blocked-by-change.js +101 -0
  125. package/cli/dist/domain/board-move.d.ts +90 -0
  126. package/cli/dist/domain/board-move.js +92 -0
  127. package/cli/dist/domain/branch-name.d.ts +5 -0
  128. package/cli/dist/domain/branch-name.js +10 -0
  129. package/cli/dist/domain/changelog.d.ts +43 -0
  130. package/cli/dist/domain/changelog.js +107 -0
  131. package/cli/dist/domain/command-hint.d.ts +85 -0
  132. package/cli/dist/domain/command-hint.js +148 -0
  133. package/cli/dist/domain/config.d.ts +219 -0
  134. package/cli/dist/domain/config.js +310 -0
  135. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  136. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  137. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  138. package/cli/dist/domain/dependabot-source.js +4 -0
  139. package/cli/dist/domain/dependabot.d.ts +47 -0
  140. package/cli/dist/domain/dependabot.js +88 -0
  141. package/cli/dist/domain/errors.d.ts +24 -0
  142. package/cli/dist/domain/errors.js +36 -0
  143. package/cli/dist/domain/field-options.d.ts +31 -0
  144. package/cli/dist/domain/field-options.js +44 -0
  145. package/cli/dist/domain/format.d.ts +94 -0
  146. package/cli/dist/domain/format.js +234 -0
  147. package/cli/dist/domain/frontmatter.d.ts +137 -0
  148. package/cli/dist/domain/frontmatter.js +290 -0
  149. package/cli/dist/domain/git-runner.d.ts +10 -0
  150. package/cli/dist/domain/git-runner.js +4 -0
  151. package/cli/dist/domain/git-url.d.ts +17 -0
  152. package/cli/dist/domain/git-url.js +30 -0
  153. package/cli/dist/domain/issue-kind.d.ts +16 -0
  154. package/cli/dist/domain/issue-kind.js +16 -0
  155. package/cli/dist/domain/issue-order.d.ts +55 -0
  156. package/cli/dist/domain/issue-order.js +65 -0
  157. package/cli/dist/domain/issue-readout.d.ts +143 -0
  158. package/cli/dist/domain/issue-readout.js +4 -0
  159. package/cli/dist/domain/json-null.d.ts +2 -0
  160. package/cli/dist/domain/json-null.js +5 -0
  161. package/cli/dist/domain/json.d.ts +21 -0
  162. package/cli/dist/domain/json.js +47 -0
  163. package/cli/dist/domain/prerequisites.d.ts +32 -0
  164. package/cli/dist/domain/prerequisites.js +192 -0
  165. package/cli/dist/domain/pull-request.d.ts +201 -0
  166. package/cli/dist/domain/pull-request.js +281 -0
  167. package/cli/dist/domain/python-format.d.ts +105 -0
  168. package/cli/dist/domain/python-format.js +304 -0
  169. package/cli/dist/domain/readiness.d.ts +199 -0
  170. package/cli/dist/domain/readiness.js +391 -0
  171. package/cli/dist/domain/reference-parser.d.ts +51 -0
  172. package/cli/dist/domain/reference-parser.js +123 -0
  173. package/cli/dist/domain/release.d.ts +53 -0
  174. package/cli/dist/domain/release.js +65 -0
  175. package/cli/dist/domain/repository-policy.d.ts +38 -0
  176. package/cli/dist/domain/repository-policy.js +66 -0
  177. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  178. package/cli/dist/domain/repository-resolver.js +122 -0
  179. package/cli/dist/domain/sections.d.ts +69 -0
  180. package/cli/dist/domain/sections.js +514 -0
  181. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  182. package/cli/dist/domain/security-alerts-source.js +4 -0
  183. package/cli/dist/domain/security-alerts.d.ts +52 -0
  184. package/cli/dist/domain/security-alerts.js +107 -0
  185. package/cli/dist/domain/security-tracker.d.ts +115 -0
  186. package/cli/dist/domain/security-tracker.js +353 -0
  187. package/cli/dist/domain/state.d.ts +59 -0
  188. package/cli/dist/domain/state.js +95 -0
  189. package/cli/dist/domain/tracker-body.d.ts +70 -0
  190. package/cli/dist/domain/tracker-body.js +65 -0
  191. package/cli/dist/domain/work-start.d.ts +34 -0
  192. package/cli/dist/domain/work-start.js +49 -0
  193. package/cli/dist/domain/yaml-document.d.ts +5 -0
  194. package/cli/dist/domain/yaml-document.js +206 -0
  195. package/cli/dist/infra/authored-notes.d.ts +37 -0
  196. package/cli/dist/infra/authored-notes.js +72 -0
  197. package/cli/dist/infra/changelog-file.d.ts +19 -0
  198. package/cli/dist/infra/changelog-file.js +43 -0
  199. package/cli/dist/infra/child-stdin.d.ts +4 -0
  200. package/cli/dist/infra/child-stdin.js +8 -0
  201. package/cli/dist/infra/config-store.d.ts +53 -0
  202. package/cli/dist/infra/config-store.js +134 -0
  203. package/cli/dist/infra/diagnostics.d.ts +9 -0
  204. package/cli/dist/infra/diagnostics.js +2 -0
  205. package/cli/dist/infra/file-kind.d.ts +9 -0
  206. package/cli/dist/infra/file-kind.js +26 -0
  207. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  208. package/cli/dist/infra/frontmatter-file.js +30 -0
  209. package/cli/dist/infra/git.d.ts +86 -0
  210. package/cli/dist/infra/git.js +145 -0
  211. package/cli/dist/infra/github/auth.d.ts +60 -0
  212. package/cli/dist/infra/github/auth.js +158 -0
  213. package/cli/dist/infra/github/client.d.ts +178 -0
  214. package/cli/dist/infra/github/client.js +579 -0
  215. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  216. package/cli/dist/infra/github/dependabot-source.js +33 -0
  217. package/cli/dist/infra/github/errors.d.ts +65 -0
  218. package/cli/dist/infra/github/errors.js +64 -0
  219. package/cli/dist/infra/github/index.d.ts +13 -0
  220. package/cli/dist/infra/github/index.js +19 -0
  221. package/cli/dist/infra/github/issues.d.ts +165 -0
  222. package/cli/dist/infra/github/issues.js +428 -0
  223. package/cli/dist/infra/github/payload.d.ts +44 -0
  224. package/cli/dist/infra/github/payload.js +80 -0
  225. package/cli/dist/infra/github/projects.d.ts +143 -0
  226. package/cli/dist/infra/github/projects.js +384 -0
  227. package/cli/dist/infra/github/pulls.d.ts +104 -0
  228. package/cli/dist/infra/github/pulls.js +217 -0
  229. package/cli/dist/infra/github/queries.d.ts +44 -0
  230. package/cli/dist/infra/github/queries.js +1031 -0
  231. package/cli/dist/infra/github/readout.d.ts +22 -0
  232. package/cli/dist/infra/github/readout.js +167 -0
  233. package/cli/dist/infra/github/repos.d.ts +86 -0
  234. package/cli/dist/infra/github/repos.js +168 -0
  235. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  236. package/cli/dist/infra/github/rest-path.js +31 -0
  237. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  238. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  239. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  240. package/cli/dist/infra/gitignore-spec.js +235 -0
  241. package/cli/dist/infra/nx-scope.d.ts +51 -0
  242. package/cli/dist/infra/nx-scope.js +182 -0
  243. package/cli/dist/infra/os-error.d.ts +24 -0
  244. package/cli/dist/infra/os-error.js +38 -0
  245. package/cli/dist/infra/paths.d.ts +88 -0
  246. package/cli/dist/infra/paths.js +234 -0
  247. package/cli/dist/infra/state-store.d.ts +54 -0
  248. package/cli/dist/infra/state-store.js +130 -0
  249. package/cli/dist/infra/template-store.d.ts +15 -0
  250. package/cli/dist/infra/template-store.js +34 -0
  251. package/cli/dist/infra/text-file.d.ts +12 -0
  252. package/cli/dist/infra/text-file.js +33 -0
  253. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  254. package/cli/dist/infra/worktree-copy.js +95 -0
  255. package/cli/dist/infra/worktree-links.d.ts +142 -0
  256. package/cli/dist/infra/worktree-links.js +440 -0
  257. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  258. package/cli/dist/infra/worktree-setup.js +41 -0
  259. package/cli/dist/infra/worktree.d.ts +185 -0
  260. package/cli/dist/infra/worktree.js +584 -0
  261. package/cli/dist/mcp/result.d.ts +61 -0
  262. package/cli/dist/mcp/result.js +96 -0
  263. package/cli/dist/mcp/serve.d.ts +51 -0
  264. package/cli/dist/mcp/serve.js +183 -0
  265. package/cli/dist/mcp/server.d.ts +21 -0
  266. package/cli/dist/mcp/server.js +142 -0
  267. package/cli/dist/mcp/session-directory.d.ts +26 -0
  268. package/cli/dist/mcp/session-directory.js +84 -0
  269. package/cli/dist/package.json +1 -0
  270. package/cli/dist/version.d.ts +17 -0
  271. package/cli/dist/version.js +42 -0
  272. package/cli/templates/comment/merge-diff.md +34 -0
  273. package/cli/templates/comment/plan.md +195 -0
  274. package/cli/templates/comment/precede-notify.md +33 -0
  275. package/cli/templates/comment/review-findings.md +42 -0
  276. package/cli/templates/comment/review-resolution.md +48 -0
  277. package/cli/templates/issue/bug.md +63 -0
  278. package/cli/templates/issue/epic.md +54 -0
  279. package/cli/templates/issue/task-implement.md +74 -0
  280. package/cli/templates/issue/task.md +48 -0
  281. package/cli/templates/issue/tracker.md +48 -0
  282. package/cli/templates/pr/create.md +123 -0
  283. package/cli/templates/pr/release.md +56 -0
  284. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  285. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  286. package/npm-shrinkwrap.json +83 -0
  287. package/package.json +22 -4
@@ -0,0 +1,215 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは利用者の引数とテンプレートの置き場で決まる */
3
+ // issue comment。cli/commands/issue.py の issue_comment とその内部関数の移植。
4
+ import { existsSync, writeFileSync } from 'node:fs';
5
+ import { z } from 'zod';
6
+ import { isRepositoryInProject } from '../domain/config.js';
7
+ import { FrontmatterError, setFrontmatterValue } from '../domain/frontmatter.js';
8
+ import { jsonField } from '../domain/json.js';
9
+ import { pythonStrip } from '../domain/python-format.js';
10
+ import { OsError, toOsError } from '../infra/os-error.js';
11
+ import { parseCommentFile } from '../infra/frontmatter-file.js';
12
+ import { GitHubAPIError } from '../infra/github/errors.js';
13
+ import { OutputPathReservationError, outputDirectory, withReservedOutputPath } from '../infra/paths.js';
14
+ import { readTextFile } from '../infra/text-file.js';
15
+ import { templateFile } from '../infra/template-store.js';
16
+ import { defineCommand, CommandExit } from './command-definition.js';
17
+ import { commandHint, hinted, inputNameHint, placeholder } from './command-hint.js';
18
+ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
19
+ import { kindOfFailure } from './failure.js';
20
+ import { createGitHubClient } from './github-client.js';
21
+ import { COMMENT_VALIDATION_EXIT_CODE, hasReportedTemplateViolations, issuePath, parseIssueReferenceOrExit, runWithExit, } from './issue-shared.js';
22
+ import { createOutput } from './output.js';
23
+ const TEMPLATE_SCHEMA = z.enum(['plan', 'merge-diff', 'review-findings', 'review-resolution', 'precede-notify']);
24
+ const TEMPLATE_CHOICES = TEMPLATE_SCHEMA.options.join(' / ');
25
+ // PR へのコメントは GitHub が /pull/ の形で html_url を返すので、両方受ける
26
+ const COMMENT_URL_PATTERN = /^https?:\/\/(?<host>[^/]+)\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/(?:issues|pull)\/(?<number>\d+)#issuecomment-(?<id>\d+)$/u;
27
+ function htmlUrlOf(comment, fallback) {
28
+ const url = jsonField(comment, 'html_url');
29
+ return typeof url === 'string' ? url : fallback;
30
+ }
31
+ // テンプレートをコピーして、そのパスを標準出力に出す。issue_ref が渡されていれば、コピーの issue_ref に入れる
32
+ function prepareTemplate(output, template, issueReference, isDryRun) {
33
+ const templatePath = templateFile('comment', template);
34
+ if (!existsSync(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;
40
+ }
41
+ let content = readTextFile(templatePath);
42
+ if (issueReference !== undefined && issueReference !== '') {
43
+ content = content.replaceAll('issue_ref: ""', () => `issue_ref: "${issueReference}"`);
44
+ }
45
+ try {
46
+ withReservedOutputPath(outputDirectory(), timestamp => `comment-${template}-${timestamp}.md`, (reserved) => {
47
+ writeFileSync(reserved, content, 'utf8');
48
+ output.data(reserved);
49
+ });
50
+ }
51
+ catch (error) {
52
+ if (!(error instanceof OutputPathReservationError))
53
+ throw error;
54
+ stopWith(output, error.message, 'other');
55
+ }
56
+ }
57
+ // comment_url からコメントの id を取る。issue_ref と別の Issue を指していたら終了コード 1
58
+ function commentIdFor(output, commentUrl, host, target) {
59
+ const groups = COMMENT_URL_PATTERN.exec(pythonStrip(commentUrl))?.groups;
60
+ if (groups === undefined) {
61
+ return stopWith(output, `comment_url has the wrong form: ${commentUrl}\nexpected: https://<host>/<owner>/<repo>/{issues|pull}/<number>#issuecomment-<id>`, 'invalid-input');
62
+ }
63
+ const { host: urlHost = '', owner = '', repo: urlRepository = '', number = '', id = '' } = groups;
64
+ if (urlHost.toLowerCase() !== host.toLowerCase()) {
65
+ return stopWith(output, `the host of comment_url (${urlHost}) differs from the configured host (${host})`, 'invalid-input');
66
+ }
67
+ const isSameIssue = owner.toLowerCase() === target.owner.toLowerCase()
68
+ && urlRepository.toLowerCase() === target.repository.toLowerCase()
69
+ && Number(number) === target.number;
70
+ const message = `comment_url (${owner}/${urlRepository}/${number}) points to a different Issue than issue_ref (${target.owner}/${target.repository}/${String(target.number)})`;
71
+ return isSameIssue ? Number(id) : stopWith(output, message, 'invalid-input');
72
+ }
73
+ // 次に同じファイルを渡したとき更新になるよう、URL を書き戻す。できなければ warning だけ出す
74
+ function writeBackCommentUrl(output, file, commentUrl) {
75
+ try {
76
+ const content = readTextFile(file);
77
+ writeFileSync(file, setFrontmatterValue(content, 'comment_url', commentUrl), 'utf8');
78
+ }
79
+ catch (error) {
80
+ const converted = toOsError(error, file);
81
+ if (converted instanceof OsError || converted instanceof FrontmatterError) {
82
+ output.warning(`could not write comment_url back to the file: ${converted.message}`);
83
+ return;
84
+ }
85
+ throw converted;
86
+ }
87
+ }
88
+ // コメントを作って created の行と URL を出す。失敗は error の行と終了コード 1。作ったコメントの URL を返す
89
+ async function createComment(output, client, target, body) {
90
+ const display = issuePath(target.owner, target.repository, target.number);
91
+ let comment;
92
+ try {
93
+ comment = await client.addIssueComment(target.owner, target.repository, target.number, body);
94
+ }
95
+ catch (error) {
96
+ if (!(error instanceof GitHubAPIError))
97
+ throw error;
98
+ return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
99
+ }
100
+ const createdUrl = htmlUrlOf(comment, '');
101
+ output.done({ verb: 'create', target: `comment on ${display}` });
102
+ output.data(createdUrl);
103
+ return createdUrl;
104
+ }
105
+ // comment_url のコメントを書き換える。失敗は error の行と終了コード 1
106
+ async function updateComment(output, client, target, commentId, commentUrl, body) {
107
+ const display = issuePath(target.owner, target.repository, target.number);
108
+ let comment;
109
+ try {
110
+ comment = await client.updateIssueComment(target.owner, target.repository, commentId, body);
111
+ }
112
+ catch (error) {
113
+ if (!(error instanceof GitHubAPIError))
114
+ throw error;
115
+ return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
116
+ }
117
+ output.done({ verb: 'update', target: `comment on ${display}` });
118
+ output.data(htmlUrlOf(comment, commentUrl));
119
+ }
120
+ async function postFromFile(output, config, repository, file, isDryRun) {
121
+ let parsed;
122
+ try {
123
+ parsed = parseCommentFile(file);
124
+ }
125
+ catch (error) {
126
+ if (!(error instanceof FrontmatterError))
127
+ throw error;
128
+ return stopWith(output, error.message, 'content-invalid');
129
+ }
130
+ const { frontmatter, body } = parsed;
131
+ const target = parseIssueReferenceOrExit(output, repository, frontmatter.issue_ref);
132
+ if (frontmatter.template === undefined) {
133
+ return stopWith(output, `specify template in the frontmatter (${TEMPLATE_CHOICES})`, 'content-invalid');
134
+ }
135
+ if (hasReportedTemplateViolations(output, body, templateFile('comment', frontmatter.template)))
136
+ throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
137
+ // comment_url は、issue_ref と同じ Issue のコメントに限る
138
+ const commentUrl = frontmatter.comment_url;
139
+ const hasCommentUrl = commentUrl !== undefined && commentUrl !== '';
140
+ const commentId = hasCommentUrl ? commentIdFor(output, commentUrl, config.host, target) : 0;
141
+ const client = createGitHubClient(output, config.host);
142
+ if (!await isRepositoryInProject(config, target.owner, target.repository, client)) {
143
+ output.warning(`${target.owner}/${target.repository} is not in the project`);
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
+ }
152
+ if (hasCommentUrl) {
153
+ await updateComment(output, client, target, commentId, commentUrl, body);
154
+ return;
155
+ }
156
+ const createdUrl = await createComment(output, client, target, body);
157
+ if (createdUrl !== '')
158
+ writeBackCommentUrl(output, file, createdUrl);
159
+ }
160
+ async function postDirect(output, config, repository, issueReference, message, template, isDryRun) {
161
+ const target = parseIssueReferenceOrExit(output, repository, issueReference);
162
+ if (hasReportedTemplateViolations(output, message, templateFile('comment', template)))
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
+ }
168
+ await createComment(output, createGitHubClient(output, config.host), target, message);
169
+ }
170
+ const COMMENT_PATH = ['issue', 'comment'];
171
+ const ISSUE_COMMENT = defineCommand({
172
+ path: COMMENT_PATH,
173
+ description: 'Post a comment on an Issue',
174
+ input: z.object({
175
+ file: z.string().optional().describe('Path of a Markdown file with frontmatter'),
176
+ message: z.string().optional().describe('Comment body'),
177
+ issue_ref: z.string().optional().describe('Issue reference (owner/repo/123 form, required with -m)'),
178
+ prepare: z.boolean().default(false).describe('Copy a template to the work directory'),
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'),
181
+ }),
182
+ positional: ['file'],
183
+ shortFlags: { message: '-m', issue_ref: '-i', prepare: '-p', template: '-t', dry_run: '-n' },
184
+ interactive: false,
185
+ run: async (input, io) => {
186
+ const output = createOutput(input.dry_run, io);
187
+ return await runWithExit(async () => {
188
+ const { file, message, issue_ref: issue, prepare, template } = input;
189
+ if (template === undefined && (prepare || (message !== undefined && file === undefined))) {
190
+ stopWith(output, hinted `specify a template with ${inputNameHint(COMMENT_PATH, 'template')} (${TEMPLATE_CHOICES})`, 'invalid-input');
191
+ }
192
+ if (prepare && template !== undefined) {
193
+ prepareTemplate(output, template, issue, input.dry_run);
194
+ return;
195
+ }
196
+ if (file !== undefined) {
197
+ await postFromFile(output, requireActiveConfigPlain(output), input.repo, file, input.dry_run);
198
+ return;
199
+ }
200
+ if (message !== undefined && template !== undefined) {
201
+ if (issue === undefined || issue === '') {
202
+ stopWith(output, hinted `${inputNameHint(COMMENT_PATH, 'issue_ref')} (Issue reference) is required with ${inputNameHint(COMMENT_PATH, 'message')}`, 'invalid-input');
203
+ }
204
+ await postDirect(output, requireActiveConfigPlain(output), input.repo, issue, message, template, input.dry_run);
205
+ return;
206
+ }
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');
211
+ });
212
+ },
213
+ });
214
+ export const ISSUE_COMMENT_COMMANDS = [ISSUE_COMMENT];
215
+ //# sourceMappingURL=issue-comment.js.map
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_CREATE_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue-create.d.ts.map