repometry 0.0.0-dev.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -1
  3. package/package.json +48 -7
  4. package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
  5. package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
  6. package/target/main/resources/report/json/config-v1.schema.json +34 -0
  7. package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
  8. package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
  9. package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
  10. package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
  11. package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
  12. package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
  13. package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
  14. package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
  15. package/target/main/resources/report/json/report-v1.schema.json +65 -0
  16. package/target/main/resources/report/json/report-v2.schema.json +238 -0
  17. package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
  18. package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
  19. package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
  20. package/target/main/resources/viewer/files.css +578 -0
  21. package/target/main/resources/viewer/index.html +130 -0
  22. package/target/main/resources/viewer/projects.html +52 -0
  23. package/target/main/resources/viewer/styles.css +586 -0
  24. package/target/main/resources/viewer/viewer-pulls.css +64 -0
  25. package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
  26. package/target/main/ts/api/gh/github-pr-comment.js +107 -0
  27. package/target/main/ts/api/gh/github.d.ts +6 -0
  28. package/target/main/ts/api/gh/github.js +91 -0
  29. package/target/main/ts/api/git/blob-batch.d.ts +10 -0
  30. package/target/main/ts/api/git/blob-batch.js +105 -0
  31. package/target/main/ts/api/git/changes.d.ts +22 -0
  32. package/target/main/ts/api/git/changes.js +107 -0
  33. package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
  34. package/target/main/ts/api/git/commit-metadata.js +54 -0
  35. package/target/main/ts/api/git/git-churn.d.ts +9 -0
  36. package/target/main/ts/api/git/git-churn.js +70 -0
  37. package/target/main/ts/api/git/git-reader.d.ts +16 -0
  38. package/target/main/ts/api/git/git-reader.js +73 -0
  39. package/target/main/ts/api/git/git.d.ts +21 -0
  40. package/target/main/ts/api/git/git.js +152 -0
  41. package/target/main/ts/api/git/inspection-source.d.ts +15 -0
  42. package/target/main/ts/api/git/inspection-source.js +30 -0
  43. package/target/main/ts/api/git/local-sources.d.ts +5 -0
  44. package/target/main/ts/api/git/local-sources.js +46 -0
  45. package/target/main/ts/api/git/local.d.ts +3 -0
  46. package/target/main/ts/api/git/local.js +35 -0
  47. package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
  48. package/target/main/ts/api/git/metabranch-worktree.js +34 -0
  49. package/target/main/ts/api/git/source-cache.d.ts +3 -0
  50. package/target/main/ts/api/git/source-cache.js +56 -0
  51. package/target/main/ts/api/import/finding-import.d.ts +9 -0
  52. package/target/main/ts/api/import/finding-import.js +226 -0
  53. package/target/main/ts/api/import/lcov-files.d.ts +5 -0
  54. package/target/main/ts/api/import/lcov-files.js +13 -0
  55. package/target/main/ts/api/import/profile-file.d.ts +4 -0
  56. package/target/main/ts/api/import/profile-file.js +16 -0
  57. package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
  58. package/target/main/ts/api/worker/remote-executor.js +45 -0
  59. package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
  60. package/target/main/ts/api/worker/worker-protocol.js +101 -0
  61. package/target/main/ts/api/worker/worker.d.ts +5 -0
  62. package/target/main/ts/api/worker/worker.js +85 -0
  63. package/target/main/ts/cli/arguments.d.ts +28 -0
  64. package/target/main/ts/cli/arguments.js +110 -0
  65. package/target/main/ts/cli/config.d.ts +14 -0
  66. package/target/main/ts/cli/config.js +60 -0
  67. package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
  68. package/target/main/ts/cli/github-pr-comment.js +12 -0
  69. package/target/main/ts/cli/imports.d.ts +7 -0
  70. package/target/main/ts/cli/imports.js +29 -0
  71. package/target/main/ts/cli/main.d.ts +2 -0
  72. package/target/main/ts/cli/main.js +343 -284
  73. package/target/main/ts/cli/reporting.d.ts +18 -0
  74. package/target/main/ts/cli/reporting.js +108 -0
  75. package/target/main/ts/cli/revisions.d.ts +6 -0
  76. package/target/main/ts/cli/revisions.js +15 -0
  77. package/target/main/ts/cli/store.d.ts +13 -0
  78. package/target/main/ts/cli/store.js +38 -0
  79. package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
  80. package/target/main/ts/compose/analyze-snapshot.js +163 -0
  81. package/target/main/ts/compose/attach-churn.d.ts +2 -0
  82. package/target/main/ts/compose/attach-churn.js +37 -0
  83. package/target/main/ts/compose/diff-coverage.d.ts +20 -0
  84. package/target/main/ts/compose/diff-coverage.js +56 -0
  85. package/target/main/ts/compose/inspect.d.ts +23 -0
  86. package/target/main/ts/compose/inspect.js +44 -0
  87. package/target/main/ts/compose/plugin-list.d.ts +6 -0
  88. package/target/main/ts/compose/plugin-list.js +9 -0
  89. package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
  90. package/target/main/ts/compose/prepare-metabranch.js +16 -0
  91. package/target/main/ts/compose/review.d.ts +16 -0
  92. package/target/main/ts/compose/review.js +38 -0
  93. package/target/main/ts/compose/sources.d.ts +3 -0
  94. package/target/main/ts/compose/sources.js +29 -0
  95. package/target/main/ts/core/engine/execute.d.ts +10 -0
  96. package/target/main/ts/core/engine/execute.js +49 -0
  97. package/target/main/ts/core/engine/manifest.d.ts +4 -0
  98. package/target/main/ts/core/engine/manifest.js +104 -0
  99. package/target/main/ts/core/engine/plan.d.ts +22 -0
  100. package/target/main/ts/core/engine/plan.js +106 -0
  101. package/target/main/ts/core/engine/plugin.d.ts +59 -0
  102. package/target/main/ts/core/engine/plugin.js +4 -0
  103. package/target/main/ts/core/engine/report-products.d.ts +16 -0
  104. package/target/main/ts/core/engine/report-products.js +85 -0
  105. package/target/main/ts/core/model/changes.d.ts +8 -0
  106. package/target/main/ts/core/model/changes.js +1 -0
  107. package/target/main/ts/core/model/churn.d.ts +11 -0
  108. package/target/main/ts/core/model/churn.js +5 -0
  109. package/target/main/ts/core/model/clone-source.d.ts +16 -0
  110. package/target/main/ts/core/model/clone-source.js +14 -0
  111. package/target/main/ts/core/model/code-structure.d.ts +30 -0
  112. package/target/main/ts/core/model/code-structure.js +31 -0
  113. package/target/main/ts/core/model/comparison.d.ts +24 -0
  114. package/target/main/ts/core/model/comparison.js +1 -0
  115. package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
  116. package/target/main/ts/core/model/diff-coverage.js +1 -0
  117. package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
  118. package/target/main/ts/core/model/finding-ignore.js +35 -0
  119. package/target/main/ts/core/model/finding.d.ts +28 -0
  120. package/target/main/ts/core/model/finding.js +29 -0
  121. package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
  122. package/target/main/ts/core/model/ignore-rule.js +1 -0
  123. package/target/main/ts/core/model/measurement.d.ts +27 -0
  124. package/target/main/ts/core/model/measurement.js +24 -0
  125. package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
  126. package/target/main/ts/core/model/metric-descriptor.js +1 -0
  127. package/target/main/ts/core/model/plugin-data.d.ts +25 -0
  128. package/target/main/ts/core/model/plugin-data.js +1 -0
  129. package/target/main/ts/core/model/pull-review.d.ts +48 -0
  130. package/target/main/ts/core/model/pull-review.js +1 -0
  131. package/target/main/ts/core/model/quality-summary.d.ts +42 -0
  132. package/target/main/ts/core/model/quality-summary.js +64 -0
  133. package/target/main/ts/core/model/report.d.ts +32 -0
  134. package/target/main/ts/core/model/report.js +5 -0
  135. package/target/main/ts/core/model/scanner-import.d.ts +39 -0
  136. package/target/main/ts/core/model/scanner-import.js +28 -0
  137. package/target/main/ts/core/model/snapshot.d.ts +15 -0
  138. package/target/main/ts/core/model/snapshot.js +50 -0
  139. package/target/main/ts/core/model/source-locator.d.ts +7 -0
  140. package/target/main/ts/core/model/source-locator.js +1 -0
  141. package/target/main/ts/core/model/source.d.ts +23 -0
  142. package/target/main/ts/core/model/source.js +1 -0
  143. package/target/main/ts/core/ports/report.d.ts +9 -0
  144. package/target/main/ts/core/ports/report.js +1 -0
  145. package/target/main/ts/core/ports/source-provider.d.ts +14 -0
  146. package/target/main/ts/core/ports/source-provider.js +4 -0
  147. package/target/main/ts/core/profile/exclusions.d.ts +11 -0
  148. package/target/main/ts/core/profile/exclusions.js +57 -0
  149. package/target/main/ts/core/profile/maintainability.d.ts +31 -0
  150. package/target/main/ts/core/profile/maintainability.js +9 -0
  151. package/target/main/ts/core/profile/profile.d.ts +4 -0
  152. package/target/main/ts/core/profile/profile.js +10 -0
  153. package/target/main/ts/core/usecases/compare.d.ts +6 -0
  154. package/target/main/ts/core/usecases/compare.js +145 -0
  155. package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
  156. package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
  157. package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
  158. package/target/main/ts/core/usecases/diff-coverage.js +15 -0
  159. package/target/main/ts/core/usecases/inspect.d.ts +38 -0
  160. package/target/main/ts/core/usecases/inspect.js +41 -0
  161. package/target/main/ts/core/usecases/review.d.ts +31 -0
  162. package/target/main/ts/core/usecases/review.js +128 -0
  163. package/target/main/ts/index.d.ts +35 -0
  164. package/target/main/ts/index.js +17 -13
  165. package/target/main/ts/plugin.d.ts +14 -0
  166. package/target/main/ts/plugin.js +5 -0
  167. package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
  168. package/target/main/ts/plugins/coverage/coverage.js +120 -0
  169. package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
  170. package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
  171. package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
  172. package/target/main/ts/plugins/duplication/duplication.js +93 -0
  173. package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
  174. package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
  175. package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
  176. package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
  177. package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
  178. package/target/main/ts/plugins/language-js/code-lines.js +35 -0
  179. package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
  180. package/target/main/ts/plugins/language-js/function-facts.js +60 -0
  181. package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
  182. package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
  183. package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
  184. package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
  185. package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
  186. package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
  187. package/target/main/ts/plugins/source/forges.d.ts +4 -0
  188. package/target/main/ts/plugins/source/forges.js +79 -0
  189. package/target/main/ts/plugins/structure/structure.d.ts +2 -0
  190. package/target/main/ts/plugins/structure/structure.js +37 -0
  191. package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
  192. package/target/main/ts/report/html/app/viewer-access.js +25 -0
  193. package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
  194. package/target/main/ts/report/html/app/viewer-chart.js +711 -0
  195. package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
  196. package/target/main/ts/report/html/app/viewer-commits.js +280 -0
  197. package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
  198. package/target/main/ts/report/html/app/viewer-data.js +105 -0
  199. package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
  200. package/target/main/ts/report/html/app/viewer-files.js +2087 -0
  201. package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
  202. package/target/main/ts/report/html/app/viewer-filter.js +492 -0
  203. package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
  204. package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
  205. package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
  206. package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
  207. package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
  208. package/target/main/ts/report/html/app/viewer-profile.js +401 -0
  209. package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
  210. package/target/main/ts/report/html/app/viewer-projects.js +90 -0
  211. package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
  212. package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
  213. package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
  214. package/target/main/ts/report/html/app/viewer-source.js +313 -0
  215. package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
  216. package/target/main/ts/report/html/app/viewer-trends.js +413 -0
  217. package/target/main/ts/report/html/app/viewer.d.ts +1 -0
  218. package/target/main/ts/report/html/app/viewer.js +794 -0
  219. package/target/main/ts/report/html/site/badges.d.ts +14 -0
  220. package/target/main/ts/report/html/site/badges.js +39 -0
  221. package/target/main/ts/report/html/site/export-site.d.ts +21 -0
  222. package/target/main/ts/report/html/site/export-site.js +157 -0
  223. package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
  224. package/target/main/ts/report/html/site/exported-server.js +70 -0
  225. package/target/main/ts/report/html/site/local-server.d.ts +7 -0
  226. package/target/main/ts/report/html/site/local-server.js +64 -0
  227. package/target/main/ts/report/html/site/projects.d.ts +3 -0
  228. package/target/main/ts/report/html/site/projects.js +79 -0
  229. package/target/main/ts/report/html/site/server.d.ts +4 -0
  230. package/target/main/ts/report/html/site/server.js +64 -0
  231. package/target/main/ts/report/html/site/source-route.d.ts +6 -0
  232. package/target/main/ts/report/html/site/source-route.js +22 -0
  233. package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
  234. package/target/main/ts/report/json/projections/commit-summary.js +118 -0
  235. package/target/main/ts/report/json/projections/components.d.ts +4 -0
  236. package/target/main/ts/report/json/projections/components.js +29 -0
  237. package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
  238. package/target/main/ts/report/json/projections/file-metrics.js +243 -0
  239. package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
  240. package/target/main/ts/report/json/projections/inspection-context.js +92 -0
  241. package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
  242. package/target/main/ts/report/json/projections/inspection-details.js +69 -0
  243. package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
  244. package/target/main/ts/report/json/projections/metric-values.js +57 -0
  245. package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
  246. package/target/main/ts/report/json/projections/public-history.js +16 -0
  247. package/target/main/ts/report/json/store/components.d.ts +2 -0
  248. package/target/main/ts/report/json/store/components.js +31 -0
  249. package/target/main/ts/report/json/store/local-store.d.ts +13 -0
  250. package/target/main/ts/report/json/store/local-store.js +179 -0
  251. package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
  252. package/target/main/ts/report/json/store/pull-review-store.js +51 -0
  253. package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
  254. package/target/main/ts/report/json/validation/metabranch.js +7 -0
  255. package/target/main/ts/report/json/validation/report.d.ts +15 -0
  256. package/target/main/ts/report/json/validation/report.js +64 -0
  257. package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
  258. package/target/main/ts/report/json/validation/summary-validation.js +27 -0
  259. package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
  260. package/target/main/ts/report/json/wire/compact-json.js +76 -0
  261. package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
  262. package/target/main/ts/report/json/wire/component-model.js +1 -0
  263. package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
  264. package/target/main/ts/report/json/wire/domain-types.js +1 -0
  265. package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
  266. package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
  267. package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
  268. package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
  269. package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
  270. package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
  271. package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
  272. package/target/main/ts/report/json/wire/project-model.js +1 -0
  273. package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
  274. package/target/main/ts/report/json/wire/public-history-model.js +6 -0
  275. package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
  276. package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
  277. package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
  278. package/target/main/ts/report/json/wire/summary-model.js +1 -0
  279. package/target/main/ts/report.d.ts +11 -0
  280. package/target/main/ts/report.js +5 -0
  281. package/index.js +0 -1
