repometry 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/package.json +1 -1
- package/target/main/resources/config/process-plugins-v1.schema.json +22 -0
- package/target/main/resources/report/json/config-v1.schema.json +41 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +23 -1
- package/target/main/resources/report/json/pull-review-v2.schema.json +100 -0
- package/target/main/ts/api/cache/root.d.ts +1 -1
- package/target/main/ts/api/cache/root.js +2 -2
- package/target/main/ts/api/gh/github.d.ts +0 -4
- package/target/main/ts/api/gh/github.js +3 -33
- package/target/main/ts/api/git/commit-metadata.d.ts +0 -1
- package/target/main/ts/api/git/commit-metadata.js +1 -10
- package/target/main/ts/api/import/cobertura.d.ts +2 -0
- package/target/main/ts/api/import/cobertura.js +160 -0
- package/target/main/ts/api/import/coverage-xml.d.ts +7 -0
- package/target/main/ts/api/import/coverage-xml.js +135 -0
- package/target/main/ts/api/import/lcov-files.d.ts +3 -1
- package/target/main/ts/api/import/lcov-files.js +23 -4
- package/target/main/ts/cli/arguments.js +2 -4
- package/target/main/ts/cli/config.d.ts +10 -6
- package/target/main/ts/cli/config.js +36 -6
- package/target/main/ts/cli/imports.d.ts +1 -0
- package/target/main/ts/cli/imports.js +6 -2
- package/target/main/ts/cli/main.js +47 -139
- package/target/main/ts/cli/range-inspection.d.ts +0 -3
- package/target/main/ts/cli/range-inspection.js +5 -17
- package/target/main/ts/cli/range-jobs.js +1 -3
- package/target/main/ts/cli/reporting.d.ts +2 -7
- package/target/main/ts/cli/reporting.js +23 -37
- package/target/main/ts/compose/analysis-report.d.ts +1 -1
- package/target/main/ts/compose/analysis-report.js +4 -5
- package/target/main/ts/compose/analysis-results.d.ts +1 -1
- package/target/main/ts/compose/analysis-results.js +4 -6
- package/target/main/ts/compose/analysis-steps.d.ts +23 -0
- package/target/main/ts/compose/analysis-steps.js +215 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -1
- package/target/main/ts/compose/analyze-snapshot.js +8 -12
- package/target/main/ts/compose/built-ins.d.ts +3 -0
- package/target/main/ts/compose/built-ins.js +5 -0
- package/target/main/ts/compose/diff-coverage.d.ts +2 -4
- package/target/main/ts/compose/diff-coverage.js +15 -12
- package/target/main/ts/compose/history-cache.d.ts +1 -1
- package/target/main/ts/compose/inspect.d.ts +6 -9
- package/target/main/ts/compose/inspect.js +8 -9
- package/target/main/ts/compose/languages.d.ts +4 -1
- package/target/main/ts/compose/languages.js +9 -6
- package/target/main/ts/compose/native-language-plugins.d.ts +0 -1
- package/target/main/ts/compose/native-language-plugins.js +4 -11
- package/target/main/ts/compose/phases.d.ts +126 -0
- package/target/main/ts/compose/phases.js +154 -0
- package/target/main/ts/compose/plugin-list.d.ts +8 -2
- package/target/main/ts/compose/plugin-list.js +4 -13
- package/target/main/ts/compose/process-plugins.js +1 -1
- package/target/main/ts/compose/review.d.ts +2 -4
- package/target/main/ts/compose/review.js +10 -9
- package/target/main/ts/compose/sources.d.ts +1 -2
- package/target/main/ts/compose/sources.js +7 -7
- package/target/main/ts/core/engine/execute.d.ts +4 -1
- package/target/main/ts/core/engine/execute.js +1 -1
- package/target/main/ts/core/engine/manifest.d.ts +0 -1
- package/target/main/ts/core/engine/manifest.js +9 -13
- package/target/main/ts/core/engine/plugin.d.ts +1 -1
- package/target/main/ts/core/engine/report-products.js +3 -2
- package/target/main/ts/core/model/changes.d.ts +2 -0
- package/target/main/ts/core/model/changes.js +5 -1
- package/target/main/ts/core/model/clone-source.d.ts +2 -0
- package/target/main/ts/core/model/clone-source.js +4 -0
- package/target/main/ts/core/model/code-structure.d.ts +4 -1
- package/target/main/ts/core/model/code-structure.js +3 -1
- package/target/main/ts/core/model/coverage-input.d.ts +12 -0
- package/target/main/ts/core/model/coverage-input.js +11 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +2 -0
- package/target/main/ts/core/model/diff-coverage.js +9 -1
- package/target/main/ts/core/model/language.d.ts +28 -0
- package/target/main/ts/core/model/language.js +25 -1
- package/target/main/ts/core/model/quality-summary.js +1 -1
- package/target/main/ts/core/model/report.d.ts +0 -2
- package/target/main/ts/core/model/report.js +0 -20
- package/target/main/ts/core/ports/tool-runner.d.ts +13 -0
- package/target/main/ts/core/usecases/inspect.d.ts +1 -2
- package/target/main/ts/core/usecases/review.js +11 -3
- package/target/main/ts/index.d.ts +6 -33
- package/target/main/ts/index.js +3 -18
- package/target/main/ts/plugin.d.ts +7 -3
- package/target/main/ts/plugin.js +3 -0
- package/target/main/ts/plugins/built-in.d.ts +6 -0
- package/target/main/ts/plugins/built-in.js +39 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +3 -24
- package/target/main/ts/plugins/coverage/coverage.js +8 -11
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +1 -5
- package/target/main/ts/plugins/coverage/diff-coverage.js +5 -14
- package/target/main/ts/plugins/duplication/duplication.d.ts +1 -3
- package/target/main/ts/plugins/duplication/duplication.js +2 -6
- package/target/main/ts/plugins/language-js/babel-provider.js +3 -2
- package/target/main/ts/plugins/language-js/structural-observations.js +1 -1
- package/target/main/ts/plugins/language-js/syntax.d.ts +2 -0
- package/target/main/ts/plugins/language-js/syntax.js +11 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +1 -8
- package/target/main/ts/plugins/maintainability/maintainability.js +4 -10
- package/target/main/ts/plugins/source/forges.js +1 -1
- package/target/main/ts/report/html/app/viewer-languages.d.ts +3 -1
- package/target/main/ts/report/html/app/viewer-languages.js +11 -1
- package/target/main/ts/report/html/app/viewer-metrics-view.js +1 -1
- package/target/main/ts/report/html/app/viewer-source-view.js +2 -2
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +7 -6
- package/target/main/ts/report/html/app/viewer-tokenizer.js +72 -71
- package/target/main/ts/report/html/site/export-site.d.ts +1 -5
- package/target/main/ts/report/html/site/export-site.js +2 -6
- package/target/main/ts/report/html/site/projects.d.ts +1 -3
- package/target/main/ts/report/html/site/projects.js +2 -4
- package/target/main/ts/report/json/projections/file-metrics.js +1 -1
- package/target/main/ts/report/json/projections/inspection-context.d.ts +1 -0
- package/target/main/ts/report/json/projections/inspection-context.js +19 -1
- package/target/main/ts/report/json/projections/inspection-details.js +7 -2
- package/target/main/ts/report/json/store/local-store.js +2 -0
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -1
- package/target/main/ts/report/json/store/replace-file.js +24 -3
- package/target/main/ts/report/json/store/store-check.js +10 -1
- package/target/main/ts/report/json/validation/metabranch.d.ts +1 -1
- package/target/main/ts/report/json/validation/metabranch.js +6 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +3 -1
- package/target/main/ts/report.d.ts +13 -1
- package/target/main/ts/report.js +7 -1
- package/target/main/ts/api/git/metabranch-worktree.d.ts +0 -1
- package/target/main/ts/api/git/metabranch-worktree.js +0 -35
- package/target/main/ts/api/worker/remote-executor.d.ts +0 -2
- package/target/main/ts/api/worker/remote-executor.js +0 -46
- package/target/main/ts/api/worker/worker-protocol.d.ts +0 -7
- package/target/main/ts/api/worker/worker-protocol.js +0 -127
- package/target/main/ts/api/worker/worker.d.ts +0 -5
- package/target/main/ts/api/worker/worker.js +0 -86
- package/target/main/ts/compose/analysis-files.d.ts +0 -15
- package/target/main/ts/compose/analysis-files.js +0 -129
- package/target/main/ts/compose/analysis-imports.d.ts +0 -7
- package/target/main/ts/compose/analysis-imports.js +0 -36
- package/target/main/ts/compose/analysis-repository.d.ts +0 -7
- package/target/main/ts/compose/analysis-repository.js +0 -99
- package/target/main/ts/compose/analysis-sources.d.ts +0 -48
- package/target/main/ts/compose/analysis-sources.js +0 -54
- package/target/main/ts/compose/prepare-metabranch.d.ts +0 -9
- package/target/main/ts/compose/prepare-metabranch.js +0 -17
- package/target/main/ts/compose/security-plugins.d.ts +0 -1
- package/target/main/ts/compose/security-plugins.js +0 -7
- package/target/main/ts/core/usecases/compare.d.ts +0 -6
- package/target/main/ts/core/usecases/compare.js +0 -189
- package/target/main/ts/report/json/store/components.d.ts +0 -2
- package/target/main/ts/report/json/store/components.js +0 -32
|
@@ -1,126 +1,85 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
3
|
+
import { relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { firstParentRange, gitRoot, resolveGitCommit } from '../api/git/git.js';
|
|
5
5
|
import { gitReportObjects } from '../api/git/git-reader.js';
|
|
6
|
-
import { resolveGitBranch } from '../api/git/commit-metadata.js';
|
|
7
6
|
import { cacheRoot, clearCaches } from '../api/cache/root.js';
|
|
8
|
-
import { gitHubPullRequest,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { defaultLanguages, languageRegistry } from '../compose/languages.js';
|
|
12
|
-
import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
|
|
13
|
-
import { measureDiffCoverage } from '../compose/diff-coverage.js';
|
|
14
|
-
import { prepareMetabranch } from '../compose/prepare-metabranch.js';
|
|
7
|
+
import { gitHubPullRequest, writeGitHubReview } from '../api/gh/github.js';
|
|
8
|
+
import { defaultLanguages } from '../compose/languages.js';
|
|
9
|
+
import { attachFindings, inspect } from '../compose/inspect.js';
|
|
15
10
|
import { review as reviewChange, reviewExitCode, reviewReason } from '../compose/review.js';
|
|
16
11
|
import { effectivePlugins } from '../compose/plugin-list.js';
|
|
17
12
|
import { validSubjectId } from '../core/model/report.js';
|
|
18
|
-
import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
19
|
-
import { compareInspections } from '../core/usecases/compare.js';
|
|
20
13
|
import { exportProjects } from '../report/html/site/projects.js';
|
|
21
14
|
import { fileMetrics } from '../report/json/projections/file-metrics.js';
|
|
22
15
|
import { pullReviewMarkdown } from '../report/markdown/pull-review.js';
|
|
23
16
|
import { LocalObjectStore } from '../report/json/store/object-store.js';
|
|
24
17
|
import { checkStore } from '../report/json/store/store-check.js';
|
|
25
18
|
import { dispatch, flag, option } from './arguments.js';
|
|
26
|
-
import { configFile, parseConfig, readConfig, readConfigValue } from './config.js';
|
|
19
|
+
import { configFile, listOption, parseConfig, readConfig, readConfigValue } from './config.js';
|
|
27
20
|
import { analyzeCommits, isSaved } from './range-jobs.js';
|
|
28
|
-
import { analysisExecutor } from './range-inspection.js';
|
|
29
21
|
import { importerIds, readInputs } from './imports.js';
|
|
30
22
|
import { outputReports, reporterIds, viewTarget } from './reporting.js';
|
|
31
23
|
import { parseRange } from './revisions.js';
|
|
32
|
-
import { findRepository, selectStore, writableStore } from './store.js';
|
|
24
|
+
import { findRepository, invocationDirectory, selectStore, writableStore } from './store.js';
|
|
33
25
|
const configOptions = { config: option('FILE', 'Read a different JSON configuration.'), 'no-config': flag('Skip configuration.') };
|
|
34
26
|
const importOption = option('FORMAT=PATH', 'Import a report produced by another tool. Repeatable.', { multiple: true });
|
|
35
27
|
const excludeOption = option('PATTERN', 'Exclude a path or glob. Repeatable.', { multiple: true });
|
|
36
28
|
const ciOption = option('PROVIDER', 'Send CI output to github or none.');
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
sources: option('auto|none|ID[:SPEC]', 'Select where the report reads source files.'),
|
|
43
|
-
title: option('NAME', 'Set the report title.'), components: option('FILE', 'Read component definitions.'),
|
|
44
|
-
'no-footer': flag('Omit the footer.'), branch: branchOption,
|
|
29
|
+
const repoOption = option('DIR', 'Run in the given repository.', { short: 'C' });
|
|
30
|
+
const storeOption = option('PATH|git:REF', 'Select a report store.');
|
|
31
|
+
const storageOptions = { repo: repoOption, store: storeOption };
|
|
32
|
+
const displayOptions = {
|
|
33
|
+
...configOptions, branch: option('NAME', 'Name the branch shown in the report.'), title: option('NAME', 'Set the report title.'),
|
|
45
34
|
};
|
|
46
35
|
const commands = {
|
|
47
36
|
analyze: {
|
|
48
37
|
description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
|
|
49
|
-
options: { ...configOptions, ...
|
|
38
|
+
options: { ...configOptions, ...storageOptions, 'working-tree': flag('Analyze the working directory.'),
|
|
50
39
|
'skip-saved': flag('Keep commits that already have a saved inspection.'),
|
|
51
40
|
concurrency: option('N', 'Maximum local analysis workers for a range. Defaults to the available cores.'),
|
|
52
|
-
import: importOption,
|
|
53
|
-
exclude: excludeOption, 'import-root': option('DIR', 'Resolve scanner locations relative to this directory.'),
|
|
54
|
-
worker: option('URL', 'Run analysis on a Repometry worker.'), ci: ciOption },
|
|
41
|
+
import: importOption,
|
|
42
|
+
exclude: excludeOption, 'import-root': option('DIR', 'Resolve scanner locations relative to this directory.') },
|
|
55
43
|
run: runAnalysis,
|
|
56
44
|
},
|
|
57
45
|
show: {
|
|
58
46
|
description: 'Print a saved report.', parameters: 'REVISION|DIGEST', min: 1, max: 1,
|
|
59
|
-
options: { files: flag('Print file metrics.') }, run: show,
|
|
47
|
+
options: { ...storageOptions, files: flag('Print file metrics.') }, run: show,
|
|
60
48
|
},
|
|
61
|
-
history: { description: 'List saved inspections.', async run(input) {
|
|
49
|
+
history: { description: 'List saved inspections.', options: storageOptions, async run(input) {
|
|
62
50
|
const { store } = await context(input);
|
|
63
51
|
print({ schema: 'urn:repometry:schema:inspection-history:1', inspections: (await store.reader.list()).map(inspectionSummary) });
|
|
64
52
|
} },
|
|
65
|
-
compare: {
|
|
66
|
-
description: 'Compare two saved reports.', parameters: 'BASE [HEAD]', min: 1, max: 2,
|
|
67
|
-
options: { 'baseline-store': baselineOption }, run: compare,
|
|
68
|
-
},
|
|
69
|
-
'diff-coverage': {
|
|
70
|
-
description: 'Measure coverage of added lines.', parameters: 'BASE [HEAD]', min: 1, max: 2,
|
|
71
|
-
options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
|
|
72
|
-
'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.') }, run: diffCoverage,
|
|
73
|
-
},
|
|
74
53
|
review: {
|
|
75
54
|
description: 'Report the issues a change adds or makes worse on the lines it changes.', parameters: 'BASE [HEAD]', min: 1, max: 2,
|
|
76
|
-
options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
|
|
55
|
+
options: { ...configOptions, repo: repoOption, import: importOption, exclude: excludeOption, ci: ciOption,
|
|
77
56
|
pull: option('NUMBER', 'Name the pull request in the result.'),
|
|
78
|
-
'min-coverage': option('PERCENT', 'Minimum changed-line coverage. Default 80.'),
|
|
79
|
-
'min-lines': option('COUNT', 'Measured changed lines from which the coverage minimum applies. Default 20.'),
|
|
80
|
-
'max-new-issues': option('COUNT', 'Allowed new and worsened issues. Default 0.'),
|
|
81
57
|
markdown: option('PATH', 'Also write the result as Markdown, for a pull request comment.') }, run: review,
|
|
82
58
|
},
|
|
83
59
|
report: {
|
|
84
60
|
description: 'Render HTML or JSON from saved reports.', parameters: '[FORMAT[=PATH]]...', max: Infinity,
|
|
85
|
-
options: { ...
|
|
61
|
+
options: { ...displayOptions, ...storageOptions, sources: option('auto|none|ID[:SPEC]', 'Select where the report reads source files.') },
|
|
62
|
+
async run(input) {
|
|
86
63
|
const { root, store } = await context(input);
|
|
87
64
|
const config = await readConfig(root, input);
|
|
88
|
-
|
|
89
|
-
print({ schema: 'urn:repometry:schema:render-result:1', reports: await outputReports(root, store, requests, input, config) });
|
|
65
|
+
print({ schema: 'urn:repometry:schema:render-result:1', reports: await outputReports(root, store, input, config) });
|
|
90
66
|
},
|
|
91
67
|
},
|
|
92
68
|
view: {
|
|
93
69
|
description: 'Open a repository, store or exported site locally.', parameters: '[TARGET]', max: 1,
|
|
94
|
-
options: { ...
|
|
95
|
-
components: renderOptions.components, 'no-footer': renderOptions['no-footer'] },
|
|
70
|
+
options: { ...displayOptions, store: storeOption, port: option('PORT', 'Listen on this localhost port.') },
|
|
96
71
|
async run(input) { announce(await viewTarget(input, port(input.text('port') ?? '0'))); },
|
|
97
72
|
},
|
|
98
73
|
projects: {
|
|
99
|
-
description: 'Generate a projects index.',
|
|
74
|
+
description: 'Generate a projects index.', parameters: '[DIR]', max: 1,
|
|
100
75
|
async run(input) {
|
|
101
|
-
const destination = resolve(input.
|
|
102
|
-
print({ schema: 'urn:repometry:schema:projects-result:1', destination,
|
|
103
|
-
projects: await exportProjects(destination, { footer: !input.flag('no-footer') }) });
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
prepare: {
|
|
107
|
-
description: 'Prepare a report for a Git storage branch.', parameters: 'REVISION', min: 1, max: 1,
|
|
108
|
-
options: { worktree: option('DIR', 'Select the storage worktree.'), branch: option('NAME', 'Select the storage branch.') },
|
|
109
|
-
async run(input) {
|
|
110
|
-
const { directory, root, store } = await context(input);
|
|
111
|
-
const path = input.text('worktree');
|
|
112
|
-
if (!path)
|
|
113
|
-
throw new Error('prepare requires --worktree');
|
|
114
|
-
const worktree = resolve(directory, path);
|
|
115
|
-
const id = await commitId(root, input.args[0]);
|
|
116
|
-
const report = await store.reader.read({ kind: 'commit', id });
|
|
117
|
-
const files = await prepareMetabranch({ repository: root, worktree, branch: input.text('branch') ?? 'repometry', report });
|
|
118
|
-
print({ schema: 'urn:repometry:schema:prepare-result:1', subject: report.subject, worktree, files });
|
|
76
|
+
const destination = resolve(input.args[0] ?? '.');
|
|
77
|
+
print({ schema: 'urn:repometry:schema:projects-result:1', destination, projects: await exportProjects(destination) });
|
|
119
78
|
},
|
|
120
79
|
},
|
|
121
|
-
plugins: { description: 'List effective plugins and supported formats.', options: configOptions,
|
|
80
|
+
plugins: { description: 'List effective plugins and supported formats.', options: { ...configOptions, repo: repoOption },
|
|
122
81
|
async run(input) {
|
|
123
|
-
const { root } = await
|
|
82
|
+
const { root } = await repositoryContext(input);
|
|
124
83
|
const config = await readConfig(root, input);
|
|
125
84
|
print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: effectivePlugins(config.plugins),
|
|
126
85
|
importers: importerIds, reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
|
|
@@ -128,22 +87,19 @@ const commands = {
|
|
|
128
87
|
},
|
|
129
88
|
cache: {
|
|
130
89
|
description: 'Find or clear the system cache.', parameters: 'path|clear', min: 1, max: 1,
|
|
131
|
-
options: { sources: flag('Clear only source blobs.') },
|
|
132
90
|
async run(input) {
|
|
133
91
|
const action = input.args[0];
|
|
134
92
|
if (action !== 'path' && action !== 'clear')
|
|
135
93
|
throw new Error('Use cache path or cache clear');
|
|
136
|
-
if (action === 'path' && input.flag('sources'))
|
|
137
|
-
throw new Error('--sources requires cache clear');
|
|
138
94
|
const path = cacheRoot();
|
|
139
|
-
const cleared = action === 'clear' ? await clearCaches(path
|
|
95
|
+
const cleared = action === 'clear' ? await clearCaches(path) : undefined;
|
|
140
96
|
print({ schema: 'urn:repometry:schema:cache-result:1', path, cleared });
|
|
141
97
|
},
|
|
142
98
|
},
|
|
143
99
|
store: {
|
|
144
100
|
description: 'Check saved inspections and repair what can be restored.', parameters: 'check', min: 1, max: 1,
|
|
145
101
|
options: {
|
|
146
|
-
repair: flag('Restore missing data from a copy.'),
|
|
102
|
+
...storageOptions, repair: flag('Restore missing data from a copy.'),
|
|
147
103
|
from: option('PATH|git:REF', 'The copy: another store or a storage branch.'),
|
|
148
104
|
},
|
|
149
105
|
async run(input) {
|
|
@@ -158,21 +114,17 @@ const commands = {
|
|
|
158
114
|
: from.startsWith('git:') ? await gitReportObjects(root, from.slice(4)) : new LocalObjectStore(resolve(directory, from)).source();
|
|
159
115
|
const result = await checkStore(path, input.flag('repair') ? { from: source } : undefined);
|
|
160
116
|
print({ ...result, store: path });
|
|
161
|
-
return result.problems.length ?
|
|
117
|
+
return result.problems.length ? 3 : 0;
|
|
162
118
|
},
|
|
163
119
|
},
|
|
164
|
-
worker: { description: 'Run the remote analysis worker.',
|
|
165
|
-
options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
|
|
166
|
-
async run(input) {
|
|
167
|
-
const host = input.text('listen') ?? '127.0.0.1';
|
|
168
|
-
if (host !== '127.0.0.1' && host !== '0.0.0.0')
|
|
169
|
-
throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
|
|
170
|
-
announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot, languageRegistry([]).isSource));
|
|
171
|
-
} },
|
|
172
120
|
};
|
|
173
|
-
async function
|
|
174
|
-
const directory =
|
|
121
|
+
async function repositoryContext(input) {
|
|
122
|
+
const directory = invocationDirectory(input);
|
|
175
123
|
const root = await findRepository(directory) ?? directory;
|
|
124
|
+
return { directory, root };
|
|
125
|
+
}
|
|
126
|
+
async function context(input) {
|
|
127
|
+
const { directory, root } = await repositoryContext(input);
|
|
176
128
|
return { directory, root, store: selectStore(root, input.text('store'), directory) };
|
|
177
129
|
}
|
|
178
130
|
function runAnalysis(input) {
|
|
@@ -190,28 +142,21 @@ async function analyze(input) {
|
|
|
190
142
|
throw new Error('Choose a revision or --working-tree');
|
|
191
143
|
if (input.flag('working-tree') && input.flag('skip-saved'))
|
|
192
144
|
throw new Error('--skip-saved applies to commits, not --working-tree');
|
|
193
|
-
const github = useGitHub(input);
|
|
194
145
|
const config = await readConfig(root, input);
|
|
195
|
-
const
|
|
196
|
-
const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
|
|
146
|
+
const revision = input.args[0] ?? 'HEAD';
|
|
197
147
|
const imports = input.many('import');
|
|
198
|
-
const {
|
|
148
|
+
const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
199
149
|
const importRoot = input.text('import-root');
|
|
200
150
|
if (importRoot && findings.length === 0)
|
|
201
151
|
throw new Error('--import-root requires a scanner report');
|
|
202
|
-
const executor = analysisExecutor(input.text('worker'), config.plugins);
|
|
203
152
|
const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
|
|
204
153
|
const skipped = savedId !== undefined && await isSaved(output, savedId);
|
|
205
154
|
const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
|
|
206
155
|
: await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
|
|
207
|
-
|
|
208
|
-
findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }
|
|
209
|
-
if (github)
|
|
210
|
-
await writeGitHubResult(report);
|
|
211
|
-
const requested = input.many('report');
|
|
212
|
-
const reports = await outputReports(root, store, requested.length ? requested : config.reports, input, config);
|
|
156
|
+
...coverage, exclude: listOption(input, 'exclude', config.exclude), ignore: config.ignore, plugins: config.plugins,
|
|
157
|
+
findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined });
|
|
213
158
|
print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
|
|
214
|
-
store: output
|
|
159
|
+
store: output });
|
|
215
160
|
return report.status === 'partial' ? 2 : 0;
|
|
216
161
|
}
|
|
217
162
|
async function analyzeRange(input, range) {
|
|
@@ -223,8 +168,6 @@ async function analyzeRange(input, range) {
|
|
|
223
168
|
throw new Error('--import describes one checkout and cannot be used with a range');
|
|
224
169
|
if (input.text('import-root'))
|
|
225
170
|
throw new Error('--import-root requires a scanner report');
|
|
226
|
-
if (useGitHub(input))
|
|
227
|
-
throw new Error('--ci github needs a single revision');
|
|
228
171
|
const concurrency = count(input.text('concurrency'), '--concurrency', 1);
|
|
229
172
|
const configValue = await readConfigValue(root, input);
|
|
230
173
|
const config = parseConfig(configValue);
|
|
@@ -233,14 +176,12 @@ async function analyzeRange(input, range) {
|
|
|
233
176
|
const { base, head, commits } = await firstParentRange(root, range.base, range.head);
|
|
234
177
|
if (!commits.length)
|
|
235
178
|
process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
|
|
236
|
-
const inspection = { directory, output, exclude: input
|
|
179
|
+
const inspection = { directory, output, exclude: listOption(input, 'exclude', config.exclude) };
|
|
237
180
|
const { interrupted, ...results } = await analyzeCommits(commits, {
|
|
238
181
|
inspection, config, configValue, concurrency, skipSaved: input.flag('skip-saved'),
|
|
239
182
|
});
|
|
240
|
-
const requested = input.many('report');
|
|
241
|
-
const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
|
|
242
183
|
print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
|
|
243
|
-
...results, store: output
|
|
184
|
+
...results, store: output });
|
|
244
185
|
return interrupted ? 130 : results.failed.length || results.partial.length ? 2 : 0;
|
|
245
186
|
}
|
|
246
187
|
async function show(input) {
|
|
@@ -259,48 +200,23 @@ async function show(input) {
|
|
|
259
200
|
}
|
|
260
201
|
print(input.flag('files') ? fileMetrics(report, defaultLanguages) : report);
|
|
261
202
|
}
|
|
262
|
-
async function compare(input) {
|
|
263
|
-
const { directory, root, store } = await context(input);
|
|
264
|
-
const baselinePath = input.text('baseline-store');
|
|
265
|
-
const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
|
|
266
|
-
const [base, head] = await Promise.all([commitId(root, input.args[0]), commitId(root, input.args[1] ?? 'HEAD')]);
|
|
267
|
-
const current = store.reader.read({ kind: 'commit', id: head });
|
|
268
|
-
const before = base === head && baseline === store ? current : baseline.reader.read({ kind: 'commit', id: base });
|
|
269
|
-
print(compareInspections(await before, await current));
|
|
270
|
-
}
|
|
271
|
-
async function diffCoverage(input) {
|
|
272
|
-
const { directory, root } = await context(input);
|
|
273
|
-
const config = await readConfig(root, input);
|
|
274
|
-
const imports = input.many('import');
|
|
275
|
-
const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
276
|
-
if ((!lcov && !goCover) || (imports.length && findings.length))
|
|
277
|
-
throw new Error('diff-coverage requires --import lcov=PATH or go-cover=PATH');
|
|
278
|
-
const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, goCover, plugins: config.plugins,
|
|
279
|
-
exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
|
|
280
|
-
if (useGitHub(input))
|
|
281
|
-
await writeGitHubDiffCoverage(report);
|
|
282
|
-
print(report);
|
|
283
|
-
return report.status === 'partial' ? 2 : report.decision?.status === 'failed' ? 3 : 0;
|
|
284
|
-
}
|
|
285
203
|
async function review(input) {
|
|
286
|
-
const { directory, root } = await
|
|
204
|
+
const { directory, root } = await repositoryContext(input);
|
|
287
205
|
const github = useGitHub(input);
|
|
288
206
|
const config = await readConfig(root, input);
|
|
289
207
|
const imports = input.many('import');
|
|
290
|
-
const {
|
|
208
|
+
const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
291
209
|
if (findings.length && imports.length)
|
|
292
210
|
throw new Error('review compares both sides of a change; scanner imports apply to full inspections only');
|
|
293
211
|
if (findings.length)
|
|
294
212
|
process.stderr.write('Scanner imports from the config are skipped: review compares both sides of a change.\n');
|
|
295
213
|
const settingsPath = configFile(root, input);
|
|
296
214
|
const { plugins, ...settings } = config;
|
|
297
|
-
const report = await reviewChange({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD',
|
|
298
|
-
exclude:
|
|
215
|
+
const report = await reviewChange({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', ...coverage,
|
|
216
|
+
exclude: listOption(input, 'exclude', config.exclude), ignore: config.ignore, plugins, settings,
|
|
299
217
|
settingsPath: settingsPath === undefined ? undefined : relative(root, settingsPath).split(sep).join('/'),
|
|
300
218
|
number: count(input.text('pull'), '--pull', 1) ?? (github ? await gitHubPullRequest() : undefined),
|
|
301
|
-
minimumPercent:
|
|
302
|
-
minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
|
|
303
|
-
maxNewIssues: count(input.text('max-new-issues') ?? config.maxNewIssues, '--max-new-issues') });
|
|
219
|
+
minimumPercent: config.minCoverage, minimumLines: config.minLines, maxNewIssues: config.maxNewIssues });
|
|
304
220
|
const markdown = pullReviewMarkdown(report);
|
|
305
221
|
if (github)
|
|
306
222
|
await writeGitHubReview(report, markdown, await gitRoot(root));
|
|
@@ -322,14 +238,6 @@ function useGitHub(input) {
|
|
|
322
238
|
throw new Error('--ci must be github or none');
|
|
323
239
|
return provider === 'github';
|
|
324
240
|
}
|
|
325
|
-
function percent(value, name) {
|
|
326
|
-
if (value === undefined)
|
|
327
|
-
return undefined;
|
|
328
|
-
const number = Number(value);
|
|
329
|
-
if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || number < 0 || number > 100)
|
|
330
|
-
throw new Error(`${name} must be a percentage from 0 to 100`);
|
|
331
|
-
return number;
|
|
332
|
-
}
|
|
333
241
|
function count(value, name, minimum = 0) {
|
|
334
242
|
if (value === undefined)
|
|
335
243
|
return undefined;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type { Plugin } from '../core/engine/plugin.js';
|
|
2
1
|
import type { Report } from '../core/model/report.js';
|
|
3
2
|
import type { parseConfig } from './config.js';
|
|
4
3
|
export interface RangeInspection {
|
|
5
4
|
readonly directory: string;
|
|
6
5
|
readonly output: string;
|
|
7
6
|
readonly exclude: readonly string[];
|
|
8
|
-
readonly worker?: string;
|
|
9
7
|
}
|
|
10
8
|
export type CommitOutcome = {
|
|
11
9
|
readonly commit: string;
|
|
@@ -23,6 +21,5 @@ export type RangeMessage = {
|
|
|
23
21
|
} | {
|
|
24
22
|
readonly kind: 'stop';
|
|
25
23
|
};
|
|
26
|
-
export declare function analysisExecutor(worker: string | undefined, plugins: readonly Plugin[]): import("../compose/inspect.js").AnalysisExecutor | undefined;
|
|
27
24
|
export declare function rangeInspector(inspection: RangeInspection, config: ReturnType<typeof parseConfig>): (revision: string) => Promise<Report>;
|
|
28
25
|
export declare function inspectCommits(commits: readonly string[], inspectCommit: (id: string) => Promise<Report>, stopped: () => boolean, report: (outcome: CommitOutcome) => void | Promise<void>): Promise<void>;
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
import { remoteExecutor } from '../api/worker/remote-executor.js';
|
|
2
|
-
import { workerToken } from '../api/worker/worker-protocol.js';
|
|
3
1
|
import { HistoryCache } from '../compose/history-cache.js';
|
|
4
|
-
import {
|
|
5
|
-
import { languageRegistry } from '../compose/languages.js';
|
|
6
|
-
export function analysisExecutor(worker, plugins) {
|
|
7
|
-
if (worker === undefined)
|
|
8
|
-
return undefined;
|
|
9
|
-
if (plugins.length)
|
|
10
|
-
throw new Error('Configured process plugins require local analysis. Use --no-config with --worker.');
|
|
11
|
-
return remoteExecutor(worker, workerToken(), languageRegistry([]).isSource);
|
|
12
|
-
}
|
|
2
|
+
import { inspectWithOptions } from '../compose/inspect.js';
|
|
13
3
|
export function rangeInspector(inspection, config) {
|
|
14
4
|
const { plugins, ...profile } = config;
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return (revision) => inspect({ directory, output, source: { revision }, exclude,
|
|
20
|
-
ignore: config.ignore, plugins }, executor, { history, deferSummary: true });
|
|
5
|
+
const history = new HistoryCache(profile);
|
|
6
|
+
const { directory, output, exclude } = inspection;
|
|
7
|
+
return (revision) => inspectWithOptions({ directory, output, source: { revision }, exclude,
|
|
8
|
+
ignore: config.ignore, plugins }, { history, deferSummary: true });
|
|
21
9
|
}
|
|
22
10
|
export async function inspectCommits(commits, inspectCommit, stopped, report) {
|
|
23
11
|
for (const commit of commits) {
|
|
@@ -38,9 +38,7 @@ export async function analyzeCommits(commits, options) {
|
|
|
38
38
|
};
|
|
39
39
|
try {
|
|
40
40
|
const pending = await pendingCommits(commits, inspection.output, skipSaved, signal, record);
|
|
41
|
-
|
|
42
|
-
const workers = inspection.worker === undefined ? concurrency ?? availableParallelism() : 1;
|
|
43
|
-
const chunks = historyChunks(pending, workers, process.availableMemory());
|
|
41
|
+
const chunks = historyChunks(pending, concurrency ?? availableParallelism(), process.availableMemory());
|
|
44
42
|
if (!signal.aborted && chunks.length === 1) {
|
|
45
43
|
await inspectCommits(chunks[0], inspectCommit, () => signal.aborted, record);
|
|
46
44
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { readConfig } from './config.js';
|
|
2
2
|
import type { Invocation } from './arguments.js';
|
|
3
3
|
import type { Store } from './store.js';
|
|
4
|
-
declare const reporters: {
|
|
5
|
-
readonly html: '.repometry/report/html';
|
|
6
|
-
readonly json: '.repometry/report/summary.json';
|
|
7
|
-
};
|
|
8
4
|
export declare const reporterIds: string[];
|
|
9
|
-
export declare function outputReports(root: string, store: Store,
|
|
10
|
-
format:
|
|
5
|
+
export declare function outputReports(root: string, store: Store, input: Invocation, config: Awaited<ReturnType<typeof readConfig>>): Promise<{
|
|
6
|
+
format: "html" | "json";
|
|
11
7
|
path: string;
|
|
12
8
|
}[]>;
|
|
13
9
|
export declare function viewTarget(input: Invocation, port: number): Promise<{
|
|
@@ -15,4 +11,3 @@ export declare function viewTarget(input: Invocation, port: number): Promise<{
|
|
|
15
11
|
close: () => void;
|
|
16
12
|
label: string;
|
|
17
13
|
}>;
|
|
18
|
-
export {};
|
|
@@ -9,42 +9,37 @@ import { commitSummary, withCommitMetadata } from '../report/json/projections/co
|
|
|
9
9
|
import { exportSite, siteSummary } from '../report/html/site/export-site.js';
|
|
10
10
|
import { readExportedSummary, serveExportedSite } from '../report/html/site/exported-server.js';
|
|
11
11
|
import { serveSite } from '../report/html/site/local-server.js';
|
|
12
|
-
import { readComponents } from '../report/json/store/components.js';
|
|
13
12
|
import { listPullReviews } from '../report/json/store/pull-review-store.js';
|
|
14
13
|
import { readConfig } from './config.js';
|
|
15
14
|
import { findRepository, invocationDirectory, isDirectory, selectStore } from './store.js';
|
|
16
15
|
const reporters = { html: '.repometry/report/html', json: '.repometry/report/summary.json' };
|
|
17
16
|
export const reporterIds = Object.keys(reporters);
|
|
18
|
-
export async function outputReports(root, store,
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
export async function outputReports(root, store, input, config) {
|
|
18
|
+
const typed = input.args.length > 0;
|
|
19
|
+
const base = typed ? invocationDirectory(input) : root;
|
|
20
|
+
const configured = config.reports.length ? config.reports : ['html'];
|
|
21
|
+
const requested = typed ? input.args : configured;
|
|
22
22
|
const requests = requested.map(spec => {
|
|
23
23
|
const equal = spec.indexOf('=');
|
|
24
24
|
const format = equal < 0 ? spec : spec.slice(0, equal);
|
|
25
25
|
const path = equal < 0 ? undefined : spec.slice(equal + 1);
|
|
26
26
|
if (!Object.hasOwn(reporters, format))
|
|
27
27
|
throw new Error(`Unknown reporter: ${format}. Choose ${reporterIds.join(', ')}.`);
|
|
28
|
-
if (path === ''
|
|
29
|
-
throw new Error('
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if (path === '')
|
|
29
|
+
throw new Error('Expected an output path after FORMAT=');
|
|
30
|
+
const name = format;
|
|
31
|
+
return { format: name, path: path === undefined ? resolve(root, reporters[name]) : resolve(base, path) };
|
|
32
32
|
});
|
|
33
33
|
if (new Set(requests.map(request => request.path)).size !== requests.length)
|
|
34
34
|
throw new Error('Each report requires a separate output');
|
|
35
|
-
if (requests.length === 0)
|
|
36
|
-
return requests;
|
|
37
35
|
const repository = await findRepository(root);
|
|
38
36
|
const readCommitMetadata = repository === undefined ? undefined : commitMetadataReader(repository);
|
|
39
37
|
const sourceOption = input.text('sources') ?? config.sources;
|
|
40
38
|
const sources = resolveSourceLocator(sourceOption, { remotes: await sourceRemotes(root), env: process.env });
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const options = { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, sources, components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
|
|
46
|
-
title: input.text('title') ?? (input.text('repo') ? basename(root) : undefined),
|
|
47
|
-
footer: !input.flag('no-footer') };
|
|
39
|
+
const pulls = store.path ? await listPullReviews(store.path) : [];
|
|
40
|
+
const options = { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, sources,
|
|
41
|
+
components: config.components, pulls, readCommitMetadata, branch: input.text('branch') ?? config.branch,
|
|
42
|
+
title: input.text('title') ?? basename(root) };
|
|
48
43
|
for (const request of requests) {
|
|
49
44
|
if (request.format === 'html')
|
|
50
45
|
await exportSite(store.reader, request.path, options);
|
|
@@ -68,10 +63,9 @@ async function writeSummary(path, data) {
|
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
export async function viewTarget(input, port) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const exported = await readExportedSummary(target);
|
|
66
|
+
const target = resolve(input.args[0] ?? '.');
|
|
67
|
+
const storeOption = input.text('store');
|
|
68
|
+
const exported = storeOption === undefined ? await readExportedSummary(target) : undefined;
|
|
75
69
|
const repository = await findRepository(target);
|
|
76
70
|
if (exported) {
|
|
77
71
|
const local = exported.sources?.provider === 'local' && repository ? readLocalSources(repository) : undefined;
|
|
@@ -80,26 +74,18 @@ export async function viewTarget(input, port) {
|
|
|
80
74
|
const data = resolve(target, 'data');
|
|
81
75
|
const dataStore = basename(target) === '.repometry' && await isDirectory(data);
|
|
82
76
|
const directStore = await isDirectory(resolve(target, 'commits'));
|
|
83
|
-
if (!repository && !dataStore && !directStore) {
|
|
77
|
+
if (!repository && !dataStore && !directStore && storeOption === undefined) {
|
|
84
78
|
throw new Error(`No report at ${target}: expected a repository, a .repometry folder or an exported report`);
|
|
85
79
|
}
|
|
86
80
|
const root = repository ?? target;
|
|
87
|
-
const store = selectStore(root,
|
|
81
|
+
const store = selectStore(root, storeOption ?? (dataStore ? data : directStore ? target : undefined), invocationDirectory(input));
|
|
88
82
|
if ((await store.reader.listSummaries?.() ?? []).length === 0)
|
|
89
|
-
throw new Error(`No saved inspections in ${store.path ??
|
|
90
|
-
const [
|
|
91
|
-
readComponents(componentsPath(root, input), input.text('components') === undefined),
|
|
92
|
-
store.path ? listPullReviews(store.path) : [],
|
|
93
|
-
readConfig(root, input),
|
|
94
|
-
]);
|
|
83
|
+
throw new Error(`No saved inspections in ${store.path ?? storeOption}. Run repometry analyze first.`);
|
|
84
|
+
const [pulls, config] = await Promise.all([store.path ? listPullReviews(store.path) : [], readConfig(root, input)]);
|
|
95
85
|
const local = repository ? readLocalSources(repository) : undefined;
|
|
96
|
-
const server = await serveSite(store.reader, port, { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, title: input.text('title') ?? basename(root), components, pulls,
|
|
86
|
+
const server = await serveSite(store.reader, port, { languages: config.plugins.length ? languageRegistry(config.plugins) : defaultLanguages, title: input.text('title') ?? basename(root), components: config.components, pulls,
|
|
97
87
|
branch: input.text('branch') ?? config.branch, readCommitMetadata: repository ? commitMetadataReader(repository) : undefined,
|
|
98
|
-
sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined
|
|
99
|
-
return { ...server, label: `${basename(root)} (live from ${store.path ??
|
|
100
|
-
}
|
|
101
|
-
function componentsPath(root, input) {
|
|
102
|
-
const explicit = input.text('components');
|
|
103
|
-
return explicit === undefined ? resolve(root, '.repometry/components.json') : resolve(invocationDirectory(input), explicit);
|
|
88
|
+
sources: local ? resolveSourceLocator('local', { remotes: [], env: {} }) : undefined }, local);
|
|
89
|
+
return { ...server, label: `${basename(root)} (live from ${store.path ?? storeOption})` };
|
|
104
90
|
}
|
|
105
91
|
//# sourceMappingURL=reporting.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Report } from '../core/model/report.js';
|
|
2
2
|
import type { AnalysisInput } from '../core/usecases/inspect.js';
|
|
3
3
|
import type { AnalysisResults } from './analysis-results.js';
|
|
4
|
-
import type { AnalysisSources } from './
|
|
4
|
+
import type { AnalysisSources } from './phases.js';
|
|
5
5
|
export declare const analysisProfile = "repository/v3";
|
|
6
6
|
export declare function assembleAnalysisReport(input: AnalysisInput, sources: AnalysisSources, results: AnalysisResults): Report;
|
|
@@ -5,7 +5,6 @@ import { reportSchema } from '../core/model/report.js';
|
|
|
5
5
|
import { comparePaths, digest, sourceDirectoriesExcluded, textLineCount } from '../core/model/snapshot.js';
|
|
6
6
|
import { defaultSourceExclusions, generatedSourcePolicy } from '../core/profile/exclusions.js';
|
|
7
7
|
import { duplicationSettings, structuralRules } from '../core/profile/maintainability.js';
|
|
8
|
-
import { defaultProvider } from './analysis-sources.js';
|
|
9
8
|
import { fileTypeId } from '../core/model/file-types.js';
|
|
10
9
|
export const analysisProfile = 'repository/v3';
|
|
11
10
|
const measurementDefinitions = {
|
|
@@ -40,14 +39,14 @@ export function assembleAnalysisReport(input, sources, results) {
|
|
|
40
39
|
inventory: reportInventory(snapshot, sources, results) } }),
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
|
-
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, { languages,
|
|
44
|
-
const securityScanners = results.securityScanners(
|
|
42
|
+
function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], coverage }, { languages, plugins }, results) {
|
|
43
|
+
const securityScanners = results.securityScanners(plugins);
|
|
45
44
|
return {
|
|
46
45
|
profile: analysisProfile, mode: snapshot.subject.kind,
|
|
47
46
|
source: { extensions: languages.extensions, ...(languages.globs.length ? { globs: languages.globs } : {}),
|
|
48
47
|
excludedDirectories: sourceDirectoriesExcluded, excludedOutput, excludedPaths,
|
|
49
48
|
defaultExclusions: defaultSourceExclusions, generatedSourcePolicy, generatedExcluded: snapshot.generatedExcluded ?? [] },
|
|
50
|
-
parser:
|
|
49
|
+
parser: languages.providers[0].plugin.settings,
|
|
51
50
|
maintainability: { structuralRules, duplication: duplicationSettings, debtModel, remediation: 'nonoverlapping-complexity/v1' },
|
|
52
51
|
coverage: coverage === undefined ? null : { inputDigest: digest(coverage.text), pathBase: coverage.sourceRoot,
|
|
53
52
|
merge: 'any-hit', hitCounts: 'sum',
|
|
@@ -60,7 +59,7 @@ function appliedConfiguration({ snapshot, excludedOutput, excludedPaths = [], co
|
|
|
60
59
|
function pluginProvenance({ id, version, api, tools, kinds, claims, settings, providesLanguages, unavailableReason }) {
|
|
61
60
|
return { id, version, api, tools: tools ?? {}, kinds,
|
|
62
61
|
...(claims === undefined ? {} : { claims }), ...(settings === undefined ? {} : { settings }),
|
|
63
|
-
...(providesLanguages === undefined ? {} : { providesLanguages }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
|
|
62
|
+
...(providesLanguages === undefined ? {} : { providesLanguages: providesLanguages.map(({ syntax, ...language }) => language) }), ...(unavailableReason === undefined ? {} : { unavailableReason }) };
|
|
64
63
|
}
|
|
65
64
|
function inspectionStatus(hasSources, results) {
|
|
66
65
|
if (results.diagnostics.length > 0)
|
|
@@ -18,7 +18,7 @@ export declare class AnalysisResults {
|
|
|
18
18
|
private readonly scanOnly;
|
|
19
19
|
private readonly securityOperations;
|
|
20
20
|
private readonly usedPlans;
|
|
21
|
-
constructor(plugins: readonly Plugin[],
|
|
21
|
+
constructor(plugins: readonly Plugin[], oversized: readonly string[]);
|
|
22
22
|
remember(task: PlannedOperation, syntaxProvider?: string): void;
|
|
23
23
|
operationRecords(): readonly ReturnType<typeof operationProvenance>[];
|
|
24
24
|
pluginData(): import("../core/model/plugin-data.js").PluginData | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ReportProducts } from '../core/engine/report-products.js';
|
|
2
|
-
import { inspectionKeys } from './analysis-sources.js';
|
|
3
2
|
export class AnalysisResults {
|
|
4
3
|
measurements = [];
|
|
5
4
|
findings = [];
|
|
@@ -14,11 +13,11 @@ export class AnalysisResults {
|
|
|
14
13
|
scanOnly;
|
|
15
14
|
securityOperations;
|
|
16
15
|
usedPlans = new Map();
|
|
17
|
-
constructor(plugins,
|
|
16
|
+
constructor(plugins, oversized) {
|
|
18
17
|
this.products = new ReportProducts(plugins);
|
|
19
18
|
this.diagnostics = oversized.map(oversizedClaim);
|
|
20
19
|
this.scanOnly = new Set(plugins.filter(plugin => plugin.claims?.scanOnly).flatMap(({ id, operations }) => operations.map(operation => `${id}/${operation.id}`)));
|
|
21
|
-
this.securityOperations = new Map(
|
|
20
|
+
this.securityOperations = new Map(plugins.filter(plugin => plugin.kinds.includes('security')).flatMap(plugin => plugin.operations.filter(({ role }) => role === 'inspection').map(({ id }) => [`${plugin.id}/${id}`, plugin.id])));
|
|
22
21
|
}
|
|
23
22
|
remember(task, syntaxProvider) {
|
|
24
23
|
this.usedPlans.set(JSON.stringify([task.key, [...task.inputs], syntaxProvider]), operationProvenance(task, syntaxProvider));
|
|
@@ -51,9 +50,8 @@ export class AnalysisResults {
|
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
recordInspection(task, messages, path, paths) {
|
|
54
|
-
for (const message of messages)
|
|
55
|
-
this.diagnostics.push({ operation: task.key, state: 'partial', message
|
|
56
|
-
...(path === undefined ? {} : { path }) });
|
|
53
|
+
for (const { message, path: own = path } of messages)
|
|
54
|
+
this.diagnostics.push({ operation: task.key, state: 'partial', ...(own === undefined ? {} : { path: own }), message });
|
|
57
55
|
const scanner = this.securityOperations.get(task.key);
|
|
58
56
|
if (scanner)
|
|
59
57
|
this.scanned.add(scanner);
|