@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,18 @@
1
+ import type { BlockedByReadout, IssueReadout, PrerequisiteFieldNames, PullRequestReadout } from '../../domain/issue-readout.js';
2
+ import type { JsonValue } from '../../domain/python-format.js';
3
+ /**
4
+ PR のノード 1 つ。`... on PullRequest` の型でない node は空で届くので、undefined を返す。
5
+ PR なのに number が無ければ GitHubAPIError
6
+ */
7
+ export declare function readPullRequest(node: JsonValue | undefined): PullRequestReadout | undefined;
8
+ export declare function readPullRequests(nodes: readonly (JsonValue | undefined)[]): readonly PullRequestReadout[];
9
+ export declare function readIssue(issue: JsonValue, projectId: string, fieldNames: Readonly<PrerequisiteFieldNames>): IssueReadout;
10
+ /**
11
+ 対象の Issue の blockedBy を読む。次のどれかなら read-failed(理由つき)。
12
+ 取りこぼしたまま前提なしと読むと、ブロック中の Issue を着手できると誤るため
13
+ - 部分エラー(errors)で blockedBy が読めなかった
14
+ - blockedBy が null、null の node がある、件数が totalCount に足りない
15
+ - 対象か前提の Issue の connection が、件数の上限で取りこぼされている
16
+ */
17
+ export declare function readBlockedBy(target: JsonValue, projectId: string, fieldNames: Readonly<PrerequisiteFieldNames>, errorMessages?: readonly string[]): BlockedByReadout;
18
+ //# sourceMappingURL=readout.d.ts.map
@@ -0,0 +1,156 @@
1
+ // 前提の読み取り(QUERY_GET_ISSUE_PREREQUISITES など)の応答を、domain/issue-readout.ts の形にする。
2
+ import { jsonField } from '../../domain/json.js';
3
+ import { JSON_NULL } from '../../domain/json-null.js';
4
+ import { GitHubAPIError } from './errors.js';
5
+ import { asArray, isTruthy, requireNumber, requireString, subIssuesTotal, truthyNodes } from './payload.js';
6
+ function readRepository(node, path) {
7
+ const repository = jsonField(node, 'repository');
8
+ return {
9
+ owner: requireString(jsonField(jsonField(repository, 'owner'), 'login'), `${path}.repository.owner.login`),
10
+ repository: requireString(jsonField(repository, 'name'), `${path}.repository.name`),
11
+ };
12
+ }
13
+ function readState(node, allowed, path) {
14
+ const state = requireString(jsonField(node, 'state'), `${path}.state`);
15
+ const matched = allowed.find(candidate => candidate === state);
16
+ if (matched === undefined)
17
+ throw new GitHubAPIError(`malformed GitHub response: ${path}.state (${state})`);
18
+ return matched;
19
+ }
20
+ /**
21
+ PR のノード 1 つ。`... on PullRequest` の型でない node は空で届くので、undefined を返す。
22
+ PR なのに number が無ければ GitHubAPIError
23
+ */
24
+ export function readPullRequest(node) {
25
+ if (!isTruthy(node))
26
+ return undefined;
27
+ const path = 'pullRequest';
28
+ return {
29
+ number: requireNumber(jsonField(node, 'number'), `${path}.number`),
30
+ repository: readRepository(node, path),
31
+ state: readState(node, ['OPEN', 'CLOSED', 'MERGED'], path),
32
+ headRefName: requireString(jsonField(node, 'headRefName'), `${path}.headRefName`),
33
+ baseRefName: requireString(jsonField(node, 'baseRefName'), `${path}.baseRefName`),
34
+ isDraft: jsonField(node, 'isDraft') === true,
35
+ isCrossRepository: jsonField(node, 'isCrossRepository') === true,
36
+ };
37
+ }
38
+ export function readPullRequests(nodes) {
39
+ return nodes.map(node => readPullRequest(node)).filter(pullRequest => pullRequest !== undefined);
40
+ }
41
+ function readLinkedBranches(issue) {
42
+ return truthyNodes(jsonField(issue, 'linkedBranches'))
43
+ .filter(branch => isTruthy(jsonField(branch, 'ref')))
44
+ .map((branch) => {
45
+ const reference = jsonField(branch, 'ref');
46
+ return {
47
+ name: requireString(jsonField(reference, 'name'), 'linkedBranch.ref.name'),
48
+ pullRequests: readPullRequests(truthyNodes(jsonField(reference, 'associatedPullRequests'))),
49
+ };
50
+ });
51
+ }
52
+ function readFieldValue(item, alias, fieldName) {
53
+ const value = jsonField(item, alias);
54
+ const fieldId = jsonField(jsonField(value, 'field'), 'id');
55
+ const optionId = jsonField(value, 'optionId');
56
+ const optionName = jsonField(value, 'name');
57
+ return typeof fieldId === 'string' && typeof optionId === 'string' && typeof optionName === 'string' ? { fieldId, fieldName, optionId, optionName } : undefined;
58
+ }
59
+ // 設定のプロジェクトのアイテムだけを見る。同じ Issue が載る別のボードの値は読まない
60
+ function readProjectFieldValues(issue, projectId, fieldNames) {
61
+ return truthyNodes(jsonField(issue, 'projectItems'))
62
+ .flatMap(item => jsonField(jsonField(item, 'project'), 'id') === projectId
63
+ ? [readFieldValue(item, 'column', fieldNames.columnFieldName), readFieldValue(item, 'label', fieldNames.labelFieldName)]
64
+ : [])
65
+ .filter(value => value !== undefined);
66
+ }
67
+ function pullRequestKey(pullRequest) {
68
+ return `${pullRequest.repository.owner}/${pullRequest.repository.repository}#${String(pullRequest.number)}`;
69
+ }
70
+ function applyTimelineEvent(entries, event, issueNumber) {
71
+ const type = jsonField(event, '__typename');
72
+ if (type === 'CrossReferencedEvent') {
73
+ const pullRequest = readPullRequest(jsonField(event, 'source'));
74
+ if (pullRequest === undefined)
75
+ return entries;
76
+ const isRelated = jsonField(event, 'willCloseTarget') === true || pullRequest.headRefName.endsWith(`/${String(issueNumber)}`);
77
+ return isRelated ? [...entries, { key: pullRequestKey(pullRequest), pullRequest, isConnection: false }] : entries;
78
+ }
79
+ if (type !== 'ConnectedEvent' && type !== 'DisconnectedEvent')
80
+ return entries;
81
+ const pullRequest = readPullRequest(jsonField(event, 'subject'));
82
+ if (pullRequest === undefined)
83
+ return entries;
84
+ const key = pullRequestKey(pullRequest);
85
+ return type === 'ConnectedEvent'
86
+ ? [...entries, { key, pullRequest, isConnection: true }]
87
+ : entries.filter(entry => !(entry.isConnection && entry.key === key));
88
+ }
89
+ // ConnectedEvent は、後で同じ PR の DisconnectedEvent が無いものだけ採る。
90
+ // CrossReferencedEvent は、本文やコメントで触れただけの PR を除くため、閉じる参照か head が `/<Issue 番号>` で終わるものだけ採る
91
+ function readTimelinePullRequests(issue, issueNumber) {
92
+ const events = truthyNodes(jsonField(issue, 'timelineItems'));
93
+ let entries = [];
94
+ for (const event of events)
95
+ entries = applyTimelineEvent(entries, event, issueNumber);
96
+ return entries.map(entry => entry.pullRequest);
97
+ }
98
+ export function readIssue(issue, projectId, fieldNames) {
99
+ const issueType = jsonField(jsonField(issue, 'issueType'), 'name');
100
+ const number = requireNumber(jsonField(issue, 'number'), 'issue.number');
101
+ return {
102
+ id: requireString(jsonField(issue, 'id'), 'issue.id'),
103
+ repository: readRepository(issue, 'issue'),
104
+ number,
105
+ state: readState(issue, ['OPEN', 'CLOSED'], 'issue'),
106
+ title: requireString(jsonField(issue, 'title'), 'issue.title'),
107
+ issueType: typeof issueType === 'string' ? issueType : JSON_NULL,
108
+ subIssuesTotal: subIssuesTotal(issue),
109
+ projectFieldValues: readProjectFieldValues(issue, projectId, fieldNames),
110
+ linkedBranches: readLinkedBranches(issue),
111
+ closingPullRequests: readPullRequests(truthyNodes(jsonField(issue, 'closedByPullRequestsReferences'))),
112
+ timelinePullRequests: readTimelinePullRequests(issue, number),
113
+ };
114
+ }
115
+ // 件数が totalCount に足りない connection の説明。足りていれば undefined
116
+ function shortfall(connection, name, where) {
117
+ const total = jsonField(connection, 'totalCount');
118
+ const returned = asArray(jsonField(connection, 'nodes')).length;
119
+ return typeof total === 'number' && returned < total ? `${name} of ${where} returned ${String(returned)} of ${String(total)}` : undefined;
120
+ }
121
+ // 件数の上限で取りこぼした connection の説明。取りこぼしたまま判定すると、済んだ前提を未完と誤るため
122
+ function connectionShortfalls(issue) {
123
+ const { owner: login, repository } = readRepository(issue, 'issue');
124
+ const where = `${login}/${repository}#${String(requireNumber(jsonField(issue, 'number'), 'issue.number'))}`;
125
+ const linkedBranches = jsonField(issue, 'linkedBranches');
126
+ return [
127
+ shortfall(jsonField(issue, 'projectItems'), 'projectItems', where),
128
+ shortfall(linkedBranches, 'linkedBranches', where),
129
+ ...truthyNodes(linkedBranches).map(branch => shortfall(jsonField(jsonField(branch, 'ref'), 'associatedPullRequests'), 'associatedPullRequests', where)),
130
+ shortfall(jsonField(issue, 'closedByPullRequestsReferences'), 'closedByPullRequestsReferences', where),
131
+ shortfall(jsonField(issue, 'timelineItems'), 'timelineItems', where),
132
+ ].filter(reason => reason !== undefined);
133
+ }
134
+ /**
135
+ 対象の Issue の blockedBy を読む。次のどれかなら read-failed(理由つき)。
136
+ 取りこぼしたまま前提なしと読むと、ブロック中の Issue を着手できると誤るため
137
+ - 部分エラー(errors)で blockedBy が読めなかった
138
+ - blockedBy が null、null の node がある、件数が totalCount に足りない
139
+ - 対象か前提の Issue の connection が、件数の上限で取りこぼされている
140
+ */
141
+ export function readBlockedBy(target, projectId, fieldNames, errorMessages = []) {
142
+ if (errorMessages.length > 0)
143
+ return { kind: 'read-failed', reason: `blockedBy could not be read: ${errorMessages.join('; ')}` };
144
+ const blockedBy = jsonField(target, 'blockedBy');
145
+ if (!isTruthy(blockedBy))
146
+ return { kind: 'read-failed', reason: 'blockedBy is null' };
147
+ const total = requireNumber(jsonField(blockedBy, 'totalCount'), 'issue.blockedBy.totalCount');
148
+ const nodes = asArray(jsonField(blockedBy, 'nodes'));
149
+ if (nodes.some(node => !isTruthy(node)))
150
+ return { kind: 'read-failed', reason: 'blockedBy has a null node' };
151
+ if (nodes.length < total)
152
+ return { kind: 'read-failed', reason: `blockedBy returned ${String(nodes.length)} of ${String(total)} issues` };
153
+ const [gap] = [target, ...nodes].flatMap(issue => connectionShortfalls(issue));
154
+ return gap === undefined ? { kind: 'ok', issues: nodes.map(node => readIssue(node, projectId, fieldNames)) } : { kind: 'read-failed', reason: gap };
155
+ }
156
+ //# sourceMappingURL=readout.js.map
@@ -0,0 +1,68 @@
1
+ import type { JsonObject } from '../../domain/json.js';
2
+ import type { JsonValue } from '../../domain/python-format.js';
3
+ import { GitHubClientBase } from './client.js';
4
+ export interface CreateReleaseOptions {
5
+ /**
6
+ タグのターゲット。既定は main
7
+ */
8
+ readonly targetCommitish?: string | undefined;
9
+ readonly draft?: boolean | undefined;
10
+ readonly prerelease?: boolean | undefined;
11
+ }
12
+ export declare class ReposApi extends GitHubClientBase {
13
+ /**
14
+ Link ヘッダの next を最後まで辿る。2 ページ目以降は next の絶対 URL を使い、params を再送すると cursor と二重になる
15
+ */
16
+ protected listAll(path: string, firstParameters: Readonly<Record<string, number | string>>): Promise<readonly JsonValue[]>;
17
+ /**
18
+ リポジトリの GraphQL Node ID。見つからなければ GitHubNotFoundError
19
+ */
20
+ getRepositoryId(owner: string, name: string): Promise<string>;
21
+ /**
22
+ ブランチの最新 commit の SHA(REST)。見つからなければ GitHubNotFoundError
23
+ */
24
+ getBranchSha(owner: string, repository: string, branch: string): Promise<string>;
25
+ /**
26
+ Issue に紐づいたブランチを作り、その名前を返す(gh issue develop と同等)。
27
+ repositoryId を省くと、Issue と同じリポジトリになる
28
+ */
29
+ createLinkedBranch(issueId: string, oid: string, name: string, repositoryId?: string): Promise<string>;
30
+ /**
31
+ ブランチを削除する。保護されたブランチなどは GitHubAPIError
32
+ */
33
+ deleteBranch(owner: string, repository: string, branch: string): Promise<void>;
34
+ /**
35
+ GitHub のリリースを作る。target_commitish を指定するので、タグも自動で作られる
36
+ */
37
+ createRelease(owner: string, repository: string, tagName: string, name: string, body: string, options?: Readonly<CreateReleaseOptions>): Promise<JsonObject>;
38
+ /**
39
+ リポジトリの既定ブランチ名
40
+ */
41
+ getRepositoryDefaultBranch(owner: string, repository: string): Promise<string>;
42
+ /**
43
+ open な Dependabot alert を全件取得する(REST)。
44
+ alerts が無効(403)などで取得できなければ GitHubAPIError
45
+ */
46
+ listOpenDependabotAlerts(owner: string, repository: string): Promise<readonly JsonValue[]>;
47
+ /**
48
+ open な code scanning alert を全件取得する(REST)。ref は付けず、既定ブランチが対象になる。
49
+ GHAS が無い(403)・解析が無い(404)などで取得できなければ GitHubAPIError
50
+ */
51
+ listOpenCodeScanningAlerts(owner: string, repository: string): Promise<readonly JsonValue[]>;
52
+ /**
53
+ open な secret scanning alert を全件取得する(REST)。secret の値が応答に載らないよう、hide_secret を必ず付ける。
54
+ secret scanning が無効(404)などで取得できなければ GitHubAPIError
55
+ */
56
+ listOpenSecretScanningAlerts(owner: string, repository: string): Promise<readonly JsonValue[]>;
57
+ /**
58
+ リポジトリの secret scanning の状態(enabled・disabled)。
59
+ security_and_analysis は admin 権限が無いと応答に載らない。載っていなければ undefined
60
+ */
61
+ getSecretScanningStatus(owner: string, repository: string): Promise<string | undefined>;
62
+ /**
63
+ リポジトリで Dependabot alerts が有効かを返す(REST)。
64
+ vulnerability-alerts は有効で 204、無効で 404 を返す。それ以外の応答は GitHubAPIError
65
+ */
66
+ isDependabotAlertsEnabled(owner: string, repository: string): Promise<boolean>;
67
+ }
68
+ //# sourceMappingURL=repos.d.ts.map
@@ -0,0 +1,137 @@
1
+ // リポジトリ・ブランチ・リリース操作の API。cli/core/github/repos.py の移植。
2
+ import { jsonField } from '../../domain/json.js';
3
+ import { GitHubClientBase } from './client.js';
4
+ import { GitHubAPIError, GitHubNotFoundError } from './errors.js';
5
+ import { asArray, isTruthy, requireString } from './payload.js';
6
+ import { MUTATION_CREATE_LINKED_BRANCH, QUERY_GET_REPOSITORY_ID } from './queries.js';
7
+ import { encodePath, repositoryPath } from './rest-path.js';
8
+ const ALERTS_PER_PAGE = 100;
9
+ const NO_CONTENT = 204;
10
+ const NOT_FOUND = 404;
11
+ export class ReposApi extends GitHubClientBase {
12
+ /**
13
+ Link ヘッダの next を最後まで辿る。2 ページ目以降は next の絶対 URL を使い、params を再送すると cursor と二重になる
14
+ */
15
+ async listAll(path, firstParameters) {
16
+ const items = [];
17
+ let target = path;
18
+ let parameters = firstParameters;
19
+ for (;;) {
20
+ const response = await this.restRequest('GET', target, { params: parameters });
21
+ if (!response.isSuccess)
22
+ this.handleHttpError(response);
23
+ items.push(...asArray(response.json()));
24
+ const next = response.links.get('next');
25
+ if (next === undefined)
26
+ return items;
27
+ target = next.url;
28
+ parameters = undefined;
29
+ }
30
+ }
31
+ /**
32
+ リポジトリの GraphQL Node ID。見つからなければ GitHubNotFoundError
33
+ */
34
+ async getRepositoryId(owner, name) {
35
+ const result = await this.executeGraphql(QUERY_GET_REPOSITORY_ID, { owner, name });
36
+ const repository = jsonField(result, 'repository');
37
+ if (!isTruthy(repository))
38
+ throw new GitHubNotFoundError(`repository not found: ${owner}/${name}`);
39
+ return requireString(jsonField(repository, 'id'), 'repository.id');
40
+ }
41
+ /**
42
+ ブランチの最新 commit の SHA(REST)。見つからなければ GitHubNotFoundError
43
+ */
44
+ async getBranchSha(owner, repository, branch) {
45
+ const reference = jsonField(await this.restJson('GET', `${repositoryPath(owner, repository)}/git/ref/heads/${encodePath(branch)}`), 'object');
46
+ return requireString(jsonField(reference, 'sha'), 'object.sha');
47
+ }
48
+ /**
49
+ Issue に紐づいたブランチを作り、その名前を返す(gh issue develop と同等)。
50
+ repositoryId を省くと、Issue と同じリポジトリになる
51
+ */
52
+ async createLinkedBranch(issueId, oid, name, repositoryId) {
53
+ const input = {
54
+ issueId,
55
+ oid,
56
+ name,
57
+ ...(repositoryId !== undefined && repositoryId !== '' && { repositoryId }),
58
+ };
59
+ const result = await this.executeGraphql(MUTATION_CREATE_LINKED_BRANCH, { input });
60
+ const linkedBranch = jsonField(jsonField(result, 'createLinkedBranch'), 'linkedBranch');
61
+ if (!isTruthy(linkedBranch))
62
+ throw new GitHubAPIError('failed to create the linked branch');
63
+ return requireString(jsonField(jsonField(linkedBranch, 'ref'), 'name'), 'linkedBranch.ref.name');
64
+ }
65
+ /**
66
+ ブランチを削除する。保護されたブランチなどは GitHubAPIError
67
+ */
68
+ async deleteBranch(owner, repository, branch) {
69
+ const response = await this.restRequest('DELETE', `${repositoryPath(owner, repository)}/git/refs/heads/${encodePath(branch)}`);
70
+ if (!response.isSuccess)
71
+ this.handleHttpError(response);
72
+ }
73
+ /**
74
+ GitHub のリリースを作る。target_commitish を指定するので、タグも自動で作られる
75
+ */
76
+ async createRelease(owner, repository, tagName, name, body, options = {}) {
77
+ const data = {
78
+ tag_name: tagName,
79
+ name,
80
+ body,
81
+ target_commitish: options.targetCommitish ?? 'main',
82
+ draft: options.draft ?? false,
83
+ prerelease: options.prerelease ?? false,
84
+ };
85
+ return this.restObject('POST', `${repositoryPath(owner, repository)}/releases`, { json: data });
86
+ }
87
+ /**
88
+ リポジトリの既定ブランチ名
89
+ */
90
+ async getRepositoryDefaultBranch(owner, repository) {
91
+ const repositoryInfo = await this.restJson('GET', repositoryPath(owner, repository));
92
+ return requireString(jsonField(repositoryInfo, 'default_branch'), 'default_branch');
93
+ }
94
+ /**
95
+ open な Dependabot alert を全件取得する(REST)。
96
+ alerts が無効(403)などで取得できなければ GitHubAPIError
97
+ */
98
+ async listOpenDependabotAlerts(owner, repository) {
99
+ return this.listAll(`${repositoryPath(owner, repository)}/dependabot/alerts`, { state: 'open', per_page: ALERTS_PER_PAGE });
100
+ }
101
+ /**
102
+ open な code scanning alert を全件取得する(REST)。ref は付けず、既定ブランチが対象になる。
103
+ GHAS が無い(403)・解析が無い(404)などで取得できなければ GitHubAPIError
104
+ */
105
+ async listOpenCodeScanningAlerts(owner, repository) {
106
+ return this.listAll(`${repositoryPath(owner, repository)}/code-scanning/alerts`, { state: 'open', per_page: ALERTS_PER_PAGE });
107
+ }
108
+ /**
109
+ open な secret scanning alert を全件取得する(REST)。secret の値が応答に載らないよう、hide_secret を必ず付ける。
110
+ secret scanning が無効(404)などで取得できなければ GitHubAPIError
111
+ */
112
+ async listOpenSecretScanningAlerts(owner, repository) {
113
+ return this.listAll(`${repositoryPath(owner, repository)}/secret-scanning/alerts`, { state: 'open', hide_secret: 'true', per_page: ALERTS_PER_PAGE });
114
+ }
115
+ /**
116
+ リポジトリの secret scanning の状態(enabled・disabled)。
117
+ security_and_analysis は admin 権限が無いと応答に載らない。載っていなければ undefined
118
+ */
119
+ async getSecretScanningStatus(owner, repository) {
120
+ const analysis = jsonField(await this.restJson('GET', repositoryPath(owner, repository)), 'security_and_analysis');
121
+ const status = jsonField(jsonField(analysis, 'secret_scanning'), 'status');
122
+ return typeof status === 'string' ? status : undefined;
123
+ }
124
+ /**
125
+ リポジトリで Dependabot alerts が有効かを返す(REST)。
126
+ vulnerability-alerts は有効で 204、無効で 404 を返す。それ以外の応答は GitHubAPIError
127
+ */
128
+ async isDependabotAlertsEnabled(owner, repository) {
129
+ const response = await this.restRequest('GET', `${repositoryPath(owner, repository)}/vulnerability-alerts`);
130
+ if (response.statusCode === NO_CONTENT)
131
+ return true;
132
+ if (response.statusCode === NOT_FOUND)
133
+ return false;
134
+ return this.handleHttpError(response);
135
+ }
136
+ }
137
+ //# sourceMappingURL=repos.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ パスの 1 セグメントを符号化する。encodeURIComponent が残す `!'()*` も符号化する。
3
+ `.` と `..` は GitHubAPIError
4
+ */
5
+ export declare function encodePathSegment(segment: string): string;
6
+ /**
7
+ `/repos/<owner>/<repository>`
8
+ */
9
+ export declare function repositoryPath(owner: string, repository: string): string;
10
+ /**
11
+ スラッシュ区切りのパス(ブランチ名など)を、セグメントごとに符号化する。スラッシュは残す
12
+ */
13
+ export declare function encodePath(path: string): string;
14
+ //# sourceMappingURL=rest-path.d.ts.map
@@ -0,0 +1,31 @@
1
+ // REST の URL に連結するパスの符号化。owner・リポジトリ名・ブランチ名は、セグメントごとに符号化する。
2
+ // `.` と `..` のセグメントは、`%2E` で書いても URL の解釈でパスを辿る意味になる。
3
+ // だから送らず、GitHubAPIError で止める。
4
+ import { GitHubAPIError } from './errors.js';
5
+ import { splitCodePoints } from '../../domain/python-format.js';
6
+ // encodeURIComponent が符号化しない記号のうち、httpx が符号化するもの
7
+ const EXTRA_RESERVED = new Map([['!', '%21'], ['\'', '%27'], ['(', '%28'], [')', '%29'], ['*', '%2A']]);
8
+ /**
9
+ パスの 1 セグメントを符号化する。encodeURIComponent が残す `!'()*` も符号化する。
10
+ `.` と `..` は GitHubAPIError
11
+ */
12
+ export function encodePathSegment(segment) {
13
+ if (segment === '.' || segment === '..')
14
+ throw new GitHubAPIError(`name not usable in a URL path: ${segment}`);
15
+ return splitCodePoints(encodeURIComponent(segment))
16
+ .map(character => EXTRA_RESERVED.get(character) ?? character)
17
+ .join('');
18
+ }
19
+ /**
20
+ `/repos/<owner>/<repository>`
21
+ */
22
+ export function repositoryPath(owner, repository) {
23
+ return `/repos/${encodePathSegment(owner)}/${encodePathSegment(repository)}`;
24
+ }
25
+ /**
26
+ スラッシュ区切りのパス(ブランチ名など)を、セグメントごとに符号化する。スラッシュは残す
27
+ */
28
+ export function encodePath(path) {
29
+ return path.split('/').map(segment => encodePathSegment(segment)).join('/');
30
+ }
31
+ //# sourceMappingURL=rest-path.js.map
@@ -0,0 +1,15 @@
1
+ import type { JsonValue } from '../../domain/python-format.js';
2
+ import type { ScanAlertSource } from '../../domain/security-alerts-source.js';
3
+ /**
4
+ 取得に使うクライアントの操作。ReposApi(GitHubClient)が満たす
5
+ */
6
+ export interface ScanAlertClient {
7
+ readonly listOpenCodeScanningAlerts: (owner: string, repository: string) => Promise<readonly JsonValue[]>;
8
+ readonly listOpenSecretScanningAlerts: (owner: string, repository: string) => Promise<readonly JsonValue[]>;
9
+ readonly getSecretScanningStatus: (owner: string, repository: string) => Promise<string | undefined>;
10
+ }
11
+ /**
12
+ GitHub のクライアントから ScanAlertSource を作る
13
+ */
14
+ export declare function createScanAlertSource(client: ScanAlertClient): ScanAlertSource;
15
+ //# sourceMappingURL=security-alerts-source.d.ts.map
@@ -0,0 +1,73 @@
1
+ // code scanning と secret scanning の alert の取得元を、GitHub の REST で満たす実体。型は domain/security-alerts-source.ts の ScanAlertSource。
2
+ // 例外を結果の種類(kind)に直す。「無効」「解析なし」「権限不足」は、応答の状態コードと本文から見分ける。
3
+ import { isJsonObject, tryParseJsonText } from '../../domain/json.js';
4
+ import { TransportFailure } from './client.js';
5
+ import { describeApiError } from '../../domain/api-error-detail.js';
6
+ import { GitHubAPIError, GitHubRateLimitError } from './errors.js';
7
+ const FORBIDDEN = 403;
8
+ const NOT_FOUND = 404;
9
+ function bodyMessage(error) {
10
+ const body = tryParseJsonText(error.responseBody ?? '');
11
+ const message = isJsonObject(body) ? body['message'] : undefined;
12
+ return typeof message === 'string' ? message.toLowerCase() : '';
13
+ }
14
+ /**
15
+ 403 の本文が Advanced Security・code scanning の未有効を示すときだけ無効とみなす。権限不足は含めない
16
+ */
17
+ function isCodeScanningDisabled(error) {
18
+ if (error.statusCode !== FORBIDDEN || error instanceof GitHubRateLimitError)
19
+ return false;
20
+ const message = bodyMessage(error);
21
+ return message.includes('advanced security') || message.includes('not enabled');
22
+ }
23
+ /**
24
+ 解析がまだ無いリポの 404(有効だが alert は 0 件)か
25
+ */
26
+ function isNoAnalysis(error) {
27
+ return error.statusCode === NOT_FOUND && bodyMessage(error).includes('no analysis found');
28
+ }
29
+ async function listCodeScanning(client, owner, repository) {
30
+ try {
31
+ return { kind: 'ok', alerts: await client.listOpenCodeScanningAlerts(owner, repository) };
32
+ }
33
+ catch (error) {
34
+ if (!(error instanceof GitHubAPIError))
35
+ throw error;
36
+ if (isCodeScanningDisabled(error))
37
+ return { kind: 'disabled' };
38
+ if (isNoAnalysis(error))
39
+ return { kind: 'ok', alerts: [] };
40
+ throw error;
41
+ }
42
+ }
43
+ // 404 は「無効」だけでなく、権限不足(admin でない)でも起きる。無効と確かめられたときだけ無効にする
44
+ async function listSecretScanning(client, owner, repository) {
45
+ try {
46
+ return { kind: 'ok', alerts: await client.listOpenSecretScanningAlerts(owner, repository) };
47
+ }
48
+ catch (error) {
49
+ if (!(error instanceof GitHubAPIError) || error.statusCode !== NOT_FOUND)
50
+ throw error;
51
+ return (await client.getSecretScanningStatus(owner, repository)) === 'disabled' ? { kind: 'disabled' } : { kind: 'unconfirmed' };
52
+ }
53
+ }
54
+ /**
55
+ GitHub のクライアントから ScanAlertSource を作る
56
+ */
57
+ export function createScanAlertSource(client) {
58
+ return {
59
+ listOpenAlerts: async (kind, owner, repository) => {
60
+ try {
61
+ return kind === 'code-scanning' ? await listCodeScanning(client, owner, repository) : await listSecretScanning(client, owner, repository);
62
+ }
63
+ catch (error) {
64
+ if (error instanceof GitHubAPIError)
65
+ return { kind: 'failure', message: describeApiError(error) };
66
+ if (error instanceof TransportFailure)
67
+ return { kind: 'network', message: error.message };
68
+ throw error;
69
+ }
70
+ },
71
+ };
72
+ }
73
+ //# sourceMappingURL=security-alerts-source.js.map
@@ -0,0 +1,36 @@
1
+ import { InvalidValueError } from '../domain/errors.js';
2
+ /**
3
+ パターンが不正(Python の GitIgnorePatternError に当たる)
4
+ */
5
+ export declare class GitIgnorePatternError extends InvalidValueError {
6
+ }
7
+ export interface PatternRegex {
8
+ /**
9
+ JS の正規表現の source(`u` フラグで使う)
10
+ */
11
+ readonly source: string;
12
+ /**
13
+ マッチしたパスを除外するなら true、否定パターンなら false
14
+ */
15
+ readonly include: boolean;
16
+ }
17
+ /**
18
+ パターン 1 行を正規表現にする。何にも当たらないパターン(空行・コメント・`/` 単体・範囲の記法が不正)は undefined。
19
+ 感嘆符だけのパターンと、末尾が `\` のパターンは GitIgnorePatternError
20
+ */
21
+ export declare function patternToRegex(line: string): PatternRegex | undefined;
22
+ export interface GitIgnoreSpec {
23
+ /**
24
+ 何かに当たりうるパターンの数。0 なら、どのパスにも当たらない
25
+ */
26
+ readonly matchablePatternCount: number;
27
+ /**
28
+ パスが除外対象か。先頭の `/`・`./` は落として判定する
29
+ */
30
+ readonly matchFile: (file: string) => boolean;
31
+ }
32
+ /**
33
+ パターンの行からコンパイルする。空の行は読み飛ばす(空白だけの行は、何にも当たらないパターンとして数える)
34
+ */
35
+ export declare function compileGitIgnoreSpec(lines: readonly string[]): GitIgnoreSpec;
36
+ //# sourceMappingURL=gitignore-spec.d.ts.map