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