repometry 0.0.0-stage → 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 (280) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -2
  3. package/package.json +63 -4
  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 +378 -0
  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 -0
  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
@@ -0,0 +1,73 @@
1
+ import { checkMetaManifest } from '../../report/json/validation/metabranch.js';
2
+ import { gitBlobText, gitTreeFiles, resolveGitCommit } from './git.js';
3
+ import { compareReports, readReportText, validSubjectId } from '../../report/json/validation/report.js';
4
+ import { commitSummary, expandSummaryCatalog, orderSummaries } from '../../report/json/projections/commit-summary.js';
5
+ import { validateSummaryIndex } from '../../report/json/validation/summary-validation.js';
6
+ export class GitReportReader {
7
+ directory;
8
+ revision;
9
+ snapshot;
10
+ constructor(directory, revision) {
11
+ this.directory = directory;
12
+ this.revision = revision;
13
+ }
14
+ async read(subject) {
15
+ if (subject.kind !== 'commit' || !validSubjectId('commit', subject.id))
16
+ throw new Error('Metabranch reports require a full source commit ID');
17
+ const commit = await this.pinnedSnapshot();
18
+ const path = `commits/${subject.id}/report.json`;
19
+ const entry = (await gitTreeFiles(this.directory, commit, path)).find(item => item.path === path);
20
+ if (!entry)
21
+ throw Object.assign(new Error(`No report for ${subject.id} in ${this.revision}`), { code: 'ENOENT' });
22
+ return readReportText(await gitBlobText(this.directory, entry.oid), subject);
23
+ }
24
+ async list() {
25
+ return this.readEntries(await this.reportEntries(await this.pinnedSnapshot()));
26
+ }
27
+ async listSummaries() {
28
+ const commit = await this.pinnedSnapshot();
29
+ const [entries, index] = await Promise.all([
30
+ this.reportEntries(commit),
31
+ gitTreeFiles(this.directory, commit, 'summary.json'),
32
+ ]);
33
+ const file = index.find(entry => entry.path === 'summary.json');
34
+ if (file) {
35
+ const value = JSON.parse(await gitBlobText(this.directory, file.oid));
36
+ if (!validateSummaryIndex(value))
37
+ throw new Error(`Invalid Repometry summary in ${this.revision}`);
38
+ const shas = new Set(value.commits.map(row => row.sha));
39
+ if (shas.size === value.commits.length && entries.length === shas.size && entries.every(({ id }) => shas.has(id))
40
+ && value.commits.every(row => row.revision && row.counts && !row.detail))
41
+ return expandSummaryCatalog(value);
42
+ }
43
+ return orderSummaries((await this.readEntries(entries)).map(commitSummary));
44
+ }
45
+ async reportEntries(commit) {
46
+ return (await gitTreeFiles(this.directory, commit, 'commits')).flatMap(({ path, oid }) => {
47
+ const id = /^commits\/([a-f0-9]+)\/report\.json$/.exec(path)?.[1];
48
+ return id && validSubjectId('commit', id) ? [{ id, oid }] : [];
49
+ });
50
+ }
51
+ async readEntries(entries) {
52
+ const reports = [];
53
+ for (const { id, oid } of entries) {
54
+ reports.push(readReportText(await gitBlobText(this.directory, oid), { kind: 'commit', id }));
55
+ }
56
+ return reports.sort(compareReports);
57
+ }
58
+ pinnedSnapshot() {
59
+ this.snapshot ??= this.resolveSnapshot().catch(error => {
60
+ this.snapshot = undefined;
61
+ throw error;
62
+ });
63
+ return this.snapshot;
64
+ }
65
+ async resolveSnapshot() {
66
+ const commit = await resolveGitCommit(this.directory, this.revision);
67
+ const entry = (await gitTreeFiles(this.directory, commit, 'manifest.json')).find(item => item.path === 'manifest.json');
68
+ if (!entry)
69
+ throw new Error(`No Repometry manifest in ${this.revision}`);
70
+ checkMetaManifest(await gitBlobText(this.directory, entry.oid));
71
+ return commit;
72
+ }
73
+ }
@@ -0,0 +1,21 @@
1
+ import type { SourceSnapshot } from '../../core/model/snapshot.js';
2
+ export declare function gitRoot(directory: string): Promise<string>;
3
+ export declare function physicalGitRoot(directory: string): Promise<string>;
4
+ export declare function gitText(directory: string, args: readonly string[], timeout?: number): Promise<string>;
5
+ export declare function gitUtf8(directory: string, args: readonly string[], timeout?: number): Promise<string>;
6
+ export declare function resolveGitCommit(directory: string, revision: string): Promise<string>;
7
+ /** Commits on the first-parent line of `head` after `base`, oldest first. */
8
+ export declare function firstParentRange(directory: string, base: string, head: string): Promise<{
9
+ readonly base: string;
10
+ readonly head: string;
11
+ readonly commits: readonly string[];
12
+ }>;
13
+ interface GitFile {
14
+ readonly path: string;
15
+ readonly oid: string;
16
+ readonly size?: number;
17
+ }
18
+ export declare function gitTreeFiles(directory: string, commit: string, prefix?: string, includeSize?: boolean): Promise<readonly GitFile[]>;
19
+ export declare function gitBlobText(directory: string, oid: string): Promise<string>;
20
+ export declare function readGitCommit(directory: string, revision: string, excludes: (path: string) => boolean): Promise<SourceSnapshot>;
21
+ export {};
@@ -0,0 +1,152 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { execFile, spawnSync } from 'node:child_process';
3
+ import { promisify } from 'node:util';
4
+ import { comparePaths, isExcludedDirectory, isSourcePath, textLineCount, utf8 } from '../../core/model/snapshot.js';
5
+ import { isGeneratedSource } from '../../core/profile/exclusions.js';
6
+ const git = promisify(execFile);
7
+ const maxBuffer = 64 * 1024 * 1024;
8
+ const oidPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
9
+ const env = { ...process.env, GIT_NO_LAZY_FETCH: '1' };
10
+ export async function gitRoot(directory) {
11
+ try {
12
+ return (await gitText(directory, ['rev-parse', '--show-toplevel'])).replace(/\r?\n$/, '');
13
+ }
14
+ catch (error) {
15
+ const detail = error instanceof Error ? error.message : String(error);
16
+ const reason = `${directory} is not a Git repository`;
17
+ throw new Error(process.env.REPOMETRY_DEBUG === '1' ? `${reason}\n${detail}` : reason, { cause: error });
18
+ }
19
+ }
20
+ export async function physicalGitRoot(directory) {
21
+ return realpath(await gitRoot(directory));
22
+ }
23
+ export async function gitText(directory, args, timeout) {
24
+ const { stdout } = await git('git', ['--no-replace-objects', ...args], { cwd: directory, env, maxBuffer, timeout });
25
+ return stdout;
26
+ }
27
+ export async function gitUtf8(directory, args, timeout) {
28
+ const result = await git('git', ['--no-replace-objects', ...args], { cwd: directory, env, encoding: 'buffer', maxBuffer, timeout });
29
+ return utf8(result.stdout);
30
+ }
31
+ export async function resolveGitCommit(directory, revision) {
32
+ let output;
33
+ try {
34
+ output = await gitText(directory, ['rev-parse', '--verify', '--end-of-options', `${revision}^{commit}`]);
35
+ }
36
+ catch (error) {
37
+ const detail = error instanceof Error ? error.message : String(error);
38
+ const reason = /not a git repository/i.test(detail) ? `${directory} is not a Git repository` : `${revision} is not a commit in ${directory}`;
39
+ throw new Error(process.env.REPOMETRY_DEBUG === '1' ? `${reason}\n${detail}` : reason, { cause: error });
40
+ }
41
+ const id = output.trim();
42
+ if (!oidPattern.test(id))
43
+ throw new Error('Git returned an invalid commit ID');
44
+ return id;
45
+ }
46
+ /** Commits on the first-parent line of `head` after `base`, oldest first. */
47
+ export async function firstParentRange(directory, base, head) {
48
+ const [from, to] = await Promise.all([resolveGitCommit(directory, base), resolveGitCommit(directory, head)]);
49
+ const commits = (await gitText(directory, ['rev-list', '--first-parent', '--reverse', `${from}..${to}`])).split('\n').filter(Boolean);
50
+ if (!commits.every(id => oidPattern.test(id)))
51
+ throw new Error('Git returned an invalid commit ID');
52
+ return { base: from, head: to, commits };
53
+ }
54
+ export async function gitTreeFiles(directory, commit, prefix, includeSize = false) {
55
+ if (!oidPattern.test(commit))
56
+ throw new Error('A full commit object ID is required');
57
+ const args = ['--no-replace-objects', '--literal-pathspecs', 'ls-tree', '-r', '-z', '--full-tree'];
58
+ if (includeSize)
59
+ args.push('--long');
60
+ args.push(commit);
61
+ if (prefix !== undefined)
62
+ args.push('--', prefix);
63
+ const tree = await git('git', args, { cwd: directory, env, encoding: 'buffer', maxBuffer });
64
+ const entries = [];
65
+ for (const entry of utf8(tree.stdout).split('\0')) {
66
+ if (!entry)
67
+ continue;
68
+ const tab = entry.indexOf('\t');
69
+ const header = entry.slice(0, tab);
70
+ const match = /^100(?:644|755) blob ([a-f0-9]+)(?: +([0-9]+|-))?$/.exec(header);
71
+ const oid = match?.[1];
72
+ const path = entry.slice(tab + 1);
73
+ const size = Number(match?.[2]);
74
+ if (oid && oidPattern.test(oid))
75
+ entries.push({ path, oid, ...(Number.isSafeInteger(size) ? { size } : {}) });
76
+ }
77
+ return entries;
78
+ }
79
+ export async function gitBlobText(directory, oid) {
80
+ if (!oidPattern.test(oid))
81
+ throw new Error('A full blob object ID is required');
82
+ const result = await git('git', ['--no-replace-objects', 'cat-file', 'blob', oid], { cwd: directory, env, encoding: 'buffer', maxBuffer });
83
+ return utf8(result.stdout);
84
+ }
85
+ export async function readGitCommit(directory, revision, excludes) {
86
+ const id = await resolveGitCommit(directory, revision);
87
+ const tracked = (await gitTreeFiles(directory, id, undefined, true)).filter(({ path }) => !path.split('/').slice(0, -1).some(isExcludedDirectory) && !excludes(path));
88
+ const entries = tracked.filter(entry => isSourcePath(entry.path));
89
+ const blobs = readBlobs(directory, [...new Set(entries.map(entry => entry.oid))]);
90
+ const generated = new Set();
91
+ const files = entries.flatMap(({ path, oid }) => {
92
+ const bytes = blobs.get(oid);
93
+ if (!bytes)
94
+ throw new Error(`Git blob unavailable: ${oid}`);
95
+ if (!isGeneratedSource(bytes))
96
+ return [{ path, bytes }];
97
+ generated.add(path);
98
+ return [];
99
+ });
100
+ files.sort((left, right) => comparePaths(left.path, right.path));
101
+ const counts = inventoryLineCounts(directory, tracked, blobs);
102
+ const inventory = tracked.filter(({ path }) => !generated.has(path)).map(({ path, oid, size }) => ({ path, lines: counts.get(oid) ?? null, ...(size === undefined ? {} : { bytes: size }) }));
103
+ return { subject: { kind: 'commit', id }, files, inventory, generatedExcluded: [...generated].sort(comparePaths) };
104
+ }
105
+ function inventoryLineCounts(directory, entries, sources) {
106
+ const lines = new Map([...sources].map(([oid, value]) => [oid, textLineCount(value)]));
107
+ const entriesById = new Map(entries.map(entry => [entry.oid, entry]));
108
+ let batch = [];
109
+ let bytes = 0;
110
+ for (const [oid, { size }] of entriesById) {
111
+ if (lines.has(oid) || size === undefined || size + 128 > maxBuffer)
112
+ continue;
113
+ const estimate = size + 128;
114
+ if (bytes + estimate > maxBuffer)
115
+ flush();
116
+ batch.push(oid);
117
+ bytes += estimate;
118
+ }
119
+ flush();
120
+ return lines;
121
+ function flush() {
122
+ for (const [oid, value] of readBlobs(directory, batch))
123
+ lines.set(oid, textLineCount(value));
124
+ batch = [];
125
+ bytes = 0;
126
+ }
127
+ }
128
+ function readBlobs(directory, ids) {
129
+ const blobs = new Map();
130
+ if (ids.length === 0)
131
+ return blobs;
132
+ const result = spawnSync('git', ['--no-replace-objects', 'cat-file', '--batch'], { cwd: directory, env, input: `${ids.join('\n')}\n`, maxBuffer });
133
+ if (result.error)
134
+ throw result.error;
135
+ if (result.status !== 0)
136
+ throw new Error(`git cat-file failed: ${result.stderr.toString('utf8').trim()}`);
137
+ let cursor = 0;
138
+ for (const oid of ids) {
139
+ const end = result.stdout.indexOf(10, cursor);
140
+ if (end < 0)
141
+ throw new Error(`Missing Git blob header: ${oid}`);
142
+ const match = /^([a-f0-9]+) blob (\d+)$/.exec(result.stdout.toString('ascii', cursor, end));
143
+ const size = Number(match?.[2]);
144
+ const from = end + 1;
145
+ const to = from + size;
146
+ if (match?.[1] !== oid || !Number.isSafeInteger(size) || result.stdout[to] !== 10)
147
+ throw new Error(`Invalid Git blob: ${oid}`);
148
+ blobs.set(oid, result.stdout.subarray(from, to));
149
+ cursor = to + 1;
150
+ }
151
+ return blobs;
152
+ }
@@ -0,0 +1,15 @@
1
+ export interface SourceSelection {
2
+ readonly directory: string;
3
+ readonly output: string;
4
+ readonly source: {
5
+ readonly workingTree: true;
6
+ } | {
7
+ readonly revision: string;
8
+ };
9
+ }
10
+ export declare function readInspectionSource(request: SourceSelection, excludes: (path: string) => boolean): Promise<{
11
+ root: string;
12
+ snapshot: import("../../plugin.js").SourceSnapshot;
13
+ excludedOutput: string | null;
14
+ output: string;
15
+ }>;
@@ -0,0 +1,30 @@
1
+ import { realpath } from 'node:fs/promises';
2
+ import { basename, dirname, join, relative, resolve, sep } from 'node:path';
3
+ import { gitRoot, readGitCommit } from './git.js';
4
+ import { containsPath, readWorkingTree } from './local.js';
5
+ export async function readInspectionSource(request, excludes) {
6
+ const root = await realpath('workingTree' in request.source ? request.directory : await gitRoot(request.directory));
7
+ const output = await physicalPath(resolve(request.output));
8
+ if (containsPath(output, root) || output.split(sep).includes('.git')) {
9
+ throw new Error('Choose a dedicated report directory outside Git metadata');
10
+ }
11
+ const snapshot = 'workingTree' in request.source
12
+ ? await readWorkingTree(root, output, excludes)
13
+ : await readGitCommit(root, request.source.revision, excludes);
14
+ const excludedOutput = snapshot.subject.kind === 'working-tree' && containsPath(root, output)
15
+ ? relative(root, output).split(sep).join('/') : null;
16
+ return { root, snapshot, excludedOutput, output };
17
+ }
18
+ async function physicalPath(path) {
19
+ try {
20
+ return await realpath(path);
21
+ }
22
+ catch (error) {
23
+ if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
24
+ throw error;
25
+ const parent = dirname(path);
26
+ if (parent === path)
27
+ throw error;
28
+ return join(await physicalPath(parent), basename(path));
29
+ }
30
+ }
@@ -0,0 +1,5 @@
1
+ export declare function readLocalSources(repository: string, cache?: string): {
2
+ read(revision: string, path: string, signal?: AbortSignal): Promise<Uint8Array | undefined>;
3
+ close: () => void;
4
+ };
5
+ export declare function sourceRemotes(repository: string): Promise<string[]>;
@@ -0,0 +1,46 @@
1
+ import { utf8 } from '../../core/model/snapshot.js';
2
+ import { validSubjectId } from '../../core/model/report.js';
3
+ import { isSourcePathname } from '../../core/ports/source-provider.js';
4
+ import { GitBlobBatch } from './blob-batch.js';
5
+ import { gitText, gitTreeFiles } from './git.js';
6
+ import { cachedBlob, sourceCacheRoot } from './source-cache.js';
7
+ export function readLocalSources(repository, cache = sourceCacheRoot()) {
8
+ const git = new GitBlobBatch(repository);
9
+ const known = new Map();
10
+ return {
11
+ async read(revision, path, signal) {
12
+ if (!validSubjectId('commit', revision) || !isSourcePathname(path))
13
+ return undefined;
14
+ const key = revision + '\0' + path;
15
+ let oid = known.get(key);
16
+ if (oid === undefined) {
17
+ oid = gitTreeFiles(repository, revision, path).then(entries => entries.find(entry => entry.path === path)?.oid).catch(error => {
18
+ known.delete(key);
19
+ if (error instanceof Error && 'code' in error && typeof error.code === 'number')
20
+ return undefined;
21
+ throw error;
22
+ });
23
+ known.set(key, oid);
24
+ }
25
+ const id = await oid;
26
+ if (!id)
27
+ return undefined;
28
+ signal?.throwIfAborted();
29
+ const bytes = await cachedBlob(cache, id, () => git.read(id, signal));
30
+ if (!bytes || bytes.includes(0))
31
+ return undefined;
32
+ try {
33
+ utf8(bytes);
34
+ return bytes;
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ },
40
+ close: () => git.close(),
41
+ };
42
+ }
43
+ export async function sourceRemotes(repository) {
44
+ const origins = await gitText(repository, ['remote', 'get-url', '--all', 'origin']).catch(() => '');
45
+ return origins.split(/\r?\n/).filter(Boolean);
46
+ }
@@ -0,0 +1,3 @@
1
+ import type { SourceSnapshot } from '../../core/model/snapshot.js';
2
+ export declare function containsPath(parent: string, path: string): boolean;
3
+ export declare function readWorkingTree(directory: string, output: string, excludes: (path: string) => boolean): Promise<SourceSnapshot>;
@@ -0,0 +1,35 @@
1
+ import { readdir, realpath, readFile } from 'node:fs/promises';
2
+ import { isAbsolute, join, relative, sep } from 'node:path';
3
+ import { comparePaths, isExcludedDirectory, isSourcePath, workingSnapshot } from '../../core/model/snapshot.js';
4
+ import { isGeneratedSource } from '../../core/profile/exclusions.js';
5
+ export function containsPath(parent, path) {
6
+ const rest = relative(parent, path);
7
+ return rest === '' || (!isAbsolute(rest) && rest !== '..' && !rest.startsWith(`..${sep}`));
8
+ }
9
+ export async function readWorkingTree(directory, output, excludes) {
10
+ const root = await realpath(directory);
11
+ const files = [];
12
+ const generatedExcluded = [];
13
+ if (containsPath(output, root))
14
+ throw new Error('The output directory must be separate from the source root');
15
+ async function visit(folder, prefix) {
16
+ for (const entry of await readdir(folder, { withFileTypes: true })) {
17
+ const path = prefix + entry.name;
18
+ const absolute = join(folder, entry.name);
19
+ if (excludes(path))
20
+ continue;
21
+ if (entry.isDirectory() && !isExcludedDirectory(entry.name) && absolute !== output) {
22
+ await visit(absolute, `${path}/`);
23
+ }
24
+ else if (entry.isFile() && isSourcePath(path)) {
25
+ const bytes = await readFile(absolute);
26
+ if (isGeneratedSource(bytes))
27
+ generatedExcluded.push(path);
28
+ else
29
+ files.push({ path, bytes });
30
+ }
31
+ }
32
+ }
33
+ await visit(root, '');
34
+ return { ...workingSnapshot(files), generatedExcluded: generatedExcluded.sort(comparePaths) };
35
+ }
@@ -0,0 +1 @@
1
+ export declare function openMetabranchWorktree(repository: string, worktree: string, branch: string, sourceCommit: string): Promise<string>;
@@ -0,0 +1,34 @@
1
+ import { lstat, readFile, readdir, realpath, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { gitRoot, gitText, resolveGitCommit } from './git.js';
4
+ import { containsPath } from './local.js';
5
+ import { checkMetaManifest, metaManifest } from '../../report/json/validation/metabranch.js';
6
+ export async function openMetabranchWorktree(repository, worktree, branch, sourceCommit) {
7
+ await resolveGitCommit(repository, sourceCommit);
8
+ const source = await realpath(await gitRoot(repository));
9
+ const target = await realpath(worktree);
10
+ if (containsPath(source, target) || containsPath(target, source) || await realpath(await gitRoot(target)) !== target) {
11
+ throw new Error('Select the root of a separate worktree outside the source checkout');
12
+ }
13
+ const commonDir = async (path) => realpath((await gitText(path, ['rev-parse', '--path-format=absolute', '--git-common-dir'])).replace(/\r?\n$/, ''));
14
+ if (await commonDir(source) !== await commonDir(target))
15
+ throw new Error('Metabranch worktree must belong to the source repository');
16
+ const expectedRef = `refs/heads/${branch}`;
17
+ await gitText(target, ['check-ref-format', expectedRef]);
18
+ if ((await gitText(target, ['symbolic-ref', '--quiet', 'HEAD'])).trim() !== expectedRef) {
19
+ throw new Error(`Metabranch worktree must be on ${expectedRef}`);
20
+ }
21
+ const marker = join(target, 'manifest.json');
22
+ const entries = await readdir(target);
23
+ if (entries.includes('manifest.json')) {
24
+ if (!(await lstat(marker)).isFile())
25
+ throw new Error('The metabranch manifest must be a regular file');
26
+ checkMetaManifest(await readFile(marker, 'utf8'));
27
+ }
28
+ else {
29
+ if (entries.some(name => name !== '.git'))
30
+ throw new Error('Start from an empty metabranch worktree or an existing Repometry manifest');
31
+ await writeFile(marker, `${JSON.stringify(metaManifest, null, 2)}\n`, { flag: 'wx', mode: 0o600 });
32
+ }
33
+ return target;
34
+ }
@@ -0,0 +1,3 @@
1
+ export declare function sourceCacheRoot(env?: NodeJS.ProcessEnv, system?: NodeJS.Platform, home?: string): string;
2
+ export declare function clearSourceCache(root?: string): Promise<void>;
3
+ export declare function cachedBlob(root: string, oid: string, load: () => Promise<Buffer | undefined>): Promise<Buffer | undefined>;
@@ -0,0 +1,56 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { lstat, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+ import { validSubjectId } from '../../core/model/report.js';
6
+ export function sourceCacheRoot(env = process.env, system = process.platform, home = homedir()) {
7
+ if (env.REPOMETRY_CACHE_DIR)
8
+ return resolve(env.REPOMETRY_CACHE_DIR);
9
+ if (env.XDG_CACHE_HOME)
10
+ return resolve(env.XDG_CACHE_HOME, 'repometry');
11
+ if (system === 'darwin')
12
+ return join(home, 'Library', 'Caches', 'repometry');
13
+ if (system === 'win32' && env.LOCALAPPDATA)
14
+ return resolve(env.LOCALAPPDATA, 'repometry', 'cache');
15
+ return join(home, '.cache', 'repometry');
16
+ }
17
+ export async function clearSourceCache(root = sourceCacheRoot()) {
18
+ await rm(join(root, 'sources'), { recursive: true, force: true });
19
+ }
20
+ export async function cachedBlob(root, oid, load) {
21
+ if (!validSubjectId('commit', oid))
22
+ throw new Error('Invalid source blob ID');
23
+ const folder = join(root, 'sources', oid.slice(0, 2));
24
+ const path = join(folder, oid);
25
+ try {
26
+ if ((await lstat(path)).isFile()) {
27
+ const hit = await readFile(path);
28
+ if (blobMatches(oid, hit))
29
+ return hit;
30
+ }
31
+ }
32
+ catch (error) {
33
+ if (!isMissing(error))
34
+ throw error;
35
+ }
36
+ const bytes = await load();
37
+ if (bytes === undefined || !blobMatches(oid, bytes))
38
+ return undefined;
39
+ await mkdir(folder, { recursive: true, mode: 0o700 });
40
+ const temporary = join(folder, `.${randomUUID()}.tmp`);
41
+ try {
42
+ await writeFile(temporary, bytes, { flag: 'wx', mode: 0o600 });
43
+ await rename(temporary, path);
44
+ }
45
+ finally {
46
+ await rm(temporary, { force: true });
47
+ }
48
+ return bytes;
49
+ }
50
+ function blobMatches(oid, bytes) {
51
+ return createHash(oid.length === 40 ? 'sha1' : 'sha256')
52
+ .update(`blob ${bytes.length}\0`).update(bytes).digest('hex') === oid;
53
+ }
54
+ function isMissing(error) {
55
+ return error instanceof Error && 'code' in error && error.code === 'ENOENT';
56
+ }
@@ -0,0 +1,9 @@
1
+ import type { Finding } from '../../core/model/finding.js';
2
+ import type { FindingInput, ImportMetadata } from '../../core/model/scanner-import.js';
3
+ export { findingImportMethods } from '../../core/model/scanner-import.js';
4
+ export type { FindingInput } from '../../core/model/scanner-import.js';
5
+ interface Imported {
6
+ readonly findings: readonly Finding[];
7
+ readonly metadata: ImportMetadata;
8
+ }
9
+ export declare function importFindings(input: FindingInput, root: string, excludes: (path: string) => boolean, knownPaths: ReadonlySet<string> | undefined): Promise<Imported>;