@pecot/workflow-mcp 0.0.0-stage → 5.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 (244) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +126 -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 +222 -0
  7. package/cli/dist/commands/cell-table.d.ts +3 -0
  8. package/cli/dist/commands/cell-table.js +495 -0
  9. package/cli/dist/commands/command-binding.d.ts +26 -0
  10. package/cli/dist/commands/command-binding.js +266 -0
  11. package/cli/dist/commands/command-definition.d.ts +136 -0
  12. package/cli/dist/commands/command-definition.js +101 -0
  13. package/cli/dist/commands/command-help.d.ts +8 -0
  14. package/cli/dist/commands/command-help.js +173 -0
  15. package/cli/dist/commands/command-stop.d.ts +19 -0
  16. package/cli/dist/commands/command-stop.js +30 -0
  17. package/cli/dist/commands/dependabot.d.ts +3 -0
  18. package/cli/dist/commands/dependabot.js +165 -0
  19. package/cli/dist/commands/directory-option.d.ts +7 -0
  20. package/cli/dist/commands/directory-option.js +48 -0
  21. package/cli/dist/commands/failure.d.ts +13 -0
  22. package/cli/dist/commands/failure.js +33 -0
  23. package/cli/dist/commands/fuzzy.d.ts +7 -0
  24. package/cli/dist/commands/fuzzy.js +79 -0
  25. package/cli/dist/commands/github-client.d.ts +12 -0
  26. package/cli/dist/commands/github-client.js +23 -0
  27. package/cli/dist/commands/global-options.d.ts +25 -0
  28. package/cli/dist/commands/global-options.js +83 -0
  29. package/cli/dist/commands/help-layout.d.ts +40 -0
  30. package/cli/dist/commands/help-layout.js +117 -0
  31. package/cli/dist/commands/help.d.ts +8 -0
  32. package/cli/dist/commands/help.js +55 -0
  33. package/cli/dist/commands/input-schema.d.ts +14 -0
  34. package/cli/dist/commands/input-schema.js +56 -0
  35. package/cli/dist/commands/issue-board.d.ts +38 -0
  36. package/cli/dist/commands/issue-board.js +62 -0
  37. package/cli/dist/commands/issue-comment.d.ts +3 -0
  38. package/cli/dist/commands/issue-comment.js +196 -0
  39. package/cli/dist/commands/issue-create.d.ts +3 -0
  40. package/cli/dist/commands/issue-create.js +329 -0
  41. package/cli/dist/commands/issue-project.d.ts +3 -0
  42. package/cli/dist/commands/issue-project.js +176 -0
  43. package/cli/dist/commands/issue-quick.d.ts +3 -0
  44. package/cli/dist/commands/issue-quick.js +126 -0
  45. package/cli/dist/commands/issue-read.d.ts +3 -0
  46. package/cli/dist/commands/issue-read.js +80 -0
  47. package/cli/dist/commands/issue-shared.d.ts +159 -0
  48. package/cli/dist/commands/issue-shared.js +419 -0
  49. package/cli/dist/commands/issue.d.ts +4 -0
  50. package/cli/dist/commands/issue.js +15 -0
  51. package/cli/dist/commands/names.d.ts +9 -0
  52. package/cli/dist/commands/names.js +16 -0
  53. package/cli/dist/commands/output.d.ts +78 -0
  54. package/cli/dist/commands/output.js +187 -0
  55. package/cli/dist/commands/pr.d.ts +3 -0
  56. package/cli/dist/commands/pr.js +933 -0
  57. package/cli/dist/commands/project-info.d.ts +48 -0
  58. package/cli/dist/commands/project-info.js +181 -0
  59. package/cli/dist/commands/project-sync.d.ts +91 -0
  60. package/cli/dist/commands/project-sync.js +273 -0
  61. package/cli/dist/commands/project.d.ts +5 -0
  62. package/cli/dist/commands/project.js +677 -0
  63. package/cli/dist/commands/registry.d.ts +6 -0
  64. package/cli/dist/commands/registry.js +27 -0
  65. package/cli/dist/commands/release.d.ts +10 -0
  66. package/cli/dist/commands/release.js +414 -0
  67. package/cli/dist/commands/repository-display.d.ts +3 -0
  68. package/cli/dist/commands/repository-display.js +7 -0
  69. package/cli/dist/commands/repository-match.d.ts +14 -0
  70. package/cli/dist/commands/repository-match.js +33 -0
  71. package/cli/dist/commands/repository.d.ts +5 -0
  72. package/cli/dist/commands/repository.js +265 -0
  73. package/cli/dist/commands/rich-panel.d.ts +22 -0
  74. package/cli/dist/commands/rich-panel.js +295 -0
  75. package/cli/dist/commands/security.d.ts +3 -0
  76. package/cli/dist/commands/security.js +164 -0
  77. package/cli/dist/commands/session.d.ts +3 -0
  78. package/cli/dist/commands/session.js +161 -0
  79. package/cli/dist/commands/tracker-sync.d.ts +58 -0
  80. package/cli/dist/commands/tracker-sync.js +53 -0
  81. package/cli/dist/commands/usage-error.d.ts +47 -0
  82. package/cli/dist/commands/usage-error.js +72 -0
  83. package/cli/dist/commands/value-types.d.ts +46 -0
  84. package/cli/dist/commands/value-types.js +94 -0
  85. package/cli/dist/commands/work-target.d.ts +13 -0
  86. package/cli/dist/commands/work-target.js +41 -0
  87. package/cli/dist/commands/worktree.d.ts +3 -0
  88. package/cli/dist/commands/worktree.js +335 -0
  89. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  90. package/cli/dist/domain/api-error-detail.js +25 -0
  91. package/cli/dist/domain/branch-name.d.ts +5 -0
  92. package/cli/dist/domain/branch-name.js +10 -0
  93. package/cli/dist/domain/changelog.d.ts +43 -0
  94. package/cli/dist/domain/changelog.js +107 -0
  95. package/cli/dist/domain/config.d.ts +215 -0
  96. package/cli/dist/domain/config.js +300 -0
  97. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  98. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  99. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  100. package/cli/dist/domain/dependabot-source.js +4 -0
  101. package/cli/dist/domain/dependabot.d.ts +47 -0
  102. package/cli/dist/domain/dependabot.js +88 -0
  103. package/cli/dist/domain/errors.d.ts +19 -0
  104. package/cli/dist/domain/errors.js +31 -0
  105. package/cli/dist/domain/field-options.d.ts +31 -0
  106. package/cli/dist/domain/field-options.js +44 -0
  107. package/cli/dist/domain/format.d.ts +47 -0
  108. package/cli/dist/domain/format.js +168 -0
  109. package/cli/dist/domain/frontmatter.d.ts +122 -0
  110. package/cli/dist/domain/frontmatter.js +264 -0
  111. package/cli/dist/domain/git-runner.d.ts +10 -0
  112. package/cli/dist/domain/git-runner.js +4 -0
  113. package/cli/dist/domain/git-url.d.ts +17 -0
  114. package/cli/dist/domain/git-url.js +30 -0
  115. package/cli/dist/domain/issue-kind.d.ts +16 -0
  116. package/cli/dist/domain/issue-kind.js +16 -0
  117. package/cli/dist/domain/issue-readout.d.ts +107 -0
  118. package/cli/dist/domain/issue-readout.js +4 -0
  119. package/cli/dist/domain/json-null.d.ts +2 -0
  120. package/cli/dist/domain/json-null.js +5 -0
  121. package/cli/dist/domain/json.d.ts +21 -0
  122. package/cli/dist/domain/json.js +47 -0
  123. package/cli/dist/domain/prerequisites.d.ts +32 -0
  124. package/cli/dist/domain/prerequisites.js +192 -0
  125. package/cli/dist/domain/pull-request.d.ts +134 -0
  126. package/cli/dist/domain/pull-request.js +232 -0
  127. package/cli/dist/domain/python-format.d.ts +105 -0
  128. package/cli/dist/domain/python-format.js +304 -0
  129. package/cli/dist/domain/readiness.d.ts +172 -0
  130. package/cli/dist/domain/readiness.js +280 -0
  131. package/cli/dist/domain/reference-parser.d.ts +49 -0
  132. package/cli/dist/domain/reference-parser.js +119 -0
  133. package/cli/dist/domain/release.d.ts +49 -0
  134. package/cli/dist/domain/release.js +72 -0
  135. package/cli/dist/domain/repository-policy.d.ts +32 -0
  136. package/cli/dist/domain/repository-policy.js +65 -0
  137. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  138. package/cli/dist/domain/repository-resolver.js +119 -0
  139. package/cli/dist/domain/sections.d.ts +69 -0
  140. package/cli/dist/domain/sections.js +514 -0
  141. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  142. package/cli/dist/domain/security-alerts-source.js +4 -0
  143. package/cli/dist/domain/security-alerts.d.ts +52 -0
  144. package/cli/dist/domain/security-alerts.js +107 -0
  145. package/cli/dist/domain/security-tracker.d.ts +115 -0
  146. package/cli/dist/domain/security-tracker.js +353 -0
  147. package/cli/dist/domain/state.d.ts +29 -0
  148. package/cli/dist/domain/state.js +56 -0
  149. package/cli/dist/domain/tracker-body.d.ts +70 -0
  150. package/cli/dist/domain/tracker-body.js +65 -0
  151. package/cli/dist/domain/yaml-document.d.ts +5 -0
  152. package/cli/dist/domain/yaml-document.js +206 -0
  153. package/cli/dist/infra/authored-notes.d.ts +37 -0
  154. package/cli/dist/infra/authored-notes.js +66 -0
  155. package/cli/dist/infra/changelog-file.d.ts +19 -0
  156. package/cli/dist/infra/changelog-file.js +43 -0
  157. package/cli/dist/infra/child-stdin.d.ts +4 -0
  158. package/cli/dist/infra/child-stdin.js +8 -0
  159. package/cli/dist/infra/config-store.d.ts +49 -0
  160. package/cli/dist/infra/config-store.js +121 -0
  161. package/cli/dist/infra/diagnostics.d.ts +9 -0
  162. package/cli/dist/infra/diagnostics.js +2 -0
  163. package/cli/dist/infra/file-kind.d.ts +9 -0
  164. package/cli/dist/infra/file-kind.js +26 -0
  165. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  166. package/cli/dist/infra/frontmatter-file.js +30 -0
  167. package/cli/dist/infra/git.d.ts +74 -0
  168. package/cli/dist/infra/git.js +133 -0
  169. package/cli/dist/infra/github/auth.d.ts +60 -0
  170. package/cli/dist/infra/github/auth.js +158 -0
  171. package/cli/dist/infra/github/client.d.ts +173 -0
  172. package/cli/dist/infra/github/client.js +576 -0
  173. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  174. package/cli/dist/infra/github/dependabot-source.js +33 -0
  175. package/cli/dist/infra/github/errors.d.ts +47 -0
  176. package/cli/dist/infra/github/errors.js +42 -0
  177. package/cli/dist/infra/github/index.d.ts +13 -0
  178. package/cli/dist/infra/github/index.js +19 -0
  179. package/cli/dist/infra/github/issues.d.ts +129 -0
  180. package/cli/dist/infra/github/issues.js +273 -0
  181. package/cli/dist/infra/github/payload.d.ts +44 -0
  182. package/cli/dist/infra/github/payload.js +80 -0
  183. package/cli/dist/infra/github/projects.d.ts +108 -0
  184. package/cli/dist/infra/github/projects.js +303 -0
  185. package/cli/dist/infra/github/pulls.d.ts +80 -0
  186. package/cli/dist/infra/github/pulls.js +161 -0
  187. package/cli/dist/infra/github/queries.d.ts +36 -0
  188. package/cli/dist/infra/github/queries.js +883 -0
  189. package/cli/dist/infra/github/readout.d.ts +18 -0
  190. package/cli/dist/infra/github/readout.js +156 -0
  191. package/cli/dist/infra/github/repos.d.ts +68 -0
  192. package/cli/dist/infra/github/repos.js +137 -0
  193. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  194. package/cli/dist/infra/github/rest-path.js +31 -0
  195. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  196. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  197. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  198. package/cli/dist/infra/gitignore-spec.js +235 -0
  199. package/cli/dist/infra/nx-scope.d.ts +51 -0
  200. package/cli/dist/infra/nx-scope.js +182 -0
  201. package/cli/dist/infra/os-error.d.ts +24 -0
  202. package/cli/dist/infra/os-error.js +38 -0
  203. package/cli/dist/infra/paths.d.ts +88 -0
  204. package/cli/dist/infra/paths.js +234 -0
  205. package/cli/dist/infra/state-store.d.ts +45 -0
  206. package/cli/dist/infra/state-store.js +118 -0
  207. package/cli/dist/infra/template-store.d.ts +15 -0
  208. package/cli/dist/infra/template-store.js +34 -0
  209. package/cli/dist/infra/text-file.d.ts +12 -0
  210. package/cli/dist/infra/text-file.js +33 -0
  211. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  212. package/cli/dist/infra/worktree-copy.js +95 -0
  213. package/cli/dist/infra/worktree-links.d.ts +139 -0
  214. package/cli/dist/infra/worktree-links.js +433 -0
  215. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  216. package/cli/dist/infra/worktree-setup.js +41 -0
  217. package/cli/dist/infra/worktree.d.ts +174 -0
  218. package/cli/dist/infra/worktree.js +567 -0
  219. package/cli/dist/mcp/result.d.ts +33 -0
  220. package/cli/dist/mcp/result.js +52 -0
  221. package/cli/dist/mcp/serve.d.ts +51 -0
  222. package/cli/dist/mcp/serve.js +183 -0
  223. package/cli/dist/mcp/server.d.ts +21 -0
  224. package/cli/dist/mcp/server.js +128 -0
  225. package/cli/dist/mcp/session-directory.d.ts +26 -0
  226. package/cli/dist/mcp/session-directory.js +84 -0
  227. package/cli/dist/package.json +1 -0
  228. package/cli/dist/version.d.ts +17 -0
  229. package/cli/dist/version.js +42 -0
  230. package/cli/templates/comment/merge-diff.md +34 -0
  231. package/cli/templates/comment/plan.md +181 -0
  232. package/cli/templates/comment/precede-notify.md +33 -0
  233. package/cli/templates/comment/review-findings.md +42 -0
  234. package/cli/templates/comment/review-resolution.md +48 -0
  235. package/cli/templates/issue/bug.md +63 -0
  236. package/cli/templates/issue/epic.md +54 -0
  237. package/cli/templates/issue/task-implement.md +67 -0
  238. package/cli/templates/issue/task.md +48 -0
  239. package/cli/templates/issue/tracker.md +48 -0
  240. package/cli/templates/pr/create.md +123 -0
  241. package/cli/templates/pr/release.md +56 -0
  242. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  243. package/npm-shrinkwrap.json +83 -0
  244. package/package.json +22 -4
