repometry 0.0.0-stage → 0.2.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 +28 -2
- package/package.json +64 -4
- 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 +33 -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 +252 -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 +120 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +560 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +92 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +106 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +108 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +53 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +71 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +74 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +153 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +31 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +47 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +36 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +35 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +57 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +227 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +14 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +17 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +46 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +102 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +86 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +111 -0
- package/target/main/ts/cli/config.d.ts +13 -0
- package/target/main/ts/cli/config.js +58 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +30 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +379 -0
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +104 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +16 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +39 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +164 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +50 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +45 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +10 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +17 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +39 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +30 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +50 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +105 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +107 -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 +86 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +2 -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 +15 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +32 -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 +36 -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 +33 -0
- package/target/main/ts/core/model/measurement.js +30 -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 +40 -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 +29 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +51 -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 +2 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +5 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +58 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +10 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +11 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +146 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +16 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +42 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +129 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +18 -0
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +6 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
- package/target/main/ts/plugins/coverage/coverage.js +199 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +94 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +36 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +61 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +80 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +38 -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 +2104 -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 +70 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -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 +73 -0
- package/target/main/ts/report/html/app/viewer-trends.js +423 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +735 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +40 -0
- package/target/main/ts/report/html/site/export-site.d.ts +22 -0
- package/target/main/ts/report/html/site/export-site.js +150 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +71 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +65 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +80 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +65 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +23 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
- package/target/main/ts/report/json/projections/commit-summary.js +124 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +30 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +244 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +93 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +70 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +58 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +17 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +32 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +180 -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 +52 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +8 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +65 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +28 -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 +6 -0
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
}
|
|
164
|
+
//# sourceMappingURL=analyze-snapshot.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
return withCommitDetails(await measureChurn(report, root, paths), root);
|
|
9
|
+
}
|
|
10
|
+
async function measureChurn(report, root, paths) {
|
|
11
|
+
if (paths.length === 0)
|
|
12
|
+
return withCommitTime(report, root);
|
|
13
|
+
const { churnWindow, ...appliedConfig } = report.appliedConfig;
|
|
14
|
+
const settings = { ...appliedConfig, churn: churnSettings };
|
|
15
|
+
const measurements = report.measurements.filter(row => row.definition !== definitions.churn);
|
|
16
|
+
const diagnostics = report.diagnostics.filter(row => row.operation !== 'git/churn');
|
|
17
|
+
try {
|
|
18
|
+
const churn = await gitChurn(root, report.subject.id, paths);
|
|
19
|
+
const rows = [...churn.touches].map(([path, value]) => ({ definition: definitions.churn, target: 'file', path, value }));
|
|
20
|
+
const status = report.status === 'partial' && diagnostics.length === 0 && report.diagnostics.length > 0 ? 'complete' : report.status;
|
|
21
|
+
return {
|
|
22
|
+
...report,
|
|
23
|
+
appliedConfig: { ...settings, churnWindow: churn.window },
|
|
24
|
+
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.' },
|
|
25
|
+
status,
|
|
26
|
+
measurements: [...measurements, ...rows],
|
|
27
|
+
diagnostics,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return withCommitTime({ ...report, appliedConfig: settings, status: 'partial', measurements, diagnostics: [...diagnostics,
|
|
32
|
+
{ operation: 'git/churn', state: 'partial', message: 'Could not measure changes in the Git history available locally.' }] }, root);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function withCommitTime(report, root) {
|
|
36
|
+
const timestamp = await gitText(root, ['show', '--no-show-signature', '--no-notes', '--no-patch', '--format=%cI', report.subject.id, '--'])
|
|
37
|
+
.catch(() => '');
|
|
38
|
+
const time = Date.parse(timestamp.trim());
|
|
39
|
+
return Number.isFinite(time) ? { ...report, schema: reportSchema, committedAt: new Date(time).toISOString() } : report;
|
|
40
|
+
}
|
|
41
|
+
/** Message title and author of the inspected commit, kept with the inspection so exports need no Git history. */
|
|
42
|
+
async function withCommitDetails(report, root) {
|
|
43
|
+
const log = await gitText(root, ['show', '--no-show-signature', '--no-notes', '--no-patch', '--format=%an%x00%ae%x00%B', report.subject.id, '--'])
|
|
44
|
+
.catch(() => '');
|
|
45
|
+
const [name, email, message] = log.split('\0');
|
|
46
|
+
if (!name || email === undefined || message === undefined)
|
|
47
|
+
return report;
|
|
48
|
+
return { ...report, schema: reportSchema, commit: { subject: message.split(/\r?\n/, 1)[0], author: { name, email } } };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=attach-churn.js.map
|
|
@@ -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,57 @@
|
|
|
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
|
+
}
|
|
57
|
+
//# sourceMappingURL=diff-coverage.js.map
|
|
@@ -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,45 @@
|
|
|
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
|
+
}
|
|
45
|
+
//# sourceMappingURL=inspect.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
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 } : {}) }));
|
|
10
|
+
//# sourceMappingURL=plugin-list.js.map
|
|
@@ -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,17 @@
|
|
|
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
|
+
}
|
|
17
|
+
//# sourceMappingURL=prepare-metabranch.js.map
|
|
@@ -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>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { findMergeBase } from '../api/git/changes.js';
|
|
3
|
+
import { gitRoot, resolveGitCommit } from '../api/git/git.js';
|
|
4
|
+
import { executeReview } from '../core/usecases/review.js';
|
|
5
|
+
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
6
|
+
import { measureChangedLines } from './diff-coverage.js';
|
|
7
|
+
export { projectReview, reviewExitCode } from '../core/usecases/review.js';
|
|
8
|
+
export async function reviewPull(request, current, baseline = current) {
|
|
9
|
+
return review(request, {
|
|
10
|
+
readHead: id => readIfAvailable(current, id),
|
|
11
|
+
readBase: id => readIfAvailable(baseline, id),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export async function review(request, overrides) {
|
|
15
|
+
const store = new LocalReportStore(resolve(request.output ?? resolve(request.directory, '.repometry')));
|
|
16
|
+
const { lcov } = request;
|
|
17
|
+
return executeReview(request, {
|
|
18
|
+
readHead: id => readIfAvailable(store, id),
|
|
19
|
+
readBase: id => readIfAvailable(store, id),
|
|
20
|
+
async readRevisions() {
|
|
21
|
+
const directory = await gitRoot(request.directory);
|
|
22
|
+
const [head, base] = await Promise.all([resolveGitCommit(directory, request.revision), resolveGitCommit(directory, request.base)]);
|
|
23
|
+
return { head, base, mergeBase: () => findMergeBase(directory, base, head) };
|
|
24
|
+
},
|
|
25
|
+
...(lcov === undefined ? {} : { measureChanged: () => measureChangedLines({ ...request, lcov }) }),
|
|
26
|
+
...overrides,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function readIfAvailable(reader, id) {
|
|
30
|
+
try {
|
|
31
|
+
return await reader.read({ kind: 'commit', id });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
35
|
+
return null;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SourceContext, SourcePlugin } from '../core/ports/source-provider.js';
|
|
2
|
+
export declare const sourceProviders: readonly SourcePlugin[];
|
|
3
|
+
export declare function resolveSourceLocator(option: string | undefined, context: Omit<SourceContext, 'option'>, providers?: readonly SourcePlugin[]): import("../plugin.js").SourceLocator | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { plan } from '../core/engine/plan.js';
|
|
2
|
+
import { githubSource, gitlabSource, localSource } from '../plugins/source/forges.js';
|
|
3
|
+
export const sourceProviders = [githubSource, gitlabSource, localSource];
|
|
4
|
+
export function resolveSourceLocator(option, context, providers = sourceProviders) {
|
|
5
|
+
plan({ plugins: providers, select: [], inputs: new Map() });
|
|
6
|
+
if (option === 'none')
|
|
7
|
+
return undefined;
|
|
8
|
+
if (option && option !== 'auto') {
|
|
9
|
+
const colon = option.indexOf(':');
|
|
10
|
+
const id = colon < 0 ? option : option.slice(0, colon);
|
|
11
|
+
const spec = colon < 0 ? undefined : option.slice(colon + 1);
|
|
12
|
+
const provider = providers.find(item => item.id === id);
|
|
13
|
+
if (!provider)
|
|
14
|
+
throw new Error(`Unknown source provider: ${id}. Choose ${providers.map(item => item.id).join(', ')}.`);
|
|
15
|
+
const locator = provider.locate({ ...context, option: spec });
|
|
16
|
+
if (!locator)
|
|
17
|
+
throw new Error(`Cannot locate sources for ${id}. Name the repository as ${id}:OWNER/REPO.`);
|
|
18
|
+
return locator;
|
|
19
|
+
}
|
|
20
|
+
const remoteProviders = providers.filter(provider => provider.id !== 'local');
|
|
21
|
+
for (const candidate of [{ env: context.env, remotes: [] }, { env: {}, remotes: context.remotes }]) {
|
|
22
|
+
for (const provider of remoteProviders) {
|
|
23
|
+
const locator = provider.locate(candidate);
|
|
24
|
+
if (locator)
|
|
25
|
+
return locator;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return providers.find(provider => provider.id === 'local')?.locate(context);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Product } from './plugin.js';
|
|
2
|
+
import type { PlannedOperation } from './plan.js';
|
|
3
|
+
export type Outcome = {
|
|
4
|
+
readonly state: 'completed';
|
|
5
|
+
readonly product: Product;
|
|
6
|
+
} | {
|
|
7
|
+
readonly state: 'failed' | 'blocked';
|
|
8
|
+
readonly reason: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function execute(plan: readonly PlannedOperation[], external: ReadonlyMap<string, Product>): Promise<ReadonlyMap<string, Outcome>>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export async function execute(plan, external) {
|
|
2
|
+
const results = new Map();
|
|
3
|
+
for (const task of plan) {
|
|
4
|
+
const inputs = new Map();
|
|
5
|
+
for (const [name, binding] of task.inputs) {
|
|
6
|
+
const producer = 'operation' in binding ? results.get(binding.operation) : undefined;
|
|
7
|
+
const product = 'external' in binding ? external.get(binding.external)
|
|
8
|
+
: producer?.state === 'completed' ? producer.product : undefined;
|
|
9
|
+
if (product)
|
|
10
|
+
inputs.set(name, product);
|
|
11
|
+
}
|
|
12
|
+
const missing = [...task.inputs.keys()].filter(name => !inputs.has(name));
|
|
13
|
+
if (missing.length > 0) {
|
|
14
|
+
results.set(task.key, { state: 'blocked', reason: `Unavailable inputs: ${missing.join(', ')}` });
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
for (const [name, contract] of Object.entries(task.operation.inputs)) {
|
|
19
|
+
readInput(inputs, name, contract);
|
|
20
|
+
}
|
|
21
|
+
const context = {
|
|
22
|
+
read: (port, contract) => {
|
|
23
|
+
if (!Object.hasOwn(task.operation.inputs, port) || task.operation.inputs[port]?.id !== contract.id) {
|
|
24
|
+
throw new Error(`Undeclared input contract: ${port} (${contract.id})`);
|
|
25
|
+
}
|
|
26
|
+
return readInput(inputs, port, contract);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
const value = await task.operation.execute(context);
|
|
30
|
+
const { output } = task.operation;
|
|
31
|
+
if (!output.accepts(value))
|
|
32
|
+
throw new Error(`Invalid output for ${output.id}`);
|
|
33
|
+
if (task.validateOutput && !task.validateOutput(value))
|
|
34
|
+
throw new Error(`Output violates the schema for ${output.id}`);
|
|
35
|
+
results.set(task.key, { state: 'completed', product: { contract: output.id, value } });
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
results.set(task.key, { state: 'failed', reason: error instanceof Error ? error.message : String(error) });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
function readInput(inputs, port, contract) {
|
|
44
|
+
const product = inputs.get(port);
|
|
45
|
+
if (!product || product.contract !== contract.id || !contract.accepts(product.value)) {
|
|
46
|
+
throw new Error(`Invalid input: ${port} (${contract.id})`);
|
|
47
|
+
}
|
|
48
|
+
return product.value;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LegacyPlugin, MetricDescriptor, Plugin, ProductDeclaration } from './plugin.js';
|
|
2
|
+
export declare function isCoreReportProduct(contract: string): boolean;
|
|
3
|
+
export declare function manifestProducts(plugin: Plugin | LegacyPlugin, allowLegacy: boolean): ReadonlyMap<string, ProductDeclaration> | undefined;
|
|
4
|
+
export declare function isMetricDescriptor(value: unknown): value is MetricDescriptor;
|