repometry 0.0.0-dev.0 → 0.1.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 (281) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -1
  3. package/package.json +48 -7
  4. package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
  5. package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
  6. package/target/main/resources/report/json/config-v1.schema.json +34 -0
  7. package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
  8. package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
  9. package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
  10. package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
  11. package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
  12. package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
  13. package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
  14. package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
  15. package/target/main/resources/report/json/report-v1.schema.json +65 -0
  16. package/target/main/resources/report/json/report-v2.schema.json +238 -0
  17. package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
  18. package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
  19. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
  20. package/target/main/resources/viewer/files.css +578 -0
  21. package/target/main/resources/viewer/index.html +130 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +586 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
  26. package/target/main/ts/api/gh/github-pr-comment.js +107 -0
  27. package/target/main/ts/api/gh/github.d.ts +6 -0
  28. package/target/main/ts/api/gh/github.js +91 -0
  29. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  30. package/target/main/ts/api/git/blob-batch.js +105 -0
  31. package/target/main/ts/api/git/changes.d.ts +22 -0
  32. package/target/main/ts/api/git/changes.js +107 -0
  33. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  34. package/target/main/ts/api/git/commit-metadata.js +54 -0
  35. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  36. package/target/main/ts/api/git/git-churn.js +70 -0
  37. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  38. package/target/main/ts/api/git/git-reader.js +73 -0
  39. package/target/main/ts/api/git/git.d.ts +21 -0
  40. package/target/main/ts/api/git/git.js +152 -0
  41. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  42. package/target/main/ts/api/git/inspection-source.js +30 -0
  43. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  44. package/target/main/ts/api/git/local-sources.js +46 -0
  45. package/target/main/ts/api/git/local.d.ts +3 -0
  46. package/target/main/ts/api/git/local.js +35 -0
  47. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  48. package/target/main/ts/api/git/metabranch-worktree.js +34 -0
  49. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  50. package/target/main/ts/api/git/source-cache.js +56 -0
  51. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  52. package/target/main/ts/api/import/finding-import.js +226 -0
  53. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  54. package/target/main/ts/api/import/lcov-files.js +13 -0
  55. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  56. package/target/main/ts/api/import/profile-file.js +16 -0
  57. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  58. package/target/main/ts/api/worker/remote-executor.js +45 -0
  59. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  60. package/target/main/ts/api/worker/worker-protocol.js +101 -0
  61. package/target/main/ts/api/worker/worker.d.ts +5 -0
  62. package/target/main/ts/api/worker/worker.js +85 -0
  63. package/target/main/ts/cli/arguments.d.ts +28 -0
  64. package/target/main/ts/cli/arguments.js +110 -0
  65. package/target/main/ts/cli/config.d.ts +14 -0
  66. package/target/main/ts/cli/config.js +60 -0
  67. package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
  68. package/target/main/ts/cli/github-pr-comment.js +12 -0
  69. package/target/main/ts/cli/imports.d.ts +7 -0
  70. package/target/main/ts/cli/imports.js +29 -0
  71. package/target/main/ts/cli/main.d.ts +2 -0
  72. package/target/main/ts/cli/main.js +343 -284
  73. package/target/main/ts/cli/reporting.d.ts +18 -0
  74. package/target/main/ts/cli/reporting.js +108 -0
  75. package/target/main/ts/cli/revisions.d.ts +6 -0
  76. package/target/main/ts/cli/revisions.js +15 -0
  77. package/target/main/ts/cli/store.d.ts +13 -0
  78. package/target/main/ts/cli/store.js +38 -0
  79. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  80. package/target/main/ts/compose/analyze-snapshot.js +163 -0
  81. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  82. package/target/main/ts/compose/attach-churn.js +37 -0
  83. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  84. package/target/main/ts/compose/diff-coverage.js +56 -0
  85. package/target/main/ts/compose/inspect.d.ts +23 -0
  86. package/target/main/ts/compose/inspect.js +44 -0
  87. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  88. package/target/main/ts/compose/plugin-list.js +9 -0
  89. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  90. package/target/main/ts/compose/prepare-metabranch.js +16 -0
  91. package/target/main/ts/compose/review.d.ts +16 -0
  92. package/target/main/ts/compose/review.js +38 -0
  93. package/target/main/ts/compose/sources.d.ts +3 -0
  94. package/target/main/ts/compose/sources.js +29 -0
  95. package/target/main/ts/core/engine/execute.d.ts +10 -0
  96. package/target/main/ts/core/engine/execute.js +49 -0
  97. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  98. package/target/main/ts/core/engine/manifest.js +104 -0
  99. package/target/main/ts/core/engine/plan.d.ts +22 -0
  100. package/target/main/ts/core/engine/plan.js +106 -0
  101. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  102. package/target/main/ts/core/engine/plugin.js +4 -0
  103. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  104. package/target/main/ts/core/engine/report-products.js +85 -0
  105. package/target/main/ts/core/model/changes.d.ts +8 -0
  106. package/target/main/ts/core/model/changes.js +1 -0
  107. package/target/main/ts/core/model/churn.d.ts +11 -0
  108. package/target/main/ts/core/model/churn.js +5 -0
  109. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  110. package/target/main/ts/core/model/clone-source.js +14 -0
  111. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  112. package/target/main/ts/core/model/code-structure.js +31 -0
  113. package/target/main/ts/core/model/comparison.d.ts +24 -0
  114. package/target/main/ts/core/model/comparison.js +1 -0
  115. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  116. package/target/main/ts/core/model/diff-coverage.js +1 -0
  117. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  118. package/target/main/ts/core/model/finding-ignore.js +35 -0
  119. package/target/main/ts/core/model/finding.d.ts +28 -0
  120. package/target/main/ts/core/model/finding.js +29 -0
  121. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  122. package/target/main/ts/core/model/ignore-rule.js +1 -0
  123. package/target/main/ts/core/model/measurement.d.ts +27 -0
  124. package/target/main/ts/core/model/measurement.js +24 -0
  125. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  126. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  127. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  128. package/target/main/ts/core/model/plugin-data.js +1 -0
  129. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  130. package/target/main/ts/core/model/pull-review.js +1 -0
  131. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  132. package/target/main/ts/core/model/quality-summary.js +64 -0
  133. package/target/main/ts/core/model/report.d.ts +32 -0
  134. package/target/main/ts/core/model/report.js +5 -0
  135. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  136. package/target/main/ts/core/model/scanner-import.js +28 -0
  137. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  138. package/target/main/ts/core/model/snapshot.js +50 -0
  139. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  140. package/target/main/ts/core/model/source-locator.js +1 -0
  141. package/target/main/ts/core/model/source.d.ts +23 -0
  142. package/target/main/ts/core/model/source.js +1 -0
  143. package/target/main/ts/core/ports/report.d.ts +9 -0
  144. package/target/main/ts/core/ports/report.js +1 -0
  145. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  146. package/target/main/ts/core/ports/source-provider.js +4 -0
  147. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  148. package/target/main/ts/core/profile/exclusions.js +57 -0
  149. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  150. package/target/main/ts/core/profile/maintainability.js +9 -0
  151. package/target/main/ts/core/profile/profile.d.ts +4 -0
  152. package/target/main/ts/core/profile/profile.js +10 -0
  153. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  154. package/target/main/ts/core/usecases/compare.js +145 -0
  155. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  156. package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
  157. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  158. package/target/main/ts/core/usecases/diff-coverage.js +15 -0
  159. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  160. package/target/main/ts/core/usecases/inspect.js +41 -0
  161. package/target/main/ts/core/usecases/review.d.ts +31 -0
  162. package/target/main/ts/core/usecases/review.js +128 -0
  163. package/target/main/ts/index.d.ts +35 -0
  164. package/target/main/ts/index.js +17 -13
  165. package/target/main/ts/plugin.d.ts +14 -0
  166. package/target/main/ts/plugin.js +5 -0
  167. package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
  168. package/target/main/ts/plugins/coverage/coverage.js +120 -0
  169. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  170. package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
  171. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  172. package/target/main/ts/plugins/duplication/duplication.js +93 -0
  173. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  174. package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
  175. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  176. package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
  177. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  178. package/target/main/ts/plugins/language-js/code-lines.js +35 -0
  179. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  180. package/target/main/ts/plugins/language-js/function-facts.js +60 -0
  181. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  182. package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
  183. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  184. package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
  185. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  186. package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
  187. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  188. package/target/main/ts/plugins/source/forges.js +79 -0
  189. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  190. package/target/main/ts/plugins/structure/structure.js +37 -0
  191. package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
  192. package/target/main/ts/report/html/app/viewer-access.js +25 -0
  193. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  194. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  195. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  196. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  197. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  198. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  199. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  200. package/target/main/ts/report/html/app/viewer-files.js +2087 -0
  201. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  202. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  203. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
  204. package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
  205. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  206. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  207. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  208. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  209. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  210. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  211. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  212. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  213. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  214. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  215. package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
  216. package/target/main/ts/report/html/app/viewer-trends.js +413 -0
  217. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  218. package/target/main/ts/report/html/app/viewer.js +794 -0
  219. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  220. package/target/main/ts/report/html/site/badges.js +39 -0
  221. package/target/main/ts/report/html/site/export-site.d.ts +21 -0
  222. package/target/main/ts/report/html/site/export-site.js +157 -0
  223. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  224. package/target/main/ts/report/html/site/exported-server.js +70 -0
  225. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  226. package/target/main/ts/report/html/site/local-server.js +64 -0
  227. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  228. package/target/main/ts/report/html/site/projects.js +79 -0
  229. package/target/main/ts/report/html/site/server.d.ts +4 -0
  230. package/target/main/ts/report/html/site/server.js +64 -0
  231. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  232. package/target/main/ts/report/html/site/source-route.js +22 -0
  233. package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
  234. package/target/main/ts/report/json/projections/commit-summary.js +118 -0
  235. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  236. package/target/main/ts/report/json/projections/components.js +29 -0
  237. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  238. package/target/main/ts/report/json/projections/file-metrics.js +243 -0
  239. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  240. package/target/main/ts/report/json/projections/inspection-context.js +92 -0
  241. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  242. package/target/main/ts/report/json/projections/inspection-details.js +69 -0
  243. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  244. package/target/main/ts/report/json/projections/metric-values.js +57 -0
  245. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  246. package/target/main/ts/report/json/projections/public-history.js +16 -0
  247. package/target/main/ts/report/json/store/components.d.ts +2 -0
  248. package/target/main/ts/report/json/store/components.js +31 -0
  249. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  250. package/target/main/ts/report/json/store/local-store.js +179 -0
  251. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  252. package/target/main/ts/report/json/store/pull-review-store.js +51 -0
  253. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  254. package/target/main/ts/report/json/validation/metabranch.js +7 -0
  255. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  256. package/target/main/ts/report/json/validation/report.js +64 -0
  257. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  258. package/target/main/ts/report/json/validation/summary-validation.js +27 -0
  259. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  260. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  261. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  262. package/target/main/ts/report/json/wire/component-model.js +1 -0
  263. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  264. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  265. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  266. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  267. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  268. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  269. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  270. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  271. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  272. package/target/main/ts/report/json/wire/project-model.js +1 -0
  273. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  274. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  275. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  276. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  277. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  278. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  279. package/target/main/ts/report.d.ts +11 -0
  280. package/target/main/ts/report.js +5 -0
  281. package/index.js +0 -1
