repometry 0.0.0-stage → 0.2.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 (274) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -2
  3. package/package.json +64 -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 +33 -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 +252 -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 +120 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +560 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github.d.ts +6 -0
  26. package/target/main/ts/api/gh/github.js +92 -0
  27. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  28. package/target/main/ts/api/git/blob-batch.js +106 -0
  29. package/target/main/ts/api/git/changes.d.ts +22 -0
  30. package/target/main/ts/api/git/changes.js +108 -0
  31. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  32. package/target/main/ts/api/git/commit-metadata.js +53 -0
  33. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  34. package/target/main/ts/api/git/git-churn.js +71 -0
  35. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  36. package/target/main/ts/api/git/git-reader.js +74 -0
  37. package/target/main/ts/api/git/git.d.ts +21 -0
  38. package/target/main/ts/api/git/git.js +153 -0
  39. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  40. package/target/main/ts/api/git/inspection-source.js +31 -0
  41. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  42. package/target/main/ts/api/git/local-sources.js +47 -0
  43. package/target/main/ts/api/git/local.d.ts +3 -0
  44. package/target/main/ts/api/git/local.js +36 -0
  45. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  46. package/target/main/ts/api/git/metabranch-worktree.js +35 -0
  47. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  48. package/target/main/ts/api/git/source-cache.js +57 -0
  49. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  50. package/target/main/ts/api/import/finding-import.js +227 -0
  51. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  52. package/target/main/ts/api/import/lcov-files.js +14 -0
  53. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  54. package/target/main/ts/api/import/profile-file.js +17 -0
  55. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  56. package/target/main/ts/api/worker/remote-executor.js +46 -0
  57. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  58. package/target/main/ts/api/worker/worker-protocol.js +102 -0
  59. package/target/main/ts/api/worker/worker.d.ts +5 -0
  60. package/target/main/ts/api/worker/worker.js +86 -0
  61. package/target/main/ts/cli/arguments.d.ts +28 -0
  62. package/target/main/ts/cli/arguments.js +111 -0
  63. package/target/main/ts/cli/config.d.ts +13 -0
  64. package/target/main/ts/cli/config.js +58 -0
  65. package/target/main/ts/cli/imports.d.ts +7 -0
  66. package/target/main/ts/cli/imports.js +30 -0
  67. package/target/main/ts/cli/main.d.ts +2 -0
  68. package/target/main/ts/cli/main.js +379 -0
  69. package/target/main/ts/cli/reporting.d.ts +18 -0
  70. package/target/main/ts/cli/reporting.js +104 -0
  71. package/target/main/ts/cli/revisions.d.ts +6 -0
  72. package/target/main/ts/cli/revisions.js +16 -0
  73. package/target/main/ts/cli/store.d.ts +13 -0
  74. package/target/main/ts/cli/store.js +39 -0
  75. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  76. package/target/main/ts/compose/analyze-snapshot.js +164 -0
  77. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  78. package/target/main/ts/compose/attach-churn.js +50 -0
  79. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  80. package/target/main/ts/compose/diff-coverage.js +57 -0
  81. package/target/main/ts/compose/inspect.d.ts +23 -0
  82. package/target/main/ts/compose/inspect.js +45 -0
  83. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  84. package/target/main/ts/compose/plugin-list.js +10 -0
  85. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  86. package/target/main/ts/compose/prepare-metabranch.js +17 -0
  87. package/target/main/ts/compose/review.d.ts +16 -0
  88. package/target/main/ts/compose/review.js +39 -0
  89. package/target/main/ts/compose/sources.d.ts +3 -0
  90. package/target/main/ts/compose/sources.js +30 -0
  91. package/target/main/ts/core/engine/execute.d.ts +10 -0
  92. package/target/main/ts/core/engine/execute.js +50 -0
  93. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  94. package/target/main/ts/core/engine/manifest.js +105 -0
  95. package/target/main/ts/core/engine/plan.d.ts +22 -0
  96. package/target/main/ts/core/engine/plan.js +107 -0
  97. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  98. package/target/main/ts/core/engine/plugin.js +4 -0
  99. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  100. package/target/main/ts/core/engine/report-products.js +86 -0
  101. package/target/main/ts/core/model/changes.d.ts +8 -0
  102. package/target/main/ts/core/model/changes.js +2 -0
  103. package/target/main/ts/core/model/churn.d.ts +11 -0
  104. package/target/main/ts/core/model/churn.js +5 -0
  105. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  106. package/target/main/ts/core/model/clone-source.js +15 -0
  107. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  108. package/target/main/ts/core/model/code-structure.js +32 -0
  109. package/target/main/ts/core/model/comparison.d.ts +24 -0
  110. package/target/main/ts/core/model/comparison.js +1 -0
  111. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  112. package/target/main/ts/core/model/diff-coverage.js +1 -0
  113. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  114. package/target/main/ts/core/model/finding-ignore.js +36 -0
  115. package/target/main/ts/core/model/finding.d.ts +28 -0
  116. package/target/main/ts/core/model/finding.js +29 -0
  117. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  118. package/target/main/ts/core/model/ignore-rule.js +1 -0
  119. package/target/main/ts/core/model/measurement.d.ts +33 -0
  120. package/target/main/ts/core/model/measurement.js +30 -0
  121. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  122. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  123. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  124. package/target/main/ts/core/model/plugin-data.js +1 -0
  125. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  126. package/target/main/ts/core/model/pull-review.js +1 -0
  127. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  128. package/target/main/ts/core/model/quality-summary.js +64 -0
  129. package/target/main/ts/core/model/report.d.ts +40 -0
  130. package/target/main/ts/core/model/report.js +5 -0
  131. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  132. package/target/main/ts/core/model/scanner-import.js +29 -0
  133. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  134. package/target/main/ts/core/model/snapshot.js +51 -0
  135. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  136. package/target/main/ts/core/model/source-locator.js +1 -0
  137. package/target/main/ts/core/model/source.d.ts +23 -0
  138. package/target/main/ts/core/model/source.js +1 -0
  139. package/target/main/ts/core/ports/report.d.ts +9 -0
  140. package/target/main/ts/core/ports/report.js +2 -0
  141. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  142. package/target/main/ts/core/ports/source-provider.js +5 -0
  143. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  144. package/target/main/ts/core/profile/exclusions.js +58 -0
  145. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  146. package/target/main/ts/core/profile/maintainability.js +10 -0
  147. package/target/main/ts/core/profile/profile.d.ts +4 -0
  148. package/target/main/ts/core/profile/profile.js +11 -0
  149. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  150. package/target/main/ts/core/usecases/compare.js +146 -0
  151. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  152. package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
  153. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  154. package/target/main/ts/core/usecases/diff-coverage.js +16 -0
  155. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  156. package/target/main/ts/core/usecases/inspect.js +42 -0
  157. package/target/main/ts/core/usecases/review.d.ts +31 -0
  158. package/target/main/ts/core/usecases/review.js +129 -0
  159. package/target/main/ts/index.d.ts +35 -0
  160. package/target/main/ts/index.js +18 -0
  161. package/target/main/ts/plugin.d.ts +14 -0
  162. package/target/main/ts/plugin.js +6 -0
  163. package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
  164. package/target/main/ts/plugins/coverage/coverage.js +199 -0
  165. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  166. package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
  167. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  168. package/target/main/ts/plugins/duplication/duplication.js +94 -0
  169. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  170. package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
  171. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  172. package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
  173. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  174. package/target/main/ts/plugins/language-js/code-lines.js +36 -0
  175. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  176. package/target/main/ts/plugins/language-js/function-facts.js +61 -0
  177. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  178. package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
  179. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  180. package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
  181. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  182. package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
  183. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  184. package/target/main/ts/plugins/source/forges.js +80 -0
  185. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  186. package/target/main/ts/plugins/structure/structure.js +38 -0
  187. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  188. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  189. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  190. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  191. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  192. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  193. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  194. package/target/main/ts/report/html/app/viewer-files.js +2104 -0
  195. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  196. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  197. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
  198. package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
  199. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  200. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  201. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  202. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  203. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  204. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  205. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  206. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  207. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  208. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  209. package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
  210. package/target/main/ts/report/html/app/viewer-trends.js +423 -0
  211. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  212. package/target/main/ts/report/html/app/viewer.js +735 -0
  213. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  214. package/target/main/ts/report/html/site/badges.js +40 -0
  215. package/target/main/ts/report/html/site/export-site.d.ts +22 -0
  216. package/target/main/ts/report/html/site/export-site.js +150 -0
  217. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  218. package/target/main/ts/report/html/site/exported-server.js +71 -0
  219. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  220. package/target/main/ts/report/html/site/local-server.js +65 -0
  221. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  222. package/target/main/ts/report/html/site/projects.js +80 -0
  223. package/target/main/ts/report/html/site/server.d.ts +4 -0
  224. package/target/main/ts/report/html/site/server.js +65 -0
  225. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  226. package/target/main/ts/report/html/site/source-route.js +23 -0
  227. package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
  228. package/target/main/ts/report/json/projections/commit-summary.js +124 -0
  229. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  230. package/target/main/ts/report/json/projections/components.js +30 -0
  231. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  232. package/target/main/ts/report/json/projections/file-metrics.js +244 -0
  233. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  234. package/target/main/ts/report/json/projections/inspection-context.js +93 -0
  235. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  236. package/target/main/ts/report/json/projections/inspection-details.js +70 -0
  237. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  238. package/target/main/ts/report/json/projections/metric-values.js +58 -0
  239. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  240. package/target/main/ts/report/json/projections/public-history.js +17 -0
  241. package/target/main/ts/report/json/store/components.d.ts +2 -0
  242. package/target/main/ts/report/json/store/components.js +32 -0
  243. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  244. package/target/main/ts/report/json/store/local-store.js +180 -0
  245. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  246. package/target/main/ts/report/json/store/pull-review-store.js +52 -0
  247. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  248. package/target/main/ts/report/json/validation/metabranch.js +8 -0
  249. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  250. package/target/main/ts/report/json/validation/report.js +65 -0
  251. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  252. package/target/main/ts/report/json/validation/summary-validation.js +28 -0
  253. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  254. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  255. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  256. package/target/main/ts/report/json/wire/component-model.js +1 -0
  257. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  258. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  259. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  260. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  261. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  262. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  263. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  264. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  265. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  266. package/target/main/ts/report/json/wire/project-model.js +1 -0
  267. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  268. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  269. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  270. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  271. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  272. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  273. package/target/main/ts/report.d.ts +11 -0
  274. package/target/main/ts/report.js +6 -0