@@ -0,0 +1,42 @@
1
+ // GitHub API 操作の例外。Python の cli/core/github/errors.py と同じ階層にする。
2
+ import { PecotError } from '../../domain/errors.js';
3
+ /**
4
+ GitHub API 操作エラーの基底
5
+ */
6
+ export class GitHubAPIError extends PecotError {
7
+ statusCode;
8
+ responseBody;
9
+ constructor(message, detail = {}) {
10
+ super(message, detail.cause === undefined ? undefined : { cause: detail.cause });
11
+ this.statusCode = detail.statusCode;
12
+ this.responseBody = detail.responseBody;
13
+ }
14
+ }
15
+ /**
16
+ 認証エラー(401 Unauthorized)。トークンが無効または期限切れのときに起きる
17
+ */
18
+ export class GitHubAuthError extends GitHubAPIError {
19
+ }
20
+ /**
21
+ リソースが見つからない(404 Not Found)。指定したリポジトリ・Issue・プロジェクトが無いときに起きる
22
+ */
23
+ export class GitHubNotFoundError extends GitHubAPIError {
24
+ }
25
+ /**
26
+ レート制限エラー(403 Forbidden で rate limit を超えたとき)
27
+ */
28
+ export class GitHubRateLimitError extends GitHubAPIError {
29
+ }
30
+ /**
31
+ このエラーが、ブランチ(ref)がもう無いことを表すか。`Reference does not exist` を含む 404・422 だけを「無い」と見なす
32
+ */
33
+ export function isMissingReferenceError(error) {
34
+ return (error.statusCode === 404 || error.statusCode === 422) && error.responseBody?.includes('Reference does not exist') === true;
35
+ }
36
+ /**
37
+ 別の要求が同時に閉じたことを示す 422 か(PR の Closes による自動 close など)
38
+ */
39
+ export function isClosedByAnotherRequest(error) {
40
+ return error.statusCode === 422 && error.responseBody?.includes('closed by another request') === true;
41
+ }
42
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,13 @@
1
+ import { PullsApi } from './pulls.js';
2
+ /**
3
+ GitHub API クライアント。操作は責務別のクラスから合成する。
4
+
5
+ 使い方は次のとおり。
6
+ - 作る: `new GitHubClient({ host: 'ghes.example.com', diagnostics })`。
7
+ - 呼ぶ: `await client.getIssueSlim('owner', 'repo', 123)`。
8
+
9
+ RepositoryMembership(domain/config.ts)と同じ形の linkedRepositories も持つ。
10
+ */
11
+ export declare class GitHubClient extends PullsApi {
12
+ }
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,19 @@
1
+ // GitHub API クライアント(REST と GraphQL、github.com と GHES に対応)。cli/core/github/__init__.py の移植。
2
+ //
3
+ // Python は IssuesAPI・ProjectsAPI・PullsAPI・ReposAPI の多重継承で合成していた。
4
+ // TypeScript は継承を一直線につなぐ。基底 → repos → projects → issues → pulls の順で、各ファイルが前のクラスを拡張する。
5
+ // この順は合成のための並びで、操作の依存を表さない。
6
+ // 操作どうしの実際の依存は projects が repos の getRepositoryId を呼ぶ 1 本だけ。
7
+ import { PullsApi } from './pulls.js';
8
+ /**
9
+ GitHub API クライアント。操作は責務別のクラスから合成する。
10
+
11
+ 使い方は次のとおり。
12
+ - 作る: `new GitHubClient({ host: 'ghes.example.com', diagnostics })`。
13
+ - 呼ぶ: `await client.getIssueSlim('owner', 'repo', 123)`。
14
+
15
+ RepositoryMembership(domain/config.ts)と同じ形の linkedRepositories も持つ。
16
+ */
17
+ export class GitHubClient extends PullsApi {
18
+ }
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,129 @@
1
+ import type { JsonObject } from '../../domain/json.js';
2
+ import type { IssuePrerequisitesReadout, PrerequisiteFieldNames } from '../../domain/issue-readout.js';
3
+ import type { JsonValue } from '../../domain/python-format.js';
4
+ import { ProjectsApi } from './projects.js';
5
+ export interface IssueNodeIdAndTitle {
6
+ readonly id: string;
7
+ readonly title: string;
8
+ }
9
+ export interface SubIssueLink {
10
+ readonly parent_number: number;
11
+ readonly child_number: number;
12
+ }
13
+ /**
14
+ Issue 種別。issue_type は issueType フィールド非対応の GHES では null になりうる
15
+ */
16
+ export interface IssueKindResult {
17
+ readonly number: number;
18
+ readonly state: string;
19
+ readonly issue_type: string | null;
20
+ readonly sub_issues_total: number;
21
+ }
22
+ export interface IssueComment {
23
+ readonly author: string;
24
+ readonly created_at: string;
25
+ readonly body: string;
26
+ }
27
+ export interface IssueParent {
28
+ readonly number: number;
29
+ readonly title: string;
30
+ readonly state: string;
31
+ readonly owner: string | null;
32
+ readonly repo: string | null;
33
+ }
34
+ export interface IssueSubIssue {
35
+ readonly number: number;
36
+ readonly state: string;
37
+ readonly title: string;
38
+ }
39
+ export interface LinkedPullRequest {
40
+ readonly number: number;
41
+ readonly title: string;
42
+ readonly state: string;
43
+ }
44
+ /**
45
+ Issue の詳細(GraphQL で必要なフィールドだけ取ったもの)
46
+ */
47
+ export interface IssueSlim {
48
+ readonly number: number;
49
+ readonly state: string;
50
+ readonly title: string;
51
+ readonly body: string;
52
+ readonly comments: {
53
+ readonly total_count: number;
54
+ readonly nodes: readonly IssueComment[];
55
+ };
56
+ readonly parent: IssueParent | null;
57
+ readonly sub_issues: readonly IssueSubIssue[];
58
+ readonly linked_branches: readonly string[];
59
+ readonly linked_prs: readonly LinkedPullRequest[];
60
+ }
61
+ export declare class IssuesApi extends ProjectsApi {
62
+ private executeDependencyMutation;
63
+ private getIssueKindPhase1;
64
+ /**
65
+ Issue を作る。labels が空なら送らない
66
+ */
67
+ createIssue(owner: string, repository: string, title: string, body?: string, labels?: readonly string[]): Promise<JsonObject>;
68
+ /**
69
+ Issue のコメントを書き換える。見つからなければ GitHubNotFoundError
70
+ */
71
+ updateIssueComment(owner: string, repository: string, commentId: number, body: string): Promise<JsonObject>;
72
+ /**
73
+ Issue にコメントを足す
74
+ */
75
+ addIssueComment(owner: string, repository: string, number: number, body: string): Promise<JsonObject>;
76
+ /**
77
+ Issue 番号から GraphQL Node ID を取る。見つからなければ GitHubNotFoundError
78
+ */
79
+ getIssueNodeId(owner: string, repository: string, number: number): Promise<string>;
80
+ /**
81
+ Issue 番号から GraphQL Node ID とタイトルを、1 回のクエリで取る
82
+ */
83
+ getIssueNodeIdAndTitle(owner: string, repository: string, number: number): Promise<IssueNodeIdAndTitle>;
84
+ /**
85
+ サブ Issue を紐づける。紐づけ結果は親と子の Issue 番号
86
+ */
87
+ addSubIssue(parentIssueId: string, childIssueId: string): Promise<SubIssueLink>;
88
+ /**
89
+ 前提(blocked by)を付ける。issueId が待つ側、blockingIssueId が前提(どちらも node ID)。
90
+ GitHub の拒否(輪・件数の上限など)は HTTP 200 の VALIDATION で返り、GitHubAPIError になる。
91
+ Issue の依存関係に対応しない GHES(3.19 より前)も GitHubAPIError
92
+ */
93
+ addBlockedBy(issueId: string, blockingIssueId: string): Promise<void>;
94
+ /**
95
+ 前提(blocked by)を外す。addBlockedBy と同じ失敗をする
96
+ */
97
+ removeBlockedBy(issueId: string, blockingIssueId: string): Promise<void>;
98
+ /**
99
+ Issue と、その前提(blockedBy 先頭 50 件)を 1 回のクエリで読む。ボードの値は projectId のものだけ。
100
+ blockedBy の部分エラーと、件数の上限による取りこぼしは、例外にせず blockedBy の read-failed で返す(呼ぶ側は判定の入力にする)。
101
+ Issue の依存関係に対応しない GHES(3.19 より前)、blockedBy 以外の失敗は GitHubAPIError
102
+ */
103
+ getIssuePrerequisites(owner: string, repository: string, number: number, projectId: string, fieldNames: Readonly<PrerequisiteFieldNames>): Promise<IssuePrerequisitesReadout>;
104
+ /**
105
+ Issue 種別を軽く取る。issueType フィールドに対応しない GHES では、subIssues だけで判定する
106
+ */
107
+ getIssueKind(owner: string, repository: string, number: number): Promise<IssueKindResult>;
108
+ /**
109
+ Issue の詳細を取る(GraphQL)。親・サブ Issue・リンクブランチ・リンク PR を 1 回のクエリで取る
110
+ */
111
+ getIssueSlim(owner: string, repository: string, number: number, commentLimit?: number): Promise<IssueSlim>;
112
+ /**
113
+ Issue を閉じる。stateReason は completed か not_planned
114
+ */
115
+ closeIssue(owner: string, repository: string, number: number, stateReason?: string): Promise<JsonObject>;
116
+ /**
117
+ Issue を再オープンする
118
+ */
119
+ reopenIssue(owner: string, repository: string, number: number): Promise<JsonObject>;
120
+ /**
121
+ ラベルの付いた Issue を open・closed の両方で全件取る(REST)。Pull Request は除く
122
+ */
123
+ listIssuesByLabel(owner: string, repository: string, label: string): Promise<readonly JsonValue[]>;
124
+ /**
125
+ Issue の本文を丸ごと置き換える。本文が上限を超える 422 は GitHubAPIError
126
+ */
127
+ updateIssueBody(owner: string, repository: string, number: number, body: string): Promise<JsonObject>;
128
+ }
129
+ //# sourceMappingURL=issues.d.ts.map
@@ -0,0 +1,273 @@
1
+ // Issue 操作の API。cli/core/github/issues.py の移植。
2
+ // 返す値のキー名は、Python の辞書と同じ snake_case にする(CLI の JSON 出力がそのまま使う)。
3
+ import { isJsonObject, jsonField } from '../../domain/json.js';
4
+ import { JSON_NULL } from '../../domain/json-null.js';
5
+ import { GitHubAPIError, GitHubNotFoundError } from './errors.js';
6
+ import { asObject, isTruthy, numberOrNull, requireNumber, requireString, requireValue, stringOrNull, subIssuesTotal, truthyNodes } from './payload.js';
7
+ import { MUTATION_ADD_BLOCKED_BY, MUTATION_ADD_SUB_ISSUE, MUTATION_REMOVE_BLOCKED_BY, QUERY_GET_ISSUE_KIND, QUERY_GET_ISSUE_KIND_PHASE1, QUERY_GET_ISSUE_NODE_ID, QUERY_GET_ISSUE_PREREQUISITES, QUERY_GET_ISSUE_SLIM, } from './queries.js';
8
+ import { readBlockedBy, readIssue } from './readout.js';
9
+ import { ProjectsApi } from './projects.js';
10
+ import { repositoryPath } from './rest-path.js';
11
+ const ISSUES_PER_PAGE = 100;
12
+ const DEFAULT_COMMENT_LIMIT = 5;
13
+ const SCHEMA_ERROR_PHRASES = ['Cannot query field', 'doesn\'t exist', 'Unknown field'];
14
+ // issueType フィールドに対応しない GHES が返すスキーマの失敗
15
+ function isIssueTypeSchemaError(error) {
16
+ return error instanceof GitHubAPIError && error.message.includes('issueType') && SCHEMA_ERROR_PHRASES.some(phrase => error.message.includes(phrase));
17
+ }
18
+ const DEPENDENCIES_UNSUPPORTED = 'this GitHub Enterprise Server does not support issue dependencies (blockedBy); version 3.19 or later is required';
19
+ // blockedBy・addBlockedBy・removeBlockedBy・issueType に対応しない GHES(3.19 より前)が返すスキーマの失敗なら、分かる失敗に替える
20
+ function asDependenciesError(error) {
21
+ const isSchemaError = error instanceof GitHubAPIError && SCHEMA_ERROR_PHRASES.some(phrase => error.message.includes(phrase));
22
+ return isSchemaError && /blockedBy|issueType/iu.test(error.message) ? new GitHubAPIError(DEPENDENCIES_UNSUPPORTED, { cause: error }) : error;
23
+ }
24
+ // 部分エラーのうち、対象の Issue の blockedBy の下のもの
25
+ function isBlockedByPath(path) {
26
+ return path[0] === 'repository' && path[1] === 'issue' && path[2] === 'blockedBy';
27
+ }
28
+ function stringOrEmpty(value) {
29
+ return typeof value === 'string' ? value : '';
30
+ }
31
+ // 見つからないときは GitHubNotFoundError。repository と issue の 2 段で確かめる
32
+ function issueNode(result, owner, repository, number) {
33
+ const repositoryNode = jsonField(result, 'repository');
34
+ if (!isTruthy(repositoryNode))
35
+ throw new GitHubNotFoundError(`repository not found: ${owner}/${repository}`);
36
+ const issue = jsonField(repositoryNode, 'issue');
37
+ if (!isTruthy(issue))
38
+ throw new GitHubNotFoundError(`Issue not found: ${owner}/${repository}/${String(number)}`);
39
+ return requireValue(issue, 'issue');
40
+ }
41
+ function formatParent(parent) {
42
+ if (!isTruthy(parent))
43
+ return JSON_NULL;
44
+ const repository = asObject(jsonField(parent, 'repository'));
45
+ return {
46
+ number: requireNumber(jsonField(parent, 'number'), 'parent.number'),
47
+ title: requireString(jsonField(parent, 'title'), 'parent.title'),
48
+ state: requireString(jsonField(parent, 'state'), 'parent.state'),
49
+ owner: stringOrNull(jsonField(repository['owner'], 'login')),
50
+ repo: stringOrNull(repository['name']),
51
+ };
52
+ }
53
+ /**
54
+ timelineItems からリンクされた PR を取り出す。
55
+ ConnectedEvent は subject、CrossReferencedEvent は source に PR がある。PR 番号で重複を除く
56
+ */
57
+ function extractLinkedPullRequests(timelineItems) {
58
+ const seen = new Set();
59
+ const pullRequests = [];
60
+ for (const node of truthyNodes(timelineItems)) {
61
+ const subject = jsonField(node, 'subject');
62
+ const pullRequest = isTruthy(subject) ? subject : jsonField(node, 'source');
63
+ if (!isTruthy(pullRequest))
64
+ continue;
65
+ const number = numberOrNull(jsonField(pullRequest, 'number'));
66
+ if (number === null || number === 0 || seen.has(number))
67
+ continue;
68
+ seen.add(number);
69
+ pullRequests.push({
70
+ number,
71
+ title: stringOrEmpty(jsonField(pullRequest, 'title')),
72
+ state: stringOrEmpty(jsonField(pullRequest, 'state')),
73
+ });
74
+ }
75
+ return pullRequests;
76
+ }
77
+ export class IssuesApi extends ProjectsApi {
78
+ async executeDependencyMutation(mutation, variables) {
79
+ try {
80
+ await this.executeGraphql(mutation, variables);
81
+ }
82
+ catch (error) {
83
+ throw asDependenciesError(error);
84
+ }
85
+ }
86
+ // issueType フィールド非対応の GHES 用の判定
87
+ async getIssueKindPhase1(owner, repository, number) {
88
+ const result = await this.executeGraphql(QUERY_GET_ISSUE_KIND_PHASE1, { owner, repo: repository, number });
89
+ const issue = issueNode(result, owner, repository, number);
90
+ return {
91
+ number: requireNumber(jsonField(issue, 'number'), 'issue.number'),
92
+ state: requireString(jsonField(issue, 'state'), 'issue.state'),
93
+ issue_type: JSON_NULL,
94
+ sub_issues_total: subIssuesTotal(issue),
95
+ };
96
+ }
97
+ /**
98
+ Issue を作る。labels が空なら送らない
99
+ */
100
+ async createIssue(owner, repository, title, body = '', labels) {
101
+ const data = {
102
+ title,
103
+ body,
104
+ ...(labels !== undefined && labels.length > 0 && { labels }),
105
+ };
106
+ return this.restObject('POST', `${repositoryPath(owner, repository)}/issues`, { json: data });
107
+ }
108
+ /**
109
+ Issue のコメントを書き換える。見つからなければ GitHubNotFoundError
110
+ */
111
+ async updateIssueComment(owner, repository, commentId, body) {
112
+ return this.restObject('PATCH', `${repositoryPath(owner, repository)}/issues/comments/${String(commentId)}`, { json: { body } });
113
+ }
114
+ /**
115
+ Issue にコメントを足す
116
+ */
117
+ async addIssueComment(owner, repository, number, body) {
118
+ return this.restObject('POST', `${repositoryPath(owner, repository)}/issues/${String(number)}/comments`, { json: { body } });
119
+ }
120
+ /**
121
+ Issue 番号から GraphQL Node ID を取る。見つからなければ GitHubNotFoundError
122
+ */
123
+ async getIssueNodeId(owner, repository, number) {
124
+ const issue = await this.getIssueNodeIdAndTitle(owner, repository, number);
125
+ return issue.id;
126
+ }
127
+ /**
128
+ Issue 番号から GraphQL Node ID とタイトルを、1 回のクエリで取る
129
+ */
130
+ async getIssueNodeIdAndTitle(owner, repository, number) {
131
+ const result = await this.executeGraphql(QUERY_GET_ISSUE_NODE_ID, { owner, repo: repository, number });
132
+ const issue = issueNode(result, owner, repository, number);
133
+ return {
134
+ id: requireString(jsonField(issue, 'id'), 'issue.id'),
135
+ title: stringOrEmpty(jsonField(issue, 'title')),
136
+ };
137
+ }
138
+ /**
139
+ サブ Issue を紐づける。紐づけ結果は親と子の Issue 番号
140
+ */
141
+ async addSubIssue(parentIssueId, childIssueId) {
142
+ const result = await this.executeGraphql(MUTATION_ADD_SUB_ISSUE, { parentId: parentIssueId, childId: childIssueId });
143
+ const linkResult = jsonField(result, 'addSubIssue');
144
+ const parent = jsonField(linkResult, 'issue');
145
+ const child = jsonField(linkResult, 'subIssue');
146
+ if (!isTruthy(parent) || !isTruthy(child))
147
+ throw new GitHubAPIError('failed to link the sub-issue');
148
+ return {
149
+ parent_number: requireNumber(jsonField(parent, 'number'), 'issue.number'),
150
+ child_number: requireNumber(jsonField(child, 'number'), 'subIssue.number'),
151
+ };
152
+ }
153
+ /**
154
+ 前提(blocked by)を付ける。issueId が待つ側、blockingIssueId が前提(どちらも node ID)。
155
+ GitHub の拒否(輪・件数の上限など)は HTTP 200 の VALIDATION で返り、GitHubAPIError になる。
156
+ Issue の依存関係に対応しない GHES(3.19 より前)も GitHubAPIError
157
+ */
158
+ async addBlockedBy(issueId, blockingIssueId) {
159
+ await this.executeDependencyMutation(MUTATION_ADD_BLOCKED_BY, { issueId, blockingIssueId });
160
+ }
161
+ /**
162
+ 前提(blocked by)を外す。addBlockedBy と同じ失敗をする
163
+ */
164
+ async removeBlockedBy(issueId, blockingIssueId) {
165
+ await this.executeDependencyMutation(MUTATION_REMOVE_BLOCKED_BY, { issueId, blockingIssueId });
166
+ }
167
+ /**
168
+ Issue と、その前提(blockedBy 先頭 50 件)を 1 回のクエリで読む。ボードの値は projectId のものだけ。
169
+ blockedBy の部分エラーと、件数の上限による取りこぼしは、例外にせず blockedBy の read-failed で返す(呼ぶ側は判定の入力にする)。
170
+ Issue の依存関係に対応しない GHES(3.19 より前)、blockedBy 以外の失敗は GitHubAPIError
171
+ */
172
+ async getIssuePrerequisites(owner, repository, number, projectId, fieldNames) {
173
+ const variables = { owner, repo: repository, number, columnFieldName: fieldNames.columnFieldName, labelFieldName: fieldNames.labelFieldName };
174
+ let outcome;
175
+ try {
176
+ outcome = await this.executeGraphqlTolerating(QUERY_GET_ISSUE_PREREQUISITES, variables, isBlockedByPath);
177
+ }
178
+ catch (error) {
179
+ throw asDependenciesError(error);
180
+ }
181
+ const { data, errors } = outcome;
182
+ const issue = issueNode(data, owner, repository, number);
183
+ const messages = errors.map(error => stringOrEmpty(jsonField(error, 'message')));
184
+ return {
185
+ issue: { ...readIssue(issue, projectId, fieldNames), body: requireString(jsonField(issue, 'body'), 'issue.body') },
186
+ blockedBy: readBlockedBy(issue, projectId, fieldNames, messages),
187
+ };
188
+ }
189
+ /**
190
+ Issue 種別を軽く取る。issueType フィールドに対応しない GHES では、subIssues だけで判定する
191
+ */
192
+ async getIssueKind(owner, repository, number) {
193
+ const variables = { owner, repo: repository, number };
194
+ let result;
195
+ try {
196
+ result = await this.executeGraphql(QUERY_GET_ISSUE_KIND, variables);
197
+ }
198
+ catch (error) {
199
+ if (isIssueTypeSchemaError(error)) {
200
+ return this.getIssueKindPhase1(owner, repository, number);
201
+ }
202
+ throw error;
203
+ }
204
+ const issue = issueNode(result, owner, repository, number);
205
+ return {
206
+ number: requireNumber(jsonField(issue, 'number'), 'issue.number'),
207
+ state: requireString(jsonField(issue, 'state'), 'issue.state'),
208
+ issue_type: stringOrNull(jsonField(jsonField(issue, 'issueType'), 'name')),
209
+ sub_issues_total: subIssuesTotal(issue),
210
+ };
211
+ }
212
+ /**
213
+ Issue の詳細を取る(GraphQL)。親・サブ Issue・リンクブランチ・リンク PR を 1 回のクエリで取る
214
+ */
215
+ async getIssueSlim(owner, repository, number, commentLimit = DEFAULT_COMMENT_LIMIT) {
216
+ const result = await this.executeGraphql(QUERY_GET_ISSUE_SLIM, { owner, repo: repository, number, commentLimit });
217
+ const issue = issueNode(result, owner, repository, number);
218
+ return {
219
+ number: requireNumber(jsonField(issue, 'number'), 'issue.number'),
220
+ state: requireString(jsonField(issue, 'state'), 'issue.state'),
221
+ title: requireString(jsonField(issue, 'title'), 'issue.title'),
222
+ body: requireString(jsonField(issue, 'body'), 'issue.body'),
223
+ comments: {
224
+ total_count: requireNumber(jsonField(jsonField(issue, 'comments'), 'totalCount'), 'issue.comments.totalCount'),
225
+ nodes: truthyNodes(jsonField(issue, 'comments')).map(comment => ({
226
+ author: isTruthy(jsonField(comment, 'author')) ? requireString(jsonField(jsonField(comment, 'author'), 'login'), 'comment.author.login') : 'ghost',
227
+ created_at: requireString(jsonField(comment, 'createdAt'), 'comment.createdAt'),
228
+ body: requireString(jsonField(comment, 'body'), 'comment.body'),
229
+ })),
230
+ },
231
+ parent: formatParent(jsonField(issue, 'parent')),
232
+ sub_issues: truthyNodes(jsonField(issue, 'subIssues')).map(sub => ({
233
+ number: requireNumber(jsonField(sub, 'number'), 'subIssue.number'),
234
+ state: requireString(jsonField(sub, 'state'), 'subIssue.state'),
235
+ title: requireString(jsonField(sub, 'title'), 'subIssue.title'),
236
+ })),
237
+ linked_branches: truthyNodes(jsonField(issue, 'linkedBranches'))
238
+ .filter(branch => isTruthy(jsonField(branch, 'ref')))
239
+ .map(branch => requireString(jsonField(jsonField(branch, 'ref'), 'name'), 'linkedBranch.ref.name')),
240
+ linked_prs: extractLinkedPullRequests(jsonField(issue, 'timelineItems')),
241
+ };
242
+ }
243
+ /**
244
+ Issue を閉じる。stateReason は completed か not_planned
245
+ */
246
+ async closeIssue(owner, repository, number, stateReason = 'completed') {
247
+ return this.restObject('PATCH', `${repositoryPath(owner, repository)}/issues/${String(number)}`, {
248
+ json: { state: 'closed', state_reason: stateReason },
249
+ });
250
+ }
251
+ /**
252
+ Issue を再オープンする
253
+ */
254
+ async reopenIssue(owner, repository, number) {
255
+ return this.restObject('PATCH', `${repositoryPath(owner, repository)}/issues/${String(number)}`, {
256
+ json: { state: 'open', state_reason: 'reopened' },
257
+ });
258
+ }
259
+ /**
260
+ ラベルの付いた Issue を open・closed の両方で全件取る(REST)。Pull Request は除く
261
+ */
262
+ async listIssuesByLabel(owner, repository, label) {
263
+ const items = await this.listAll(`${repositoryPath(owner, repository)}/issues`, { state: 'all', labels: label, per_page: ISSUES_PER_PAGE });
264
+ return items.filter(item => !(isJsonObject(item) && 'pull_request' in item));
265
+ }
266
+ /**
267
+ Issue の本文を丸ごと置き換える。本文が上限を超える 422 は GitHubAPIError
268
+ */
269
+ async updateIssueBody(owner, repository, number, body) {
270
+ return this.restObject('PATCH', `${repositoryPath(owner, repository)}/issues/${String(number)}`, { json: { body } });
271
+ }
272
+ }
273
+ //# sourceMappingURL=issues.js.map
@@ -0,0 +1,44 @@
1
+ import type { JsonObject } from '../../domain/json.js';
2
+ import type { JsonValue } from '../../domain/python-format.js';
3
+ /**
4
+ as_dict と同じ。オブジェクトでなければ空のオブジェクト
5
+ */
6
+ export declare function asObject(value: JsonValue | undefined): JsonObject;
7
+ /**
8
+ 配列でなければ空の配列
9
+ */
10
+ export declare function asArray(value: JsonValue | undefined): readonly JsonValue[];
11
+ /**
12
+ Python の真偽値と同じ。None・False・0・空文字・空の配列・空の辞書は偽
13
+ */
14
+ export declare function isTruthy(value: JsonValue | undefined): boolean;
15
+ /**
16
+ `value.get(key, [])` の `nodes` の読み方。真偽値が偽の要素(None・空の辞書)を落とした配列
17
+ */
18
+ export declare function truthyNodes(value: JsonValue | undefined): readonly JsonValue[];
19
+ export declare function throwMalformed(path: string): never;
20
+ /**
21
+ 必須の文字列。無い、または文字列でなければ GitHubAPIError
22
+ */
23
+ export declare function requireString(value: JsonValue | undefined, path: string): string;
24
+ /**
25
+ 必須の数。無い、または数でなければ GitHubAPIError
26
+ */
27
+ export declare function requireNumber(value: JsonValue | undefined, path: string): number;
28
+ /**
29
+ 文字列か null。無いときと文字列以外は null
30
+ */
31
+ export declare function stringOrNull(value: JsonValue | undefined): string | null;
32
+ /**
33
+ 数か null。無いときと数以外は null
34
+ */
35
+ export declare function numberOrNull(value: JsonValue | undefined): number | null;
36
+ /**
37
+ 必須の値(null でもよい)。キーが無ければ GitHubAPIError
38
+ */
39
+ export declare function requireValue(value: JsonValue | undefined, path: string): JsonValue;
40
+ /**
41
+ Issue の subIssues.totalCount。無いときは 0
42
+ */
43
+ export declare function subIssuesTotal(issue: JsonValue): number;
44
+ //# sourceMappingURL=payload.d.ts.map
@@ -0,0 +1,80 @@
1
+ // GitHub の応答(REST の JSON と GraphQL の data)を読む補助。
2
+ // Python の dict.get と as_dict に当たる。形が合わないときは、辞書や配列を空として読む。
3
+ // 必須の値が無い、または型が違うときは GitHubAPIError にする(Python は KeyError で落ちる所)。
4
+ import { isJsonObject, jsonField } from '../../domain/json.js';
5
+ import { JSON_NULL } from '../../domain/json-null.js';
6
+ import { isJsonArray } from '../../domain/python-format.js';
7
+ import { GitHubAPIError } from './errors.js';
8
+ const EMPTY_OBJECT = {};
9
+ const EMPTY_ARRAY = [];
10
+ /**
11
+ as_dict と同じ。オブジェクトでなければ空のオブジェクト
12
+ */
13
+ export function asObject(value) {
14
+ return isJsonObject(value) ? value : EMPTY_OBJECT;
15
+ }
16
+ /**
17
+ 配列でなければ空の配列
18
+ */
19
+ export function asArray(value) {
20
+ return isJsonArray(value) ? value : EMPTY_ARRAY;
21
+ }
22
+ /**
23
+ Python の真偽値と同じ。None・False・0・空文字・空の配列・空の辞書は偽
24
+ */
25
+ export function isTruthy(value) {
26
+ if (value === undefined || value === null || value === false || value === 0 || value === '')
27
+ return false;
28
+ if (isJsonArray(value))
29
+ return value.length > 0;
30
+ if (typeof value === 'object')
31
+ return Object.keys(value).length > 0;
32
+ return true;
33
+ }
34
+ /**
35
+ `value.get(key, [])` の `nodes` の読み方。真偽値が偽の要素(None・空の辞書)を落とした配列
36
+ */
37
+ export function truthyNodes(value) {
38
+ return asArray(jsonField(value, 'nodes')).filter(node => isTruthy(node));
39
+ }
40
+ export function throwMalformed(path) {
41
+ throw new GitHubAPIError(`malformed GitHub response: ${path}`);
42
+ }
43
+ /**
44
+ 必須の文字列。無い、または文字列でなければ GitHubAPIError
45
+ */
46
+ export function requireString(value, path) {
47
+ return typeof value === 'string' ? value : throwMalformed(path);
48
+ }
49
+ /**
50
+ 必須の数。無い、または数でなければ GitHubAPIError
51
+ */
52
+ export function requireNumber(value, path) {
53
+ return typeof value === 'number' ? value : throwMalformed(path);
54
+ }
55
+ /**
56
+ 文字列か null。無いときと文字列以外は null
57
+ */
58
+ export function stringOrNull(value) {
59
+ return typeof value === 'string' ? value : JSON_NULL;
60
+ }
61
+ /**
62
+ 数か null。無いときと数以外は null
63
+ */
64
+ export function numberOrNull(value) {
65
+ return typeof value === 'number' ? value : JSON_NULL;
66
+ }
67
+ /**
68
+ 必須の値(null でもよい)。キーが無ければ GitHubAPIError
69
+ */
70
+ export function requireValue(value, path) {
71
+ return value === undefined ? throwMalformed(path) : value;
72
+ }
73
+ /**
74
+ Issue の subIssues.totalCount。無いときは 0
75
+ */
76
+ export function subIssuesTotal(issue) {
77
+ const total = jsonField(jsonField(issue, 'subIssues'), 'totalCount');
78
+ return typeof total === 'number' ? total : 0;
79
+ }
80
+ //# sourceMappingURL=payload.js.map