@@ -1,317 +1,376 @@
1
1
  #!/usr/bin/env node
2
- import { readFile } from 'node:fs/promises';
3
- import { basename, resolve } from 'node:path';
4
- import { parseArgs } from 'node:util';
5
- import { isRecord } from '../analysis/plugin.js';
6
- import { measureDiffCoverage } from '../application/diff-coverage.js';
7
- import { inspect } from '../application/inspect.js';
8
- import { prepareMetabranch } from '../application/prepare-metabranch.js';
9
- import { reviewExitCode, reviewPull } from '../application/review.js';
10
- import { compareInspections } from '../comparison/compare.js';
11
- import { remoteExecutor } from '../execution/remote-executor.js';
12
- import { serveWorker } from '../execution/worker.js';
13
- import { workerToken } from '../execution/worker-protocol.js';
14
- import { normalizeFindingIgnore } from '../inspections/finding-ignore.js';
15
- import { exportSite } from '../presentation/export-site.js';
16
- import { readComponents } from '../presentation/components.js';
17
- import { fileMetrics } from '../presentation/file-metrics.js';
18
- import { serveSite } from '../presentation/local-server.js';
19
- import { exportProjects } from '../presentation/projects.js';
20
- import { GitReportReader } from '../reporting/git-reader.js';
21
- import { LocalReportStore } from '../reporting/local-store.js';
22
- import { listPullReviews } from '../reporting/pull-review-store.js';
23
- import { savePullReview } from '../reporting/pull-review-store.js';
24
- import { validSubjectId } from '../reporting/report.js';
25
- import { normalizeExclusions } from '../source/exclusions.js';
26
- import { gitRoot, resolveGitCommit } from '../source/git.js';
27
- import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from './github.js';
28
- const usage = `Repometry
29
-
30
- repometry inspect [--repo DIR] [--revision REF | --working-tree] [--output DIR] [--profile FILE | --no-profile] [--exclude PATTERN]... [--lcov FILE]... [--worker-url URL]
31
- [--sarif FILE]... [--security-sarif FILE]... [--secret-sarif FILE]... [--eslint-report FILE]... [--osv-report FILE]... [--finding-root DIR]
32
- repometry show <ID> [--working-tree] [--repo DIR] [--output DIR | --meta-ref REF]
33
- repometry files <ID> [--working-tree] [--repo DIR] [--output DIR | --meta-ref REF]
34
- repometry history [--repo DIR] [--output DIR | --meta-ref REF]
35
- repometry compare <BASE> <HEAD> [--repo DIR] [--output DIR | --meta-ref REF] [--baseline-output DIR]
36
- repometry diff-coverage --base REF --lcov FILE [--lcov FILE]... [--repo DIR] [--revision REF] [--profile FILE] [--exclude PATTERN]... [--min-diff-coverage PERCENT]
37
- repometry review --base REF [--lcov FILE]... [--repo DIR] [--revision REF] [--number NUMBER] [--output DIR] [--baseline-output DIR]
38
- [--profile FILE] [--exclude PATTERN]... [--min-diff-coverage PERCENT] [--min-diff-lines COUNT]
39
- [--max-coverage-drop POINTS] [--max-new-issues COUNT] [--github-summary] [--github-annotations]
40
- repometry prepare <SHA> --meta-worktree DIR [--meta-branch NAME] [--repo DIR] [--output DIR]
41
- repometry export --destination DIR [--local-details] [--title NAME] [--components FILE] [--repo DIR] [--output DIR | --meta-ref REF]
42
- repometry view [--port NUMBER] [--title NAME] [--components FILE] [--repo DIR] [--output DIR | --meta-ref REF]
43
- repometry projects --destination DIR
44
- repometry worker [--port NUMBER] [--listen ADDRESS]
45
-
46
- Inspect reads HEAD by default. Use --working-tree to inspect a directory as it is.
47
- The output defaults to .repometry inside --repo (the current directory by default).
48
- Use --working-tree with show to select a working snapshot digest.
49
- Exit codes: 0 success, 1 command or input error, 2 incomplete result, 3 quality gate failed.
50
- `;
51
- const commandOptions = {
52
- inspect: ['revision', 'profile', 'no-profile', 'exclude', 'lcov', 'working-tree', 'github-summary', 'worker-url',
53
- 'sarif', 'security-sarif', 'secret-sarif', 'eslint-report', 'osv-report', 'finding-root'],
54
- show: ['working-tree', 'meta-ref'],
55
- files: ['working-tree', 'meta-ref'],
56
- history: ['meta-ref'],
57
- compare: ['meta-ref', 'baseline-output'],
58
- 'diff-coverage': ['revision', 'base', 'lcov', 'profile', 'exclude', 'min-diff-coverage', 'github-summary'],
59
- review: ['revision', 'base', 'lcov', 'profile', 'exclude', 'number', 'min-diff-coverage', 'min-diff-lines',
60
- 'max-coverage-drop', 'max-new-issues', 'baseline-output', 'github-summary', 'github-annotations'],
61
- prepare: ['meta-worktree', 'meta-branch'],
62
- export: ['meta-ref', 'destination', 'local-details', 'title', 'components'],
63
- view: ['meta-ref', 'port', 'title', 'components'],
64
- projects: ['destination'],
65
- worker: ['port', 'listen'],
2
+ import { lstat, readFile } from 'node:fs/promises';
3
+ import { join, resolve } from 'node:path';
4
+ import { firstParentRange, gitRoot, resolveGitCommit } from '../api/git/git.js';
5
+ import { resolveGitBranch } from '../api/git/commit-metadata.js';
6
+ import { clearSourceCache, sourceCacheRoot } from '../api/git/source-cache.js';
7
+ import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from '../api/gh/github.js';
8
+ import { remoteExecutor } from '../api/worker/remote-executor.js';
9
+ import { serveWorker } from '../api/worker/worker.js';
10
+ import { workerToken } from '../api/worker/worker-protocol.js';
11
+ import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
12
+ import { measureDiffCoverage } from '../compose/diff-coverage.js';
13
+ import { prepareMetabranch } from '../compose/prepare-metabranch.js';
14
+ import { reviewExitCode, reviewPull } from '../compose/review.js';
15
+ import { builtInPlugins } from '../compose/plugin-list.js';
16
+ import { isRecord } from '../core/engine/plugin.js';
17
+ import { validSubjectId } from '../core/model/report.js';
18
+ import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
19
+ import { compareInspections } from '../core/usecases/compare.js';
20
+ import { exportProjects } from '../report/html/site/projects.js';
21
+ import { fileMetrics } from '../report/json/projections/file-metrics.js';
22
+ import { savePullReview } from '../report/json/store/pull-review-store.js';
23
+ import { dispatch, flag, option } from './arguments.js';
24
+ import { readConfig } from './config.js';
25
+ import { importerIds, readInputs } from './imports.js';
26
+ import { outputReports, reporterIds, viewTarget } from './reporting.js';
27
+ import { parseRange } from './revisions.js';
28
+ import { findRepository, selectStore, writableStore } from './store.js';
29
+ const configOptions = { config: option('FILE', 'Read a different JSON configuration.'), 'no-config': flag('Skip configuration.') };
30
+ const importOption = option('FORMAT=PATH', 'Import a report produced by another tool. Repeatable.', { multiple: true });
31
+ const excludeOption = option('PATTERN', 'Exclude a path or glob. Repeatable.', { multiple: true });
32
+ const ciOption = option('PROVIDER', 'Send CI output to github or none.');
33
+ const outputOption = option('PATH', 'Set the report output path.', { short: 'o' });
34
+ const baselineOption = option('PATH|git:REF', 'Select the baseline report store.');
35
+ const branchOption = option('NAME', 'Name the branch represented by the report.');
36
+ const renderOptions = {
37
+ output: outputOption, mode: option('public|private', 'Select the report data to expose.'),
38
+ sources: option('auto|none|ID[:SPEC]', 'Select source navigation for a private report.'),
39
+ title: option('NAME', 'Set the report title.'), components: option('FILE', 'Read component definitions.'),
40
+ 'no-footer': flag('Omit the footer.'), branch: branchOption,
66
41
  };
67
- function isCommand(command) {
68
- return Object.hasOwn(commandOptions, command);
69
- }
70
- async function run(args) {
71
- const [command, ...argv] = args;
72
- if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
73
- process.stdout.write(usage);
74
- return 0;
75
- }
76
- if (!isCommand(command))
77
- throw new Error(`Unknown command: ${command}`);
78
- const { values, positionals, tokens } = parseArgs({
79
- args: argv,
80
- options: {
81
- repo: { type: 'string' }, output: { type: 'string' }, help: { type: 'boolean', short: 'h' },
82
- revision: { type: 'string' }, lcov: { type: 'string', multiple: true }, 'working-tree': { type: 'boolean' },
83
- profile: { type: 'string' }, 'no-profile': { type: 'boolean' }, exclude: { type: 'string', multiple: true },
84
- 'meta-ref': { type: 'string' }, 'meta-worktree': { type: 'string' }, 'meta-branch': { type: 'string' }, 'github-summary': { type: 'boolean' },
85
- 'baseline-output': { type: 'string' },
86
- base: { type: 'string' }, 'min-diff-coverage': { type: 'string' },
87
- number: { type: 'string' }, 'min-diff-lines': { type: 'string' }, 'max-coverage-drop': { type: 'string' },
88
- 'max-new-issues': { type: 'string' }, 'github-annotations': { type: 'boolean' },
89
- destination: { type: 'string' }, port: { type: 'string' }, title: { type: 'string' },
90
- 'local-details': { type: 'boolean' }, components: { type: 'string' },
91
- 'worker-url': { type: 'string' }, listen: { type: 'string' },
92
- sarif: { type: 'string', multiple: true }, 'security-sarif': { type: 'string', multiple: true },
93
- 'secret-sarif': { type: 'string', multiple: true }, 'eslint-report': { type: 'string', multiple: true },
94
- 'osv-report': { type: 'string', multiple: true }, 'finding-root': { type: 'string' },
42
+ const commands = {
43
+ analyze: {
44
+ description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
45
+ options: { ...configOptions, ...renderOptions, 'working-tree': flag('Analyze the working directory.'),
46
+ 'skip-saved': flag('Keep commits that already have a saved inspection.'),
47
+ import: importOption, report: option('FORMAT[=PATH]', 'Generate a report after inspection. Repeatable.', { multiple: true }),
48
+ exclude: excludeOption, 'import-root': option('DIR', 'Resolve scanner locations relative to this directory.'),
49
+ worker: option('URL', 'Run analysis on a Repometry worker.'), ci: ciOption },
50
+ run: analyze,
51
+ },
52
+ show: {
53
+ description: 'Print a saved report.', parameters: 'REVISION|DIGEST', min: 1, max: 1,
54
+ options: { files: flag('Print file metrics.') }, run: show,
55
+ },
56
+ history: { description: 'List saved inspections.', async run(input) {
57
+ const { store } = await context(input);
58
+ print({ schema: 'urn:repometry:schema:inspection-history:1', inspections: (await store.reader.list()).map(inspectionSummary) });
59
+ } },
60
+ compare: {
61
+ description: 'Compare two saved reports.', parameters: 'BASE [HEAD]', min: 1, max: 2,
62
+ options: { 'baseline-store': baselineOption }, run: compare,
63
+ },
64
+ 'diff-coverage': {
65
+ description: 'Measure coverage of added lines.', parameters: 'BASE [HEAD]', min: 1, max: 2,
66
+ options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
67
+ 'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.') }, run: diffCoverage,
68
+ },
69
+ review: {
70
+ description: 'Review coverage and issues introduced by a change.', parameters: 'BASE [HEAD]', min: 1, max: 2,
71
+ options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
72
+ 'baseline-store': baselineOption, pull: option('NUMBER', 'Store a review for this pull request.'),
73
+ 'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.'),
74
+ 'min-lines': option('COUNT', 'Minimum measured lines for the changed-line coverage gate.'),
75
+ 'max-coverage-drop': option('POINTS', 'Maximum total coverage drop.'),
76
+ 'max-new-issues': option('COUNT', 'Maximum count of new quality findings.'),
77
+ annotations: flag('Write GitHub line annotations.') }, run: review,
78
+ },
79
+ report: {
80
+ description: 'Render HTML or JSON from saved reports.', parameters: '[FORMAT[=PATH]]...', max: Infinity,
81
+ options: { ...configOptions, ...renderOptions }, async run(input) {
82
+ const { root, store } = await context(input);
83
+ const config = await readConfig(root, input);
84
+ const requests = input.args.length ? input.args : config.reports.length ? config.reports : ['html'];
85
+ print({ schema: 'urn:repometry:schema:render-result:1', reports: await outputReports(root, store, requests, input, config) });
95
86
  },
96
- allowPositionals: command === 'show' || command === 'files' || command === 'prepare' || command === 'compare',
97
- tokens: true,
98
- });
99
- if (values.help) {
100
- process.stdout.write(usage);
101
- return 0;
102
- }
103
- const repositoryOptions = command === 'worker' || command === 'projects' ? [] : command === 'diff-coverage' ? ['repo'] : ['repo', 'output'];
104
- const allowed = new Set([...repositoryOptions, ...commandOptions[command]]);
105
- for (const token of tokens) {
106
- if (token.kind === 'option' && !allowed.has(token.name))
107
- throw new Error(`${token.rawName} is unavailable for ${command}`);
108
- }
109
- if (values['meta-ref'] !== undefined && (values.output !== undefined || values['working-tree'])) {
110
- throw new Error('Use --meta-ref to read Git reports separately from --output and --working-tree');
111
- }
112
- if (command === 'worker') {
113
- const host = values.listen ?? '127.0.0.1';
114
- if (host !== '127.0.0.1' && host !== '0.0.0.0')
115
- throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
116
- const server = await serveWorker(host, parsePort(values.port ?? '7331'), workerToken());
117
- announce(server);
118
- return 0;
119
- }
120
- if (command === 'projects') {
121
- if (!values.destination)
122
- throw new Error('projects requires --destination');
123
- const destination = resolve(values.destination);
124
- print({ destination, projects: await exportProjects(destination) });
125
- return 0;
126
- }
127
- const directory = resolve(values.repo ?? '.');
128
- const lcov = values.lcov?.length ? values.lcov.map(file => resolve(file)) : undefined;
129
- if (command === 'diff-coverage') {
130
- if (!values.base || lcov === undefined)
131
- throw new Error('diff-coverage requires --base and --lcov');
132
- const report = await measureDiffCoverage({
133
- directory, revision: values.revision ?? 'HEAD', base: values.base, lcov,
134
- exclude: await profileExclusions(values.profile, values.exclude),
135
- minimumPercent: parsePercentage(values['min-diff-coverage']),
136
- });
137
- if (values['github-summary'])
138
- await writeGitHubDiffCoverage(report);
139
- print(report);
140
- if (report.status === 'partial')
141
- return 2;
142
- return report.decision?.status === 'failed' ? 3 : 0;
143
- }
144
- const output = resolve(values.output ?? resolve(directory, '.repometry'));
145
- if (command === 'inspect') {
146
- if (values['working-tree'] && values.revision !== undefined)
147
- throw new Error('Choose either --working-tree or --revision');
148
- const executor = values['worker-url'] === undefined ? undefined : remoteExecutor(values['worker-url'], workerToken());
149
- if (values['no-profile'] && values.profile !== undefined)
150
- throw new Error('Choose either --profile or --no-profile');
151
- const defaultProfile = values.profile === undefined && !values['no-profile']
152
- ? resolve(values['working-tree'] ? directory : await gitRoot(directory), '.repometry', 'profile.json') : undefined;
153
- const profile = await readProfile(values.profile ?? defaultProfile, defaultProfile !== undefined);
154
- const findingInputs = [
155
- ...(values.sarif ?? []).map(file => ({ file: resolve(file), format: 'sarif', category: 'lint' })),
156
- ...(values['security-sarif'] ?? []).map(file => ({ file: resolve(file), format: 'sarif', category: 'security' })),
157
- ...(values['secret-sarif'] ?? []).map(file => ({ file: resolve(file), format: 'sarif', category: 'secret' })),
158
- ...(values['eslint-report'] ?? []).map(file => ({ file: resolve(file), format: 'eslint', category: 'lint' })),
159
- ...(values['osv-report'] ?? []).map(file => ({ file: resolve(file), format: 'osv', category: 'dependency' })),
160
- ];
161
- if (values['finding-root'] !== undefined && findingInputs.length === 0)
162
- throw new Error('--finding-root requires a scanner report');
163
- const report = await inspect({ directory, output, source: values['working-tree'] ? { workingTree: true } : { revision: values.revision ?? 'HEAD' },
164
- lcov,
165
- exclude: [...profile.exclude, ...values.exclude ?? []], ignore: profile.ignore,
166
- findingInputs, findingRoot: values['finding-root'] }, executor);
167
- if (values['github-summary'])
168
- await writeGitHubResult(report);
169
- print({ ...summary(report), output });
170
- return report.status === 'partial' ? 2 : 0;
171
- }
172
- const local = new LocalReportStore(output);
173
- if (command === 'review') {
174
- if (!values.base)
175
- throw new Error('review requires --base');
176
- if (values['github-annotations'] && !values['github-summary'])
177
- throw new Error('--github-annotations requires --github-summary');
178
- const number = parseCount(values.number, '--number', 1);
179
- const minimumPercent = parsePercentage(values['min-diff-coverage']);
180
- const minimumLines = parseCount(values['min-diff-lines'], '--min-diff-lines');
181
- const maxCoverageDrop = parsePercentage(values['max-coverage-drop'], '--max-coverage-drop');
182
- const maxNewIssues = parseCount(values['max-new-issues'], '--max-new-issues');
183
- const baseline = values['baseline-output'] === undefined ? local : new LocalReportStore(resolve(values['baseline-output']));
184
- const report = await reviewPull({ directory, revision: values.revision ?? 'HEAD', base: values.base,
185
- lcov,
186
- exclude: await profileExclusions(values.profile, values.exclude), number, minimumPercent, minimumLines, maxCoverageDrop, maxNewIssues }, local, baseline);
187
- if (number !== undefined)
188
- await savePullReview(output, report);
189
- if (values['github-summary'])
190
- await writeGitHubReview(report, values['github-annotations'] ? await gitRoot(directory) : undefined);
191
- print(report);
192
- return reviewExitCode(report);
193
- }
194
- if (command === 'prepare') {
195
- const id = positionals[0];
196
- const worktree = values['meta-worktree'];
197
- if (positionals.length !== 1 || id === undefined || worktree === undefined)
198
- throw new Error('prepare requires a source commit ID and --meta-worktree');
199
- const report = await local.read({ kind: 'commit', id });
200
- const files = await prepareMetabranch({ repository: directory, worktree: resolve(worktree), branch: values['meta-branch'] ?? 'repometry', report });
201
- print({ subject: report.subject, worktree: resolve(worktree), files });
202
- return 0;
203
- }
204
- if (command === 'compare') {
205
- const [base, head] = positionals;
206
- if (positionals.length !== 2 || !base || !head)
207
- throw new Error('compare requires an explicit baseline and current Git commit');
208
- const id = (revision) => validSubjectId('commit', revision) ? revision : resolveGitCommit(directory, revision);
209
- const [baseId, headId, metaId] = await Promise.all([id(base), id(head),
210
- values['meta-ref'] === undefined ? undefined : resolveGitCommit(directory, values['meta-ref'])]);
211
- const currentReader = metaId === undefined ? local : new GitReportReader(directory, metaId);
212
- const baselineReader = values['baseline-output'] === undefined ? currentReader : new LocalReportStore(resolve(values['baseline-output']));
213
- const current = currentReader.read({ kind: 'commit', id: headId });
214
- const baseline = baseId === headId && baselineReader === currentReader ? current : baselineReader.read({ kind: 'commit', id: baseId });
215
- const [before, after] = await Promise.all([baseline, current]);
216
- print(compareInspections(before, after));
217
- return 0;
218
- }
219
- const store = values['meta-ref'] === undefined ? local : new GitReportReader(directory, values['meta-ref']);
220
- if (command === 'export') {
221
- if (!values.destination)
222
- throw new Error('export requires --destination');
223
- const destination = resolve(values.destination);
224
- const title = values.title ?? (values.repo === undefined ? undefined : basename(directory));
225
- const detailed = values['local-details'] === true;
226
- if (values.components && !detailed)
227
- throw new Error('--components requires --local-details when exporting');
228
- const [components, pulls] = detailed ? await Promise.all([
229
- readComponents(values.components ?? resolve(directory, '.repometry', 'components.json'), values.components === undefined),
230
- listPullReviews(output),
231
- ]) : [undefined, undefined];
232
- await exportSite(store, destination, { title, mode: detailed ? 'private' : 'public', components, pulls });
233
- print({ destination });
234
- return 0;
235
- }
236
- if (command === 'view') {
237
- const [components, pulls] = await Promise.all([
238
- readComponents(values.components ?? resolve(directory, '.repometry', 'components.json'), values.components === undefined),
239
- listPullReviews(output),
240
- ]);
241
- announce(await serveSite(store, parsePort(values.port ?? '0'), { title: values.title ?? basename(directory), components, pulls }));
242
- return 0;
87
+ },
88
+ view: {
89
+ description: 'Open a repository, store or exported site locally.', parameters: '[TARGET]', max: 1,
90
+ options: { ...configOptions, branch: branchOption, port: option('PORT', 'Listen on this localhost port.'), title: renderOptions.title,
91
+ components: renderOptions.components, 'no-footer': renderOptions['no-footer'] },
92
+ async run(input) { announce(await viewTarget(input, port(input.text('port') ?? '0'))); },
93
+ },
94
+ projects: {
95
+ description: 'Generate a projects index.', options: { output: outputOption, 'no-footer': renderOptions['no-footer'] },
96
+ async run(input) {
97
+ const destination = resolve(input.text('repo') ?? '.', input.text('output') ?? '.');
98
+ print({ schema: 'urn:repometry:schema:projects-result:1', destination,
99
+ projects: await exportProjects(destination, { footer: !input.flag('no-footer') }) });
100
+ },
101
+ },
102
+ prepare: {
103
+ description: 'Prepare a report for a Git storage branch.', parameters: 'REVISION', min: 1, max: 1,
104
+ options: { worktree: option('DIR', 'Select the storage worktree.'), branch: option('NAME', 'Select the storage branch.') },
105
+ async run(input) {
106
+ const { directory, root, store } = await context(input);
107
+ const path = input.text('worktree');
108
+ if (!path)
109
+ throw new Error('prepare requires --worktree');
110
+ const worktree = resolve(directory, path);
111
+ const id = await commitId(root, input.args[0]);
112
+ const report = await store.reader.read({ kind: 'commit', id });
113
+ const files = await prepareMetabranch({ repository: root, worktree, branch: input.text('branch') ?? 'repometry', report });
114
+ print({ schema: 'urn:repometry:schema:prepare-result:1', subject: report.subject, worktree, files });
115
+ },
116
+ },
117
+ plugins: { description: 'List plugins and supported formats.', run() {
118
+ print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: builtInPlugins, importers: importerIds,
119
+ reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
120
+ } },
121
+ cache: {
122
+ description: 'Find or clear the system cache.', parameters: 'path|clear', min: 1, max: 1,
123
+ options: { sources: flag('Clear only source blobs.') },
124
+ async run(input) {
125
+ const action = input.args[0];
126
+ if (action !== 'path' && action !== 'clear')
127
+ throw new Error('Use cache path or cache clear');
128
+ if (action === 'path' && input.flag('sources'))
129
+ throw new Error('--sources requires cache clear');
130
+ const path = sourceCacheRoot();
131
+ if (action === 'clear')
132
+ await clearSourceCache(path);
133
+ print({ schema: 'urn:repometry:schema:cache-result:1', path, ...(action === 'clear' ? { cleared: ['sources'] } : {}) });
134
+ },
135
+ },
136
+ worker: { description: 'Run the remote analysis worker.',
137
+ options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
138
+ async run(input) {
139
+ const host = input.text('listen') ?? '127.0.0.1';
140
+ if (host !== '127.0.0.1' && host !== '0.0.0.0')
141
+ throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
142
+ announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot));
143
+ } },
144
+ };
145
+ async function context(input) {
146
+ const directory = resolve(input.text('repo') ?? '.');
147
+ const root = await findRepository(directory) ?? directory;
148
+ return { directory, root, store: selectStore(root, input.text('store'), directory) };
149
+ }
150
+ async function analyze(input) {
151
+ const range = input.args[0] === undefined ? undefined : parseRange(input.args[0]);
152
+ if (range)
153
+ return analyzeRange(input, range);
154
+ const { directory, root, store } = await context(input);
155
+ const output = writableStore(store);
156
+ if (input.flag('working-tree') && input.args.length)
157
+ throw new Error('Choose a revision or --working-tree');
158
+ if (input.flag('working-tree') && input.flag('skip-saved'))
159
+ throw new Error('--skip-saved applies to commits, not --working-tree');
160
+ const github = useGitHub(input);
161
+ const config = await readConfig(root, input);
162
+ const branch = input.text('branch') ?? config.branch;
163
+ const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
164
+ const imports = input.many('import');
165
+ const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
166
+ const importRoot = input.text('import-root');
167
+ if (importRoot && findings.length === 0)
168
+ throw new Error('--import-root requires a scanner report');
169
+ const worker = input.text('worker');
170
+ const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
171
+ const skipped = savedId !== undefined && await isSaved(output, savedId);
172
+ const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
173
+ : await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
174
+ lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore,
175
+ findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, worker === undefined ? undefined : remoteExecutor(worker, workerToken()));
176
+ if (github)
177
+ await writeGitHubResult(report);
178
+ const requested = input.many('report');
179
+ const reports = await outputReports(root, store, requested.length ? requested : config.reports, input, config);
180
+ print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
181
+ store: output, reports });
182
+ return report.status === 'partial' ? 2 : 0;
183
+ }
184
+ async function analyzeRange(input, range) {
185
+ const { directory, root, store } = await context(input);
186
+ const output = writableStore(store);
187
+ if (input.flag('working-tree'))
188
+ throw new Error('Choose a range or --working-tree');
189
+ if (input.many('import').length)
190
+ throw new Error('--import describes one checkout and cannot be used with a range');
191
+ if (input.text('import-root'))
192
+ throw new Error('--import-root requires a scanner report');
193
+ if (useGitHub(input))
194
+ throw new Error('--ci github needs a single revision');
195
+ const config = await readConfig(root, input);
196
+ if (config.imports.length)
197
+ process.stderr.write('Imports from the config describe one checkout and are skipped for a range.\n');
198
+ const { base, head, commits } = await firstParentRange(root, range.base, range.head);
199
+ if (!commits.length)
200
+ process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
201
+ const worker = input.text('worker');
202
+ const executor = worker === undefined ? undefined : remoteExecutor(worker, workerToken());
203
+ const exclude = [...config.exclude, ...input.many('exclude')];
204
+ const analyzed = [], partial = [], skipped = [];
205
+ const failed = [];
206
+ let interrupted = false;
207
+ const stop = () => { interrupted = true; process.stderr.write('Stopping after the current commit.\n'); };
208
+ process.once('SIGINT', stop);
209
+ const width = String(commits.length).length;
210
+ const progress = (index, id, state) => process.stderr.write(`[${String(index + 1).padStart(width)}/${commits.length}] ${id.slice(0, 7)} ${state}\n`);
211
+ try {
212
+ for (const [index, id] of commits.entries()) {
213
+ if (interrupted)
214
+ break;
215
+ if (input.flag('skip-saved') && await isSaved(output, id)) {
216
+ skipped.push(id);
217
+ progress(index, id, 'skipped');
218
+ continue;
219
+ }
220
+ try {
221
+ const report = await inspect({ directory, output, source: { revision: id }, exclude, ignore: config.ignore }, executor);
222
+ analyzed.push(id);
223
+ if (report.status === 'partial')
224
+ partial.push(id);
225
+ progress(index, id, report.status === 'partial' ? 'partial' : 'analyzed');
226
+ }
227
+ catch (error) {
228
+ if (interrupted)
229
+ break;
230
+ const message = error instanceof Error ? error.message : String(error);
231
+ failed.push({ commit: id, error: message });
232
+ progress(index, id, `failed: ${message}`);
233
+ }
234
+ }
243
235
  }
244
- if (command === 'history') {
245
- print((await store.list()).map(summary));
246
- return 0;
236
+ finally {
237
+ process.removeListener('SIGINT', stop);
247
238
  }
248
- if (positionals.length !== 1 || positionals[0] === undefined)
249
- throw new Error(`${command} requires one full commit ID or snapshot digest`);
250
- const report = await store.read({ kind: values['working-tree'] ? 'working-tree' : 'commit', id: positionals[0] });
251
- print(command === 'files' ? fileMetrics(report) : report);
252
- return 0;
253
- }
254
- async function profileExclusions(file, additional = []) {
255
- const preset = await readProfile(file);
256
- return [...preset.exclude, ...additional];
239
+ const requested = input.many('report');
240
+ const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
241
+ print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
242
+ analyzed, partial, skipped, failed, store: output, reports });
243
+ return interrupted ? 130 : failed.length || partial.length ? 2 : 0;
257
244
  }