@@ -0,0 +1,124 @@
1
+ import { isRecord } from '../../../core/engine/plugin.js';
2
+ import { definitions } from '../../../core/model/measurement.js';
3
+ import { qualitySummary } from '../../../core/model/quality-summary.js';
4
+ import { isSensitiveFinding } from '../../../core/model/finding.js';
5
+ import { findingImportMethods } from '../../../core/model/scanner-import.js';
6
+ import { compareHistoryEntries } from '../wire/public-history-model.js';
7
+ import { inspectionProfileDigest } from './inspection-context.js';
8
+ import { reportRevision } from '../validation/report.js';
9
+ import { metricProjection } from './metric-values.js';
10
+ import { summarySchema } from '../wire/summary-model.js';
11
+ export function commitSummary(report) {
12
+ const history = historyEntry(report);
13
+ const profileDigest = inspectionProfileDigest(report);
14
+ const metrics = metricProjection(report);
15
+ const tracksSecurity = findingImportMethods(report.appliedConfig.findingImports)
16
+ .some(({ category }) => isSensitiveFinding(category));
17
+ const security = tracksSecurity ? { low: 0, medium: 0, high: 0, unknown: 0 } : undefined;
18
+ if (security) {
19
+ for (const finding of report.findings ?? []) {
20
+ if (isSensitiveFinding(finding.category))
21
+ security[finding.level]++;
22
+ }
23
+ }
24
+ return {
25
+ ...history,
26
+ ...(report.commit === undefined ? {} : { subject: report.commit.subject, author: report.commit.author }),
27
+ revision: reportRevision(report),
28
+ ...(profileDigest === undefined ? {} : { profileDigest }),
29
+ quality: qualitySummary(report),
30
+ counts: {
31
+ findingCount: report.findings?.length ?? 0,
32
+ diagnosticCount: report.diagnostics.length,
33
+ componentCount: 0,
34
+ hasCoverage: history.lineCoverage !== null,
35
+ ...(security ? { security } : {}),
36
+ },
37
+ ...(metrics === undefined ? {} : { metrics: metrics.catalog, values: metrics.values(),
38
+ ...(metrics.privateMetrics === undefined ? {} : { privateMetrics: metrics.privateMetrics }) }),
39
+ };
40
+ }
41
+ export function orderSummaries(rows) {
42
+ return [...rows].sort(compareHistoryEntries);
43
+ }
44
+ /** Values recorded at analysis win; Git fills in older inspections and adds tags, which can land after analysis. */
45
+ export async function withCommitMetadata(rows, read) {
46
+ if (!read || !rows.length)
47
+ return rows;
48
+ const metadata = await read(rows.map(row => row.sha));
49
+ return rows.map(row => {
50
+ const found = metadata.get(row.sha);
51
+ return found === undefined ? row : { ...found, ...row, ...(found.tags === undefined ? {} : { tags: found.tags }) };
52
+ });
53
+ }
54
+ export function expandSummaryCatalog(summary) {
55
+ return orderSummaries(summary.commits).map(row => summary.metrics === undefined || row.values === undefined ? row
56
+ : { ...row, metrics: summary.metrics, ...(summary.privateMetrics === undefined ? {} : { privateMetrics: summary.privateMetrics }) });
57
+ }
58
+ export function repositorySummary(rows, pullReviewCount, includePrivateMetrics = true) {
59
+ const ordered = orderSummaries(rows);
60
+ const privateMetrics = new Set(ordered.flatMap(row => row.privateMetrics ?? []));
61
+ const catalog = new Map();
62
+ for (const row of ordered) {
63
+ for (const metric of row.metrics ?? []) {
64
+ if ((includePrivateMetrics || !privateMetrics.has(metric.id)) && !catalog.has(metric.id))
65
+ catalog.set(metric.id, metric);
66
+ }
67
+ }
68
+ const metrics = [...catalog.values()];
69
+ const positions = new Map(metrics.map(({ id }, index) => [id, index]));
70
+ const commits = ordered.map(({ metrics: local, values, privateMetrics: _private, ...row }) => {
71
+ if (!local || !values)
72
+ return row;
73
+ const mapped = {};
74
+ for (const [index, value] of Object.entries(values)) {
75
+ const id = local[Number(index)]?.id;
76
+ const position = id === undefined ? undefined : positions.get(id);
77
+ if (position !== undefined)
78
+ mapped[position] = value;
79
+ }
80
+ return Object.keys(mapped).length ? { ...row, values: mapped } : row;
81
+ });
82
+ return {
83
+ schema: summarySchema,
84
+ commits,
85
+ ...(metrics.length ? { metrics } : {}),
86
+ ...(includePrivateMetrics && privateMetrics.size ? { privateMetrics: [...privateMetrics] } : {}),
87
+ ...(pullReviewCount === undefined ? {} : { pullReviewCount }),
88
+ };
89
+ }
90
+ export function historyEntry(report) {
91
+ let lines = null;
92
+ let functions = null;
93
+ let maxComplexity = null;
94
+ let lineCoverage = null;
95
+ for (const item of report.measurements) {
96
+ if (item.value === null || item.value < 0)
97
+ continue;
98
+ if (item.target === 'file' && Number.isSafeInteger(item.value)) {
99
+ if (item.definition === definitions.lines)
100
+ lines = (lines ?? 0) + item.value;
101
+ if (item.definition === definitions.functions)
102
+ functions = (functions ?? 0) + item.value;
103
+ }
104
+ if (item.target === 'function' && item.definition === definitions.complexity && Number.isSafeInteger(item.value)) {
105
+ maxComplexity = Math.max(maxComplexity ?? 0, item.value);
106
+ }
107
+ if (item.target === 'repository' && item.definition === definitions.coverage && item.covered !== undefined && item.total !== undefined && item.total > 0) {
108
+ lineCoverage = { covered: item.covered, total: item.total };
109
+ }
110
+ }
111
+ const committedAt = commitTime(report);
112
+ const generatedAt = Date.parse(report.generatedAt);
113
+ return { sha: report.subject.id, generatedAt: Number.isFinite(generatedAt) ? new Date(generatedAt).toISOString() : '',
114
+ ...(committedAt === null ? {} : { committedAt }), status: report.status,
115
+ files: report.scope.files, parsed: report.scope.parsed, lines, functions, maxComplexity, lineCoverage };
116
+ }
117
+ /** Earlier reports only recorded the committer time in the churn window. */
118
+ function commitTime(report) {
119
+ const window = report.appliedConfig.churnWindow;
120
+ const legacy = isRecord(window) && typeof window.endingAt === 'string' ? window.endingAt : '';
121
+ const time = Date.parse(report.committedAt ?? legacy);
122
+ return Number.isFinite(time) ? new Date(time).toISOString() : null;
123
+ }
124
+ //# sourceMappingURL=commit-summary.js.map
@@ -0,0 +1,4 @@
1
+ import type { FileMetricsReport } from './file-metrics.js';
2
+ import type { Component, ComponentMetrics } from '../wire/component-model.js';
3
+ export type { Component, ComponentMetrics } from '../wire/component-model.js';
4
+ export declare function componentFiles(components: readonly Component[], metrics: FileMetricsReport): readonly ComponentMetrics[];
@@ -0,0 +1,30 @@
1
+ export function componentFiles(components, metrics) {
2
+ return components.map(component => {
3
+ const matchers = component.pathGlobs.map(matcher);
4
+ return { component, paths: metrics.files.filter(({ path }) => matchers.some(match => match(path))).map(({ path }) => path) };
5
+ });
6
+ }
7
+ function matcher(pattern) {
8
+ const parts = pattern.split(/\*+/);
9
+ if (parts.length === 1)
10
+ return path => path === pattern;
11
+ const first = parts[0];
12
+ const last = parts[parts.length - 1];
13
+ const middle = parts.slice(1, -1);
14
+ return path => {
15
+ if (!path.startsWith(first) || !path.endsWith(last))
16
+ return false;
17
+ const limit = path.length - last.length;
18
+ let position = first.length;
19
+ if (position > limit)
20
+ return false;
21
+ for (const part of middle) {
22
+ const found = path.indexOf(part, position);
23
+ if (found < 0 || found + part.length > limit)
24
+ return false;
25
+ position = found + part.length;
26
+ }
27
+ return true;
28
+ };
29
+ }
30
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1,5 @@
1
+ import type { Report } from '../validation/report.js';
2
+ import type { FileMetricsReport } from '../wire/file-metrics-model.js';
3
+ export { fileMetricsSchema } from '../wire/file-metrics-model.js';
4
+ export type { FileMetricsReport } from '../wire/file-metrics-model.js';
5
+ export declare function fileMetrics(report: Report): FileMetricsReport;
@@ -0,0 +1,244 @@
1
+ import { isRecord } from '../../../core/engine/plugin.js';
2
+ import { definitions } from '../../../core/model/measurement.js';
3
+ import { comparePaths } from '../../../core/model/snapshot.js';
4
+ import { metricProjection } from './metric-values.js';
5
+ import { fileMetricsSchema } from '../wire/file-metrics-model.js';
6
+ export { fileMetricsSchema } from '../wire/file-metrics-model.js';
7
+ export function fileMetrics(report) {
8
+ const byPath = new Map();
9
+ const duplicatedLines = new Map();
10
+ const pluginMetrics = metricProjection(report);
11
+ const languages = [];
12
+ const languageIndexes = new Map();
13
+ function file(path) {
14
+ const existing = byPath.get(path);
15
+ if (existing)
16
+ return existing;
17
+ const metrics = emptyMetrics(path);
18
+ byPath.set(path, metrics);
19
+ return metrics;
20
+ }
21
+ for (const { path, lines, bytes, language, analysed } of report.pluginData?.inventory ?? []) {
22
+ let index = languageIndexes.get(language);
23
+ if (index === undefined) {
24
+ index = languages.length;
25
+ languageIndexes.set(language, index);
26
+ languages.push({ id: language, analysed });
27
+ }
28
+ else if (analysed) {
29
+ languages[index].analysed = true;
30
+ }
31
+ const entry = file(path);
32
+ entry.lines = lines;
33
+ if (bytes !== undefined)
34
+ entry.bytes = bytes;
35
+ entry.language = index;
36
+ entry.analysed = analysed;
37
+ }
38
+ for (const row of report.measurements) {
39
+ if (!row.path)
40
+ continue;
41
+ if (pluginMetrics)
42
+ file(row.path);
43
+ if (row.target === 'file' && row.definition === definitions.coverage && row.covered !== undefined && row.total !== undefined) {
44
+ file(row.path).lineCoverage = { covered: row.covered, total: row.total };
45
+ }
46
+ if (row.value === null || !Number.isSafeInteger(row.value) || row.value < 0)
47
+ continue;
48
+ if (row.target === 'file' && row.definition === definitions.lines)
49
+ file(row.path).lines = row.value;
50
+ if (row.target === 'file' && row.definition === definitions.functions)
51
+ file(row.path).functions = row.value;
52
+ if (row.target === 'file') {
53
+ switch (row.definition) {
54
+ case definitions.codeLines:
55
+ quality(file(row.path)).codeLines = row.value;
56
+ break;
57
+ case definitions.comments:
58
+ quality(file(row.path)).commentLines = row.value;
59
+ break;
60
+ case definitions.classes:
61
+ quality(file(row.path)).classes = row.value;
62
+ break;
63
+ case definitions.cognitiveComplexity:
64
+ quality(file(row.path)).cognitiveComplexity = row.value;
65
+ break;
66
+ case definitions.churn:
67
+ quality(file(row.path)).churn = row.value;
68
+ break;
69
+ case definitions.duplicatedLines:
70
+ duplicatedLines.set(row.path, row.value);
71
+ break;
72
+ }
73
+ }
74
+ if (row.target === 'function' && row.definition === definitions.complexity) {
75
+ const target = file(row.path);
76
+ target.complexity = addComplexity(target.complexity, { sum: row.value, maximum: row.value, measuredFunctions: 1 });
77
+ }
78
+ }
79
+ for (const [path, duplicateCount] of duplicatedLines) {
80
+ const entry = byPath.get(path);
81
+ const codeLines = entry?.quality?.codeLines;
82
+ if (entry && codeLines !== undefined && duplicateCount <= codeLines) {
83
+ quality(entry).duplication = { duplicatedLines: duplicateCount, codeLines };
84
+ }
85
+ }
86
+ if (report.findings !== undefined) {
87
+ for (const entry of byPath.values()) {
88
+ if (entry.quality?.duplication)
89
+ entry.quality.maintainability = { smells: 0, effortMinutes: 0 };
90
+ }
91
+ for (const finding of report.findings) {
92
+ if (!finding.path || (finding.category !== 'structure' && finding.category !== 'duplication'))
93
+ continue;
94
+ const observations = byPath.get(finding.path)?.quality;
95
+ if (!observations?.maintainability)
96
+ continue;
97
+ observations.maintainability = addMaintainability(observations.maintainability, {
98
+ smells: 1, effortMinutes: finding.effortMinutes ?? null,
99
+ });
100
+ }
101
+ }
102
+ let unassignedDiagnostics = 0;
103
+ for (const diagnostic of report.diagnostics) {
104
+ const { path, operation } = diagnostic;
105
+ const target = path === undefined ? undefined
106
+ : operation === 'babel-syntax/parse' || operation.startsWith('structure/') ? file(path) : byPath.get(path);
107
+ if (target)
108
+ target.diagnosticCount++;
109
+ else
110
+ unassignedDiagnostics++;
111
+ }
112
+ const files = [...byPath.values()].sort(byName);
113
+ const directories = new Map();
114
+ for (const entry of files) {
115
+ if (pluginMetrics && entry.analysed !== false) {
116
+ const values = pluginMetrics.values(entry.path);
117
+ if (Object.keys(values).length)
118
+ entry.values = values;
119
+ }
120
+ if (entry.functions === 0 && !entry.complexity) {
121
+ entry.complexity = { sum: 0, maximum: null, measuredFunctions: 0 };
122
+ }
123
+ let path = entry.path;
124
+ do {
125
+ path = path.slice(0, Math.max(0, path.lastIndexOf('/')));
126
+ let directory = directories.get(path);
127
+ if (!directory) {
128
+ directory = { ...emptyMetrics(path), files: 0, sizeMeasuredFiles: 0, coverageMeasuredFiles: 0 };
129
+ directories.set(path, directory);
130
+ }
131
+ addFile(directory, entry);
132
+ } while (path !== '');
133
+ }
134
+ if (pluginMetrics) {
135
+ for (const entry of directories.values()) {
136
+ const values = pluginMetrics.values(entry.path, true);
137
+ if (Object.keys(values).length)
138
+ entry.values = values;
139
+ }
140
+ }
141
+ const complexity = files.filter(entry => entry.complexity?.maximum != null)
142
+ .sort((left, right) => right.complexity.maximum - left.complexity.maximum
143
+ || right.complexity.sum - left.complexity.sum || byName(left, right));
144
+ const coverage = files.filter(entry => missedLines(entry) > 0)
145
+ .sort((left, right) => missedLines(right) - missedLines(left) || byName(left, right));
146
+ const cognitive = ranked(files, entry => entry.quality?.cognitiveComplexity);
147
+ const duplication = ranked(files, entry => entry.quality?.duplication?.duplicatedLines);
148
+ const churn = ranked(files, entry => entry.quality?.churn);
149
+ const churnWindow = readChurnWindow(report.appliedConfig);
150
+ return { schema: fileMetricsSchema, subject: report.subject, generatedAt: report.generatedAt,
151
+ status: report.status, scope: report.scope, files, directories: [...directories.values()].sort(byName), unassignedDiagnostics,
152
+ ...(pluginMetrics === undefined ? {} : { catalog: pluginMetrics.catalog }),
153
+ ...(languages.length === 0 ? {} : { languages }),
154
+ ...(churnWindow === undefined ? {} : { churnWindow }),
155
+ hotspots: { complexity: complexity.map(entry => entry.path), missedLines: coverage.map(entry => entry.path),
156
+ ...(cognitive === undefined ? {} : { cognitive }), ...(duplication === undefined ? {} : { duplication }),
157
+ ...(churn === undefined ? {} : { churn }) } };
158
+ }
159
+ function emptyMetrics(path) {
160
+ return { path, lines: null, functions: null, complexity: null, lineCoverage: null, diagnosticCount: 0 };
161
+ }
162
+ function byName(left, right) {
163
+ return comparePaths(left.path, right.path);
164
+ }
165
+ function addFile(directory, file) {
166
+ directory.files++;
167
+ if (file.lines !== null)
168
+ directory.sizeMeasuredFiles++;
169
+ directory.lines = sumKnown(directory.lines, file.lines);
170
+ if (file.bytes !== undefined)
171
+ directory.bytes = (directory.bytes ?? 0) + file.bytes;
172
+ directory.functions = sumKnown(directory.functions, file.functions);
173
+ directory.complexity = addComplexity(directory.complexity, file.complexity);
174
+ if (file.lineCoverage) {
175
+ directory.coverageMeasuredFiles++;
176
+ directory.lineCoverage = {
177
+ covered: (directory.lineCoverage?.covered ?? 0) + file.lineCoverage.covered,
178
+ total: (directory.lineCoverage?.total ?? 0) + file.lineCoverage.total,
179
+ };
180
+ }
181
+ directory.diagnosticCount += file.diagnosticCount;
182
+ if (file.quality)
183
+ addQuality(quality(directory), file.quality);
184
+ }
185
+ function quality(entry) {
186
+ return entry.quality ??= {};
187
+ }
188
+ function addQuality(target, source) {
189
+ for (const key of ['codeLines', 'commentLines', 'classes', 'cognitiveComplexity', 'churn']) {
190
+ const value = source[key];
191
+ if (value !== undefined)
192
+ target[key] = (target[key] ?? 0) + value;
193
+ }
194
+ if (source.duplication) {
195
+ target.duplication = {
196
+ duplicatedLines: (target.duplication?.duplicatedLines ?? 0) + source.duplication.duplicatedLines,
197
+ codeLines: (target.duplication?.codeLines ?? 0) + source.duplication.codeLines,
198
+ };
199
+ }
200
+ if (source.maintainability) {
201
+ target.maintainability = addMaintainability(target.maintainability ?? { smells: 0, effortMinutes: 0 }, source.maintainability);
202
+ }
203
+ }
204
+ function readChurnWindow(config) {
205
+ const { churn, churnWindow } = config;
206
+ if (!isRecord(churn) || !isRecord(churnWindow))
207
+ return undefined;
208
+ const { lookbackDays, maxCommits } = churn;
209
+ const { endingAt, commits, shallow, capReached } = churnWindow;
210
+ if (typeof lookbackDays !== 'number' || !Number.isSafeInteger(lookbackDays) || lookbackDays < 1
211
+ || typeof maxCommits !== 'number' || !Number.isSafeInteger(maxCommits) || maxCommits < 1
212
+ || typeof commits !== 'number' || !Number.isSafeInteger(commits) || commits < 0 || commits > maxCommits
213
+ || typeof endingAt !== 'string' || !Number.isFinite(Date.parse(endingAt))
214
+ || typeof shallow !== 'boolean' || typeof capReached !== 'boolean')
215
+ return undefined;
216
+ return { lookbackDays, maxCommits, endingAt, commits, shallow, capReached };
217
+ }
218
+ function addMaintainability(left, right) {
219
+ return { smells: left.smells + right.smells, effortMinutes: left.effortMinutes === null || right.effortMinutes === null
220
+ ? null : left.effortMinutes + right.effortMinutes };
221
+ }
222
+ function ranked(files, score) {
223
+ const entries = files.flatMap(entry => {
224
+ const value = score(entry);
225
+ return value === undefined ? [] : [{ entry, value }];
226
+ });
227
+ if (entries.length === 0)
228
+ return undefined;
229
+ return entries.filter(({ value }) => value > 0).sort((left, right) => right.value - left.value || byName(left.entry, right.entry))
230
+ .map(({ entry }) => entry.path);
231
+ }
232
+ function sumKnown(left, right) {
233
+ return right === null ? left : (left ?? 0) + right;
234
+ }
235
+ function addComplexity(left, right) {
236
+ if (!left || !right)
237
+ return left ?? right;
238
+ const maximum = left.maximum === null ? right.maximum : Math.max(left.maximum, right.maximum ?? left.maximum);
239
+ return { sum: left.sum + right.sum, maximum, measuredFunctions: left.measuredFunctions + right.measuredFunctions };
240
+ }
241
+ function missedLines(entry) {
242
+ return entry.lineCoverage ? entry.lineCoverage.total - entry.lineCoverage.covered : 0;
243
+ }
244
+ //# sourceMappingURL=file-metrics.js.map
@@ -0,0 +1,6 @@
1
+ import type { Report } from '../validation/report.js';
2
+ import type { InspectionContext } from '../wire/inspection-context-model.js';
3
+ export type { InspectionContext, ProfileBoundary, SourceExclusions } from '../wire/inspection-context-model.js';
4
+ export declare function inspectionProfileDigest(report: Report): string | undefined;
5
+ /** Reports arrive in the same newest-first order as the public history. */
6
+ export declare function inspectionHistory(reports: readonly Report[]): Record<string, InspectionContext>;
@@ -0,0 +1,93 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { isRecord } from '../../../core/engine/plugin.js';
3
+ import { isSensitiveFinding } from '../../../core/model/finding.js';
4
+ import { findingImportMethods } from '../../../core/model/scanner-import.js';
5
+ import { normalizeFindingIgnore } from '../../../core/model/finding-ignore.js';
6
+ import { comparePaths, digest } from '../../../core/model/snapshot.js';
7
+ export function inspectionProfileDigest(report) {
8
+ const profile = readProfile(report.appliedConfig);
9
+ return profile ? digest(JSON.stringify(profile.settings, (_key, value) => isRecord(value)
10
+ ? Object.fromEntries(Object.entries(value).sort(([a], [b]) => comparePaths(a, b))) : value)) : undefined;
11
+ }
12
+ /** Reports arrive in the same newest-first order as the public history. */
13
+ export function inspectionHistory(reports) {
14
+ const entries = reports.filter(report => report.subject.kind === 'commit')
15
+ .map(report => ({ report, profile: readProfile(report.appliedConfig) }));
16
+ return Object.fromEntries(entries.map(({ report, profile }, index) => {
17
+ const previous = entries[index + 1];
18
+ let boundary = null;
19
+ if (previous) {
20
+ if (!profile || !previous.profile)
21
+ boundary = 'unavailable';
22
+ else if (!isDeepStrictEqual(profile.settings, previous.profile.settings))
23
+ boundary = 'changed';
24
+ }
25
+ const context = {
26
+ exclusions: profile?.exclusions ?? null,
27
+ boundary,
28
+ ...scannerContext(report),
29
+ ...ignoreContext(report),
30
+ };
31
+ return [report.subject.id, context];
32
+ }));
33
+ }
34
+ function ignoreContext(report) {
35
+ if (report.appliedConfig.findingIgnore === undefined)
36
+ return {};
37
+ try {
38
+ const rules = normalizeFindingIgnore(report.appliedConfig.findingIgnore);
39
+ return { ignores: { rules, count: report.ignoredFindings?.length ?? 0 } };
40
+ }
41
+ catch {
42
+ return {};
43
+ }
44
+ }
45
+ function scannerContext(report) {
46
+ const methods = findingImportMethods(report.appliedConfig.findingImports);
47
+ if (!methods.length)
48
+ return {};
49
+ const scanners = [...new Map(methods.flatMap(({ tools }) => tools.map(tool => [JSON.stringify(tool), tool]))).values()];
50
+ const security = methods.some(({ category }) => isSensitiveFinding(category))
51
+ ? { low: 0, medium: 0, high: 0, unknown: 0 } : undefined;
52
+ if (security) {
53
+ for (const finding of report.findings ?? []) {
54
+ if (isSensitiveFinding(finding.category))
55
+ security[finding.level]++;
56
+ }
57
+ }
58
+ return security ? { scanners, security } : { scanners };
59
+ }
60
+ function readProfile(config) {
61
+ const source = config.source;
62
+ if (!isRecord(source))
63
+ return null;
64
+ // The original JS/TS profile recorded directory exclusions before path rules existed.
65
+ const recordedPaths = config.profile === 'js-ts/v1' && source.excludedPaths === undefined ? [] : source.excludedPaths;
66
+ const paths = stringList(recordedPaths);
67
+ const directories = stringList(source.excludedDirectories);
68
+ if (!paths || !directories)
69
+ return null;
70
+ const extensions = stringList(source.extensions);
71
+ let coverage = config.coverage;
72
+ if (isRecord(coverage)) {
73
+ const { inputDigest, inputDigests, pathBase, ...settings } = coverage;
74
+ coverage = settings;
75
+ }
76
+ const { churnWindow, ...settings } = config;
77
+ // The policy is stable across commits; its matched paths describe this snapshot alone.
78
+ const { generatedExcluded, ...sourceSettings } = source;
79
+ return {
80
+ exclusions: { paths: [...new Set([...(stringList(source.defaultExclusions) ?? []), ...paths, ...(stringList(generatedExcluded) ?? [])])], directories },
81
+ settings: { ...settings, coverage, findingImports: findingImportMethods(config.findingImports), source: { ...sourceSettings,
82
+ extensions: extensions ? ordered(extensions) : source.extensions,
83
+ excludedPaths: ordered(paths), excludedDirectories: ordered(directories),
84
+ } },
85
+ };
86
+ }
87
+ function stringList(value) {
88
+ return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : null;
89
+ }
90
+ function ordered(values) {
91
+ return [...new Set(values)].sort(comparePaths);
92
+ }
93
+ //# sourceMappingURL=inspection-context.js.map
@@ -0,0 +1,11 @@
1
+ import type { Report } from '../validation/report.js';
2
+ import type { InspectionContext } from './inspection-context.js';
3
+ import type { ComplexFunction } from '../wire/public-history-model.js';
4
+ import type { Component } from './components.js';
5
+ import type { InspectionAsset, InspectionDetails, ProfileSettings } from '../wire/inspection-details-model.js';
6
+ export type { DetailsBundle, InspectionAsset, InspectionDetails, ProfileSettings } from '../wire/inspection-details-model.js';
7
+ export declare function inspectionAsset(report: Report, components: readonly Component[] | undefined, context?: InspectionContext | undefined): InspectionAsset;
8
+ export declare function inspectionDetails(report: Report, components?: readonly Component[]): InspectionDetails;
9
+ /** The applied configuration, field by field; whatever is missing or malformed is left out rather than guessed. */
10
+ export declare function profileSettings(applied: unknown): ProfileSettings | undefined;
11
+ export declare function complexFunctions(report: Report): readonly ComplexFunction[];
@@ -0,0 +1,70 @@
1
+ import { definitions } from '../../../core/model/measurement.js';
2
+ import { comparePaths } from '../../../core/model/snapshot.js';
3
+ import { fileMetrics } from './file-metrics.js';
4
+ import { inspectionHistory } from './inspection-context.js';
5
+ import { componentFiles } from './components.js';
6
+ export function inspectionAsset(report, components, context = inspectionHistory([report])[report.subject.id]) {
7
+ return { schema: 'urn:repometry:schema:viewer-inspection:1', sha: report.subject.id,
8
+ context, inspection: inspectionDetails(report, components) };
9
+ }
10
+ export function inspectionDetails(report, components = []) {
11
+ const metrics = fileMetrics(report);
12
+ const profile = profileSettings(report.appliedConfig);
13
+ const ruleCatalog = report.pluginData?.rules.flatMap(({ plugin, rules }) => rules.map(rule => ({
14
+ source: plugin, kind: 'check', rule: rule.id, category: rule.category,
15
+ ...(rule.description === undefined ? {} : { title: rule.description }),
16
+ ...(rule.defaults?.limit === undefined ? {} : { limit: rule.defaults.limit }),
17
+ ...(rule.defaults?.cost === undefined ? {} : { minutesPerExcess: rule.defaults.cost }),
18
+ })));
19
+ return { metrics, functions: complexFunctions(report), diagnostics: report.diagnostics, findings: report.findings,
20
+ components: components.length ? componentFiles(components, metrics) : undefined,
21
+ ...(profile ? { profile: { ...profile, ...(ruleCatalog?.length ? { ruleCatalog } : {}) } } : {}) };
22
+ }
23
+ /** The applied configuration, field by field; whatever is missing or malformed is left out rather than guessed. */
24
+ export function profileSettings(applied) {
25
+ if (!record(applied))
26
+ return undefined;
27
+ const source = record(applied.source) ? applied.source : {};
28
+ const maintainability = record(applied.maintainability) ? applied.maintainability : {};
29
+ const rules = record(maintainability.structuralRules) ? Object.entries(maintainability.structuralRules).flatMap(([rule, value]) => record(value) && finite(value.limit) && finite(value.minutesPerExcess)
30
+ ? [{ plugin: 'maintainability', rule, limit: value.limit, minutesPerExcess: value.minutesPerExcess }] : []) : [];
31
+ const duplication = maintainability.duplication;
32
+ const model = maintainability.debtModel;
33
+ const churn = applied.churn;
34
+ return {
35
+ id: typeof applied.profile === 'string' ? applied.profile : null,
36
+ extensions: strings(source.extensions),
37
+ excludedPaths: [...new Set([...strings(source.defaultExclusions), ...strings(source.excludedPaths), ...strings(source.generatedExcluded)])],
38
+ excludedDirectories: strings(source.excludedDirectories),
39
+ rules,
40
+ duplication: record(duplication) && finite(duplication.minCodeLines) && finite(duplication.minNodes) && finite(duplication.minutesPerRepeatedLine)
41
+ ? { minCodeLines: duplication.minCodeLines, minNodes: duplication.minNodes, minutesPerRepeatedLine: duplication.minutesPerRepeatedLine } : null,
42
+ debtModel: record(model) && typeof model.name === 'string' && finite(model.scale) && finite(model.exponent) && finite(model.minutesPerPersonMonth)
43
+ ? { name: model.name, scale: model.scale, exponent: model.exponent, minutesPerPersonMonth: model.minutesPerPersonMonth } : null,
44
+ churn: record(churn) && finite(churn.lookbackDays) && finite(churn.maxCommits) ? { lookbackDays: churn.lookbackDays, maxCommits: churn.maxCommits } : null,
45
+ ignore: Array.isArray(applied.findingIgnore) ? applied.findingIgnore.flatMap(entry => record(entry) ? [Object.fromEntries(['tool', 'rule', 'path', 'reason'].flatMap(key => typeof entry[key] === 'string' ? [[key, entry[key]]] : []))] : []) : [],
46
+ analyzers: Array.isArray(applied.plugins) ? applied.plugins.flatMap(plugin => record(plugin) && typeof plugin.id === 'string' && typeof plugin.version === 'string'
47
+ ? [{ id: plugin.id, version: plugin.version, tools: record(plugin.tools)
48
+ ? Object.fromEntries(Object.entries(plugin.tools).filter((entry) => typeof entry[1] === 'string')) : {} }] : []) : [],
49
+ };
50
+ }
51
+ function record(value) {
52
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
53
+ }
54
+ function finite(value) {
55
+ return typeof value === 'number' && Number.isFinite(value);
56
+ }
57
+ function strings(value) {
58
+ return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
59
+ }
60
+ export function complexFunctions(report) {
61
+ const functions = [];
62
+ for (const row of report.measurements) {
63
+ if (row.definition === definitions.complexity && row.target === 'function' && row.path !== undefined && row.value !== null) {
64
+ functions.push({ name: row.name ?? '(anonymous)', path: row.path, line: row.line ?? null, complexity: row.value });
65
+ }
66
+ }
67
+ return functions.sort((left, right) => right.complexity - left.complexity
68
+ || comparePaths(left.path, right.path) || (left.line ?? 0) - (right.line ?? 0));
69
+ }
70
+ //# sourceMappingURL=inspection-details.js.map
@@ -0,0 +1,7 @@
1
+ import type { MetricDescriptor, MetricValues } from '../wire/summary-model.js';
2
+ import type { Report } from '../../../core/model/report.js';
3
+ export declare function metricProjection(report: Report): {
4
+ catalog: MetricDescriptor[];
5
+ privateMetrics: string[] | undefined;
6
+ values: (path?: string, directory?: boolean) => MetricValues;
7
+ } | undefined;
@@ -0,0 +1,58 @@
1
+ export function metricProjection(report) {
2
+ const metadata = report.pluginData;
3
+ if (!metadata?.metrics.length)
4
+ return undefined;
5
+ const measured = new Set(metadata.measured);
6
+ const metrics = metadata.metrics.filter(metric => measured.has(metric.id));
7
+ if (metrics.length === 0)
8
+ return undefined;
9
+ const rows = new Map();
10
+ for (const row of report.measurements) {
11
+ const existing = rows.get(row.definition);
12
+ if (existing)
13
+ existing.push(row);
14
+ else
15
+ rows.set(row.definition, [row]);
16
+ }
17
+ function values(path, directory = false) {
18
+ const result = {};
19
+ for (const [index, metric] of metrics.entries()) {
20
+ if (path !== undefined && metric.scope === 'repository')
21
+ continue;
22
+ const rowValues = (id) => rows.get(id) ?? [];
23
+ let value;
24
+ if (metric.ratio) {
25
+ const numerator = rollup(rowValues(metric.ratio.of), 'sum', path, directory);
26
+ const denominator = rollup(rowValues(metric.ratio.over), 'sum', path, directory);
27
+ value = denominator && numerator !== null ? numerator / denominator : null;
28
+ }
29
+ else {
30
+ value = rollup(rowValues(metric.id), metric.aggregate, path, directory);
31
+ }
32
+ if (path === undefined || value !== 0)
33
+ result[index] = value;
34
+ }
35
+ return result;
36
+ }
37
+ const privateMetrics = metadata.privateMetrics?.filter(id => measured.has(id));
38
+ return { catalog: metrics, privateMetrics: privateMetrics?.length ? privateMetrics : undefined, values };
39
+ }
40
+ function rollup(rows, aggregate, path, directory) {
41
+ if (path === undefined) {
42
+ const explicit = rows.find(row => row.target === 'repository');
43
+ if (explicit)
44
+ return explicit.value;
45
+ }
46
+ const candidates = rows.filter(row => row.path !== undefined && (path === undefined || (directory
47
+ ? path === '' || row.path.startsWith(path + '/') : row.path === path)));
48
+ // A file-level measurement already represents the function rows for that file.
49
+ const fileTotals = new Set(candidates.filter(row => row.target === 'file').map(row => row.path));
50
+ const selected = candidates.filter(row => row.target === 'file' || !fileTotals.has(row.path));
51
+ if (aggregate === 'none')
52
+ return path !== undefined && !directory && selected.length === 1 ? selected[0].value : null;
53
+ const values = selected.flatMap(row => row.value === null ? [] : [row.value]);
54
+ if (values.length === 0)
55
+ return selected.length === 0 && aggregate === 'sum' ? 0 : null;
56
+ return aggregate === 'sum' ? values.reduce((sum, value) => sum + value, 0) : values.reduce((max, value) => Math.max(max, value));
57
+ }
58
+ //# sourceMappingURL=metric-values.js.map