repometry 0.5.0 → 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 +35 -17
- 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 +197 -10
- 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 +5 -0
- 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 +1 -1
- package/target/main/ts/api/git/git.js +4 -4
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +3 -3
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +4 -4
- 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 +2 -2
- package/target/main/ts/compose/analyze-snapshot.js +19 -250
- 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.js +8 -5
- 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/manifest.d.ts +2 -2
- package/target/main/ts/core/engine/manifest.js +25 -5
- package/target/main/ts/core/engine/plan.d.ts +2 -4
- package/target/main/ts/core/engine/plan.js +13 -15
- package/target/main/ts/core/engine/plugin.d.ts +2 -1
- package/target/main/ts/core/model/clone-source.d.ts +1 -0
- package/target/main/ts/core/model/clone-source.js +1 -0
- package/target/main/ts/core/model/code-structure.d.ts +2 -0
- package/target/main/ts/core/model/code-structure.js +6 -0
- 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/measurement.d.ts +7 -6
- package/target/main/ts/core/model/measurement.js +17 -6
- package/target/main/ts/core/model/plugin-data.d.ts +3 -0
- package/target/main/ts/core/model/quality-summary.js +5 -4
- 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/snapshot.d.ts +0 -2
- package/target/main/ts/core/model/snapshot.js +0 -6
- 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 +3 -2
- package/target/main/ts/plugin.js +1 -1
- 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/js-security.js +3 -2
- 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-metric-registry.js +7 -7
- package/target/main/ts/report/html/app/viewer-overview-cards.js +8 -2
- package/target/main/ts/report/html/app/viewer-route.d.ts +2 -2
- package/target/main/ts/report/html/app/viewer-route.js +3 -3
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +6 -1
- package/target/main/ts/report/html/app/viewer-trend-data.js +6 -2
- package/target/main/ts/report/html/app/viewer.js +3 -3
- 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/pull-review-store.js +1 -2
- 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 +2 -3
- package/target/main/ts/report.js +1 -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
|
@@ -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');
|
|
@@ -5,10 +5,9 @@ import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
|
5
5
|
import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
|
|
6
6
|
import comparison from '../../../../resources/report/json/comparison-v1.schema.json' with { type: 'json' };
|
|
7
7
|
import diffCoverage from '../../../../resources/report/json/diff-coverage-v1.schema.json' with { type: 'json' };
|
|
8
|
-
import inspection from '../../../../resources/report/json/report-v1.schema.json' with { type: 'json' };
|
|
9
8
|
import currentInspection from '../../../../resources/report/json/report-v2.schema.json' with { type: 'json' };
|
|
10
9
|
import schema from '../../../../resources/report/json/pull-review-v1.schema.json' with { type: 'json' };
|
|
11
|
-
const ajv = new Ajv2020({ schemas: [metricCatalog,
|
|
10
|
+
const ajv = new Ajv2020({ schemas: [metricCatalog, currentInspection, comparison, diffCoverage] });
|
|
12
11
|
const validate = ajv.compile(schema);
|
|
13
12
|
export async function savePullReview(output, review) {
|
|
14
13
|
if (!validate(review))
|
|
@@ -2,7 +2,7 @@ import type { Subject } from '../../../core/model/source.js';
|
|
|
2
2
|
import type { CommitSummary } from '../wire/summary-model.js';
|
|
3
3
|
import type { Report } from '../../../core/model/report.js';
|
|
4
4
|
import type { ReportReader as DomainReportReader, ReportWriter } from '../../../core/ports/report.js';
|
|
5
|
-
export {
|
|
5
|
+
export { reportSchema, validSubjectId } from '../../../core/model/report.js';
|
|
6
6
|
export type { Diagnostic, Report } from '../../../core/model/report.js';
|
|
7
7
|
export interface ReportReader extends DomainReportReader {
|
|
8
8
|
listSummaries?(): Promise<readonly CommitSummary[]>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
2
2
|
import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
|
|
3
|
-
import schemaV1 from '../../../../resources/report/json/report-v1.schema.json' with { type: 'json' };
|
|
4
3
|
import schemaV2 from '../../../../resources/report/json/report-v2.schema.json' with { type: 'json' };
|
|
5
4
|
import { isRecord } from '../../../core/engine/plugin.js';
|
|
6
5
|
import { isMetricDescriptor } from '../../../core/engine/manifest.js';
|
|
7
6
|
import { isFinding } from '../../../core/model/finding.js';
|
|
7
|
+
import { canonicalMetricId } from '../../../core/model/measurement.js';
|
|
8
8
|
import { lcovLines } from '../../../core/model/line-coverage.js';
|
|
9
9
|
import { digest } from '../../../core/model/snapshot.js';
|
|
10
10
|
import { compactJsonSchema, unpackJson } from '../wire/compact-json.js';
|
|
11
|
-
import {
|
|
12
|
-
export {
|
|
11
|
+
import { reportSchema } from '../../../core/model/report.js';
|
|
12
|
+
export { reportSchema, validSubjectId } from '../../../core/model/report.js';
|
|
13
13
|
export function readReportText(text, subject) {
|
|
14
14
|
const envelope = JSON.parse(text);
|
|
15
15
|
const report = readReport(unpackJson(envelope));
|
|
@@ -28,19 +28,21 @@ export function compareReports(a, b) {
|
|
|
28
28
|
return b.generatedAt.localeCompare(a.generatedAt) || a.subject.id.localeCompare(b.subject.id);
|
|
29
29
|
}
|
|
30
30
|
const ajv = new Ajv2020({ schemas: [metricCatalog] });
|
|
31
|
-
const
|
|
32
|
-
const validateV2 = ajv.compile(schemaV2);
|
|
31
|
+
const validate = ajv.compile(schemaV2);
|
|
33
32
|
export function readReport(value) {
|
|
34
|
-
if (!isRecord(value) ||
|
|
33
|
+
if (!isRecord(value) || value.schema !== reportSchema) {
|
|
35
34
|
throw new Error('Unsupported or missing report schema');
|
|
36
35
|
}
|
|
37
|
-
const validate = value.schema === reportSchema ? validateV2 : validateV1;
|
|
38
36
|
if (!validate(value))
|
|
39
37
|
throw new Error(`Invalid report: ${ajv.errorsText(validate.errors)}`);
|
|
38
|
+
const definitionIds = Object.keys(value.definitions);
|
|
39
|
+
if (new Set(definitionIds.map(canonicalMetricId)).size !== definitionIds.length) {
|
|
40
|
+
throw new Error('Invalid report: the same measurement uses multiple IDs');
|
|
41
|
+
}
|
|
40
42
|
if (value.pluginData) {
|
|
41
43
|
const { metrics, measured, privateMetrics } = value.pluginData;
|
|
42
44
|
const ids = new Set(metrics.map(metric => metric.id));
|
|
43
|
-
if (ids.size !== metrics.length || !metrics.every(isMetricDescriptor)
|
|
45
|
+
if (new Set([...ids].map(canonicalMetricId)).size !== metrics.length || !metrics.every(isMetricDescriptor)
|
|
44
46
|
|| [...measured, ...privateMetrics ?? []].some(id => !ids.has(id)))
|
|
45
47
|
throw new Error('Invalid report: inconsistent metric catalog');
|
|
46
48
|
const lines = value.pluginData.products[lcovLines.id];
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
2
2
|
import metricCatalog from '../../../../resources/report/json/metric-catalog-v1.schema.json' with { type: 'json' };
|
|
3
|
-
import historySchema from '../../../../resources/report/json/public-history-v1.schema.json' with { type: 'json' };
|
|
4
|
-
import qualitySchema from '../../../../resources/report/json/quality-history-v1.schema.json' with { type: 'json' };
|
|
5
3
|
import summaryContract from '../../../../resources/report/json/repository-summary-v1.schema.json' with { type: 'json' };
|
|
6
4
|
import { summarySchema } from '../wire/summary-model.js';
|
|
7
5
|
import { isMetricDescriptor } from '../../../core/engine/manifest.js';
|
|
8
|
-
const validator = new Ajv2020({ schemas: [metricCatalog,
|
|
6
|
+
const validator = new Ajv2020({ schemas: [metricCatalog, summaryContract] });
|
|
9
7
|
export const validateSummary = validator.compile(summaryContract);
|
|
10
8
|
const rowShape = validator.compile({ $ref: `${summarySchema}#/$defs/commit` });
|
|
11
9
|
export function validateSummaryIndex(value) {
|
|
@@ -40,6 +40,7 @@ export interface Metrics {
|
|
|
40
40
|
quality?: Quality;
|
|
41
41
|
values?: MetricValues;
|
|
42
42
|
language?: number;
|
|
43
|
+
provider?: string;
|
|
43
44
|
analysed?: boolean;
|
|
44
45
|
}
|
|
45
46
|
export interface DirectoryMetrics extends Metrics {
|
|
@@ -60,6 +61,7 @@ export interface FileMetricsReport {
|
|
|
60
61
|
readonly languages?: readonly {
|
|
61
62
|
readonly id: string;
|
|
62
63
|
readonly label?: string;
|
|
64
|
+
readonly color?: string;
|
|
63
65
|
readonly analysed: boolean;
|
|
64
66
|
}[];
|
|
65
67
|
readonly churnWindow?: ChurnWindow & {
|
|
@@ -71,11 +71,6 @@ export interface ProfileRule {
|
|
|
71
71
|
readonly level?: string;
|
|
72
72
|
readonly help?: string;
|
|
73
73
|
}
|
|
74
|
-
export interface DetailsBundle {
|
|
75
|
-
readonly schema: 'urn:repometry:schema:viewer-details:1';
|
|
76
|
-
readonly context: Record<string, InspectionContext>;
|
|
77
|
-
readonly inspections: Record<string, InspectionDetails>;
|
|
78
|
-
}
|
|
79
74
|
export interface InspectionAsset {
|
|
80
75
|
readonly schema: 'urn:repometry:schema:viewer-inspection:1';
|
|
81
76
|
readonly sha: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Report } from '../../../core/model/report.js';
|
|
2
2
|
import type { QualitySummary } from '../../../core/model/quality-summary.js';
|
|
3
|
-
export declare const historySchema = "urn:repometry:schema:public-history:1";
|
|
4
3
|
export interface PublicHistoryEntry {
|
|
5
4
|
readonly sha: string;
|
|
6
5
|
readonly generatedAt: string;
|
|
@@ -26,12 +25,7 @@ export interface PublicHistoryEntry {
|
|
|
26
25
|
} | null;
|
|
27
26
|
}
|
|
28
27
|
export declare function compareHistoryEntries(a: PublicHistoryEntry, b: PublicHistoryEntry): number;
|
|
29
|
-
export interface PublicHistory {
|
|
30
|
-
readonly schema: typeof historySchema;
|
|
31
|
-
readonly reports: readonly PublicHistoryEntry[];
|
|
32
|
-
}
|
|
33
28
|
export interface QualityHistory {
|
|
34
|
-
readonly schema: 'urn:repometry:schema:quality-history:1';
|
|
35
29
|
readonly reports: Record<string, QualitySummary>;
|
|
36
30
|
}
|
|
37
31
|
export interface ComplexFunction {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export const historySchema = 'urn:repometry:schema:public-history:1';
|
|
2
1
|
export function compareHistoryEntries(a, b) {
|
|
3
2
|
return Number(b.committedAt !== undefined) - Number(a.committedAt !== undefined)
|
|
4
3
|
|| (b.committedAt ?? b.generatedAt).localeCompare(a.committedAt ?? a.generatedAt)
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { readReport, reportSchema } from './report/json/validation/report.js';
|
|
2
2
|
export type { Diagnostic, Report, ReportReader, ReportStore } from './report/json/validation/report.js';
|
|
3
3
|
export type { ReportWriter } from './core/ports/report.js';
|
|
4
4
|
export { LocalOperationCache } from './report/json/store/operation-cache.js';
|
|
5
5
|
export { validateSummary } from './report/json/validation/summary-validation.js';
|
|
6
|
-
export {
|
|
7
|
-
export type { PublicHistory, PublicHistoryEntry, QualityHistory } from './report/json/wire/public-history-model.js';
|
|
6
|
+
export type { PublicHistoryEntry } from './report/json/wire/public-history-model.js';
|
|
8
7
|
export { summarySchema } from './report/json/wire/summary-model.js';
|
|
9
8
|
export type { CommitSummary, RepositorySummary } from './report/json/wire/summary-model.js';
|
|
10
9
|
export type { SourceLocator } from './report/json/wire/summary-model.js';
|
package/target/main/ts/report.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { readReport, reportSchema } from './report/json/validation/report.js';
|
|
2
2
|
export { LocalOperationCache } from './report/json/store/operation-cache.js';
|
|
3
3
|
export { validateSummary } from './report/json/validation/summary-validation.js';
|
|
4
|
-
export { historySchema } from './report/json/wire/public-history-model.js';
|
|
5
4
|
export { summarySchema } from './report/json/wire/summary-model.js';
|
|
6
5
|
export { fileMetricsSchema } from './report/json/wire/file-metrics-model.js';
|
|
7
6
|
//# sourceMappingURL=report.js.map
|