258
- async function readProfile(file, optional = false) {
259
- if (file === undefined)
260
- return { exclude: [], ignore: [] };
261
- let text;
245
+ async function isSaved(store, id) {
262
246
  try {
263
- text = await readFile(file, 'utf8');
247
+ return (await lstat(join(store, 'commits', id, 'report.json'))).isFile();
264
248
  }
265
249
  catch (error) {
266
- if (optional && error instanceof Error && 'code' in error && error.code === 'ENOENT')
267
- return { exclude: [], ignore: [] };
250
+ if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
251
+ return false;
268
252
  throw error;
269
253
  }
270
- const profile = JSON.parse(text);
271
- if (!isRecord(profile) || Object.keys(profile).some(key => key !== 'exclude' && key !== 'ignore')) {
272
- throw new Error('Expected a JSON profile with optional exclude and ignore arrays');
254
+ }
255
+ async function show(input) {
256
+ const { root, store } = await context(input);
257
+ const ref = input.args[0];
258
+ const id = await commitId(root, ref);
259
+ let report;
260
+ try {
261
+ report = await store.reader.read({ kind: 'commit', id });
262
+ }
263
+ catch (error) {
264
+ if (!validSubjectId('working-tree', ref) || store.path === undefined || !(error instanceof Error)
265
+ || !('code' in error) || error.code !== 'ENOENT')
266
+ throw error;
267
+ report = await store.reader.read({ kind: 'working-tree', id: ref });
273
268
  }
274
- return { exclude: normalizeExclusions(profile.exclude === undefined ? [] : profile.exclude),
275
- ignore: normalizeFindingIgnore(profile.ignore === undefined ? [] : profile.ignore) };
269
+ print(input.flag('files') ? fileMetrics(report) : report);
276
270
  }
277
- function parsePercentage(value, option = '--min-diff-coverage') {
271
+ async function compare(input) {
272
+ const { directory, root, store } = await context(input);
273
+ const baselinePath = input.text('baseline-store');
274
+ const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
275
+ const [base, head] = await Promise.all([commitId(root, input.args[0]), commitId(root, input.args[1] ?? 'HEAD')]);
276
+ const current = store.reader.read({ kind: 'commit', id: head });
277
+ const before = base === head && baseline === store ? current : baseline.reader.read({ kind: 'commit', id: base });
278
+ print(compareInspections(await before, await current));
279
+ }
280
+ async function diffCoverage(input) {
281
+ const { directory, root } = await context(input);
282
+ const config = await readConfig(root, input);
283
+ const imports = input.many('import');
284
+ const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
285
+ if (!lcov || (imports.length && findings.length))
286
+ throw new Error('diff-coverage requires --import lcov=PATH');
287
+ const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov,
288
+ exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
289
+ if (useGitHub(input))
290
+ await writeGitHubDiffCoverage(report);
291
+ print(report);
292
+ return report.status === 'partial' ? 2 : report.decision?.status === 'failed' ? 3 : 0;
293
+ }
294
+ async function review(input) {
295
+ const { directory, root, store } = await context(input);
296
+ const github = useGitHub(input);
297
+ if (input.flag('annotations') && !github)
298
+ throw new Error('--annotations requires --ci github');
299
+ const config = await readConfig(root, input);
300
+ const imports = input.many('import');
301
+ const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
302
+ const baselinePath = input.text('baseline-store');
303
+ const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
304
+ const exclude = [...config.exclude, ...input.many('exclude')];
305
+ const current = imports.length && findings.length ? {
306
+ list: () => store.reader.list(),
307
+ read: async (subject) => {
308
+ const report = await store.reader.read(subject);
309
+ const source = report.appliedConfig.source;
310
+ const generated = isRecord(source) && Array.isArray(source.generatedExcluded)
311
+ ? source.generatedExcluded.filter((path) => typeof path === 'string') : [];
312
+ return attachFindings(report, findings, root, root, sourceExclusionMatcher(exclude, generated));
313
+ },
314
+ } : store.reader;
315
+ const number = count(input.text('pull'), '--pull', 1);
316
+ const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number,
317
+ minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage'),
318
+ minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
319
+ maxCoverageDrop: percent(input.text('max-coverage-drop') ?? config.maxCoverageDrop, '--max-coverage-drop'),
320
+ maxNewIssues: count(input.text('max-new-issues') ?? config.maxNewIssues, '--max-new-issues') }, current, baseline.reader);
321
+ if (number !== undefined)
322
+ await savePullReview(writableStore(store), report);
323
+ if (github)
324
+ await writeGitHubReview(report, input.flag('annotations') ? await gitRoot(root) : undefined);
325
+ print(report);
326
+ return reviewExitCode(report);
327
+ }
328
+ function commitId(root, revision) {
329
+ return validSubjectId('commit', revision) ? Promise.resolve(revision) : resolveGitCommit(root, revision);
330
+ }
331
+ function useGitHub(input) {
332
+ const provider = input.text('ci') ?? 'none';
333
+ if (provider !== 'none' && provider !== 'github')
334
+ throw new Error('--ci must be github or none');
335
+ return provider === 'github';
336
+ }
337
+ function percent(value, name) {
278
338
  if (value === undefined)
279
339
  return undefined;
280
- const percent = Number(value);
281
- if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || percent < 0 || percent > 100) {
282
- throw new Error(`${option} must be a percentage from 0 to 100`);
283
- }
284
- return percent;
340
+ const number = Number(value);
341
+ if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || number < 0 || number > 100)
342
+ throw new Error(`${name} must be a percentage from 0 to 100`);
343
+ return number;
285
344
  }
