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,794 @@
1
+ import { loadViewerData, ViewerSummaryChanged } from './viewer-data.js';
2
+ import { band, bandLimits, codeSmellCategories, renderFileView, mapStub, renderSunburst, securityCategories } from './viewer-files.js';
3
+ import { count, difference, formatMetric, labelOf, metricValue, securityGrades, securityRisks, useCatalog } from './viewer-metrics.js';
4
+ import { charted, commitTime, isPeriod, stableWindow, isTrendView, renderSeries, renderTrendsPage, seriesPoints, trendLegend } from './viewer-trends.js';
5
+ import { createCommitPicker } from './viewer-commits.js';
6
+ import { renderProfile } from './viewer-profile.js';
7
+ import { loadSource, sourcePage, useSources } from './viewer-source.js';
8
+ import { renderDiffCoverageTrend, renderPulls } from './viewer-pulls.js';
9
+ import { isDetailed, pageAccess, publicNotice, unavailableTabs } from './viewer-access.js';
10
+ const percent = new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 });
11
+ const dateTime = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
12
+ /**
13
+ * Each quality area brings its own figures under the chart, and a second series drawn in grey behind the first:
14
+ * maintainability pairs the debt ratio with the remediation time, coverage pairs the ratio with the uncovered lines.
15
+ */
16
+ const areas = {
17
+ debt: { figures: ['debt', 'effort', 'duplication', 'complexity'] },
18
+ coverage: { figures: ['coverage', 'coverable-lines', 'covered-lines', 'uncovered-lines'] },
19
+ security: { figures: ['security', 'security-high', 'security-medium', 'security-low'] },
20
+ complexity: { figures: ['complexity', 'functions', 'cognitive', 'code-lines'] },
21
+ };
22
+ const pages = ['overview', 'metrics', 'hotspots', 'trends', 'issues', 'diagnostics', 'settings', 'pulls'];
23
+ const mode = document.querySelector('meta[name="repometry-view"]')?.content;
24
+ const detailed = isDetailed(mode);
25
+ const title = document.querySelector('meta[name="repometry-project"]')?.content.trim();
26
+ if (title) {
27
+ document.title = `${title} · Repometry`;
28
+ element('project-name').textContent = title;
29
+ }
30
+ document.querySelector('.skip')?.addEventListener('click', (event) => {
31
+ event.preventDefault();
32
+ element('main').focus();
33
+ });
34
+ const message = element('message');
35
+ try {
36
+ const data = await loadViewerData(mode);
37
+ if (data.reports.length === 0)
38
+ message.textContent = 'No commit inspections yet.';
39
+ else
40
+ start(data);
41
+ }
42
+ catch {
43
+ message.textContent = 'Could not load inspection history.';
44
+ }
45
+ function start({ reports, quality, context, counts, pullReviewCount, branch, metrics, sources, loadDetails }) {
46
+ useCatalog(metrics);
47
+ useSources(sources);
48
+ const first = reports[0];
49
+ const bySha = new Map(reports.map(report => [report.sha, report]));
50
+ const cached = new Map();
51
+ const pending = new Map();
52
+ function selectedDetails(sha) {
53
+ const existing = pending.get(sha);
54
+ if (existing)
55
+ return existing;
56
+ const request = loadDetails(sha).catch(error => {
57
+ if (error instanceof ViewerSummaryChanged && route().sha === sha)
58
+ location.reload();
59
+ return null;
60
+ }).then(asset => {
61
+ if (asset) {
62
+ cached.set(sha, asset.inspection);
63
+ if (asset.context)
64
+ context[sha] = { ...asset.context, boundary: context[sha]?.boundary ?? asset.context.boundary };
65
+ }
66
+ else
67
+ pending.delete(sha);
68
+ return asset;
69
+ });
70
+ pending.set(sha, request);
71
+ return request;
72
+ }
73
+ const verdicts = document.querySelectorAll('.verdict-tab');
74
+ const compact = window.matchMedia('(max-width: 43rem)');
75
+ const navLinks = document.querySelectorAll('#navigation a');
76
+ let pulls;
77
+ let revision = 0;
78
+ const commit = createCommitPicker(element('commit-control'), reports, sha => {
79
+ const { page, view, period } = route();
80
+ location.hash = href({ page, sha, view, period });
81
+ }, branch);
82
+ let chartMetric = reports.some(report => quality[report.sha]?.maintainability?.debtRatio != null) ? 'debt'
83
+ : reports.some(report => report.lineCoverage !== null) ? 'coverage' : 'complexity';
84
+ function selectVerdict() {
85
+ for (const verdict of verdicts) {
86
+ const selected = verdict.dataset.metric === chartMetric;
87
+ verdict.setAttribute('aria-selected', String(selected));
88
+ verdict.tabIndex = selected || (!verdicts.length) ? 0 : -1;
89
+ }
90
+ }
91
+ for (const verdict of verdicts) {
92
+ verdict.addEventListener('click', () => {
93
+ chartMetric = verdict.dataset.metric;
94
+ selectVerdict();
95
+ const { sha } = route();
96
+ renderTrend(trendData(), bySha.get(sha), chartMetric, compact.matches);
97
+ renderLead(reports, bySha.get(sha), quality, context, chartMetric, cached.get(sha));
98
+ const details = cached.get(sha);
99
+ if (details)
100
+ renderOverviewHotspots(details, sha, chartMetric, context[sha]?.security !== undefined);
101
+ });
102
+ verdict.addEventListener('keydown', event => {
103
+ if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft')
104
+ return;
105
+ const visible = [...verdicts].filter(item => !item.closest('.verdict').hidden);
106
+ const next = visible[(visible.indexOf(verdict) + (event.key === 'ArrowRight' ? 1 : -1) + visible.length) % visible.length];
107
+ next.focus();
108
+ next.click();
109
+ });
110
+ }
111
+ selectVerdict();
112
+ element('inspection-meta').hidden = false;
113
+ commit.hidden = false;
114
+ if (detailed) {
115
+ for (const item of document.querySelectorAll('[data-private]'))
116
+ item.hidden = false;
117
+ }
118
+ else {
119
+ // A public report keeps the sections of the full one in view: picking one says how to see it.
120
+ for (const page of unavailableTabs) {
121
+ const tab = document.querySelector(`#navigation a[data-page="${page}"]`);
122
+ if (!tab)
123
+ continue;
124
+ tab.hidden = false;
125
+ tab.dataset.unavailable = '';
126
+ const note = document.createElement('span');
127
+ note.className = 'visually-hidden';
128
+ note.textContent = ', not in the public report';
129
+ tab.append(note);
130
+ }
131
+ fillPanel(element('overview-public-content'));
132
+ element('overview-public').hidden = false;
133
+ }
134
+ function route() {
135
+ const [rawPage = '', query = ''] = location.hash.slice(1).split('?', 2);
136
+ if (bySha.has(rawPage))
137
+ return { page: 'overview', sha: rawPage };
138
+ const params = new URLSearchParams(query);
139
+ // Components became a grouping of Metrics; old links land there.
140
+ if (rawPage === 'components')
141
+ return { page: 'metrics', sha: bySha.get(params.get('sha') ?? '')?.sha ?? first.sha, group: 'components' };
142
+ const page = pages.find(candidate => candidate === rawPage);
143
+ return {
144
+ page: page ?? 'overview',
145
+ sha: bySha.get(params.get('sha') ?? '')?.sha ?? first.sha,
146
+ directory: params.get('dir') ?? undefined,
147
+ file: params.get('file') ?? undefined,
148
+ view: isTrendView(params.get('view')) ? params.get('view') : undefined,
149
+ period: isPeriod(params.get('period')) ? params.get('period') : undefined,
150
+ query: params.get('q') ?? undefined,
151
+ group: params.get('group') ?? undefined,
152
+ line: Number(params.get('line')) > 0 ? Number(params.get('line')) : undefined,
153
+ category: params.get('category') ?? undefined,
154
+ level: params.get('level') ?? undefined,
155
+ rank: params.get('rank') ?? undefined,
156
+ };
157
+ }
158
+ function loadPulls() {
159
+ pulls ??= readOptional('./pulls.json').then(bundle => bundle?.schema === 'urn:repometry:schema:pull-reviews:1' ? bundle.reviews : null);
160
+ return pulls;
161
+ }
162
+ function render() {
163
+ const current = route();
164
+ const version = ++revision;
165
+ const report = bySha.get(current.sha);
166
+ const inspection = context?.[current.sha];
167
+ const locked = pageAccess(current.page, detailed) === 'notice';
168
+ const previousPage = [...pages, 'unavailable'].find(page => !element(page).hidden);
169
+ const focusWasInPage = previousPage && element(previousPage).contains(document.activeElement);
170
+ commit.set(report.sha);
171
+ commit.hidden = current.page === 'pulls';
172
+ element('inspection-meta').hidden = current.page === 'pulls';
173
+ for (const page of pages)
174
+ element(page).hidden = locked || page !== current.page;
175
+ element('unavailable').hidden = !locked;
176
+ const shown = locked ? 'unavailable' : current.page;
177
+ if (previousPage && previousPage !== shown) {
178
+ window.scrollTo({ top: 0 });
179
+ if (focusWasInPage) {
180
+ const section = element(shown);
181
+ section.tabIndex = -1;
182
+ section.focus({ preventScroll: true });
183
+ }
184
+ }
185
+ for (const link of navLinks) {
186
+ const page = link.dataset.page;
187
+ link.href = href({ page, sha: current.sha });
188
+ if (page === current.page)
189
+ link.setAttribute('aria-current', 'page');
190
+ else
191
+ link.removeAttribute('aria-current');
192
+ }
193
+ document.querySelector('.brand').href = href({ page: 'overview', sha: current.sha });
194
+ renderInspection(report);
195
+ renderQuality(report, quality[report.sha]);
196
+ if (locked) {
197
+ const tab = document.querySelector(`#navigation a[data-page="${current.page}"]`);
198
+ element('unavailable-title').textContent = tab?.firstChild?.textContent ?? 'Not in this report';
199
+ fillNotice(element('unavailable-content'));
200
+ return;
201
+ }
202
+ if (current.page === 'overview')
203
+ renderLead(reports, report, quality, context, chartMetric, cached.get(report.sha));
204
+ renderScannerContext(inspection, report.sha);
205
+ const needsDetail = isFilePage(current.page) || ['overview', 'settings'].includes(current.page) || !counts;
206
+ const detail = detailed && needsDetail ? selectedDetails(report.sha) : undefined;
207
+ if (detailed) {
208
+ const row = counts?.[report.sha];
209
+ const cachedDetail = cached.get(report.sha);
210
+ if (row)
211
+ updateTabs(current.page, row.findingCount, row.diagnosticCount, row.componentCount);
212
+ else if (cachedDetail)
213
+ updateDetailsTabs(current.page, cachedDetail);
214
+ if (pullReviewCount !== undefined)
215
+ showTab('pulls', pullReviewCount > 0 || current.page === 'pulls');
216
+ else
217
+ void loadPulls().then(records => {
218
+ if (version === revision)
219
+ showTab('pulls', Boolean(records?.length) || current.page === 'pulls');
220
+ });
221
+ void detail?.then(asset => {
222
+ if (!asset || version !== revision)
223
+ return;
224
+ updateDetailsTabs(current.page, asset.inspection);
225
+ const latest = context[report.sha];
226
+ renderScannerContext(latest, report.sha);
227
+ });
228
+ }
229
+ if (current.page === 'overview')
230
+ renderTrend(trendData(), report, chartMetric, compact.matches);
231
+ if (current.page === 'trends') {
232
+ const slot = renderTrendsPage(element('trends-content'), trendData(), report, current.view, current.period);
233
+ if (slot) {
234
+ notice(slot, 'Loading saved pull request reviews…');
235
+ void loadPulls().then(records => {
236
+ if (version !== revision)
237
+ return;
238
+ if (records?.length)
239
+ renderDiffCoverageTrend(slot, records);
240
+ else
241
+ notice(slot, 'No saved pull request reviews yet.');
242
+ });
243
+ }
244
+ }
245
+ const page = current.page;
246
+ if (page === 'pulls') {
247
+ const target = element('pulls');
248
+ notice(target, 'Loading saved pull request reviews…');
249
+ void loadPulls().then(records => {
250
+ if (version !== revision)
251
+ return;
252
+ if (records)
253
+ renderPulls(target, records);
254
+ else
255
+ notice(target, 'Could not load saved pull request reviews.');
256
+ });
257
+ return;
258
+ }
259
+ if (page === 'settings') {
260
+ // The profile draws at once from the summary, and again with the details: exclusions, rules and ignores.
261
+ const newest = reports[0];
262
+ const draw = (details) => renderProfile(element('settings-content'), {
263
+ report, context: context[report.sha], details,
264
+ latest: { report: newest, quality: quality[newest.sha], context: context[newest.sha] },
265
+ });
266
+ draw(cached.get(report.sha));
267
+ if (detailed && !cached.has(report.sha))
268
+ void detail?.then(asset => {
269
+ if (asset && version === revision)
270
+ draw(asset.inspection);
271
+ });
272
+ return;
273
+ }
274
+ if (!detailed || (!isFilePage(page) && page !== 'overview'))
275
+ return;
276
+ const target = element(page === 'overview' ? 'overview-hotspot-list' : `${page}-content`);
277
+ function display(details) {
278
+ if (page === 'overview') {
279
+ // The details name the most complex function, so its figure can now lead to its line.
280
+ renderLead(reports, report, quality, context, chartMetric, details);
281
+ renderOverviewHotspots(details, report.sha, chartMetric, context[report.sha]?.security !== undefined);
282
+ }
283
+ else if (isFilePage(page)) {
284
+ renderFileView(target, page, details, {
285
+ directory: current.directory ?? '',
286
+ file: current.file ?? '',
287
+ query: current.query,
288
+ group: current.group,
289
+ line: current.line,
290
+ category: current.category,
291
+ level: current.level,
292
+ rank: current.rank,
293
+ source: path => loadSource(report.sha, path),
294
+ sourcePage: (path, line) => sourcePage(report.sha, path, line),
295
+ href: (destination, options) => href({ page: destination, sha: report.sha, ...options }),
296
+ });
297
+ }
298
+ }
299
+ const existing = cached.get(report.sha);
300
+ if (existing)
301
+ display(existing);
302
+ else {
303
+ if (page === 'overview')
304
+ overviewStub(report.sha);
305
+ else
306
+ notice(target, 'Loading inspection details…');
307
+ void detail?.then(asset => {
308
+ if (version !== revision)
309
+ return;
310
+ if (asset)
311
+ display(asset.inspection);
312
+ else
313
+ notice(target, 'Could not load inspection details.');
314
+ });
315
+ }
316
+ }
317
+ function showTab(page, visible) {
318
+ const tab = document.querySelector(`#navigation a[data-page="${page}"]`);
319
+ if (tab)
320
+ tab.hidden = !visible;
321
+ }
322
+ /** Tabs follow the code: pages with nothing to show leave the bar, and issues and diagnostics carry their count. */
323
+ function updateDetailsTabs(page, details) {
324
+ updateTabs(page, details.findings?.length ?? 0, details.diagnostics.length, details.components?.length ?? 0);
325
+ }
326
+ function updateTabs(page, findings, diagnostics, components) {
327
+ element('issues-count').textContent = count(findings);
328
+ element('diagnostics-count').textContent = count(diagnostics);
329
+ showTab('diagnostics', diagnostics > 0 || page === 'diagnostics');
330
+ }
331
+ function trendData() {
332
+ return {
333
+ reports, quality, context, detailed, compact: compact.matches,
334
+ link: (sha, view, period) => href({ page: 'trends', sha, view, period }),
335
+ };
336
+ }
337
+ window.addEventListener('hashchange', render);
338
+ compact.addEventListener('change', render);
339
+ message.hidden = true;
340
+ render();
341
+ }
342
+ function href({ page, sha, directory, file, view, period, query, group, line, category, level, rank }) {
343
+ const params = new URLSearchParams({ sha });
344
+ if (directory)
345
+ params.set('dir', directory);
346
+ if (file)
347
+ params.set('file', file);
348
+ if (view)
349
+ params.set('view', view);
350
+ if (period)
351
+ params.set('period', period);
352
+ if (query)
353
+ params.set('q', query);
354
+ if (group)
355
+ params.set('group', group);
356
+ if (line)
357
+ params.set('line', String(line));
358
+ if (category)
359
+ params.set('category', category);
360
+ if (level)
361
+ params.set('level', level);
362
+ if (rank)
363
+ params.set('rank', rank);
364
+ // Category lists read as written: category=structure,duplication.
365
+ return `#${page}?${params.toString().replaceAll('%2C', ',')}`;
366
+ }
367
+ function isFilePage(page) {
368
+ return page === 'metrics' || page === 'hotspots' || page === 'issues' || page === 'diagnostics';
369
+ }
370
+ /**
371
+ * A detail that counts something leads to exactly what it counts, where the report has a page for it: a link in the
372
+ * local and private views, plain text in the public one.
373
+ */
374
+ function detailText(id, text, link) {
375
+ if (!detailed || link === undefined) {
376
+ element(id).textContent = text;
377
+ return;
378
+ }
379
+ const anchor = document.createElement('a');
380
+ anchor.href = link;
381
+ anchor.textContent = text;
382
+ element(id).replaceChildren(anchor);
383
+ }
384
+ /** Where each Overview figure leads: the findings it counts, the files it ranks, the function it names. */
385
+ function smellsLink(sha) {
386
+ return href({ page: 'issues', sha, category: codeSmellCategories.join(',') });
387
+ }
388
+ function securityLink(sha, level) {
389
+ return href({ page: 'issues', sha, category: securityCategories.join(','), ...level ? { level } : {} });
390
+ }
391
+ function uncoveredLink(sha) {
392
+ return href({ page: 'hotspots', sha, rank: 'missedLines' });
393
+ }
394
+ function renderInspection(report) {
395
+ const coverage = report.lineCoverage && report.lineCoverage.total > 0 ? report.lineCoverage.covered / report.lineCoverage.total : null;
396
+ if (coverage === null)
397
+ detailText('coverage-detail', 'No coverage report');
398
+ else
399
+ detailText('coverage-detail', `${coverageText(report.lineCoverage)} of ${count(report.lineCoverage.total)} lines`, coverage < 1 ? uncoveredLink(report.sha) : undefined);
400
+ element('coverage-mark').replaceChildren(ring(coverage));
401
+ }
402
+ function renderQuality(report, quality) {
403
+ const maintainability = quality?.maintainability ?? null;
404
+ const grade = element('maintainability');
405
+ grade.textContent = maintainability?.grade ?? '–';
406
+ grade.dataset.grade = maintainability?.grade ?? 'none';
407
+ if (!maintainability)
408
+ detailText('maintainability-detail', 'Not measured');
409
+ else
410
+ detailText('maintainability-detail', quantity(maintainability.smells, 'code smell'), maintainability.smells > 0 ? smellsLink(report.sha) : undefined);
411
+ }
412
+ function quantity(amount, noun) {
413
+ return `${count(amount)} ${amount === 1 ? noun : `${noun}s`}`;
414
+ }
415
+ function renderLead(reports, selected, quality, context, area, details) {
416
+ const index = reports.indexOf(selected);
417
+ const previous = reports[index + 1];
418
+ const comparable = previous !== undefined;
419
+ // A figure shows its change only when it moved; what it is measured from is in the change's tooltip.
420
+ const time = previous ? commitTime(previous) : null;
421
+ const inspectedAt = Date.parse(previous?.generatedAt ?? '');
422
+ const before = time !== null ? `the commit of ${dateTime.format(time)}` : Number.isFinite(inspectedAt)
423
+ ? `the inspection of ${dateTime.format(inspectedAt)}` : 'the previous inspection';
424
+ const profileChanged = context?.[selected.sha]?.boundary === 'changed';
425
+ const figures = (areas[area] ?? areas.debt).figures.map(metric => {
426
+ const value = metricValue(selected, metric, quality[selected.sha], context?.[selected.sha]);
427
+ const prior = previous ? metricValue(previous, metric, quality[previous.sha], context?.[previous.sha]) : null;
428
+ const change = comparable && !profileChanged && value !== null && prior !== null ? difference(value, prior, metric) : null;
429
+ return { metric, value, change, text: change && change.direction !== 'same' ? change.text : '' };
430
+ });
431
+ // An area with nothing measured at this commit says so once, instead of a row of dashes.
432
+ if (figures.every(entry => entry.value === null)) {
433
+ const empty = document.createElement('p');
434
+ empty.className = 'lead-empty';
435
+ empty.textContent = { coverage: 'No coverage report for this commit.', security: 'No security scanner report for this commit.' }[area]
436
+ ?? 'Not measured for this commit.';
437
+ element('lead').replaceChildren(empty);
438
+ return;
439
+ }
440
+ element('lead').replaceChildren(...figures.map(({ metric, value, change, text }) => {
441
+ const figure = document.createElement('div');
442
+ figure.className = 'figure';
443
+ const label = document.createElement('dt');
444
+ label.textContent = labelOf(metric);
445
+ const shown = document.createElement('dd');
446
+ shown.className = 'figure-value';
447
+ const destination = value === null || value <= 0 ? undefined : figureLink(metric, value, selected.sha, details);
448
+ if (value === null)
449
+ shown.textContent = '—';
450
+ else if (!detailed || !destination)
451
+ shown.textContent = formatMetric(value, metric);
452
+ else {
453
+ const anchor = document.createElement('a');
454
+ anchor.href = destination;
455
+ anchor.textContent = formatMetric(value, metric);
456
+ shown.append(anchor);
457
+ }
458
+ const delta = document.createElement('dd');
459
+ delta.className = 'figure-delta';
460
+ delta.textContent = text;
461
+ delta.dataset.direction = change?.direction ?? 'none';
462
+ if (text)
463
+ delta.title = `Since ${before} (${previous.sha.slice(0, 7)})`;
464
+ figure.append(label, shown, delta);
465
+ return figure;
466
+ }));
467
+ }
468
+ /**
469
+ * Where a lead figure leads, when it counts things the report lists: remediation time to the code smells it prices,
470
+ * duplication to the duplicated code, uncovered lines to the files that hold them, security counts to the findings,
471
+ * and the most complex function to its line. Ratios and sizes lead nowhere.
472
+ */
473
+ function figureLink(metric, value, sha, details) {
474
+ switch (metric) {
475
+ case 'effort': return smellsLink(sha);
476
+ case 'duplication': return href({ page: 'issues', sha, category: 'duplication' });
477
+ case 'uncovered-lines': return uncoveredLink(sha);
478
+ case 'security': return securityLink(sha);
479
+ case 'security-high': return securityLink(sha, 'high');
480
+ case 'security-medium': return securityLink(sha, 'medium');
481
+ case 'security-low': return securityLink(sha, 'low');
482
+ case 'complexity': {
483
+ const top = details?.functions.find(item => item.complexity === value);
484
+ if (!top)
485
+ return undefined;
486
+ const slash = top.path.lastIndexOf('/');
487
+ return href({ page: 'metrics', sha, file: top.path, directory: slash < 0 ? '' : top.path.slice(0, slash), ...top.line ? { line: top.line } : {} });
488
+ }
489
+ default: return undefined;
490
+ }
491
+ }
492
+ /** A small progress ring for a ratio; an empty ring when there is no value. */
493
+ function ring(ratio) {
494
+ const namespace = 'http://www.w3.org/2000/svg';
495
+ const svg = document.createElementNS(namespace, 'svg');
496
+ svg.setAttribute('viewBox', '0 0 40 40');
497
+ const track = document.createElementNS(namespace, 'circle');
498
+ const arc = document.createElementNS(namespace, 'circle');
499
+ for (const circle of [track, arc]) {
500
+ circle.setAttribute('cx', '20');
501
+ circle.setAttribute('cy', '20');
502
+ circle.setAttribute('r', '16');
503
+ }
504
+ track.setAttribute('class', 'ring-track');
505
+ arc.setAttribute('class', 'ring-arc');
506
+ const length = 2 * Math.PI * 16;
507
+ arc.setAttribute('stroke-dasharray', `${(ratio ?? 0) * length} ${length}`);
508
+ // Flat ends keep the gap true to the value: a round cap would close 95.9% into a full circle and turn
509
+ // a zero into a dot. An unknown or zero ratio shows the track alone.
510
+ svg.append(...(ratio !== null && ratio > 0 ? [track, arc] : [track]));
511
+ return svg;
512
+ }
513
+ function renderScannerContext(context, sha) {
514
+ const security = context?.security;
515
+ const mark = element('security-mark');
516
+ const critical = security?.critical ?? 0;
517
+ const total = security ? critical + security.high + security.medium + security.low + security.unknown : null;
518
+ // A grade like maintainability's, by the worst finding: the line beside it gives the counts per risk level.
519
+ const step = !security ? null : critical ? 4 : security.high ? 3 : security.medium ? 2 : total ? 1 : 0;
520
+ mark.textContent = step === null ? '–' : securityGrades[step];
521
+ mark.title = step === null ? '' : `Security ${securityGrades[step]}: ${securityRisks[step].toLowerCase()}`;
522
+ // The same five steps as every grade: clear A, low B, medium C, high D, critical F.
523
+ mark.dataset.severity = !security ? 'none' : critical ? 'critical' : security.high ? 'high' : security.medium ? 'medium' : total ? 'low' : 'clear';
524
+ // The mark carries the level; the text gives the counts by severity.
525
+ const levels = security ? [['critical', critical], ['high', security.high], ['medium', security.medium], ['low', security.low], ['unclassified', security.unknown]]
526
+ .filter(([, amount]) => amount > 0) : [];
527
+ detailText('security-detail', !security ? 'No scanner report'
528
+ : levels.length === 0 ? 'No findings'
529
+ : levels.map(([name, amount]) => `${count(amount)} ${name}`).join(' · '), levels.length ? securityLink(sha) : undefined);
530
+ }
531
+ function renderOverviewHotspots(details, sha, chartMetric, scanned) {
532
+ const metric = chartMetric === 'coverage' ? 'missedLines' : chartMetric === 'cognitive' || chartMetric === 'duplication'
533
+ ? chartMetric : 'complexity';
534
+ const output = element('overview-hotspot-list');
535
+ const aside = element('overview-hotspots');
536
+ aside.removeAttribute('aria-busy');
537
+ aside.classList.remove('overview-stale');
538
+ listHeading(true);
539
+ if (chartMetric === 'security') {
540
+ renderSecurityHotspots(details, sha, scanned);
541
+ return;
542
+ }
543
+ const labels = {
544
+ complexity: 'Maintainability hotspots',
545
+ cognitive: 'Cognitive complexity hotspots',
546
+ duplication: 'Duplication hotspots',
547
+ missedLines: 'Coverage hotspots',
548
+ };
549
+ element('overview-hotspots-title').textContent = labels[metric];
550
+ const ranks = details.metrics.hotspots[metric] ?? [];
551
+ const chart = element('overview-sunburst');
552
+ const map = () => chart.replaceChildren(renderSunburst(details, {
553
+ metric, compact: true, href: (page, options) => href({ page, sha, ...options }), reshape: map,
554
+ }));
555
+ map();
556
+ const byPath = new Map(details.metrics.files.map(file => [file.path, file]));
557
+ const list = document.createElement('ol');
558
+ list.className = 'overview-hotspot-list';
559
+ const all = document.querySelector('#all-hotspots');
560
+ all.href = href({ page: 'hotspots', sha });
561
+ all.hidden = false;
562
+ const top = ranks.slice(0, 5).map(path => {
563
+ const entry = byPath.get(path);
564
+ const lines = entry?.lineCoverage;
565
+ const value = metric === 'missedLines' ? (lines ? lines.total - lines.covered : null)
566
+ : metric === 'duplication' ? entry?.quality?.duplication?.duplicatedLines ?? null
567
+ : metric === 'cognitive' ? entry?.quality?.cognitiveComplexity ?? null : entry?.complexity?.maximum ?? null;
568
+ return { path, value, entry };
569
+ });
570
+ for (const { path, value, entry } of top) {
571
+ const link = document.createElement('a');
572
+ const slash = path.lastIndexOf('/');
573
+ const directory = slash < 0 ? '' : path.slice(0, slash);
574
+ link.href = href({ page: 'metrics', sha, file: path, directory });
575
+ const label = document.createElement('span');
576
+ label.className = 'hotspot-name';
577
+ const name = document.createElement('strong');
578
+ name.textContent = path.slice(slash + 1);
579
+ label.append(name);
580
+ // A file in the repository root has no folder to name.
581
+ if (directory) {
582
+ const parent = document.createElement('small');
583
+ parent.textContent = directory;
584
+ label.append(parent);
585
+ }
586
+ const score = document.createElement('span');
587
+ score.className = 'chip';
588
+ score.textContent = count(value);
589
+ if (value !== null && entry)
590
+ score.dataset.band = String(band(entry, metric, value, Math.max(1, ...top.map(item => item.value ?? 0)), bandLimits(details, metric)));
591
+ link.append(label, score);
592
+ const row = document.createElement('li');
593
+ row.append(link);
594
+ list.append(row);
595
+ }
596
+ if (list.childElementCount)
597
+ output.replaceChildren(list);
598
+ else if (metric === 'missedLines' && !details.metrics.files.some(file => file.lineCoverage))
599
+ unranked();
600
+ else
601
+ notice(output, 'No files in this ranking.');
602
+ }
603
+ /** The ranking's heading and link show only when there is something to rank. */
604
+ function listHeading(visible) {
605
+ element('overview-hotspots-title').parentElement.hidden = !visible;
606
+ }
607
+ /** Nothing measured: the grey map stands alone; the quality area's tab already says what is missing. */
608
+ function unranked() {
609
+ listHeading(false);
610
+ element('overview-hotspot-list').replaceChildren();
611
+ }
612
+ /**
613
+ * Security has no measure of its own on the map: the map shows sizes in grey, and the list ranks files by their
614
+ * scanner findings. Without a scanner report there is nothing to rank, and the grey map says so.
615
+ */
616
+ function renderSecurityHotspots(details, sha, scanned) {
617
+ element('overview-hotspots-title').textContent = 'Security hotspots';
618
+ const sensitive = new Set(['security', 'dependency', 'secret', 'infrastructure']);
619
+ // Each file's worst finding, in the steps of the security mark; until findings carry a critical level, high is the top.
620
+ const rank = { low: 1, unknown: 1, medium: 2, high: 3 };
621
+ const levels = new Map();
622
+ for (const finding of details.findings ?? []) {
623
+ if (sensitive.has(finding.category) && finding.path)
624
+ levels.set(finding.path, Math.max(levels.get(finding.path) ?? 0, rank[finding.level]));
625
+ }
626
+ const chart = element('overview-sunburst');
627
+ const map = () => chart.replaceChildren(renderSunburst(details, {
628
+ metric: 'complexity', compact: true, href: (page, options) => href({ page, sha, ...options }), reshape: map,
629
+ ...scanned ? { levels } : { muted: true },
630
+ }));
631
+ map();
632
+ const all = document.querySelector('#all-hotspots');
633
+ all.href = href({ page: 'issues', sha });
634
+ all.hidden = !scanned;
635
+ const output = element('overview-hotspot-list');
636
+ if (!scanned) {
637
+ unranked();
638
+ return;
639
+ }
640
+ const counts = new Map();
641
+ for (const finding of details.findings ?? []) {
642
+ if (sensitive.has(finding.category) && finding.path)
643
+ counts.set(finding.path, (counts.get(finding.path) ?? 0) + 1);
644
+ }
645
+ // The worst level first, then the most findings; the chip names the level, as the map colours it.
646
+ const top = [...levels].sort((a, b) => b[1] - a[1] || counts.get(b[0]) - counts.get(a[0]) || a[0].localeCompare(b[0])).slice(0, 5);
647
+ if (!top.length) {
648
+ notice(output, 'No security findings.');
649
+ return;
650
+ }
651
+ const list = document.createElement('ol');
652
+ list.className = 'overview-hotspot-list';
653
+ for (const [path, level] of top) {
654
+ const link = document.createElement('a');
655
+ const slash = path.lastIndexOf('/');
656
+ link.href = href({ page: 'issues', sha, query: path });
657
+ const label = document.createElement('span');
658
+ label.className = 'hotspot-name';
659
+ const name = document.createElement('strong');
660
+ name.textContent = path.slice(slash + 1);
661
+ label.append(name);
662
+ if (slash > 0) {
663
+ const parent = document.createElement('small');
664
+ parent.textContent = path.slice(0, slash);
665
+ label.append(parent);
666
+ }
667
+ const score = document.createElement('span');
668
+ score.className = 'chip chip-level';
669
+ score.dataset.level = String(level);
670
+ score.textContent = securityGrades[level];
671
+ score.title = `${securityRisks[level]} · ${quantity(counts.get(path), 'finding')}`;
672
+ link.append(label, score);
673
+ const row = document.createElement('li');
674
+ row.append(link);
675
+ list.append(row);
676
+ }
677
+ output.replaceChildren(list);
678
+ }
679
+ function renderTrend(data, selected, metric, compact) {
680
+ // Enough inspections to show a curve, not a pair of dots; the Trends page holds the whole history.
681
+ const size = compact ? 24 : 60;
682
+ const { start, end } = stableWindow(data.reports, data.reports.indexOf(selected), size, 'overview');
683
+ const shown = charted(data.reports.slice(start, end).reverse());
684
+ const link = (sha) => href({ page: 'overview', sha });
685
+ const chart = element('chart');
686
+ const hasData = renderSeries(chart, element('trend-key'), data, shown, metric, selected.sha, link, { compact, height: compact ? undefined : 296, labelCurrent: false });
687
+ chart.hidden = !hasData;
688
+ element('trend-empty').hidden = hasData;
689
+ // With no chart, its empty line is the panel's one statement: no key, no reading notes, no second "not measured".
690
+ element('trend').dataset.empty = String(!hasData);
691
+ const points = seriesPoints(data, shown, metric, selected.sha, link);
692
+ // The figures under the chart state the value and its change, so the chart is named for screen readers only.
693
+ element('trend-title').textContent = `${labelOf(metric)} by commit`;
694
+ const legend = trendLegend(points, data);
695
+ element('trend-detail').textContent = legend;
696
+ element('trend-detail').hidden = legend === '' || !hasData;
697
+ }
698
+ function coverageText(value) {
699
+ return formatPercent(value && value.total > 0 ? value.covered / value.total : null);
700
+ }
701
+ function formatPercent(value) {
702
+ return value === null ? '—' : percent.format(value);
703
+ }
704
+ function element(id) {
705
+ return document.getElementById(id);
706
+ }
707
+ /**
708
+ * The hotspot column while the inspection loads. A map and ranking already on screen stay, dimmed, until the next ones
709
+ * replace them; on a first visit placeholders of the same size hold the column, so nothing beside it moves.
710
+ */
711
+ function overviewStub(sha) {
712
+ const chart = element('overview-sunburst');
713
+ const output = element('overview-hotspot-list');
714
+ const all = document.querySelector('#all-hotspots');
715
+ all.href = href({ page: 'hotspots', sha });
716
+ all.hidden = false;
717
+ const aside = element('overview-hotspots');
718
+ aside.setAttribute('aria-busy', 'true');
719
+ listHeading(true);
720
+ if (chart.querySelector('.fx-sunburst:not(.fx-map-stub)') && output.querySelector('.overview-hotspot-list')) {
721
+ aside.classList.add('overview-stale');
722
+ return;
723
+ }
724
+ chart.replaceChildren(mapStub());
725
+ const list = document.createElement('ol');
726
+ list.className = 'overview-hotspot-list overview-hotspot-stub';
727
+ for (let row = 0; row < 5; row++) {
728
+ const item = document.createElement('li');
729
+ item.innerHTML = '<span><span class="stub-line"></span><span class="stub-line stub-line-short"></span></span><span class="stub-chip"></span>';
730
+ list.append(item);
731
+ }
732
+ output.replaceChildren(list);
733
+ }
734
+ /** The public report notice in a page's place: what this report holds and the command that shows all of it. */
735
+ function fillNotice(container) {
736
+ const text = document.createElement('p');
737
+ text.className = 'report-notice-text';
738
+ const lead = document.createElement('strong');
739
+ lead.textContent = publicNotice.lead;
740
+ text.append(lead, ` ${publicNotice.text} `, commandChip(), ` ${publicNotice.tail}`);
741
+ container.replaceChildren(text);
742
+ }
743
+ /** The same notice in the Overview's side panel, where the hotspots sit in a detailed report. */
744
+ function fillPanel(container) {
745
+ const text = document.createElement('p');
746
+ text.textContent = publicNotice.panel;
747
+ const command = commandChip();
748
+ command.classList.add('public-panel-command');
749
+ container.replaceChildren(text, command);
750
+ }
751
+ /** The command as code, copied with one click; where the browser refuses the clipboard, it is selected instead. */
752
+ function commandChip() {
753
+ const code = document.createElement('code');
754
+ code.textContent = publicNotice.command;
755
+ if (!navigator.clipboard)
756
+ return code;
757
+ const copy = document.createElement('button');
758
+ copy.type = 'button';
759
+ copy.className = 'report-notice-command';
760
+ copy.title = 'Copy the command';
761
+ const status = document.createElement('span');
762
+ status.className = 'visually-hidden';
763
+ status.setAttribute('role', 'status');
764
+ copy.append(code, status);
765
+ copy.addEventListener('click', () => {
766
+ void navigator.clipboard.writeText(publicNotice.command).then(() => {
767
+ copy.dataset.copied = '';
768
+ status.textContent = 'Copied';
769
+ setTimeout(() => { delete copy.dataset.copied; status.textContent = ''; }, 1600);
770
+ }, () => window.getSelection()?.selectAllChildren(code));
771
+ });
772
+ return copy;
773
+ }
774
+ function notice(container, text) {
775
+ const paragraph = document.createElement('p');
776
+ paragraph.className = 'detail empty';
777
+ paragraph.setAttribute('role', 'status');
778
+ paragraph.textContent = text;
779
+ container.replaceChildren(paragraph);
780
+ }
781
+ async function readJson(path) {
782
+ const response = await fetch(path);
783
+ if (!response.ok)
784
+ throw new Error(`Could not read ${path}`);
785
+ return await response.json();
786
+ }
787
+ async function readOptional(path) {
788
+ try {
789
+ return await readJson(path);
790
+ }
791
+ catch {
792
+ return null;
793
+ }
794
+ }