@@ -0,0 +1,36 @@
1
+ import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
2
+ export interface CommitMatch {
3
+ readonly entry: PublicHistoryEntry;
4
+ readonly index: number;
5
+ }
6
+ interface Indexed {
7
+ readonly entry: PublicHistoryEntry;
8
+ readonly sha: string;
9
+ readonly tags: readonly string[];
10
+ /** Everything else a person may type: subject, tags, author, and the date in ISO and local form. */
11
+ readonly text: string;
12
+ }
13
+ export declare function commitIndex(entries: readonly PublicHistoryEntry[]): readonly Indexed[];
14
+ /**
15
+ * Commits matching every word of the query, in history order, with exact tags and hash prefixes first. A hash
16
+ * matches from its start only, so "a1" does not match every commit that merely contains it.
17
+ */
18
+ export declare function searchCommits(index: readonly Indexed[], query: string, limit?: number): {
19
+ matches: CommitMatch[];
20
+ total: number;
21
+ };
22
+ export interface CommitPicker {
23
+ set(sha: string): void;
24
+ hidden: boolean;
25
+ }
26
+ /**
27
+ * Renders the picker into the slot; picking a commit calls back with its SHA. The branch, when the configuration names
28
+ * one, heads the field: the commits are that branch's history.
29
+ */
30
+ export declare function createCommitPicker(slot: HTMLElement, entries: readonly PublicHistoryEntry[], pick: (sha: string) => void, branch?: string): CommitPicker;
31
+ /**
32
+ * How a commit's author reads in the list: the name, with the email only when the search found the email and not the
33
+ * name. A public export carries the name alone, and then it is the name alone; nothing reads as missing.
34
+ */
35
+ export declare function authorLabel(author: PublicHistoryEntry['author'], words: readonly string[]): string | null;
36
+ export {};
@@ -0,0 +1,280 @@
1
+ const shown = 50;
2
+ const day = new Intl.DateTimeFormat(undefined, { day: 'numeric', month: 'short', year: 'numeric' });
3
+ const dayTime = new Intl.DateTimeFormat(undefined, { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' });
4
+ export function commitIndex(entries) {
5
+ return entries.map(entry => {
6
+ const time = when(entry);
7
+ const tags = (entry.tags ?? []).map(tag => tag.toLowerCase());
8
+ const text = [entry.subject ?? '', ...tags, entry.author?.name ?? '', entry.author?.email ?? '',
9
+ time === null ? '' : new Date(time).toISOString().slice(0, 10), time === null ? '' : day.format(new Date(time))]
10
+ .join('\n').toLowerCase();
11
+ return { entry, sha: entry.sha.toLowerCase(), tags, text };
12
+ });
13
+ }
14
+ /**
15
+ * Commits matching every word of the query, in history order, with exact tags and hash prefixes first. A hash
16
+ * matches from its start only, so "a1" does not match every commit that merely contains it.
17
+ */
18
+ export function searchCommits(index, query, limit = shown) {
19
+ const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
20
+ const exact = [];
21
+ const rest = [];
22
+ let total = 0;
23
+ for (const [position, item] of index.entries()) {
24
+ if (!words.every(word => item.sha.startsWith(word) || item.text.includes(word)))
25
+ continue;
26
+ total += 1;
27
+ const strong = words.length > 0 && words.some(word => item.tags.includes(word) || (word.length >= 4 && item.sha.startsWith(word)));
28
+ const bucket = strong ? exact : rest;
29
+ if (exact.length + rest.length < limit || strong)
30
+ bucket.push({ entry: item.entry, index: position });
31
+ }
32
+ return { matches: [...exact, ...rest].slice(0, limit), total };
33
+ }
34
+ /**
35
+ * Renders the picker into the slot; picking a commit calls back with its SHA. The branch, when the configuration names
36
+ * one, heads the field: the commits are that branch's history.
37
+ */
38
+ export function createCommitPicker(slot, entries, pick, branch) {
39
+ const index = commitIndex(entries);
40
+ const bySha = new Map(entries.map(entry => [entry.sha, entry]));
41
+ const searchable = entries.some(entry => entry.subject || entry.author || entry.tags?.length);
42
+ let current = entries[0].sha;
43
+ let active = 0;
44
+ let matches = [];
45
+ // One control: the field shows the selected commit and, once focused, takes the search; the list opens attached
46
+ // under it, inside the same frame.
47
+ const field = element('div', 'commit-field');
48
+ const input = element('input', 'commit-search');
49
+ input.type = 'text';
50
+ input.autocomplete = 'off';
51
+ input.spellcheck = false;
52
+ input.placeholder = searchable ? 'Message, tag, author, date or hash' : 'Hash or date';
53
+ input.setAttribute('role', 'combobox');
54
+ input.setAttribute('aria-autocomplete', 'list');
55
+ input.setAttribute('aria-expanded', 'false');
56
+ const shown = element('span', 'commit-current');
57
+ shown.setAttribute('aria-hidden', 'true');
58
+ // The selected commit is drawn over the empty input, so both share one box after the branch.
59
+ const entry = element('span', 'commit-entry');
60
+ entry.append(input, shown);
61
+ if (branch) {
62
+ const name = element('span', 'commit-branch', branch);
63
+ name.title = `Branch ${branch}`;
64
+ name.setAttribute('aria-hidden', 'true');
65
+ field.append(name);
66
+ }
67
+ field.append(entry);
68
+ const popover = element('div', 'commit-popover');
69
+ popover.hidden = true;
70
+ const list = element('ul', 'commit-options');
71
+ list.id = 'commit-options';
72
+ list.setAttribute('role', 'listbox');
73
+ list.setAttribute('aria-label', 'Commits');
74
+ input.setAttribute('aria-controls', list.id);
75
+ const status = element('p', 'commit-status');
76
+ status.setAttribute('aria-live', 'polite');
77
+ popover.append(list, status);
78
+ slot.replaceChildren(field, popover);
79
+ function label() {
80
+ const entry = bySha.get(current);
81
+ const time = when(entry);
82
+ shown.replaceChildren(element('span', 'commit-hash', entry.sha.slice(0, 7)), element('span', 'commit-current-text', entry.subject ?? (time === null ? '' : dayTime.format(new Date(time)))));
83
+ field.title = [entry.sha, entry.subject].filter(Boolean).join('\n');
84
+ input.setAttribute('aria-label', `${branch ? `Branch ${branch}, commit` : 'Commit'} ${entry.sha.slice(0, 7)}${entry.subject ? `: ${entry.subject}` : ''}. Type to search commits`);
85
+ }
86
+ function update() {
87
+ const result = searchCommits(index, input.value);
88
+ matches = result.matches;
89
+ active = Math.max(0, matches.findIndex(match => match.entry.sha === current));
90
+ if (input.value.trim())
91
+ active = 0;
92
+ const words = input.value.trim().toLowerCase().split(/\s+/).filter(Boolean);
93
+ list.replaceChildren(...matches.map((match, position) => option(match.entry, position, words)));
94
+ status.textContent = result.total === 0 ? `No commits match “${input.value.trim()}”`
95
+ : result.total > matches.length ? `${matches.length} of ${result.total.toLocaleString()} ${input.value.trim() ? 'matches' : 'commits'} · type to narrow`
96
+ : `${result.total.toLocaleString()} ${result.total === 1 ? 'commit' : 'commits'}${branch && !input.value.trim() ? ` on ${branch}` : ''}`;
97
+ highlight();
98
+ }
99
+ function option(entry, position, words) {
100
+ const item = element('li', 'commit-option');
101
+ item.id = `commit-option-${position}`;
102
+ item.setAttribute('role', 'option');
103
+ item.setAttribute('aria-selected', String(entry.sha === current));
104
+ const time = when(entry);
105
+ const head = element('span', 'commit-option-head');
106
+ head.append(marked('span', 'commit-hash', entry.sha.slice(0, 7), words, true), marked('span', 'commit-subject', entry.subject ?? (time === null ? '' : dayTime.format(new Date(time))), words));
107
+ item.append(head);
108
+ // The second line names who and when, then the tags: two fit, the rest fold into a count, and the tags the
109
+ // search found come first. The email appears only when the search found it.
110
+ const author = authorLabel(entry.author, words);
111
+ const meta = [author, entry.subject && time !== null ? dayTime.format(new Date(time)) : null].filter(Boolean).join(' · ');
112
+ const tags = [...entry.tags ?? []].sort((a, b) => Number(hit(b, words)) - Number(hit(a, words)));
113
+ if (meta || tags.length) {
114
+ const line = element('span', 'commit-option-meta');
115
+ line.append(marked('span', 'commit-meta', meta, words));
116
+ for (const tag of tags.slice(0, 2))
117
+ line.append(marked('span', 'commit-tag', tag, words));
118
+ if (tags.length > 2) {
119
+ const more = element('span', 'commit-tag commit-tag-more', `+${tags.length - 2}`);
120
+ more.title = tags.slice(2).join('\n');
121
+ line.append(more);
122
+ }
123
+ item.append(line);
124
+ }
125
+ item.addEventListener('mousedown', event => event.preventDefault());
126
+ item.addEventListener('click', () => choose(entry.sha));
127
+ item.addEventListener('mousemove', () => { if (active !== position) {
128
+ active = position;
129
+ highlight();
130
+ } });
131
+ return item;
132
+ }
133
+ function highlight() {
134
+ for (const [position, item] of [...list.children].entries())
135
+ item.classList.toggle('active', position === active);
136
+ const item = list.children[active];
137
+ if (item) {
138
+ input.setAttribute('aria-activedescendant', item.id);
139
+ item.scrollIntoView({ block: 'nearest' });
140
+ }
141
+ else
142
+ input.removeAttribute('aria-activedescendant');
143
+ }
144
+ const isOpen = () => !popover.hidden;
145
+ function open() {
146
+ if (isOpen())
147
+ return;
148
+ popover.hidden = false;
149
+ slot.classList.add('open');
150
+ input.setAttribute('aria-expanded', 'true');
151
+ update();
152
+ document.addEventListener('pointerdown', outside, true);
153
+ }
154
+ function close() {
155
+ if (!isOpen())
156
+ return;
157
+ popover.hidden = true;
158
+ slot.classList.remove('open');
159
+ input.setAttribute('aria-expanded', 'false');
160
+ input.removeAttribute('aria-activedescendant');
161
+ input.value = '';
162
+ document.removeEventListener('pointerdown', outside, true);
163
+ }
164
+ function outside(event) {
165
+ if (!slot.contains(event.target))
166
+ close();
167
+ }
168
+ function choose(sha) {
169
+ close();
170
+ input.blur();
171
+ if (sha !== current)
172
+ pick(sha);
173
+ }
174
+ field.addEventListener('pointerdown', event => {
175
+ if (event.target !== input)
176
+ event.preventDefault();
177
+ input.focus();
178
+ open();
179
+ });
180
+ input.addEventListener('focus', open);
181
+ input.addEventListener('blur', () => { if (!slot.matches(':hover'))
182
+ close(); });
183
+ input.addEventListener('input', () => isOpen() ? update() : open());
184
+ input.addEventListener('keydown', event => {
185
+ const last = matches.length - 1;
186
+ if (!isOpen() && (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter')) {
187
+ event.preventDefault();
188
+ open();
189
+ }
190
+ else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
191
+ event.preventDefault();
192
+ active = last < 0 ? 0 : (active + (event.key === 'ArrowDown' ? 1 : -1) + matches.length) % matches.length;
193
+ highlight();
194
+ }
195
+ else if (event.key === 'PageDown' || event.key === 'PageUp') {
196
+ event.preventDefault();
197
+ active = Math.min(last, Math.max(0, active + (event.key === 'PageDown' ? 8 : -8)));
198
+ highlight();
199
+ }
200
+ else if (event.key === 'Enter') {
201
+ event.preventDefault();
202
+ const match = matches[active];
203
+ if (match)
204
+ choose(match.entry.sha);
205
+ }
206
+ else if (event.key === 'Escape' && isOpen()) {
207
+ event.preventDefault();
208
+ close();
209
+ }
210
+ });
211
+ label();
212
+ return {
213
+ set(sha) {
214
+ if (!bySha.has(sha))
215
+ return;
216
+ current = sha;
217
+ label();
218
+ },
219
+ get hidden() { return slot.hidden === true; },
220
+ set hidden(value) {
221
+ if (value)
222
+ close();
223
+ slot.hidden = value;
224
+ },
225
+ };
226
+ }
227
+ /**
228
+ * How a commit's author reads in the list: the name, with the email only when the search found the email and not the
229
+ * name. A public export carries the name alone, and then it is the name alone; nothing reads as missing.
230
+ */
231
+ export function authorLabel(author, words) {
232
+ if (!author?.name)
233
+ return null;
234
+ return author.email && hit(author.email, words) && !hit(author.name, words) ? `${author.name} <${author.email}>` : author.name;
235
+ }
236
+ function hit(text, words) {
237
+ const lower = text.toLowerCase();
238
+ return words.some(word => lower.includes(word));
239
+ }
240
+ function when(entry) {
241
+ const time = Date.parse(entry.committedAt ?? entry.generatedAt);
242
+ return Number.isFinite(time) ? time : null;
243
+ }
244
+ /** Text with the typed words marked; a hash is marked only from its start, as it is matched. */
245
+ function marked(tag, className, text, words, prefixOnly = false) {
246
+ const node = element(tag, className);
247
+ const lower = text.toLowerCase();
248
+ const ranges = [];
249
+ for (const word of words) {
250
+ if (prefixOnly) {
251
+ if (lower.startsWith(word))
252
+ ranges.push([0, word.length]);
253
+ continue;
254
+ }
255
+ for (let at = lower.indexOf(word); at >= 0; at = lower.indexOf(word, at + word.length))
256
+ ranges.push([at, at + word.length]);
257
+ }
258
+ ranges.sort((a, b) => a[0] - b[0]);
259
+ let cursor = 0;
260
+ for (const [start, end] of ranges) {
261
+ if (end <= cursor)
262
+ continue;
263
+ const from = Math.max(start, cursor);
264
+ if (from > cursor)
265
+ node.append(text.slice(cursor, from));
266
+ node.append(element('mark', '', text.slice(from, end)));
267
+ cursor = end;
268
+ }
269
+ if (cursor < text.length)
270
+ node.append(text.slice(cursor));
271
+ return node;
272
+ }
273
+ function element(tag, className, text) {
274
+ const node = document.createElement(tag);
275
+ if (className)
276
+ node.className = className;
277
+ if (text !== undefined)
278
+ node.textContent = text;
279
+ return node;
280
+ }
@@ -0,0 +1,23 @@
1
+ import type { InspectionAsset } from '../../json/wire/inspection-details-model.js';
2
+ import type { InspectionContext } from '../../json/wire/inspection-context-model.js';
3
+ import type { PublicHistoryEntry, QualityHistory } from '../../json/wire/public-history-model.js';
4
+ import type { InspectionCounts, MetricDescriptor } from '../../json/wire/summary-model.js';
5
+ import type { SourceLocator } from './viewer-source.js';
6
+ export interface ViewerData {
7
+ readonly reports: readonly PublicHistoryEntry[];
8
+ readonly quality: QualityHistory['reports'];
9
+ readonly context: Record<string, InspectionContext>;
10
+ readonly counts?: Record<string, InspectionCounts | undefined>;
11
+ readonly pullReviewCount?: number;
12
+ /** The branch whose first-parent history the commits are, when the configuration names it. */
13
+ readonly branch?: string;
14
+ /** The metrics the history's plugins declare; each commit's values are indexed by it. */
15
+ readonly metrics?: readonly MetricDescriptor[];
16
+ /** Where file sources come from, in a detailed export that names a place. */
17
+ readonly sources?: SourceLocator;
18
+ loadDetails(sha: string): Promise<InspectionAsset | null>;
19
+ }
20
+ export declare class ViewerSummaryChanged extends Error {
21
+ constructor();
22
+ }
23
+ export declare function loadViewerData(mode: string | undefined): Promise<ViewerData>;
@@ -0,0 +1,105 @@
1
+ import { unpackJson } from '../../json/wire/compact-json.js';
2
+ import { summarySchema } from '../../json/wire/summary-model.js';
3
+ import { compareHistoryEntries, historySchema } from '../../json/wire/public-history-model.js';
4
+ import { sourceLocator } from './viewer-source.js';
5
+ const shaPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
6
+ export class ViewerSummaryChanged extends Error {
7
+ constructor() {
8
+ super('The repository summary changed');
9
+ this.name = 'ViewerSummaryChanged';
10
+ }
11
+ }
12
+ export async function loadViewerData(mode) {
13
+ const summary = await readSummary();
14
+ if (!summary)
15
+ return legacyViewerData(mode);
16
+ const counts = Object.fromEntries(summary.commits.map(commit => [commit.sha, commit.counts]));
17
+ const details = new Map(summary.commits.map(commit => [commit.sha, commit.detail]));
18
+ return {
19
+ reports: summary.commits,
20
+ quality: Object.fromEntries(summary.commits.map(commit => [commit.sha, commit.quality])),
21
+ context: Object.fromEntries(summary.commits.map(commit => [commit.sha, {
22
+ exclusions: null, boundary: commit.profileBoundary ?? null, security: commit.counts?.security,
23
+ }])),
24
+ counts: mode === 'public' ? undefined : counts,
25
+ pullReviewCount: summary.pullReviewCount,
26
+ ...(Array.isArray(summary.metrics) ? { metrics: summary.metrics } : {}),
27
+ ...(() => {
28
+ const sources = mode === 'public' ? undefined : sourceLocator(summary.sources);
29
+ return sources ? { sources } : {};
30
+ })(),
31
+ ...(typeof summary.source?.branch === 'string' && summary.source.branch.trim() ? { branch: summary.source.branch.trim() } : {}),
32
+ async loadDetails(sha) {
33
+ const path = details.get(sha);
34
+ if (path === undefined || (mode !== 'local' && mode !== 'private'))
35
+ return null;
36
+ const asset = await readInspection(path, sha, mode);
37
+ if (asset)
38
+ return asset;
39
+ const next = await readSummary('reload').catch(() => null);
40
+ if (!next)
41
+ return null;
42
+ if (next.commits.find(commit => commit.sha === sha)?.detail !== path)
43
+ throw new ViewerSummaryChanged();
44
+ return readInspection(path, sha, mode);
45
+ },
46
+ };
47
+ }
48
+ async function readSummary(cache) {
49
+ const response = await fetch('./summary.json', { cache });
50
+ if (response.status === 404)
51
+ return null;
52
+ if (!response.ok)
53
+ throw new Error('Could not load the repository summary');
54
+ const data = await response.json();
55
+ if (data?.schema !== summarySchema || !Array.isArray(data.commits)
56
+ || data.commits.some(commit => !shaPattern.test(commit.sha) || !commit.quality))
57
+ throw new Error('Unsupported repository summary');
58
+ return data;
59
+ }
60
+ async function readInspection(path, sha, mode) {
61
+ const prefix = `${mode === 'local' ? 'inspection' : 'details'}/${sha}-`;
62
+ const allowed = path.startsWith(prefix) && /^[a-f0-9]{64}\.json$/.test(path.slice(prefix.length));
63
+ if (!allowed)
64
+ return null;
65
+ try {
66
+ const asset = unpackJson(await readOptional(`./${path}`));
67
+ return asset?.schema === 'urn:repometry:schema:viewer-inspection:1' && asset.sha === sha ? asset : null;
68
+ }
69
+ catch {
70
+ return null;
71
+ }
72
+ }
73
+ async function legacyViewerData(mode) {
74
+ const [history, quality, saved, localContext] = await Promise.all([
75
+ readOptional('./history.json'),
76
+ readOptional('./quality-history.json'),
77
+ mode === 'private' ? readOptional('./details.json') : null,
78
+ mode === 'local' ? readOptional('./inspection-context.json') : null,
79
+ ]);
80
+ if (history?.schema !== historySchema || !Array.isArray(history.reports))
81
+ throw new Error('Unsupported history format');
82
+ const bundle = saved?.schema === 'urn:repometry:schema:viewer-details:1' ? saved : null;
83
+ const context = localContext ?? bundle?.context ?? {};
84
+ const reports = [...history.reports].sort(compareHistoryEntries);
85
+ return {
86
+ reports, context, quality: quality?.schema === 'urn:repometry:schema:quality-history:1' ? quality.reports : {},
87
+ async loadDetails(sha) {
88
+ if (!shaPattern.test(sha))
89
+ return null;
90
+ const inspection = mode === 'local'
91
+ ? await readOptional(`./details/${sha}.json`)
92
+ : bundle?.inspections[sha];
93
+ return inspection ? { schema: 'urn:repometry:schema:viewer-inspection:1', sha, context: context[sha], inspection } : null;
94
+ },
95
+ };
96
+ }
97
+ async function readOptional(path) {
98
+ try {
99
+ const response = await fetch(path);
100
+ return response.ok ? await response.json() : null;
101
+ }
102
+ catch {
103
+ return null;
104
+ }
105
+ }
@@ -0,0 +1,117 @@
1
+ import type { FileMetricsReport } from '../../json/wire/file-metrics-model.js';
2
+ import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
3
+ import type { PluginMetric } from './viewer-metrics.js';
4
+ type View = 'metrics' | 'hotspots' | 'diagnostics' | 'issues';
5
+ type Metrics = FileMetricsReport['files'][number];
6
+ type BuiltinHotspot = keyof FileMetricsReport['hotspots'];
7
+ /** What the code map and the ranking measure: one of Repometry's rankings, or another plugin's metric by its key. */
8
+ export type HotspotMetric = BuiltinHotspot | PluginMetric;
9
+ interface Navigation {
10
+ readonly directory: string;
11
+ readonly file: string;
12
+ /** The Metrics query and grouping from the URL. */
13
+ readonly query?: string | undefined;
14
+ readonly group?: string | undefined;
15
+ /** A source line to bring into view. */
16
+ readonly line?: number | undefined;
17
+ /** The Issues filters from the URL: finding categories, comma-separated, and a severity. */
18
+ readonly category?: string | undefined;
19
+ readonly level?: string | undefined;
20
+ /** What Hotspots ranks by. */
21
+ readonly rank?: string | undefined;
22
+ /** Source text of a file at this commit; absent where the view cannot load source. */
23
+ readonly source?: ((path: string) => Promise<string | null>) | undefined;
24
+ /** The file's page on its forge, when the export names one. */
25
+ readonly sourcePage?: ((path: string, line?: number) => {
26
+ readonly href: string;
27
+ readonly provider: string;
28
+ } | null) | undefined;
29
+ href(view: View, options?: LinkOptions): string;
30
+ }
31
+ export interface LinkOptions {
32
+ readonly directory?: string;
33
+ readonly file?: string;
34
+ readonly query?: string;
35
+ readonly group?: string;
36
+ readonly line?: number;
37
+ readonly category?: string;
38
+ readonly level?: string;
39
+ readonly rank?: string;
40
+ }
41
+ /**
42
+ * The finding categories Repometry counts as code smells, mirroring core's quality summary (structure and
43
+ * duplication), so the Overview's smell count links to exactly the findings it counts.
44
+ */
45
+ export declare const codeSmellCategories: readonly ['structure', 'duplication'];
46
+ /** The finding categories behind the security level, as the Overview's security column counts them. */
47
+ export declare const securityCategories: readonly ['security', 'dependency', 'secret', 'infrastructure'];
48
+ export declare function renderFileView(container: HTMLElement, view: View, details: InspectionDetails, navigation: Navigation): void;
49
+ /** The folders all of whose files are only counted, found in one pass over the files. */
50
+ export declare function unreadFolders(files: readonly Pick<Metrics, 'path' | 'analysed'>[]): Set<string>;
51
+ type MapShape = 'rings' | 'tiles';
52
+ interface SunburstOptions {
53
+ readonly metric: HotspotMetric;
54
+ readonly directory?: string;
55
+ readonly compact?: boolean;
56
+ /** Rings (a sunburst) or tiles (a treemap); the last choice is remembered for this viewer. */
57
+ readonly shape?: MapShape;
58
+ /** Offered beside the map's title, where the page lets the viewer switch shapes. */
59
+ readonly reshape?: (shape: MapShape) => void;
60
+ /** More controls for the map's title row, such as what it is coloured by. */
61
+ readonly controls?: HTMLElement;
62
+ /** Sizes only, in grey: the map stands for an area with no measurement of its own, as security without a scanner. */
63
+ readonly muted?: boolean;
64
+ /**
65
+ * Security: each file's worst finding level, 0 none to 4 critical, coloured in the grade steps of the security mark.
66
+ * A folder takes the worst level inside it. Files missing from the map have no findings.
67
+ */
68
+ readonly levels?: ReadonlyMap<string, number>;
69
+ href(view: 'hotspots' | 'metrics', options?: {
70
+ directory?: string;
71
+ file?: string;
72
+ }): string;
73
+ }
74
+ /**
75
+ * The top of a relative colour scale, per level: files against files, folders against the folders at their depth. One
76
+ * scale for both would let a folder's sum outshine every file in it, and the map would read hot folders over pale files.
77
+ */
78
+ export declare function relativePeaks(entries: readonly {
79
+ readonly path: string;
80
+ readonly folder: boolean;
81
+ readonly score: number;
82
+ }[]): (path: string, folder: boolean) => number;
83
+ export declare function renderSunburst(details: InspectionDetails, options: SunburstOptions): HTMLElement;
84
+ /**
85
+ * The handle between a list and its side panel: a line that shows on hover and drags the panel wider or narrower.
86
+ * Arrow keys move it too, a double click restores the default, and the width is remembered for this viewer.
87
+ */
88
+ export declare function splitter(split: HTMLElement): HTMLElement;
89
+ /**
90
+ * The compact map's stand-in while the inspection loads: the same frame, switch and canvas size in a flat tone, so the
91
+ * column keeps its shape and the map fades in where it will stand.
92
+ */
93
+ export declare function mapStub(): HTMLElement;
94
+ /** The profile's limits for a metric with a meaningful scale, when they are well formed; otherwise the defaults. */
95
+ export declare function bandLimits(details: Pick<InspectionDetails, 'bands'>, metric: HotspotMetric): readonly number[] | undefined;
96
+ export declare function band(entry: Metrics, metric: HotspotMetric, score: number, highest: number, limits?: readonly number[] | undefined): number;
97
+ /** Each file's worst level spread to the folders above it. */
98
+ export declare function spreadLevels(files: ReadonlyMap<string, number>): Map<string, number>;
99
+ /** The common copy glyph, two offset sheets, with the check it turns into once copied. */
100
+ export declare function copyIcon(): SVGSVGElement;
101
+ export declare function navigationButtons(label: string, previous: () => void, next: () => void): {
102
+ section: HTMLElement;
103
+ update: (page: number, pages: number) => void;
104
+ };
105
+ export declare function searchField(text: string, placeholder: string): {
106
+ label: HTMLLabelElement;
107
+ input: HTMLInputElement;
108
+ };
109
+ /**
110
+ * A dropdown of checkboxes: none ticked means all. The button names what is chosen, so the filter reads at a glance;
111
+ * each option carries its count. It hides itself when there is nothing to choose between.
112
+ */
113
+ export declare function multiChoice(text: string, all: string, plural: string, options: readonly (readonly [string, string, number])[], change: () => void, initial?: Iterable<string>): {
114
+ element: HTMLDetailsElement;
115
+ values: Set<string>;
116
+ };
117
+ export {};