286
- function parseCount(value, option, minimum = 0) {
345
+ function count(value, name, minimum = 0) {
287
346
  if (value === undefined)
288
347
  return undefined;
289
- const count = Number(value);
290
- if (!/^\d+$/.test(value) || !Number.isSafeInteger(count) || count < minimum) {
291
- throw new Error(`${option} must be an integer of at least ${minimum}`);
292
- }
293
- return count;
348
+ const number = Number(value);
349
+ if (!/^\d+$/.test(value) || !Number.isSafeInteger(number) || number < minimum)
350
+ throw new Error(`${name} must be an integer of at least ${minimum}`);
351
+ return number;
294
352
  }
295
- function parsePort(raw) {
296
- const port = Number(raw);
297
- if (!/^\d+$/.test(raw) || port > 65_535)
353
+ function port(value) {
354
+ const number = count(value, '--port');
355
+ if (number > 65535)
298
356
  throw new Error('--port must be an integer from 0 to 65535');
299
- return port;
357
+ return number;
300
358
  }
301
359
  function announce(server) {
302
- process.once('SIGINT', server.close);
360
+ process.once('SIGINT', () => { process.exitCode = 130; server.close(); });
303
361
  process.once('SIGTERM', server.close);
304
- process.stdout.write(`${server.url}\n`);
362
+ process.stderr.write(`Serving${server.label ? ' ' + server.label : ''} at ${server.url}\n`);
305
363
  }
306
- function summary(report) {
364
+ function inspectionSummary(report) {
307
365
  return { subject: report.subject, generatedAt: report.generatedAt, status: report.status, scope: report.scope,
308
366
  measurements: report.measurements.length, diagnostics: report.diagnostics.length };
309
367
  }
310
368
  function print(value) {
311
- process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
369
+ process.stdout.write(JSON.stringify(value, null, 2) + '\n');
312
370
  }
313
371
  try {
314
- process.exitCode = await run(process.argv.slice(2));
372
+ const manifest = JSON.parse(await readFile(new URL('../../../../package.json', import.meta.url), 'utf8'));
373
+ process.exitCode = await dispatch(commands, process.argv.slice(2), manifest.version);
315
374
  }
316
375
  catch (error) {
317
376
  process.stderr.write(`repometry: ${error instanceof Error ? error.message : String(error)}\n`);