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.
- package/README.md +36 -14
- package/package.json +1 -1
- package/target/main/resources/report/json/comparison-v1.schema.json +6 -6
- package/target/main/resources/report/json/file-metrics-v1.schema.json +7 -6
- package/target/main/resources/report/json/pull-review-v1.schema.json +5 -5
- package/target/main/resources/report/json/report-v2.schema.json +210 -11
- package/target/main/resources/report/json/repository-summary-v1.schema.json +161 -14
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +518 -6
- package/target/main/resources/viewer/styles.css +7 -2
- package/target/main/ts/api/git/changes.d.ts +1 -1
- package/target/main/ts/api/git/changes.js +3 -3
- package/target/main/ts/api/git/commit-metadata.js +6 -4
- package/target/main/ts/api/git/git.d.ts +2 -1
- package/target/main/ts/api/git/git.js +16 -4
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +4 -10
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +41 -7
- package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
- package/target/main/ts/api/process/docker-tool-runner.js +108 -0
- package/target/main/ts/api/process/failure.d.ts +1 -0
- package/target/main/ts/api/process/failure.js +12 -0
- package/target/main/ts/api/process/plugin.d.ts +10 -0
- package/target/main/ts/api/process/plugin.js +96 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +1 -1
- package/target/main/ts/api/worker/remote-executor.js +2 -2
- package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
- package/target/main/ts/api/worker/worker-protocol.js +8 -8
- package/target/main/ts/api/worker/worker.d.ts +1 -1
- package/target/main/ts/api/worker/worker.js +4 -4
- package/target/main/ts/cli/main.js +4 -3
- package/target/main/ts/cli/reporting.d.ts +1 -1
- package/target/main/ts/cli/reporting.js +1 -1
- package/target/main/ts/compose/analysis-files.d.ts +13 -0
- package/target/main/ts/compose/analysis-files.js +95 -0
- package/target/main/ts/compose/analysis-imports.d.ts +7 -0
- package/target/main/ts/compose/analysis-imports.js +34 -0
- package/target/main/ts/compose/analysis-report.d.ts +5 -0
- package/target/main/ts/compose/analysis-report.js +78 -0
- package/target/main/ts/compose/analysis-repository.d.ts +6 -0
- package/target/main/ts/compose/analysis-repository.js +61 -0
- package/target/main/ts/compose/analysis-results.d.ts +38 -0
- package/target/main/ts/compose/analysis-results.js +78 -0
- package/target/main/ts/compose/analysis-sources.d.ts +73 -0
- package/target/main/ts/compose/analysis-sources.js +47 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +19 -197
- package/target/main/ts/compose/diff-coverage.d.ts +2 -0
- package/target/main/ts/compose/diff-coverage.js +6 -4
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +14 -7
- package/target/main/ts/compose/languages.d.ts +29 -0
- package/target/main/ts/compose/languages.js +87 -0
- package/target/main/ts/compose/sources.js +14 -12
- package/target/main/ts/core/engine/execute.d.ts +3 -1
- package/target/main/ts/core/engine/execute.js +14 -2
- package/target/main/ts/core/engine/manifest.d.ts +2 -2
- package/target/main/ts/core/engine/manifest.js +25 -5
- package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
- package/target/main/ts/core/engine/operation-cache.js +66 -0
- package/target/main/ts/core/engine/plan.d.ts +3 -4
- package/target/main/ts/core/engine/plan.js +28 -11
- package/target/main/ts/core/engine/plugin.d.ts +10 -2
- package/target/main/ts/core/engine/plugin.js +1 -3
- package/target/main/ts/core/engine/report-products.js +2 -13
- package/target/main/ts/core/model/clone-source.d.ts +1 -0
- package/target/main/ts/core/model/clone-source.js +2 -1
- package/target/main/ts/core/model/code-structure.d.ts +5 -0
- package/target/main/ts/core/model/code-structure.js +10 -1
- package/target/main/ts/core/model/finding-ignore.js +1 -1
- package/target/main/ts/core/model/finding.js +1 -1
- package/target/main/ts/core/model/language.d.ts +10 -0
- package/target/main/ts/core/model/language.js +6 -0
- package/target/main/ts/core/model/line-coverage.d.ts +5 -1
- package/target/main/ts/core/model/line-coverage.js +14 -11
- package/target/main/ts/core/model/measurement.d.ts +7 -6
- package/target/main/ts/core/model/measurement.js +18 -7
- package/target/main/ts/core/model/plugin-data.d.ts +5 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +6 -5
- package/target/main/ts/core/model/report.d.ts +1 -2
- package/target/main/ts/core/model/report.js +0 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -2
- package/target/main/ts/core/model/snapshot.js +5 -7
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +15 -0
- package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
- package/target/main/ts/core/ports/tool-runner.js +2 -0
- package/target/main/ts/core/usecases/compare.js +61 -17
- package/target/main/ts/core/usecases/inspect.js +2 -2
- package/target/main/ts/plugin.d.ts +10 -3
- package/target/main/ts/plugin.js +4 -2
- package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
- package/target/main/ts/plugins/coverage/coverage.js +35 -10
- package/target/main/ts/plugins/duplication/duplication.js +10 -4
- package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
- package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
- package/target/main/ts/plugins/language-js/extensions.js +4 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
- package/target/main/ts/plugins/language-js/function-facts.js +30 -4
- package/target/main/ts/plugins/language-js/js-security.js +3 -2
- package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
- package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
- package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
- package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
- package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
- package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
- package/target/main/ts/report/html/app/viewer-chart.js +16 -677
- package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
- package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
- package/target/main/ts/report/html/app/viewer-columns.js +92 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
- package/target/main/ts/report/html/app/viewer-commits.js +17 -216
- package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
- package/target/main/ts/report/html/app/viewer-controls.js +141 -0
- package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-copy.js +64 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +1 -1
- package/target/main/ts/report/html/app/viewer-data.js +2 -29
- package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
- package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-dom.js +99 -0
- package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
- package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
- package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
- package/target/main/ts/report/html/app/viewer-files.js +24 -2184
- package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
- package/target/main/ts/report/html/app/viewer-filter.js +111 -450
- package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
- package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
- package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
- package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
- package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-issues.js +173 -0
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
- package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-languages.js +93 -0
- package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-layout.js +134 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
- package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-locations.js +31 -0
- package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
- package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
- package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
- package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
- package/target/main/ts/report/html/app/viewer-metric-registry.js +7 -84
- package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +118 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
- package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
- package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
- package/target/main/ts/report/html/app/viewer-profile.js +6 -248
- package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
- package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
- package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
- package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
- package/target/main/ts/report/html/app/viewer-route.js +55 -0
- package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
- package/target/main/ts/report/html/app/viewer-shell.js +116 -0
- package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
- package/target/main/ts/report/html/app/viewer-source.js +7 -365
- package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
- package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
- package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
- package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
- package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
- package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
- package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-totals.js +89 -0
- package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +109 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
- package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
- package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
- package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
- package/target/main/ts/report/html/app/viewer-trends.js +41 -392
- package/target/main/ts/report/html/app/viewer.js +152 -663
- package/target/main/ts/report/html/site/export-site.d.ts +3 -4
- package/target/main/ts/report/html/site/export-site.js +24 -41
- package/target/main/ts/report/html/site/exported-server.js +2 -1
- package/target/main/ts/report/html/site/local-server.d.ts +1 -1
- package/target/main/ts/report/html/site/local-server.js +13 -19
- package/target/main/ts/report/html/site/projects.js +8 -17
- package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
- package/target/main/ts/report/json/projections/commit-summary.js +18 -19
- package/target/main/ts/report/json/projections/file-metrics.js +31 -24
- package/target/main/ts/report/json/projections/inspection-context.js +10 -1
- package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
- package/target/main/ts/report/json/projections/inspection-details.js +2 -2
- package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
- package/target/main/ts/report/json/projections/metric-values.js +15 -5
- package/target/main/ts/report/json/store/local-store.js +2 -12
- package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
- package/target/main/ts/report/json/store/operation-cache.js +32 -0
- package/target/main/ts/report/json/store/pull-review-store.js +1 -2
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
- package/target/main/ts/report/json/store/replace-file.js +14 -0
- package/target/main/ts/report/json/validation/report.d.ts +1 -1
- package/target/main/ts/report/json/validation/report.js +10 -8
- package/target/main/ts/report/json/validation/summary-validation.js +1 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
- package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
- package/target/main/ts/report/json/wire/public-history-model.js +0 -1
- package/target/main/ts/report.d.ts +3 -3
- package/target/main/ts/report.js +2 -2
- package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
- package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
- package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
- package/target/main/resources/report/json/report-v1.schema.json +0 -65
- package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
- package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
- package/target/main/ts/report/json/projections/public-history.js +0 -17
|
@@ -5,8 +5,6 @@ import type { PullReview } from '../../json/wire/pull-review-model.js';
|
|
|
5
5
|
import type { Component } from '../../json/projections/components.js';
|
|
6
6
|
export interface SiteOptions {
|
|
7
7
|
readonly title?: string;
|
|
8
|
-
/** `local` for `repometry view`, which serves details live; an export writes them as files. */
|
|
9
|
-
readonly mode?: 'local' | 'private';
|
|
10
8
|
readonly components?: readonly Component[];
|
|
11
9
|
readonly pulls?: readonly PullReview[];
|
|
12
10
|
readonly sources?: SourceLocator;
|
|
@@ -17,6 +15,7 @@ export interface SiteOptions {
|
|
|
17
15
|
}
|
|
18
16
|
/** A page without its footer, for reports published under someone else's name. */
|
|
19
17
|
export declare function withoutFooter(html: string): string;
|
|
20
|
-
export declare function
|
|
21
|
-
export declare function
|
|
18
|
+
export declare function viewerAssets(rows: readonly CommitSummary[], { title, pulls, footer }: SiteOptions): Promise<Map<string, Buffer<ArrayBufferLike>>>;
|
|
19
|
+
export declare function siteFiles(reports: readonly Report[], options?: SiteOptions): Promise<Map<string, Buffer>>;
|
|
20
|
+
export declare function siteSummary(rows: readonly CommitSummary[], { components, pulls, sources, branch }: SiteOptions, inspectionPath?: (row: CommitSummary) => string | undefined): Buffer;
|
|
22
21
|
export declare function exportSite(reader: ReportReader, destination: string, options?: SiteOptions): Promise<void>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { historySchema } from '../../json/wire/public-history-model.js';
|
|
5
4
|
import { inspectionAsset } from '../../json/projections/inspection-details.js';
|
|
6
|
-
import {
|
|
5
|
+
import { validateSummaryIndex } from '../../json/validation/summary-validation.js';
|
|
7
6
|
import { commitSummary, orderSummaries, repositorySummary, withCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
8
7
|
import { packJson } from '../../json/wire/compact-json.js';
|
|
9
8
|
import { comparePaths, digest } from '../../../core/model/snapshot.js';
|
|
@@ -33,7 +32,7 @@ async function listAssets(directory, include) {
|
|
|
33
32
|
export function withoutFooter(html) {
|
|
34
33
|
return html.replace(/\n[ \t]*<footer class="site-footer">[\s\S]*?<\/footer>/, '');
|
|
35
34
|
}
|
|
36
|
-
export async function
|
|
35
|
+
export async function viewerAssets(rows, { title = '', pulls = [], footer = true }) {
|
|
37
36
|
const files = new Map(await Promise.all((await listViewerAssets()).map(async ([name, source]) => {
|
|
38
37
|
const bytes = await readFile(source);
|
|
39
38
|
// The published viewer keeps its existing flat URLs for static hosts and open tabs.
|
|
@@ -43,42 +42,38 @@ export async function siteFiles(reports, { title = '', mode = 'private', compone
|
|
|
43
42
|
return [name, contents];
|
|
44
43
|
})));
|
|
45
44
|
const index = files.get('index.html').toString('utf8')
|
|
46
|
-
.replace('name="repometry-view" content="private"', `name="repometry-view" content="${mode}"`)
|
|
47
45
|
.replace('name="repometry-project" content=""', () => `name="repometry-project" content="${escapeAttribute(title)}"`);
|
|
48
46
|
files.set('index.html', Buffer.from(footer ? index : withoutFooter(index)));
|
|
49
|
-
const commits = reports.filter(report => report.subject.kind === 'commit');
|
|
50
|
-
const rows = orderSummaries(await withCommitMetadata(indexed ?? commits.map(commitSummary), readCommitMetadata));
|
|
51
|
-
const publicRows = rows.map(({ quality, counts, detail, revision, profileDigest, profileBoundary, subject, author, tags, metrics, values, privateMetrics, ...history }) => ({ ...history, subject, author, tags }));
|
|
52
|
-
const history = { schema: historySchema, reports: publicRows };
|
|
53
|
-
const quality = { schema: 'urn:repometry:schema:quality-history:1',
|
|
54
|
-
reports: Object.fromEntries(rows.map(row => [row.sha, row.quality])) };
|
|
55
|
-
files.set('history.json', Buffer.from(`${JSON.stringify(history)}\n`));
|
|
56
|
-
files.set('quality-history.json', Buffer.from(`${JSON.stringify(quality)}\n`));
|
|
57
47
|
const latest = rows[0];
|
|
58
48
|
for (const [name, data] of badges(latest, latest?.quality, latest?.counts?.security))
|
|
59
49
|
files.set(name, data);
|
|
60
50
|
files.set('pulls.json', Buffer.from(`${JSON.stringify({ schema: pullReviewsSchema, reviews: pulls })}\n`));
|
|
51
|
+
return files;
|
|
52
|
+
}
|
|
53
|
+
export async function siteFiles(reports, options = {}) {
|
|
54
|
+
const commits = reports.filter(report => report.subject.kind === 'commit');
|
|
55
|
+
const rows = orderSummaries(await withCommitMetadata(commits.map(commitSummary), options.readCommitMetadata));
|
|
56
|
+
const files = await viewerAssets(rows, options);
|
|
61
57
|
const details = new Map();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
files.set(name, Buffer.from(data));
|
|
69
|
-
}
|
|
58
|
+
for (const report of commits) {
|
|
59
|
+
const sha = report.subject.id;
|
|
60
|
+
const data = JSON.stringify(packJson(inspectionAsset(report, options.components))) + '\n';
|
|
61
|
+
const name = `details/${sha}-${digest(data)}.json`;
|
|
62
|
+
details.set(sha, name);
|
|
63
|
+
files.set(name, Buffer.from(data));
|
|
70
64
|
}
|
|
71
|
-
files.set('summary.json', siteSummary(rows,
|
|
65
|
+
files.set('summary.json', siteSummary(rows, options, row => details.get(row.sha)));
|
|
72
66
|
return files;
|
|
73
67
|
}
|
|
74
|
-
export function siteSummary(rows, {
|
|
68
|
+
export function siteSummary(rows, { components, pulls = [], sources, branch }, inspectionPath) {
|
|
75
69
|
const ordered = orderSummaries(rows);
|
|
76
|
-
const commits = ordered.map((
|
|
70
|
+
const commits = ordered.map((current, index) => {
|
|
71
|
+
const { counts, detail, revision, profileDigest, profileBoundary, subject, author, tags, ...row } = current;
|
|
77
72
|
const previous = ordered[index + 1];
|
|
78
73
|
const boundary = !previous ? undefined : !profileDigest || !previous.profileDigest ? 'unavailable'
|
|
79
74
|
: profileDigest === previous.profileDigest ? undefined : 'changed';
|
|
80
75
|
return {
|
|
81
|
-
...row, subject, author, tags, detail:
|
|
76
|
+
...row, subject, author, tags, detail: inspectionPath?.(current),
|
|
82
77
|
counts: counts && { ...counts, componentCount: components?.length ?? 0 },
|
|
83
78
|
...(boundary === undefined ? {} : { profileBoundary: boundary }),
|
|
84
79
|
};
|
|
@@ -93,19 +88,10 @@ export async function exportSite(reader, destination, options = {}) {
|
|
|
93
88
|
if (!(await lstat(destination)).isDirectory())
|
|
94
89
|
throw new Error('The viewer destination must be a directory');
|
|
95
90
|
const entries = await readdir(destination, { withFileTypes: true });
|
|
96
|
-
const oldDetails = entries.some(entry => entry.name === 'details.json' && entry.isFile());
|
|
97
91
|
const detailDirectory = entries.some(entry => entry.name === 'details' && entry.isDirectory());
|
|
98
|
-
if (entries.some(entry => !(entry.isFile() && files.has(entry.name))
|
|
99
|
-
&& !(entry.name === 'details' && entry.isDirectory())
|
|
100
|
-
&& !(oldDetails && entry.name === 'details.json' && entry.isFile()))) {
|
|
92
|
+
if (entries.some(entry => !(entry.isFile() && files.has(entry.name)) && !(entry.name === 'details' && entry.isDirectory()))) {
|
|
101
93
|
throw new Error('Use a dedicated viewer destination containing only Repometry export files');
|
|
102
94
|
}
|
|
103
|
-
if (oldDetails) {
|
|
104
|
-
const legacy = JSON.parse(await readFile(join(destination, 'details.json'), 'utf8'));
|
|
105
|
-
if (!isRecord(legacy) || legacy.schema !== 'urn:repometry:schema:viewer-details:1') {
|
|
106
|
-
throw new Error('Existing details.json is not a Repometry export');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
95
|
if (detailDirectory) {
|
|
110
96
|
const existing = await readdir(join(destination, 'details'), { withFileTypes: true });
|
|
111
97
|
if (existing.some(entry => !entry.isFile() || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})-[a-f0-9]{64}\.json$/.test(entry.name))) {
|
|
@@ -113,9 +99,9 @@ export async function exportSite(reader, destination, options = {}) {
|
|
|
113
99
|
}
|
|
114
100
|
}
|
|
115
101
|
if (entries.length > 0) {
|
|
116
|
-
const existing = entries.some(entry => entry.name === '
|
|
117
|
-
? JSON.parse(await readFile(join(destination, '
|
|
118
|
-
if (!
|
|
102
|
+
const existing = entries.some(entry => entry.name === 'summary.json')
|
|
103
|
+
? JSON.parse(await readFile(join(destination, 'summary.json'), 'utf8')) : undefined;
|
|
104
|
+
if (!validateSummaryIndex(existing))
|
|
119
105
|
throw new Error('Choose an empty viewer directory or an existing Repometry export');
|
|
120
106
|
}
|
|
121
107
|
const staging = join(destination, `.export-${randomUUID()}`);
|
|
@@ -128,17 +114,14 @@ export async function exportSite(reader, destination, options = {}) {
|
|
|
128
114
|
await writeFile(join(staging, name), bytes, { mode: 0o644 });
|
|
129
115
|
const afterDependencies = ['viewer.js', 'summary.json', 'index.html'];
|
|
130
116
|
const install = (name) => rename(join(staging, name), join(destination, name));
|
|
131
|
-
await install('history.json');
|
|
132
117
|
if (hasDetails && !detailDirectory)
|
|
133
118
|
await mkdir(join(destination, 'details'));
|
|
134
119
|
for (const name of files.keys()) {
|
|
135
|
-
if (
|
|
120
|
+
if (!afterDependencies.includes(name))
|
|
136
121
|
await install(name);
|
|
137
122
|
}
|
|
138
123
|
for (const name of afterDependencies)
|
|
139
124
|
await install(name);
|
|
140
|
-
if (oldDetails)
|
|
141
|
-
await rm(join(destination, 'details.json'));
|
|
142
125
|
}
|
|
143
126
|
finally {
|
|
144
127
|
await rm(staging, { recursive: true, force: true });
|
|
@@ -28,7 +28,8 @@ export async function serveExportedSite(directory, port, access) {
|
|
|
28
28
|
const details = new Map(summary.commits.map(row => [row.sha, row.detail]));
|
|
29
29
|
const local = summary.sources?.provider === 'local' && summary.sources.url === './sources/{revision}/{path}' ? access : undefined;
|
|
30
30
|
async function file(name) {
|
|
31
|
-
if (!/^[A-Za-z0-9_-]+\.(?:html|css|js|
|
|
31
|
+
if (name !== 'summary.json' && name !== 'pulls.json' && !/^[A-Za-z0-9_-]+\.(?:html|css|js|svg)$/.test(name)
|
|
32
|
+
&& !/^details\/[a-f0-9]+-[a-f0-9]{64}\.json$/.test(name)) {
|
|
32
33
|
return undefined;
|
|
33
34
|
}
|
|
34
35
|
const path = join(root, name);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReportReader } from '../../json/validation/report.js';
|
|
2
2
|
import type { SiteOptions } from './export-site.js';
|
|
3
3
|
import type { SourceAccess } from './source-route.js';
|
|
4
|
-
export declare function serveSite(reader: ReportReader, port: number, options?:
|
|
4
|
+
export declare function serveSite(reader: ReportReader, port: number, options?: SiteOptions, source?: SourceAccess): Promise<{
|
|
5
5
|
url: string;
|
|
6
6
|
close: () => void;
|
|
7
7
|
}>;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { reportRevision, validSubjectId } from '../../json/validation/report.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { inspectionHistory } from '../../json/projections/inspection-context.js';
|
|
5
|
-
import { complexFunctions, inspectionAsset, inspectionDetails } from '../../json/projections/inspection-details.js';
|
|
2
|
+
import { siteSummary, viewerAssets } from './export-site.js';
|
|
3
|
+
import { inspectionAsset } from '../../json/projections/inspection-details.js';
|
|
6
4
|
import { packJson } from '../../json/wire/compact-json.js';
|
|
7
|
-
import { withCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
5
|
+
import { commitSummary, orderSummaries, withCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
8
6
|
import { serveAssets } from './server.js';
|
|
9
7
|
import { sourceResponse } from './source-route.js';
|
|
10
8
|
export async function serveSite(reader, port, options = {}, source) {
|
|
11
9
|
const indexed = await reader.listSummaries?.();
|
|
12
10
|
const reports = indexed ? [] : await reader.list();
|
|
13
|
-
const siteOptions = { ...options, mode: 'local' };
|
|
14
|
-
const files = await siteFiles(reports, siteOptions, indexed);
|
|
15
11
|
const commits = new Map(reports.filter(report => report.subject.kind === 'commit').map(report => [report.subject.id, report]));
|
|
12
|
+
const rows = orderSummaries(await withCommitMetadata(indexed ?? [...commits.values()].map(commitSummary), options.readCommitMetadata));
|
|
13
|
+
const files = await viewerAssets(rows, options);
|
|
14
|
+
files.set('index.html', Buffer.from(files.get('index.html').toString('utf8')
|
|
15
|
+
.replace('name="repometry-view" content="private"', 'name="repometry-view" content="local"')));
|
|
16
|
+
files.set('summary.json', siteSummary(rows, options, liveInspectionPath));
|
|
16
17
|
async function read(sha) {
|
|
17
18
|
if (!validSubjectId('commit', sha))
|
|
18
19
|
return undefined;
|
|
@@ -34,28 +35,21 @@ export async function serveSite(reader, port, options = {}, source) {
|
|
|
34
35
|
return report !== undefined && sourceListed(report, path);
|
|
35
36
|
});
|
|
36
37
|
if (name === 'summary.json' && reader.listSummaries) {
|
|
37
|
-
return siteSummary(await withCommitMetadata(await reader.listSummaries(), options.readCommitMetadata),
|
|
38
|
+
return siteSummary(await withCommitMetadata(await reader.listSummaries(), options.readCommitMetadata), options, liveInspectionPath);
|
|
38
39
|
}
|
|
39
|
-
if (name === 'inspection-context.json')
|
|
40
|
-
return Buffer.from(JSON.stringify(inspectionHistory(indexed ? await reader.list() : reports)));
|
|
41
40
|
const versioned = /^inspection\/([a-f0-9]+)-([a-f0-9]{64})\.json$/.exec(name);
|
|
42
41
|
if (versioned) {
|
|
43
42
|
const inspection = await read(versioned[1]);
|
|
44
43
|
return inspection && reportRevision(inspection) === versioned[2]
|
|
45
44
|
? Buffer.from(JSON.stringify(packJson(inspectionAsset(inspection, options.components)))) : undefined;
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
if (!resource)
|
|
49
|
-
return files.get(name);
|
|
50
|
-
const inspection = await read(resource[2]);
|
|
51
|
-
if (!inspection)
|
|
52
|
-
return undefined;
|
|
53
|
-
const value = resource[1] === 'files' ? fileMetrics(inspection)
|
|
54
|
-
: resource[1] === 'functions' ? complexFunctions(inspection).slice(0, 5) : inspectionDetails(inspection, options.components);
|
|
55
|
-
return Buffer.from(JSON.stringify(value));
|
|
46
|
+
return files.get(name);
|
|
56
47
|
}
|
|
57
48
|
return serveAssets(port, asset, source?.close);
|
|
58
49
|
}
|
|
50
|
+
function liveInspectionPath({ sha, revision }) {
|
|
51
|
+
return revision === undefined ? undefined : `inspection/${sha}-${revision}.json`;
|
|
52
|
+
}
|
|
59
53
|
function sourceListed(report, path) {
|
|
60
54
|
return (report.pluginData?.inventory ?? []).some(file => file.path === path)
|
|
61
55
|
|| report.measurements.some(row => row.path === path)
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
import historyContract from '../../../../resources/report/json/public-history-v1.schema.json' with { type: 'json' };
|
|
6
|
-
import qualityContract from '../../../../resources/report/json/quality-history-v1.schema.json' with { type: 'json' };
|
|
4
|
+
import { readExportedSummary } from './exported-server.js';
|
|
7
5
|
import { withoutFooter } from './export-site.js';
|
|
8
6
|
const indexMarker = '<meta name="repometry-projects" content="1">';
|
|
9
7
|
const resources = '../../../../resources/viewer/';
|
|
10
|
-
const validator = new Ajv2020();
|
|
11
|
-
const validHistory = validator.compile(historyContract);
|
|
12
|
-
const validQuality = validator.compile(qualityContract);
|
|
13
8
|
export async function exportProjects(directory, { footer = true } = {}) {
|
|
14
9
|
const folders = await readdir(directory, { withFileTypes: true });
|
|
15
10
|
const candidates = folders.filter(entry => (entry.isDirectory() || entry.isSymbolicLink()) && !entry.name.startsWith('.'));
|
|
@@ -51,18 +46,14 @@ export async function exportProjects(directory, { footer = true } = {}) {
|
|
|
51
46
|
return entries.length;
|
|
52
47
|
}
|
|
53
48
|
async function readProject(directory, name) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (text === null)
|
|
49
|
+
const summary = await readExportedSummary(join(directory, name));
|
|
50
|
+
if (!summary)
|
|
57
51
|
return null;
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
60
|
-
return null;
|
|
61
|
-
const inspection =
|
|
62
|
-
|
|
63
|
-
const quality = qualityText ? JSON.parse(qualityText) : null;
|
|
64
|
-
return { name, inspection, quality: inspection && validQuality(quality)
|
|
65
|
-
? quality.reports[inspection.sha] ?? null : null };
|
|
52
|
+
const latest = summary.commits[0];
|
|
53
|
+
if (!latest)
|
|
54
|
+
return { name, inspection: null, quality: null };
|
|
55
|
+
const { quality, counts, detail, revision, profileDigest, profileBoundary, metrics, values, privateMetrics, ...inspection } = latest;
|
|
56
|
+
return { name, inspection, quality };
|
|
66
57
|
}
|
|
67
58
|
async function readOptional(path) {
|
|
68
59
|
try {
|
|
@@ -3,9 +3,9 @@ import type { Report } from '../validation/report.js';
|
|
|
3
3
|
import type { CommitSummary, RepositorySummary } from '../wire/summary-model.js';
|
|
4
4
|
export declare function commitSummary(report: Report): CommitSummary;
|
|
5
5
|
export declare function orderSummaries(rows: readonly CommitSummary[]): CommitSummary[];
|
|
6
|
-
export type CommitMetadata = Pick<PublicHistoryEntry, 'subject' | 'author' | 'tags'>;
|
|
6
|
+
export type CommitMetadata = Pick<PublicHistoryEntry, 'subject' | 'author' | 'tags' | 'committedAt'>;
|
|
7
7
|
export type ReadCommitMetadata = (revisions: readonly string[]) => Promise<ReadonlyMap<string, CommitMetadata>>;
|
|
8
|
-
/** Values recorded at analysis win; Git fills in
|
|
8
|
+
/** Values recorded at analysis win; Git fills in missing metadata and adds current tag names. */
|
|
9
9
|
export declare function withCommitMetadata(rows: readonly CommitSummary[], read?: ReadCommitMetadata): Promise<readonly CommitSummary[]>;
|
|
10
10
|
export declare function expandSummaryCatalog(summary: RepositorySummary): CommitSummary[];
|
|
11
11
|
export declare function repositorySummary(rows: readonly CommitSummary[], pullReviewCount?: number, includePrivateMetrics?: boolean): RepositorySummary;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { definitions } from '../../../core/model/measurement.js';
|
|
1
|
+
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
3
2
|
import { qualitySummary } from '../../../core/model/quality-summary.js';
|
|
4
3
|
import { securityCounts } from './security-summary.js';
|
|
5
4
|
import { compareHistoryEntries } from '../wire/public-history-model.js';
|
|
6
5
|
import { inspectionProfileDigest } from './inspection-context.js';
|
|
7
6
|
import { reportRevision } from '../validation/report.js';
|
|
8
|
-
import { metricProjection } from './metric-values.js';
|
|
7
|
+
import { canonicalMetricDescriptor, metricProjection } from './metric-values.js';
|
|
9
8
|
import { summarySchema } from '../wire/summary-model.js';
|
|
10
9
|
export function commitSummary(report) {
|
|
11
10
|
const history = historyEntry(report);
|
|
@@ -32,14 +31,19 @@ export function commitSummary(report) {
|
|
|
32
31
|
export function orderSummaries(rows) {
|
|
33
32
|
return [...rows].sort(compareHistoryEntries);
|
|
34
33
|
}
|
|
35
|
-
/** Values recorded at analysis win; Git fills in
|
|
34
|
+
/** Values recorded at analysis win; Git fills in missing metadata and adds current tag names. */
|
|
36
35
|
export async function withCommitMetadata(rows, read) {
|
|
37
36
|
if (!read || !rows.length)
|
|
38
37
|
return rows;
|
|
39
38
|
const metadata = await read(rows.map(row => row.sha));
|
|
40
39
|
return rows.map(row => {
|
|
41
40
|
const found = metadata.get(row.sha);
|
|
42
|
-
|
|
41
|
+
if (found === undefined)
|
|
42
|
+
return row;
|
|
43
|
+
const { committedAt: gitTime, ...gitFields } = found;
|
|
44
|
+
const { sha, generatedAt, committedAt = gitTime, ...rest } = row;
|
|
45
|
+
return { ...gitFields, sha, generatedAt, ...(committedAt === undefined ? {} : { committedAt }), ...rest,
|
|
46
|
+
...(gitFields.tags === undefined ? {} : { tags: gitFields.tags }) };
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
export function expandSummaryCatalog(summary) {
|
|
@@ -48,10 +52,11 @@ export function expandSummaryCatalog(summary) {
|
|
|
48
52
|
}
|
|
49
53
|
export function repositorySummary(rows, pullReviewCount, includePrivateMetrics = true) {
|
|
50
54
|
const ordered = orderSummaries(rows);
|
|
51
|
-
const privateMetrics = new Set(ordered.flatMap(row => row.privateMetrics ?? []));
|
|
55
|
+
const privateMetrics = new Set(ordered.flatMap(row => row.privateMetrics ?? []).map(canonicalMetricId));
|
|
52
56
|
const catalog = new Map();
|
|
53
57
|
for (const row of ordered) {
|
|
54
|
-
for (const
|
|
58
|
+
for (const descriptor of row.metrics ?? []) {
|
|
59
|
+
const metric = canonicalMetricDescriptor(descriptor);
|
|
55
60
|
if ((includePrivateMetrics || !privateMetrics.has(metric.id)) && !catalog.has(metric.id))
|
|
56
61
|
catalog.set(metric.id, metric);
|
|
57
62
|
}
|
|
@@ -64,8 +69,9 @@ export function repositorySummary(rows, pullReviewCount, includePrivateMetrics =
|
|
|
64
69
|
const mapped = {};
|
|
65
70
|
for (const [index, value] of Object.entries(values)) {
|
|
66
71
|
const id = local[Number(index)]?.id;
|
|
67
|
-
const
|
|
68
|
-
|
|
72
|
+
const canonical = id === undefined ? undefined : canonicalMetricId(id);
|
|
73
|
+
const position = canonical === undefined ? undefined : positions.get(canonical);
|
|
74
|
+
if (position !== undefined && (canonical === id || !Object.hasOwn(mapped, position)))
|
|
69
75
|
mapped[position] = value;
|
|
70
76
|
}
|
|
71
77
|
return Object.keys(mapped).length ? { ...row, values: mapped } : row;
|
|
@@ -92,24 +98,17 @@ export function historyEntry(report) {
|
|
|
92
98
|
if (item.definition === definitions.functions)
|
|
93
99
|
functions = (functions ?? 0) + item.value;
|
|
94
100
|
}
|
|
95
|
-
if (item.target === 'function' && item.definition === definitions.complexity && Number.isSafeInteger(item.value)) {
|
|
101
|
+
if (item.target === 'function' && canonicalMetricId(item.definition) === definitions.complexity && Number.isSafeInteger(item.value)) {
|
|
96
102
|
maxComplexity = Math.max(maxComplexity ?? 0, item.value);
|
|
97
103
|
}
|
|
98
104
|
if (item.target === 'repository' && item.definition === definitions.coverage && item.covered !== undefined && item.total !== undefined && item.total > 0) {
|
|
99
105
|
lineCoverage = { covered: item.covered, total: item.total };
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
|
-
const committedAt =
|
|
108
|
+
const committedAt = Date.parse(report.committedAt ?? '');
|
|
103
109
|
const generatedAt = Date.parse(report.generatedAt);
|
|
104
110
|
return { sha: report.subject.id, generatedAt: Number.isFinite(generatedAt) ? new Date(generatedAt).toISOString() : '',
|
|
105
|
-
...(committedAt
|
|
111
|
+
...(Number.isFinite(committedAt) ? { committedAt: new Date(committedAt).toISOString() } : {}), status: report.status,
|
|
106
112
|
files: report.scope.files, parsed: report.scope.parsed, lines, functions, maxComplexity, lineCoverage };
|
|
107
113
|
}
|
|
108
|
-
/** Earlier reports only recorded the committer time in the churn window. */
|
|
109
|
-
function commitTime(report) {
|
|
110
|
-
const window = report.appliedConfig.churnWindow;
|
|
111
|
-
const legacy = isRecord(window) && typeof window.endingAt === 'string' ? window.endingAt : '';
|
|
112
|
-
const time = Date.parse(report.committedAt ?? legacy);
|
|
113
|
-
return Number.isFinite(time) ? new Date(time).toISOString() : null;
|
|
114
|
-
}
|
|
115
114
|
//# sourceMappingURL=commit-summary.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
2
|
-
import { definitions } from '../../../core/model/measurement.js';
|
|
2
|
+
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
3
3
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
4
4
|
import { metricProjection } from './metric-values.js';
|
|
5
5
|
import { fileMetricsSchema } from '../wire/file-metrics-model.js';
|
|
@@ -9,6 +9,7 @@ export function fileMetrics(report) {
|
|
|
9
9
|
const duplicatedLines = new Map();
|
|
10
10
|
const pluginMetrics = metricProjection(report);
|
|
11
11
|
const languages = [];
|
|
12
|
+
const languageCatalog = new Map(report.pluginData?.languages?.map(language => [language.id, language]));
|
|
12
13
|
const languageIndexes = new Map();
|
|
13
14
|
function file(path) {
|
|
14
15
|
const existing = byPath.get(path);
|
|
@@ -18,12 +19,12 @@ export function fileMetrics(report) {
|
|
|
18
19
|
byPath.set(path, metrics);
|
|
19
20
|
return metrics;
|
|
20
21
|
}
|
|
21
|
-
for (const { path, lines, bytes, language, analysed } of report.pluginData?.inventory ?? []) {
|
|
22
|
+
for (const { path, lines, bytes, language, analysed, provider } of report.pluginData?.inventory ?? []) {
|
|
22
23
|
let index = languageIndexes.get(language);
|
|
23
24
|
if (index === undefined) {
|
|
24
25
|
index = languages.length;
|
|
25
26
|
languageIndexes.set(language, index);
|
|
26
|
-
languages.push({ id: language, analysed });
|
|
27
|
+
languages.push({ id: language, ...languageCatalog.get(language), analysed });
|
|
27
28
|
}
|
|
28
29
|
else if (analysed) {
|
|
29
30
|
languages[index].analysed = true;
|
|
@@ -34,23 +35,26 @@ export function fileMetrics(report) {
|
|
|
34
35
|
entry.bytes = bytes;
|
|
35
36
|
entry.language = index;
|
|
36
37
|
entry.analysed = analysed;
|
|
38
|
+
if (provider !== undefined)
|
|
39
|
+
entry.provider = provider;
|
|
37
40
|
}
|
|
38
41
|
for (const row of report.measurements) {
|
|
39
42
|
if (!row.path)
|
|
40
43
|
continue;
|
|
44
|
+
const id = canonicalMetricId(row.definition);
|
|
41
45
|
if (pluginMetrics)
|
|
42
46
|
file(row.path);
|
|
43
|
-
if (row.target === 'file' &&
|
|
47
|
+
if (row.target === 'file' && id === definitions.coverage && row.covered !== undefined && row.total !== undefined) {
|
|
44
48
|
file(row.path).lineCoverage = { covered: row.covered, total: row.total };
|
|
45
49
|
}
|
|
46
50
|
if (row.value === null || !Number.isSafeInteger(row.value) || row.value < 0)
|
|
47
51
|
continue;
|
|
48
|
-
if (row.target === 'file' &&
|
|
52
|
+
if (row.target === 'file' && id === definitions.lines)
|
|
49
53
|
file(row.path).lines = row.value;
|
|
50
|
-
if (row.target === 'file' &&
|
|
54
|
+
if (row.target === 'file' && id === definitions.functions)
|
|
51
55
|
file(row.path).functions = row.value;
|
|
52
56
|
if (row.target === 'file') {
|
|
53
|
-
switch (
|
|
57
|
+
switch (id) {
|
|
54
58
|
case definitions.codeLines:
|
|
55
59
|
quality(file(row.path)).codeLines = row.value;
|
|
56
60
|
break;
|
|
@@ -71,7 +75,7 @@ export function fileMetrics(report) {
|
|
|
71
75
|
break;
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
|
-
if (row.target === 'function' &&
|
|
78
|
+
if (row.target === 'function' && id === definitions.complexity) {
|
|
75
79
|
const target = file(row.path);
|
|
76
80
|
target.complexity = addComplexity(target.complexity, { sum: row.value, maximum: row.value, measuredFunctions: 1 });
|
|
77
81
|
}
|
|
@@ -83,22 +87,7 @@ export function fileMetrics(report) {
|
|
|
83
87
|
quality(entry).duplication = { duplicatedLines: duplicateCount, codeLines };
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
|
-
|
|
87
|
-
for (const entry of byPath.values()) {
|
|
88
|
-
if (entry.quality?.duplication)
|
|
89
|
-
entry.quality.maintainability = { smells: 0, effortMinutes: 0 };
|
|
90
|
-
}
|
|
91
|
-
for (const finding of report.findings) {
|
|
92
|
-
if (!finding.path || (finding.category !== 'structure' && finding.category !== 'duplication'))
|
|
93
|
-
continue;
|
|
94
|
-
const observations = byPath.get(finding.path)?.quality;
|
|
95
|
-
if (!observations?.maintainability)
|
|
96
|
-
continue;
|
|
97
|
-
observations.maintainability = addMaintainability(observations.maintainability, {
|
|
98
|
-
smells: 1, effortMinutes: finding.effortMinutes ?? null,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
90
|
+
addFileFindings(byPath, report.findings);
|
|
102
91
|
let unassignedDiagnostics = 0;
|
|
103
92
|
for (const diagnostic of report.diagnostics) {
|
|
104
93
|
const { path, operation } = diagnostic;
|
|
@@ -156,6 +145,24 @@ export function fileMetrics(report) {
|
|
|
156
145
|
...(cognitive === undefined ? {} : { cognitive }), ...(duplication === undefined ? {} : { duplication }),
|
|
157
146
|
...(churn === undefined ? {} : { churn }) } };
|
|
158
147
|
}
|
|
148
|
+
function addFileFindings(byPath, findings) {
|
|
149
|
+
if (findings === undefined)
|
|
150
|
+
return;
|
|
151
|
+
for (const entry of byPath.values()) {
|
|
152
|
+
if (entry.quality?.duplication)
|
|
153
|
+
entry.quality.maintainability = { smells: 0, effortMinutes: 0 };
|
|
154
|
+
}
|
|
155
|
+
for (const finding of findings) {
|
|
156
|
+
if (!finding.path || (finding.category !== 'structure' && finding.category !== 'duplication'))
|
|
157
|
+
continue;
|
|
158
|
+
const observations = byPath.get(finding.path)?.quality;
|
|
159
|
+
if (!observations?.maintainability)
|
|
160
|
+
continue;
|
|
161
|
+
observations.maintainability = addMaintainability(observations.maintainability, {
|
|
162
|
+
smells: 1, effortMinutes: finding.effortMinutes ?? null,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
159
166
|
function emptyMetrics(path) {
|
|
160
167
|
return { path, lines: null, functions: null, complexity: null, lineCoverage: null, diagnosticCount: 0 };
|
|
161
168
|
}
|
|
@@ -68,11 +68,20 @@ function readProfile(config) {
|
|
|
68
68
|
coverage = settings;
|
|
69
69
|
}
|
|
70
70
|
const { churnWindow, securityScanners, ...settings } = config;
|
|
71
|
+
const plugins = Array.isArray(settings.plugins) ? settings.plugins.map(plugin => {
|
|
72
|
+
if (!isRecord(plugin))
|
|
73
|
+
return plugin;
|
|
74
|
+
const { providesLanguages, ...entry } = plugin;
|
|
75
|
+
if (entry.id === 'babel-syntax' && isDeepStrictEqual(entry.settings, config.parser))
|
|
76
|
+
delete entry.settings;
|
|
77
|
+
return entry;
|
|
78
|
+
}) : settings.plugins;
|
|
71
79
|
// The policy is stable across commits; its matched paths describe this snapshot alone.
|
|
72
80
|
const { generatedExcluded, ...sourceSettings } = source;
|
|
73
81
|
return {
|
|
74
82
|
exclusions: { paths: [...new Set([...(stringList(source.defaultExclusions) ?? []), ...paths, ...(stringList(generatedExcluded) ?? [])])], directories },
|
|
75
|
-
settings: { ...settings,
|
|
83
|
+
settings: { ...settings, ...(plugins === undefined ? {} : { plugins }), coverage,
|
|
84
|
+
findingImports: findingImportMethods(config.findingImports), source: { ...sourceSettings,
|
|
76
85
|
extensions: extensions ? ordered(extensions) : source.extensions,
|
|
77
86
|
excludedPaths: ordered(paths), excludedDirectories: ordered(directories),
|
|
78
87
|
} },
|
|
@@ -3,7 +3,7 @@ import type { InspectionContext } from './inspection-context.js';
|
|
|
3
3
|
import type { ComplexFunction } from '../wire/public-history-model.js';
|
|
4
4
|
import type { Component } from './components.js';
|
|
5
5
|
import type { InspectionAsset, InspectionDetails, ProfileSettings } from '../wire/inspection-details-model.js';
|
|
6
|
-
export type {
|
|
6
|
+
export type { InspectionAsset, InspectionDetails, ProfileSettings } from '../wire/inspection-details-model.js';
|
|
7
7
|
export declare function inspectionAsset(report: Report, components: readonly Component[] | undefined, context?: InspectionContext | undefined): InspectionAsset;
|
|
8
8
|
export declare function inspectionDetails(report: Report, components?: readonly Component[]): InspectionDetails;
|
|
9
9
|
/** The applied configuration, field by field; whatever is missing or malformed is left out rather than guessed. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { definitions } from '../../../core/model/measurement.js';
|
|
1
|
+
import { canonicalMetricId, definitions } from '../../../core/model/measurement.js';
|
|
2
2
|
import { lcovLines } from '../../../core/model/line-coverage.js';
|
|
3
3
|
import { comparePaths } from '../../../core/model/snapshot.js';
|
|
4
4
|
import { fileMetrics } from './file-metrics.js';
|
|
@@ -63,7 +63,7 @@ function strings(value) {
|
|
|
63
63
|
export function complexFunctions(report) {
|
|
64
64
|
const functions = [];
|
|
65
65
|
for (const row of report.measurements) {
|
|
66
|
-
if (row.definition === definitions.complexity && row.target === 'function' && row.path !== undefined && row.value !== null) {
|
|
66
|
+
if (canonicalMetricId(row.definition) === definitions.complexity && row.target === 'function' && row.path !== undefined && row.value !== null) {
|
|
67
67
|
functions.push({ name: row.name ?? '(anonymous)', path: row.path, line: row.line ?? null, complexity: row.value });
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -5,3 +5,4 @@ export declare function metricProjection(report: Report): {
|
|
|
5
5
|
privateMetrics: string[] | undefined;
|
|
6
6
|
values: (path?: string, directory?: boolean) => MetricValues;
|
|
7
7
|
} | undefined;
|
|
8
|
+
export declare function canonicalMetricDescriptor(metric: MetricDescriptor): MetricDescriptor;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
+
import { canonicalMetricId } from '../../../core/model/measurement.js';
|
|
1
2
|
export function metricProjection(report) {
|
|
2
3
|
const metadata = report.pluginData;
|
|
3
4
|
if (!metadata?.metrics.length)
|
|
4
5
|
return undefined;
|
|
5
|
-
const measured = new Set(metadata.measured);
|
|
6
|
-
const metrics = metadata.metrics.filter(metric => measured.has(metric.id));
|
|
6
|
+
const measured = new Set(metadata.measured.map(canonicalMetricId));
|
|
7
|
+
const metrics = metadata.metrics.map(canonicalMetricDescriptor).filter(metric => measured.has(metric.id));
|
|
7
8
|
if (metrics.length === 0)
|
|
8
9
|
return undefined;
|
|
9
10
|
const rows = new Map();
|
|
10
11
|
for (const row of report.measurements) {
|
|
11
|
-
const
|
|
12
|
+
const id = canonicalMetricId(row.definition);
|
|
13
|
+
const existing = rows.get(id);
|
|
12
14
|
if (existing)
|
|
13
15
|
existing.push(row);
|
|
14
16
|
else
|
|
15
|
-
rows.set(
|
|
17
|
+
rows.set(id, [row]);
|
|
16
18
|
}
|
|
17
19
|
function values(path, directory = false) {
|
|
18
20
|
const result = {};
|
|
@@ -34,9 +36,17 @@ export function metricProjection(report) {
|
|
|
34
36
|
}
|
|
35
37
|
return result;
|
|
36
38
|
}
|
|
37
|
-
const privateMetrics = metadata.privateMetrics?.filter(id => measured.has(id));
|
|
39
|
+
const privateMetrics = metadata.privateMetrics?.map(canonicalMetricId).filter(id => measured.has(id));
|
|
38
40
|
return { catalog: metrics, privateMetrics: privateMetrics?.length ? privateMetrics : undefined, values };
|
|
39
41
|
}
|
|
42
|
+
export function canonicalMetricDescriptor(metric) {
|
|
43
|
+
const id = canonicalMetricId(metric.id);
|
|
44
|
+
if (!metric.ratio)
|
|
45
|
+
return metric.id === id ? metric : { ...metric, id };
|
|
46
|
+
const { of, over } = metric.ratio;
|
|
47
|
+
const ratio = { of: canonicalMetricId(of), over: canonicalMetricId(over) };
|
|
48
|
+
return metric.id === id && ratio.of === of && ratio.over === over ? metric : { ...metric, id, ratio };
|
|
49
|
+
}
|
|
40
50
|
function rollup(rows, aggregate, path, directory) {
|
|
41
51
|
if (path === undefined) {
|
|
42
52
|
const explicit = rows.find(row => row.target === 'repository');
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { lstat, mkdir, open, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { lstat, mkdir, open, readFile, readdir } from 'node:fs/promises';
|
|
3
2
|
import { join } from 'node:path';
|
|
4
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
5
4
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
@@ -8,6 +7,7 @@ import { summarySchema } from '../wire/summary-model.js';
|
|
|
8
7
|
import { compactJsonSchema, packJson } from '../wire/compact-json.js';
|
|
9
8
|
import { compareReports, readReport, readReportText, validSubjectId } from '../validation/report.js';
|
|
10
9
|
import { validateSummaryRow } from '../validation/summary-validation.js';
|
|
10
|
+
import { replaceFile } from './replace-file.js';
|
|
11
11
|
const packedHeader = `{"schema":"${compactJsonSchema}","summary":`;
|
|
12
12
|
export class LocalReportStore {
|
|
13
13
|
directory;
|
|
@@ -147,16 +147,6 @@ async function readSummaryHeader(path, sha) {
|
|
|
147
147
|
await file.close();
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
async function replaceFile(directory, name, contents) {
|
|
151
|
-
const temporary = join(directory, `.repometry-${randomUUID()}.tmp`);
|
|
152
|
-
try {
|
|
153
|
-
await writeFile(temporary, contents, { flag: 'wx', mode: 0o600 });
|
|
154
|
-
await rename(temporary, join(directory, name));
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
await rm(temporary, { force: true });
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
150
|
function subjectFolder(kind) {
|
|
161
151
|
return kind === 'commit' ? 'commits' : 'working-trees';
|
|
162
152
|
}
|