repometry 0.0.0-dev.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +24 -1
- package/package.json +48 -7
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +34 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +238 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +130 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +586 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
- package/target/main/ts/api/gh/github-pr-comment.js +107 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +91 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +105 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +107 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +54 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +70 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +73 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +152 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +30 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +46 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +35 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +34 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +56 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +226 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +13 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +16 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +45 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +101 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +85 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +110 -0
- package/target/main/ts/cli/config.d.ts +14 -0
- package/target/main/ts/cli/config.js +60 -0
- package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
- package/target/main/ts/cli/github-pr-comment.js +12 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +29 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +343 -284
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +108 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +15 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +38 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +163 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +37 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +56 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +44 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +9 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +16 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +38 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +29 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +49 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +104 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +106 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +85 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +1 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +14 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +31 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +35 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +27 -0
- package/target/main/ts/core/model/measurement.js +24 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +32 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +28 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +50 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +1 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +4 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +57 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +9 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +10 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +145 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +15 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +41 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +128 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +17 -13
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +5 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
- package/target/main/ts/plugins/coverage/coverage.js +120 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +93 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +35 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +60 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +79 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +37 -0
- package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-access.js +25 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2087 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
- package/target/main/ts/report/html/app/viewer-trends.js +413 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +794 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +39 -0
- package/target/main/ts/report/html/site/export-site.d.ts +21 -0
- package/target/main/ts/report/html/site/export-site.js +157 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +70 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +64 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +79 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +64 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +22 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
- package/target/main/ts/report/json/projections/commit-summary.js +118 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +29 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +243 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +92 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +69 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +57 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +16 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +31 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +179 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +51 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +7 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +64 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +27 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +5 -0
- package/index.js +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readConfig } from './config.js';
|
|
2
|
+
import type { Invocation } from './arguments.js';
|
|
3
|
+
import type { Store } from './store.js';
|
|
4
|
+
declare const reporters: {
|
|
5
|
+
readonly html: '.repometry/report/html';
|
|
6
|
+
readonly json: '.repometry/report/history.json';
|
|
7
|
+
};
|
|
8
|
+
export declare const reporterIds: string[];
|
|
9
|
+
export declare function outputReports(root: string, store: Store, requested: readonly string[], input: Invocation, config: Awaited<ReturnType<typeof readConfig>>): Promise<{
|
|
10
|
+
format: keyof typeof reporters;
|
|
11
|
+
path: string;
|
|
12
|
+
}[]>;
|
|
13
|
+
export declare function viewTarget(input: Invocation, port: number): Promise<{
|
|
14
|
+
url: string;
|
|
15
|
+
close: () => void;
|
|
16
|
+
label: string;
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
4
|
+
import { commitMetadataReader } from '../api/git/commit-metadata.js';
|
|
5
|
+
import { readLocalSources, sourceRemotes } from '../api/git/local-sources.js';
|
|
6
|
+
import { resolveSourceLocator } from '../compose/sources.js';
|
|
7
|
+
import { commitSummary, withCommitMetadata } from '../report/json/projections/commit-summary.js';
|
|
8
|
+
import { exportSite, siteSummary } from '../report/html/site/export-site.js';
|
|
9
|
+
import { readExportedSummary, serveExportedSite } from '../report/html/site/exported-server.js';
|
|
10
|
+
import { serveSite } from '../report/html/site/local-server.js';
|
|
11
|
+
import { readComponents } from '../report/json/store/components.js';
|
|
12
|
+
import { listPullReviews } from '../report/json/store/pull-review-store.js';
|
|
13
|
+
import { readConfig } from './config.js';
|
|
14
|
+
import { findRepository, invocationDirectory, isDirectory, selectStore } from './store.js';
|
|
15
|
+
const reporters = { html: '.repometry/report/html', json: '.repometry/report/history.json' };
|
|
16
|
+
export const reporterIds = Object.keys(reporters);
|
|
17
|
+
export async function outputReports(root, store, requested, input, config) {
|
|
18
|
+
const output = input.text('output');
|
|
19
|
+
if (output !== undefined && requested.length !== 1)
|
|
20
|
+
throw new Error('--output requires exactly one report; use FORMAT=PATH for multiple reports');
|
|
21
|
+
const mode = input.text('mode') ?? config.mode ?? 'public';
|
|
22
|
+
if (mode !== 'public' && mode !== 'private')
|
|
23
|
+
throw new Error('--mode must be public or private');
|
|
24
|
+
if (input.text('components') && mode !== 'private')
|
|
25
|
+
throw new Error('--components requires --mode private');
|
|
26
|
+
const requests = requested.map(spec => {
|
|
27
|
+
const equal = spec.indexOf('=');
|
|
28
|
+
const format = equal < 0 ? spec : spec.slice(0, equal);
|
|
29
|
+
const path = equal < 0 ? undefined : spec.slice(equal + 1);
|
|
30
|
+
if (!Object.hasOwn(reporters, format))
|
|
31
|
+
throw new Error(`Unknown reporter: ${format}. Choose ${reporterIds.join(', ')}.`);
|
|
32
|
+
if (path === '' || (output !== undefined && path !== undefined))
|
|
33
|
+
throw new Error('Specify one output per report with FORMAT=PATH or --output');
|
|
34
|
+
return { format: format, path: output ?? path
|
|
35
|
+
? resolve(invocationDirectory(input), (output ?? path)) : resolve(root, reporters[format]) };
|
|
36
|
+
});
|
|
37
|
+
if (new Set(requests.map(request => request.path)).size !== requests.length)
|
|
38
|
+
throw new Error('Each report requires a separate output');
|
|
39
|
+
if (requests.length === 0)
|
|
40
|
+
return requests;
|
|
41
|
+
const repository = await findRepository(root);
|
|
42
|
+
const readCommitMetadata = repository === undefined ? undefined : commitMetadataReader(repository);
|
|
43
|
+
const sourceOption = input.text('sources') ?? config.sources;
|
|
44
|
+
const sources = mode === 'private' ? resolveSourceLocator(sourceOption, { remotes: await sourceRemotes(root), env: process.env }) : undefined;
|
|
45
|
+
const [components, pulls] = mode === 'private' ? await Promise.all([
|
|
46
|
+
readComponents(componentsPath(root, input), input.text('components') === undefined),
|
|
47
|
+
store.path ? listPullReviews(store.path) : [],
|
|
48
|
+
]) : [undefined, undefined];
|
|
49
|
+
const options = { mode, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
|
|
50
|
+
title: input.text('title') ?? (input.text('repo') ? basename(root) : undefined),
|
|
51
|
+
footer: !input.flag('no-footer') };
|
|
52
|
+
for (const request of requests) {
|
|
53
|
+
if (request.format === 'html')
|
|
54
|
+
await exportSite(store.reader, request.path, options);
|
|
55
|
+
else {
|
|
56
|
+
const rows = await store.reader.listSummaries?.() ?? (await store.reader.list()).filter(report => report.subject.kind === 'commit').map(commitSummary);
|
|
57
|
+
const data = siteSummary(await withCommitMetadata(rows, readCommitMetadata), options);
|
|
58
|
+
await writeSummary(request.path, data, mode === 'private');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return requests;
|
|
62
|
+
}
|
|
63
|
+
async function writeSummary(path, data, privateReport) {
|
|
64
|
+
await mkdir(dirname(path), { recursive: true });
|
|
65
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
66
|
+
try {
|
|
67
|
+
await writeFile(temporary, data, { mode: privateReport ? 0o600 : 0o644, flag: 'wx' });
|
|
68
|
+
await rename(temporary, path);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
await rm(temporary, { force: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export async function viewTarget(input, port) {
|
|
75
|
+
if (input.args[0] !== undefined && input.text('repo') !== undefined)
|
|
76
|
+
throw new Error('Choose a view target or --repo, not both');
|
|
77
|
+
const target = resolve(input.args[0] ?? input.text('repo') ?? '.');
|
|
78
|
+
const exported = await readExportedSummary(target);
|
|
79
|
+
const repository = await findRepository(target);
|
|
80
|
+
if (exported) {
|
|
81
|
+
const local = exported.sources?.provider === 'local' && repository ? readLocalSources(repository) : undefined;
|
|
82
|
+
return { ...await serveExportedSite(target, port, local), label: target + ' (exported report)' };
|
|
83
|
+
}
|
|
84
|
+
const data = resolve(target, 'data');
|
|
85
|
+
const dataStore = basename(target) === '.repometry' && await isDirectory(data);
|
|
86
|
+
const directStore = await isDirectory(resolve(target, 'commits'));
|
|
87
|
+
if (!repository && !dataStore && !directStore) {
|
|
88
|
+
throw new Error(`No report at ${target}: expected a repository, a .repometry folder or an exported report`);
|
|
89
|
+
}
|
|
90
|
+
const root = repository ?? target;
|
|
91
|
+
const store = selectStore(root, input.text('store') ?? (dataStore ? data : directStore ? target : undefined), resolve('.'));
|
|
92
|
+
if ((await store.reader.listSummaries?.() ?? []).length === 0)
|
|
93
|
+
throw new Error(`No saved inspections in ${store.path ?? input.text('store')}. Run repometry analyze first.`);
|
|
94
|
+
const [components, pulls, config] = await Promise.all([
|
|
95
|
+
readComponents(componentsPath(root, input), input.text('components') === undefined),
|
|
96
|
+
store.path ? listPullReviews(store.path) : [],
|
|
97
|
+
readConfig(root, input),
|
|
98
|
+
]);
|
|
99
|
+
const local = repository ? readLocalSources(repository) : undefined;
|
|
100
|
+
const server = await serveSite(store.reader, port, { title: input.text('title') ?? basename(root), components, pulls,
|
|
101
|
+
branch: input.text('branch') ?? config.branch, readCommitMetadata: repository ? commitMetadataReader(repository) : undefined,
|
|
102
|
+
sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined, footer: !input.flag('no-footer') }, local);
|
|
103
|
+
return { ...server, label: `${basename(root)} (live from ${store.path ?? input.text('store')})` };
|
|
104
|
+
}
|
|
105
|
+
function componentsPath(root, input) {
|
|
106
|
+
const explicit = input.text('components');
|
|
107
|
+
return explicit === undefined ? resolve(root, '.repometry/components.json') : resolve(invocationDirectory(input), explicit);
|
|
108
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface RevisionRange {
|
|
2
|
+
readonly base: string;
|
|
3
|
+
readonly head: string;
|
|
4
|
+
}
|
|
5
|
+
/** Reads `BASE..HEAD` or `BASE..`; returns undefined for a single revision. Git refnames cannot contain `..`. */
|
|
6
|
+
export declare function parseRange(value: string): RevisionRange | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Reads `BASE..HEAD` or `BASE..`; returns undefined for a single revision. Git refnames cannot contain `..`. */
|
|
2
|
+
export function parseRange(value) {
|
|
3
|
+
if (!value.includes('..'))
|
|
4
|
+
return undefined;
|
|
5
|
+
if (value.includes('...'))
|
|
6
|
+
throw new Error(`${value}: a symmetric range has no first-parent line; use BASE..HEAD`);
|
|
7
|
+
const index = value.indexOf('..');
|
|
8
|
+
const base = value.slice(0, index);
|
|
9
|
+
const head = value.slice(index + 2);
|
|
10
|
+
if (!base)
|
|
11
|
+
throw new Error(`${value}: a range needs a base, as in HEAD~10..HEAD`);
|
|
12
|
+
if (head.includes('..'))
|
|
13
|
+
throw new Error(`${value}: use one BASE..HEAD range`);
|
|
14
|
+
return { base, head: head || 'HEAD' };
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Invocation } from './arguments.js';
|
|
2
|
+
import type { ReportReader } from '../report/json/validation/report.js';
|
|
3
|
+
export type Store = {
|
|
4
|
+
readonly reader: ReportReader;
|
|
5
|
+
readonly path?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function findRepository(directory: string): Promise<string | undefined>;
|
|
8
|
+
/** Where relative paths typed on the command line resolve: --repo/-C, like git -C, or else the current directory. */
|
|
9
|
+
export declare function invocationDirectory(input: Invocation): string;
|
|
10
|
+
/** A typed path resolves against `base`; the default store resolves against the repository root. */
|
|
11
|
+
export declare function selectStore(root: string, value?: string, base?: string): Store;
|
|
12
|
+
export declare function writableStore(store: Store): string;
|
|
13
|
+
export declare function isDirectory(path: string): Promise<boolean>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { lstat } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { GitReportReader } from '../api/git/git-reader.js';
|
|
4
|
+
import { gitRoot } from '../api/git/git.js';
|
|
5
|
+
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
6
|
+
export async function findRepository(directory) {
|
|
7
|
+
return gitRoot(directory).catch(() => undefined);
|
|
8
|
+
}
|
|
9
|
+
/** Where relative paths typed on the command line resolve: --repo/-C, like git -C, or else the current directory. */
|
|
10
|
+
export function invocationDirectory(input) {
|
|
11
|
+
return resolve(input.text('repo') ?? '.');
|
|
12
|
+
}
|
|
13
|
+
/** A typed path resolves against `base`; the default store resolves against the repository root. */
|
|
14
|
+
export function selectStore(root, value, base = root) {
|
|
15
|
+
if (value?.startsWith('git:')) {
|
|
16
|
+
const ref = value.slice(4);
|
|
17
|
+
if (!ref)
|
|
18
|
+
throw new Error('--store git: requires a ref');
|
|
19
|
+
return { reader: new GitReportReader(root, ref) };
|
|
20
|
+
}
|
|
21
|
+
const path = value === undefined ? resolve(root, '.repometry') : resolve(base, value);
|
|
22
|
+
return { path, reader: new LocalReportStore(path) };
|
|
23
|
+
}
|
|
24
|
+
export function writableStore(store) {
|
|
25
|
+
if (store.path === undefined)
|
|
26
|
+
throw new Error('Use a local store when writing inspections or reviews');
|
|
27
|
+
return store.path;
|
|
28
|
+
}
|
|
29
|
+
export async function isDirectory(path) {
|
|
30
|
+
try {
|
|
31
|
+
return (await lstat(path)).isDirectory();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
|
|
35
|
+
return false;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Plugin } from '../core/engine/plugin.js';
|
|
2
|
+
import type { Report } from '../core/model/report.js';
|
|
3
|
+
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
4
|
+
export declare function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths, coverage: inputCoverage }: AnalysisInput, additional?: readonly Plugin[]): Promise<Report>;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { extname } from 'node:path';
|
|
2
|
+
import { execute } from '../core/engine/execute.js';
|
|
3
|
+
import { plan } from '../core/engine/plan.js';
|
|
4
|
+
import { ReportProducts } from '../core/engine/report-products.js';
|
|
5
|
+
import { definitions } from '../core/model/measurement.js';
|
|
6
|
+
import { debtModel } from '../core/model/quality-summary.js';
|
|
7
|
+
import { reportSchema } from '../core/model/report.js';
|
|
8
|
+
import { comparePaths, digest, sourceDirectoriesExcluded, sourceExtensions, sourceFile, sourceLineCounts, textLineCount } from '../core/model/snapshot.js';
|
|
9
|
+
import { defaultSourceExclusions, exclusionMatcher, generatedSourcePolicy, sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
10
|
+
import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
|
|
11
|
+
import { coverage, coverageResult, lcovInput } from '../plugins/coverage/coverage.js';
|
|
12
|
+
import { duplication, duplicationInput } from '../plugins/duplication/duplication.js';
|
|
13
|
+
import { babelProvider, babelTypes, parserDefaults } from '../plugins/language-js/babel-provider.js';
|
|
14
|
+
import { fileQuality, maintainability } from '../plugins/maintainability/maintainability.js';
|
|
15
|
+
import { structure } from '../plugins/structure/structure.js';
|
|
16
|
+
const sourcePlugins = [babelProvider, { ...structure, tools: babelTypes }, { ...maintainability, tools: babelTypes }];
|
|
17
|
+
const selected = ['structure/size', 'structure/complexity', 'maintainability/file'];
|
|
18
|
+
const bindings = new Map(selected.map(operation => [operation, { syntax: { operation: 'babel-syntax/parse' } }]));
|
|
19
|
+
const sourcePlan = plan({ plugins: sourcePlugins, select: selected, inputs: new Map([['file', sourceFile.id]]), bindings });
|
|
20
|
+
const duplicationPlan = plan({ plugins: [duplication], select: ['duplication/detect'], inputs: new Map([['sources', duplicationInput.id]]) });
|
|
21
|
+
const coveragePlan = plan({ plugins: [coverage], select: ['lcov/import'], inputs: new Map([['lcov', lcovInput.id]]) });
|
|
22
|
+
const measurementDefinitions = {
|
|
23
|
+
[definitions.lines]: 'Physical lines including blank lines and comments. A final line terminator does not add a line.',
|
|
24
|
+
[definitions.functions]: 'Babel function nodes with bodies, including nested functions and methods.',
|
|
25
|
+
[definitions.complexity]: 'One plus branches in the function body: if, ternary, loops, catch, non-default switch cases and logical operators. Nested functions are measured separately. Line and column are 1-based and columns count UTF-16 units.',
|
|
26
|
+
[definitions.coverage]: 'Distinct covered DA lines divided by the distinct DA lines listed for mapped files. Duplicate records are merged by the presence of any hit. A zero denominator has no ratio.',
|
|
27
|
+
[definitions.codeLines]: 'Nonblank physical lines after removing Babel comment spans and the interpreter directive. A line containing both code and a comment counts as code.',
|
|
28
|
+
[definitions.comments]: 'Physical lines containing only a Babel comment or interpreter directive.',
|
|
29
|
+
[definitions.classes]: 'Babel class declaration and expression nodes.',
|
|
30
|
+
[definitions.cognitiveComplexity]: 'Flow breaks plus nesting weight and logical operator sequences. Nested functions are measured separately. File complexity sums functions and module-level flow breaks.',
|
|
31
|
+
[definitions.duplicatedLines]: 'Distinct code lines inside repeated Babel syntax subtrees, including original and repeated occurrences. Identifier and literal spellings are ignored for similar-code matches.',
|
|
32
|
+
};
|
|
33
|
+
export async function analyzeSnapshot({ snapshot, excludedOutput, excludedPaths = [], coverage: inputCoverage }, additional = []) {
|
|
34
|
+
const rows = [];
|
|
35
|
+
const diagnostics = [];
|
|
36
|
+
const findings = [];
|
|
37
|
+
const cloneSources = [];
|
|
38
|
+
const enabled = [...sourcePlugins, duplication, ...(inputCoverage === undefined ? [] : [coverage])];
|
|
39
|
+
const plugins = [...enabled, ...additional];
|
|
40
|
+
if (additional.length)
|
|
41
|
+
plan({ plugins, select: [], inputs: new Map() });
|
|
42
|
+
if (inputCoverage === undefined && additional.some(plugin => plugin.id === coverage.id))
|
|
43
|
+
throw new Error('An additional plugin uses a built-in plugin ID');
|
|
44
|
+
const reportProducts = new ReportProducts(plugins);
|
|
45
|
+
const sourcePlans = new Map([['', sourcePlan]]);
|
|
46
|
+
const usedPlans = new Map(sourcePlan.map(task => [task.key, task]));
|
|
47
|
+
const matches = additional.map(plugin => claimMatcher(plugin.claims));
|
|
48
|
+
const parsed = new Set();
|
|
49
|
+
for (const file of snapshot.files) {
|
|
50
|
+
const selectedPlugins = additional.filter((_, index) => matches[index](file.path));
|
|
51
|
+
const group = JSON.stringify(selectedPlugins.map(plugin => plugin.id));
|
|
52
|
+
const groupKey = selectedPlugins.length === 0 ? '' : group;
|
|
53
|
+
const tasks = sourcePlans.get(groupKey) ?? plan({
|
|
54
|
+
plugins: [...sourcePlugins, ...additional],
|
|
55
|
+
select: [...selected, ...selectedPlugins.flatMap(plugin => plugin.operations
|
|
56
|
+
.filter(operation => operation.role === 'inspection').map(operation => `${plugin.id}/${operation.id}`))],
|
|
57
|
+
inputs: new Map([['file', sourceFile.id]]), bindings,
|
|
58
|
+
});
|
|
59
|
+
sourcePlans.set(groupKey, tasks);
|
|
60
|
+
const results = await execute(tasks, new Map([['file', { contract: sourceFile.id, value: file }]]));
|
|
61
|
+
if (results.get('babel-syntax/parse')?.state === 'completed')
|
|
62
|
+
parsed.add(file.path);
|
|
63
|
+
for (const task of tasks) {
|
|
64
|
+
usedPlans.set(task.key, task);
|
|
65
|
+
const outcome = results.get(task.key);
|
|
66
|
+
record(task, outcome, file.path);
|
|
67
|
+
if (outcome.state === 'completed' && outcome.product.contract === fileQuality.id && fileQuality.accepts(outcome.product.value)) {
|
|
68
|
+
cloneSources.push(outcome.product.value.cloneSource);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const copies = (await execute(duplicationPlan, new Map([['sources', { contract: duplicationInput.id, value: cloneSources }]])))
|
|
73
|
+
.get('duplication/detect');
|
|
74
|
+
record(duplicationPlan[0], copies);
|
|
75
|
+
if (inputCoverage !== undefined) {
|
|
76
|
+
const value = { text: inputCoverage.text, root: inputCoverage.sourceRoot, sourceLines: sourceLineCounts(snapshot.files),
|
|
77
|
+
excludes: sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded) };
|
|
78
|
+
const result = (await execute(coveragePlan, new Map([['lcov', { contract: lcovInput.id, value }]]))).get('lcov/import');
|
|
79
|
+
record(coveragePlan[0], result);
|
|
80
|
+
if (result.state === 'completed' && coverageResult.accepts(result.product.value)) {
|
|
81
|
+
for (const { path, reason } of result.product.value.gaps) {
|
|
82
|
+
diagnostics.push({ operation: 'lcov/import', state: 'partial', path, message: reason });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const pluginData = reportProducts.result();
|
|
87
|
+
const inventory = new Map((snapshot.inventory ?? []).map(({ path, lines, bytes }) => [path, { lines, bytes }]));
|
|
88
|
+
for (const { path, bytes } of snapshot.files) {
|
|
89
|
+
if (!inventory.has(path))
|
|
90
|
+
inventory.set(path, { lines: textLineCount(bytes), bytes: bytes.length });
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
schema: reportSchema,
|
|
94
|
+
subject: snapshot.subject,
|
|
95
|
+
generatedAt: new Date().toISOString(),
|
|
96
|
+
appliedConfig: {
|
|
97
|
+
profile: 'js-ts/v2', mode: snapshot.subject.kind,
|
|
98
|
+
source: { extensions: sourceExtensions, excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
|
|
99
|
+
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
100
|
+
parser: parserDefaults,
|
|
101
|
+
maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
|
|
102
|
+
coverage: inputCoverage === undefined ? null : { inputDigest: digest(inputCoverage.text), pathBase: inputCoverage.sourceRoot, merge: 'any-hit' },
|
|
103
|
+
plugins: plugins.map(({ id, version, api, tools, kinds, claims }) => ({ id, version, api, tools: tools ?? {}, ...(kinds === undefined ? {} : { kinds }), ...(claims === undefined ? {} : { claims }) })),
|
|
104
|
+
operations: [...usedPlans.values(), ...duplicationPlan, ...(inputCoverage === undefined ? [] : coveragePlan)]
|
|
105
|
+
.map(task => ({ key: task.key, inputs: Object.fromEntries(task.inputs) })),
|
|
106
|
+
},
|
|
107
|
+
definitions: { ...Object.fromEntries((pluginData?.metrics ?? []).map(metric => [metric.id, metric.description ?? metric.label])),
|
|
108
|
+
...measurementDefinitions },
|
|
109
|
+
scope: { files: snapshot.files.length, parsed: parsed.size },
|
|
110
|
+
status: diagnostics.length > 0 ? 'partial' : snapshot.files.length === 0 ? 'not-applicable' : 'complete',
|
|
111
|
+
measurements: rows,
|
|
112
|
+
diagnostics,
|
|
113
|
+
findings,
|
|
114
|
+
...(pluginData === undefined ? {} : { pluginData: { ...pluginData,
|
|
115
|
+
inventory: [...inventory].sort(([left], [right]) => comparePaths(left, right)).map(([path, { lines, bytes }]) => ({ path, lines, ...(bytes === undefined ? {} : { bytes }), language: languageId(path), analysed: parsed.has(path) })) } }),
|
|
116
|
+
};
|
|
117
|
+
function record(task, outcome, path) {
|
|
118
|
+
if (outcome.state !== 'completed') {
|
|
119
|
+
diagnostics.push(diagnostic(task.key, outcome, path));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const stored = reportProducts.record(task, outcome.product, path);
|
|
124
|
+
if (stored) {
|
|
125
|
+
rows.push(...stored.measurements);
|
|
126
|
+
findings.push(...stored.findings);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
diagnostics.push({ operation: task.key, state: 'failed', path, message: error instanceof Error ? error.message : String(error) });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function languageId(path) {
|
|
135
|
+
const suffix = extname(path).toLowerCase();
|
|
136
|
+
if (['.js', '.mjs', '.cjs', '.jsx'].includes(suffix))
|
|
137
|
+
return 'javascript';
|
|
138
|
+
if (['.ts', '.mts', '.cts', '.tsx'].includes(suffix))
|
|
139
|
+
return 'typescript';
|
|
140
|
+
if (suffix === '.md' || suffix === '.mdx')
|
|
141
|
+
return 'markdown';
|
|
142
|
+
if (suffix === '.yml')
|
|
143
|
+
return 'yaml';
|
|
144
|
+
if (suffix === '.py')
|
|
145
|
+
return 'python';
|
|
146
|
+
if (suffix === '.rs')
|
|
147
|
+
return 'rust';
|
|
148
|
+
if (suffix === '.kt' || suffix === '.kts')
|
|
149
|
+
return 'kotlin';
|
|
150
|
+
return suffix.slice(1) || 'other';
|
|
151
|
+
}
|
|
152
|
+
function claimMatcher(claims) {
|
|
153
|
+
const { extensions = [], globs = [], languages = [] } = claims ?? {};
|
|
154
|
+
if (extensions.length === 0 && globs.length === 0 && languages.length === 0)
|
|
155
|
+
return () => true;
|
|
156
|
+
const glob = exclusionMatcher(globs);
|
|
157
|
+
const suffixes = new Set(extensions);
|
|
158
|
+
const languageSet = new Set(languages);
|
|
159
|
+
return path => suffixes.has(extname(path)) || glob(path) || languageSet.has(languageId(path));
|
|
160
|
+
}
|
|
161
|
+
function diagnostic(operation, outcome, path) {
|
|
162
|
+
return { operation, state: outcome.state, message: outcome.reason, ...(path === undefined ? {} : { path }) };
|
|
163
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { definitions } from '../core/model/measurement.js';
|
|
2
|
+
import { reportSchema } from '../report/json/validation/report.js';
|
|
3
|
+
import { gitText } from '../api/git/git.js';
|
|
4
|
+
import { churnSettings, gitChurn } from '../api/git/git-churn.js';
|
|
5
|
+
export async function attachChurn(report, root, paths) {
|
|
6
|
+
if (report.subject.kind !== 'commit')
|
|
7
|
+
return report;
|
|
8
|
+
if (paths.length === 0)
|
|
9
|
+
return withCommitTime(report, root);
|
|
10
|
+
const { churnWindow, ...appliedConfig } = report.appliedConfig;
|
|
11
|
+
const settings = { ...appliedConfig, churn: churnSettings };
|
|
12
|
+
const measurements = report.measurements.filter(row => row.definition !== definitions.churn);
|
|
13
|
+
const diagnostics = report.diagnostics.filter(row => row.operation !== 'git/churn');
|
|
14
|
+
try {
|
|
15
|
+
const churn = await gitChurn(root, report.subject.id, paths);
|
|
16
|
+
const rows = [...churn.touches].map(([path, value]) => ({ definition: definitions.churn, target: 'file', path, value }));
|
|
17
|
+
const status = report.status === 'partial' && diagnostics.length === 0 && report.diagnostics.length > 0 ? 'complete' : report.status;
|
|
18
|
+
return {
|
|
19
|
+
...report,
|
|
20
|
+
appliedConfig: { ...settings, churnWindow: churn.window },
|
|
21
|
+
definitions: { ...report.definitions, [definitions.churn]: 'First-parent commits that touched the current path, in the 90 days ending at the inspected commit. Root snapshots are omitted and renames start a new path.' },
|
|
22
|
+
status,
|
|
23
|
+
measurements: [...measurements, ...rows],
|
|
24
|
+
diagnostics,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return withCommitTime({ ...report, appliedConfig: settings, status: 'partial', measurements, diagnostics: [...diagnostics,
|
|
29
|
+
{ operation: 'git/churn', state: 'partial', message: 'Could not measure changes in the Git history available locally.' }] }, root);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function withCommitTime(report, root) {
|
|
33
|
+
const timestamp = await gitText(root, ['show', '--no-show-signature', '--no-notes', '--no-patch', '--format=%cI', report.subject.id, '--'])
|
|
34
|
+
.catch(() => '');
|
|
35
|
+
const time = Date.parse(timestamp.trim());
|
|
36
|
+
return Number.isFinite(time) ? { ...report, schema: reportSchema, committedAt: new Date(time).toISOString() } : report;
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DiffCoveragePorts, DiffCoverageReport } from '../core/usecases/diff-coverage.js';
|
|
2
|
+
import type { LcovFiles } from '../api/import/lcov-files.js';
|
|
3
|
+
export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
|
|
4
|
+
export type { DiffCoverageReport } from '../core/usecases/diff-coverage.js';
|
|
5
|
+
export interface DiffCoverageRequest {
|
|
6
|
+
readonly directory: string;
|
|
7
|
+
readonly revision: string;
|
|
8
|
+
readonly base: string;
|
|
9
|
+
readonly lcov: LcovFiles;
|
|
10
|
+
readonly exclude?: readonly string[];
|
|
11
|
+
readonly minimumPercent?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function measureDiffCoverage(request: DiffCoverageRequest, overrides?: Partial<DiffCoveragePorts>): Promise<DiffCoverageReport>;
|
|
14
|
+
export declare function measureChangedLines(request: DiffCoverageRequest, overrides?: Partial<DiffCoveragePorts>): Promise<{
|
|
15
|
+
report: DiffCoverageReport;
|
|
16
|
+
uncovered: readonly {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly lines: readonly number[];
|
|
19
|
+
}[];
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { execute } from '../core/engine/execute.js';
|
|
2
|
+
import { plan } from '../core/engine/plan.js';
|
|
3
|
+
import { digest, sourceDirectoriesExcluded, sourceExtensions, sourceLineCounts } from '../core/model/snapshot.js';
|
|
4
|
+
import { executeDiffCoverage } from '../core/usecases/diff-coverage.js';
|
|
5
|
+
import { defaultSourceExclusions, generatedSourcePolicy, sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
6
|
+
import { coverage, lcovInput } from '../plugins/coverage/coverage.js';
|
|
7
|
+
import { changesInput, diffCoverage, diffCoverageResult } from '../plugins/coverage/diff-coverage.js';
|
|
8
|
+
import { diffMethod, findMergeBase, readChanges } from '../api/git/changes.js';
|
|
9
|
+
import { gitText, physicalGitRoot, readGitCommit, resolveGitCommit } from '../api/git/git.js';
|
|
10
|
+
import { readLcovFiles } from '../api/import/lcov-files.js';
|
|
11
|
+
export { diffCoverageSchema } from '../core/usecases/diff-coverage.js';
|
|
12
|
+
const operation = 'diff-coverage/measure';
|
|
13
|
+
const steps = plan({ plugins: [diffCoverage], select: [operation],
|
|
14
|
+
inputs: new Map([['changes', changesInput.id], ['lcov', lcovInput.id]]) });
|
|
15
|
+
export async function measureDiffCoverage(request, overrides) {
|
|
16
|
+
return (await measureChangedLines(request, overrides)).report;
|
|
17
|
+
}
|
|
18
|
+
export async function measureChangedLines(request, overrides) {
|
|
19
|
+
return executeDiffCoverage(request, {
|
|
20
|
+
readInputs: (excludedPaths, excludes) => readInputs(request, excludedPaths, excludes),
|
|
21
|
+
async measure({ changes, lcovText, root, snapshot }, excludes) {
|
|
22
|
+
const inputs = new Map([
|
|
23
|
+
['changes', { contract: changesInput.id, value: changes }],
|
|
24
|
+
['lcov', { contract: lcovInput.id, value: { text: lcovText, root, sourceLines: sourceLineCounts(snapshot.files), excludes } }],
|
|
25
|
+
]);
|
|
26
|
+
const result = (await execute(steps, inputs)).get(operation);
|
|
27
|
+
if (!result || result.state !== 'completed')
|
|
28
|
+
throw new Error(result?.reason ?? 'Diff coverage did not run');
|
|
29
|
+
const value = result.product.value;
|
|
30
|
+
if (!diffCoverageResult.accepts(value))
|
|
31
|
+
throw new Error('Invalid diff coverage result');
|
|
32
|
+
return value;
|
|
33
|
+
},
|
|
34
|
+
...overrides,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async function readInputs(request, excludedPaths, excludes) {
|
|
38
|
+
const root = await physicalGitRoot(request.directory);
|
|
39
|
+
const [requestedBase, head, lcov, gitVersion] = await Promise.all([
|
|
40
|
+
resolveGitCommit(root, request.base),
|
|
41
|
+
resolveGitCommit(root, request.revision),
|
|
42
|
+
readLcovFiles(request.lcov),
|
|
43
|
+
gitText(root, ['--version']).then(text => text.trim()),
|
|
44
|
+
]);
|
|
45
|
+
const base = await findMergeBase(root, requestedBase, head);
|
|
46
|
+
const snapshot = await readGitCommit(root, head, excludes);
|
|
47
|
+
const changes = await readChanges(root, base, snapshot, sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded));
|
|
48
|
+
return { requestedBase, base, head, snapshot, changes, root, lcovText: lcov.text, appliedConfig: {
|
|
49
|
+
source: { extensions: sourceExtensions, excludedDirectories: sourceDirectoriesExcluded, excludedPaths,
|
|
50
|
+
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
51
|
+
gitDiff: { ...diffMethod, version: gitVersion },
|
|
52
|
+
lcov: { inputDigest: digest(lcov.text), pathBase: root, merge: 'any-hit', importerVersion: coverage.version,
|
|
53
|
+
...(lcov.inputDigests.length > 1 ? { inputDigests: lcov.inputDigests } : {}) },
|
|
54
|
+
plugin: { id: diffCoverage.id, version: diffCoverage.version, api: diffCoverage.api },
|
|
55
|
+
} };
|
|
56
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LcovFiles } from '../api/import/lcov-files.js';
|
|
2
|
+
import type { FindingIgnoreRule } from '../core/model/finding-ignore.js';
|
|
3
|
+
import type { Report } from '../core/model/report.js';
|
|
4
|
+
import type { FindingInput } from '../core/model/scanner-import.js';
|
|
5
|
+
import type { AnalysisExecutor, InspectionPorts } from '../core/usecases/inspect.js';
|
|
6
|
+
export { analyzeSnapshot } from './analyze-snapshot.js';
|
|
7
|
+
export type { AnalysisExecutor, AnalysisInput, InspectionPorts } from '../core/usecases/inspect.js';
|
|
8
|
+
export interface InspectRequest {
|
|
9
|
+
readonly directory: string;
|
|
10
|
+
readonly output: string;
|
|
11
|
+
readonly source: {
|
|
12
|
+
readonly workingTree: true;
|
|
13
|
+
} | {
|
|
14
|
+
readonly revision: string;
|
|
15
|
+
};
|
|
16
|
+
readonly lcov?: LcovFiles;
|
|
17
|
+
readonly exclude?: readonly string[];
|
|
18
|
+
readonly findingInputs?: readonly FindingInput[];
|
|
19
|
+
readonly findingRoot?: string;
|
|
20
|
+
readonly ignore?: readonly FindingIgnoreRule[];
|
|
21
|
+
}
|
|
22
|
+
export declare function inspect(request: InspectRequest, overrides?: AnalysisExecutor | Partial<InspectionPorts>): Promise<Report>;
|
|
23
|
+
export declare function attachFindings(report: Report, inputs: readonly FindingInput[], root: string, findingRoot: string, excludes: (path: string) => boolean): Promise<Report>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { gitTreeFiles } from '../api/git/git.js';
|
|
3
|
+
import { readInspectionSource } from '../api/git/inspection-source.js';
|
|
4
|
+
import { importFindings } from '../api/import/finding-import.js';
|
|
5
|
+
import { readLcovFiles } from '../api/import/lcov-files.js';
|
|
6
|
+
import { reportSchema } from '../core/model/report.js';
|
|
7
|
+
import { isExcludedDirectory } from '../core/model/snapshot.js';
|
|
8
|
+
import { executeInspection } from '../core/usecases/inspect.js';
|
|
9
|
+
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
10
|
+
import { analyzeSnapshot } from './analyze-snapshot.js';
|
|
11
|
+
import { attachChurn } from './attach-churn.js';
|
|
12
|
+
export { analyzeSnapshot } from './analyze-snapshot.js';
|
|
13
|
+
export async function inspect(request, overrides) {
|
|
14
|
+
const { lcov, findingInputs = [] } = request;
|
|
15
|
+
const ports = {
|
|
16
|
+
readSource: excludes => readSource(request, excludes),
|
|
17
|
+
analyze: analyzeSnapshot,
|
|
18
|
+
...(lcov === undefined ? {} : { readCoverage: () => readLcovFiles(lcov) }),
|
|
19
|
+
...(findingInputs.length === 0 ? {} : { importFindings: (report, root, excludes) => attachFindings(report, findingInputs, root, request.findingRoot === undefined ? root : resolve(request.findingRoot), excludes) }),
|
|
20
|
+
recordChurn: attachChurn,
|
|
21
|
+
...(typeof overrides === 'function' ? { analyze: overrides } : overrides),
|
|
22
|
+
};
|
|
23
|
+
return executeInspection(request, ports);
|
|
24
|
+
}
|
|
25
|
+
async function readSource(request, excludes) {
|
|
26
|
+
const source = await readInspectionSource(request, excludes);
|
|
27
|
+
const store = new LocalReportStore(source.output);
|
|
28
|
+
return { ...source, save: (report) => store.save(report) };
|
|
29
|
+
}
|
|
30
|
+
export async function attachFindings(report, inputs, root, findingRoot, excludes) {
|
|
31
|
+
const known = report.subject.kind === 'commit'
|
|
32
|
+
? new Set((await gitTreeFiles(root, report.subject.id)).map(entry => entry.path)) : undefined;
|
|
33
|
+
const isExcluded = (path) => path.split('/').slice(0, -1).some(isExcludedDirectory) || excludes(path);
|
|
34
|
+
const imports = await Promise.all(inputs.map(input => importFindings(input, findingRoot, isExcluded, known)));
|
|
35
|
+
const findingImports = imports.map(({ metadata }) => metadata);
|
|
36
|
+
const gaps = findingImports.filter(({ unmapped }) => unmapped > 0).map(({ category, format, unmapped }) => ({
|
|
37
|
+
operation: `findings/${category}/${format}`, state: 'partial', message: `${unmapped} finding locations could not be mapped to the source`,
|
|
38
|
+
}));
|
|
39
|
+
const findings = [...report.findings ?? [], ...imports.flatMap(({ findings }) => findings)];
|
|
40
|
+
// Import provenance identifies the normalized finding set and does not store an analyzer's raw report or host path.
|
|
41
|
+
return { ...report, schema: reportSchema, findings, appliedConfig: { ...report.appliedConfig, findingImports },
|
|
42
|
+
status: gaps.length > 0 ? 'partial' : report.status === 'not-applicable' && findingImports.some(item => item.units > 0)
|
|
43
|
+
? 'complete' : report.status, diagnostics: [...report.diagnostics, ...gaps] };
|
|
44
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { coverage } from '../plugins/coverage/coverage.js';
|
|
2
|
+
import { diffCoverage } from '../plugins/coverage/diff-coverage.js';
|
|
3
|
+
import { duplication } from '../plugins/duplication/duplication.js';
|
|
4
|
+
import { babelProvider } from '../plugins/language-js/babel-provider.js';
|
|
5
|
+
import { maintainability } from '../plugins/maintainability/maintainability.js';
|
|
6
|
+
import { structure } from '../plugins/structure/structure.js';
|
|
7
|
+
import { sourceProviders } from './sources.js';
|
|
8
|
+
export const builtInPlugins = [babelProvider, structure, maintainability, duplication, coverage, diffCoverage, ...sourceProviders]
|
|
9
|
+
.map(({ id, version, kinds, claims }) => ({ id, version, kinds, ...(claims ? { claims } : {}) }));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Report } from '../report/json/validation/report.js';
|
|
2
|
+
interface MetabranchRequest {
|
|
3
|
+
readonly repository: string;
|
|
4
|
+
readonly worktree: string;
|
|
5
|
+
readonly branch: string;
|
|
6
|
+
readonly report: Report;
|
|
7
|
+
}
|
|
8
|
+
export declare function prepareMetabranch({ repository, worktree, branch, report }: MetabranchRequest): Promise<readonly string[]>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isSensitiveFinding } from '../core/model/finding.js';
|
|
2
|
+
import { findingImportMethods } from '../core/model/scanner-import.js';
|
|
3
|
+
import { openMetabranchWorktree } from '../api/git/metabranch-worktree.js';
|
|
4
|
+
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
5
|
+
export async function prepareMetabranch({ repository, worktree, branch, report }) {
|
|
6
|
+
if (report.subject.kind !== 'commit')
|
|
7
|
+
throw new Error('Only reports for source commits can go into a metabranch');
|
|
8
|
+
if (report.findings?.some(finding => isSensitiveFinding(finding.category))
|
|
9
|
+
|| report.ignoredFindings?.some(({ finding }) => isSensitiveFinding(finding.category))
|
|
10
|
+
|| findingImportMethods(report.appliedConfig.findingImports).some(method => isSensitiveFinding(method.category))) {
|
|
11
|
+
throw new Error('Security scanner imports belong in the local report store');
|
|
12
|
+
}
|
|
13
|
+
const target = await openMetabranchWorktree(repository, worktree, branch, report.subject.id);
|
|
14
|
+
await new LocalReportStore(target).save(report);
|
|
15
|
+
return ['manifest.json', 'summary.json', `commits/${report.subject.id}/report.json`];
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PullReview } from '../core/model/pull-review.js';
|
|
2
|
+
import type { ReportReader } from '../core/ports/report.js';
|
|
3
|
+
import type { ReviewPorts } from '../core/usecases/review.js';
|
|
4
|
+
import type { DiffCoverageRequest } from './diff-coverage.js';
|
|
5
|
+
export { projectReview, reviewExitCode } from '../core/usecases/review.js';
|
|
6
|
+
export interface ReviewRequest extends Omit<DiffCoverageRequest, 'lcov'> {
|
|
7
|
+
readonly lcov?: DiffCoverageRequest['lcov'];
|
|
8
|
+
readonly number?: number;
|
|
9
|
+
readonly minimumLines?: number;
|
|
10
|
+
readonly maxCoverageDrop?: number;
|
|
11
|
+
readonly maxNewIssues?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function reviewPull(request: ReviewRequest, current: ReportReader, baseline?: ReportReader): Promise<PullReview>;
|
|
14
|
+
export declare function review(request: ReviewRequest & {
|
|
15
|
+
readonly output?: string;
|
|
16
|
+
}, overrides?: Partial<ReviewPorts>): Promise<PullReview>;
|