repometry 0.10.0 → 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 +5 -3
- 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 +125 -2
- 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 +3 -0
- package/target/main/ts/api/cache/root.js +21 -0
- 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/blob-batch.js +2 -1
- package/target/main/ts/api/git/blob-history.d.ts +20 -0
- package/target/main/ts/api/git/blob-history.js +54 -0
- 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/git/git-executable.d.ts +1 -0
- package/target/main/ts/api/git/git-executable.js +31 -0
- package/target/main/ts/api/git/git.d.ts +8 -1
- package/target/main/ts/api/git/git.js +58 -61
- package/target/main/ts/api/git/inspection-source.d.ts +2 -1
- package/target/main/ts/api/git/inspection-source.js +3 -2
- package/target/main/ts/api/git/local-sources.js +3 -2
- package/target/main/ts/api/git/source-cache.d.ts +0 -2
- package/target/main/ts/api/git/source-cache.js +1 -16
- 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/api/process/go-parser-cache.d.ts +1 -0
- package/target/main/ts/api/process/go-parser-cache.js +71 -0
- package/target/main/ts/api/process/go-parser-files.d.ts +5 -0
- package/target/main/ts/api/process/go-parser-files.js +65 -0
- package/target/main/ts/api/process/host-language-runner.d.ts +3 -5
- package/target/main/ts/api/process/host-language-runner.js +21 -66
- package/target/main/ts/api/process/host-tool.d.ts +22 -0
- package/target/main/ts/api/process/host-tool.js +87 -0
- package/target/main/ts/cli/arguments.js +2 -4
- package/target/main/ts/cli/config.d.ts +20 -3
- package/target/main/ts/cli/config.js +43 -10
- 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 +66 -215
- package/target/main/ts/cli/range-inspection.d.ts +25 -0
- package/target/main/ts/cli/range-inspection.js +29 -0
- package/target/main/ts/cli/range-jobs.d.ts +22 -0
- package/target/main/ts/cli/range-jobs.js +150 -0
- package/target/main/ts/cli/range-worker.d.ts +1 -0
- package/target/main/ts/cli/range-worker.js +36 -0
- 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 +8 -8
- 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 +16 -13
- package/target/main/ts/compose/history-cache.d.ts +3 -1
- package/target/main/ts/compose/history-cache.js +2 -0
- package/target/main/ts/compose/inspect.d.ts +6 -9
- package/target/main/ts/compose/inspect.js +11 -12
- 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 +11 -17
- 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/commit-summary.js +5 -7
- 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/projections/metric-values.d.ts +5 -0
- package/target/main/ts/report/json/projections/metric-values.js +9 -6
- 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
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { serveWorker } from '../api/worker/worker.js';
|
|
11
|
-
import { workerToken } from '../api/worker/worker-protocol.js';
|
|
12
|
-
import { HistoryCache } from '../compose/history-cache.js';
|
|
13
|
-
import { defaultLanguages, languageRegistry } from '../compose/languages.js';
|
|
14
|
-
import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
|
|
15
|
-
import { measureDiffCoverage } from '../compose/diff-coverage.js';
|
|
16
|
-
import { prepareMetabranch } from '../compose/prepare-metabranch.js';
|
|
6
|
+
import { cacheRoot, clearCaches } from '../api/cache/root.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';
|
|
17
10
|
import { review as reviewChange, reviewExitCode, reviewReason } from '../compose/review.js';
|
|
18
11
|
import { effectivePlugins } from '../compose/plugin-list.js';
|
|
19
12
|
import { validSubjectId } from '../core/model/report.js';
|
|
20
|
-
import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
21
|
-
import { compareInspections } from '../core/usecases/compare.js';
|
|
22
13
|
import { exportProjects } from '../report/html/site/projects.js';
|
|
23
14
|
import { fileMetrics } from '../report/json/projections/file-metrics.js';
|
|
24
|
-
import { LocalReportStore } from '../report/json/store/local-store.js';
|
|
25
15
|
import { pullReviewMarkdown } from '../report/markdown/pull-review.js';
|
|
26
16
|
import { LocalObjectStore } from '../report/json/store/object-store.js';
|
|
27
17
|
import { checkStore } from '../report/json/store/store-check.js';
|
|
28
18
|
import { dispatch, flag, option } from './arguments.js';
|
|
29
|
-
import { configFile, readConfig } from './config.js';
|
|
19
|
+
import { configFile, listOption, parseConfig, readConfig, readConfigValue } from './config.js';
|
|
20
|
+
import { analyzeCommits, isSaved } from './range-jobs.js';
|
|
30
21
|
import { importerIds, readInputs } from './imports.js';
|
|
31
22
|
import { outputReports, reporterIds, viewTarget } from './reporting.js';
|
|
32
23
|
import { parseRange } from './revisions.js';
|
|
33
|
-
import { findRepository, selectStore, writableStore } from './store.js';
|
|
24
|
+
import { findRepository, invocationDirectory, selectStore, writableStore } from './store.js';
|
|
34
25
|
const configOptions = { config: option('FILE', 'Read a different JSON configuration.'), 'no-config': flag('Skip configuration.') };
|
|
35
26
|
const importOption = option('FORMAT=PATH', 'Import a report produced by another tool. Repeatable.', { multiple: true });
|
|
36
27
|
const excludeOption = option('PATTERN', 'Exclude a path or glob. Repeatable.', { multiple: true });
|
|
37
28
|
const ciOption = option('PROVIDER', 'Send CI output to github or none.');
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
sources: option('auto|none|ID[:SPEC]', 'Select where the report reads source files.'),
|
|
44
|
-
title: option('NAME', 'Set the report title.'), components: option('FILE', 'Read component definitions.'),
|
|
45
|
-
'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.'),
|
|
46
34
|
};
|
|
47
35
|
const commands = {
|
|
48
36
|
analyze: {
|
|
49
37
|
description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
|
|
50
|
-
options: { ...configOptions, ...
|
|
38
|
+
options: { ...configOptions, ...storageOptions, 'working-tree': flag('Analyze the working directory.'),
|
|
51
39
|
'skip-saved': flag('Keep commits that already have a saved inspection.'),
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
run:
|
|
40
|
+
concurrency: option('N', 'Maximum local analysis workers for a range. Defaults to the available cores.'),
|
|
41
|
+
import: importOption,
|
|
42
|
+
exclude: excludeOption, 'import-root': option('DIR', 'Resolve scanner locations relative to this directory.') },
|
|
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') }) });
|
|
76
|
+
const destination = resolve(input.args[0] ?? '.');
|
|
77
|
+
print({ schema: 'urn:repometry:schema:projects-result:1', destination, projects: await exportProjects(destination) });
|
|
104
78
|
},
|
|
105
79
|
},
|
|
106
|
-
|
|
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.') },
|
|
80
|
+
plugins: { description: 'List effective plugins and supported formats.', options: { ...configOptions, repo: repoOption },
|
|
109
81
|
async run(input) {
|
|
110
|
-
const {
|
|
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 });
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
plugins: { description: 'List effective plugins and supported formats.', options: configOptions,
|
|
122
|
-
async run(input) {
|
|
123
|
-
const { root } = await context(input);
|
|
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,23 +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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (action === 'clear')
|
|
140
|
-
await clearSourceCache(path);
|
|
141
|
-
print({ schema: 'urn:repometry:schema:cache-result:1', path, ...(action === 'clear' ? { cleared: ['sources'] } : {}) });
|
|
94
|
+
const path = cacheRoot();
|
|
95
|
+
const cleared = action === 'clear' ? await clearCaches(path) : undefined;
|
|
96
|
+
print({ schema: 'urn:repometry:schema:cache-result:1', path, cleared });
|
|
142
97
|
},
|
|
143
98
|
},
|
|
144
99
|
store: {
|
|
145
100
|
description: 'Check saved inspections and repair what can be restored.', parameters: 'check', min: 1, max: 1,
|
|
146
101
|
options: {
|
|
147
|
-
repair: flag('Restore missing data from a copy.'),
|
|
102
|
+
...storageOptions, repair: flag('Restore missing data from a copy.'),
|
|
148
103
|
from: option('PATH|git:REF', 'The copy: another store or a storage branch.'),
|
|
149
104
|
},
|
|
150
105
|
async run(input) {
|
|
@@ -159,55 +114,49 @@ const commands = {
|
|
|
159
114
|
: from.startsWith('git:') ? await gitReportObjects(root, from.slice(4)) : new LocalObjectStore(resolve(directory, from)).source();
|
|
160
115
|
const result = await checkStore(path, input.flag('repair') ? { from: source } : undefined);
|
|
161
116
|
print({ ...result, store: path });
|
|
162
|
-
return result.problems.length ?
|
|
117
|
+
return result.problems.length ? 3 : 0;
|
|
163
118
|
},
|
|
164
119
|
},
|
|
165
|
-
worker: { description: 'Run the remote analysis worker.',
|
|
166
|
-
options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
|
|
167
|
-
async run(input) {
|
|
168
|
-
const host = input.text('listen') ?? '127.0.0.1';
|
|
169
|
-
if (host !== '127.0.0.1' && host !== '0.0.0.0')
|
|
170
|
-
throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
|
|
171
|
-
announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot, languageRegistry([]).isSource));
|
|
172
|
-
} },
|
|
173
120
|
};
|
|
174
|
-
async function
|
|
175
|
-
const directory =
|
|
121
|
+
async function repositoryContext(input) {
|
|
122
|
+
const directory = invocationDirectory(input);
|
|
176
123
|
const root = await findRepository(directory) ?? directory;
|
|
124
|
+
return { directory, root };
|
|
125
|
+
}
|
|
126
|
+
async function context(input) {
|
|
127
|
+
const { directory, root } = await repositoryContext(input);
|
|
177
128
|
return { directory, root, store: selectStore(root, input.text('store'), directory) };
|
|
178
129
|
}
|
|
179
|
-
|
|
130
|
+
function runAnalysis(input) {
|
|
180
131
|
const range = input.args[0] === undefined ? undefined : parseRange(input.args[0]);
|
|
181
132
|
if (range)
|
|
182
133
|
return analyzeRange(input, range);
|
|
134
|
+
if (input.text('concurrency') !== undefined)
|
|
135
|
+
throw new Error('--concurrency requires a revision range');
|
|
136
|
+
return analyze(input);
|
|
137
|
+
}
|
|
138
|
+
async function analyze(input) {
|
|
183
139
|
const { directory, root, store } = await context(input);
|
|
184
140
|
const output = writableStore(store);
|
|
185
141
|
if (input.flag('working-tree') && input.args.length)
|
|
186
142
|
throw new Error('Choose a revision or --working-tree');
|
|
187
143
|
if (input.flag('working-tree') && input.flag('skip-saved'))
|
|
188
144
|
throw new Error('--skip-saved applies to commits, not --working-tree');
|
|
189
|
-
const github = useGitHub(input);
|
|
190
145
|
const config = await readConfig(root, input);
|
|
191
|
-
const
|
|
192
|
-
const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
|
|
146
|
+
const revision = input.args[0] ?? 'HEAD';
|
|
193
147
|
const imports = input.many('import');
|
|
194
|
-
const {
|
|
148
|
+
const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
195
149
|
const importRoot = input.text('import-root');
|
|
196
150
|
if (importRoot && findings.length === 0)
|
|
197
151
|
throw new Error('--import-root requires a scanner report');
|
|
198
|
-
const executor = analysisExecutor(input, config.plugins);
|
|
199
152
|
const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
|
|
200
153
|
const skipped = savedId !== undefined && await isSaved(output, savedId);
|
|
201
154
|
const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
|
|
202
155
|
: await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
|
|
203
|
-
|
|
204
|
-
findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }
|
|
205
|
-
if (github)
|
|
206
|
-
await writeGitHubResult(report);
|
|
207
|
-
const requested = input.many('report');
|
|
208
|
-
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 });
|
|
209
158
|
print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
|
|
210
|
-
store: output
|
|
159
|
+
store: output });
|
|
211
160
|
return report.status === 'partial' ? 2 : 0;
|
|
212
161
|
}
|
|
213
162
|
async function analyzeRange(input, range) {
|
|
@@ -219,87 +168,22 @@ async function analyzeRange(input, range) {
|
|
|
219
168
|
throw new Error('--import describes one checkout and cannot be used with a range');
|
|
220
169
|
if (input.text('import-root'))
|
|
221
170
|
throw new Error('--import-root requires a scanner report');
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const config =
|
|
171
|
+
const concurrency = count(input.text('concurrency'), '--concurrency', 1);
|
|
172
|
+
const configValue = await readConfigValue(root, input);
|
|
173
|
+
const config = parseConfig(configValue);
|
|
225
174
|
if (config.imports.length)
|
|
226
175
|
process.stderr.write('Imports from the config describe one checkout and are skipped for a range.\n');
|
|
227
176
|
const { base, head, commits } = await firstParentRange(root, range.base, range.head);
|
|
228
177
|
if (!commits.length)
|
|
229
178
|
process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const inspectCommit = (id) => inspect({ directory, output, source: { revision: id }, exclude,
|
|
235
|
-
ignore: config.ignore, plugins }, executor, { history, deferSummary: true });
|
|
236
|
-
const skip = input.flag('skip-saved') ? (id) => isSaved(output, id) : undefined;
|
|
237
|
-
const { interrupted, ...results } = await analyzeCommits(commits, inspectCommit, skip);
|
|
238
|
-
if (results.analyzed.length || results.skipped.length) {
|
|
239
|
-
await new LocalReportStore(await realpath(output)).refreshSummary();
|
|
240
|
-
}
|
|
241
|
-
const requested = input.many('report');
|
|
242
|
-
const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
|
|
179
|
+
const inspection = { directory, output, exclude: listOption(input, 'exclude', config.exclude) };
|
|
180
|
+
const { interrupted, ...results } = await analyzeCommits(commits, {
|
|
181
|
+
inspection, config, configValue, concurrency, skipSaved: input.flag('skip-saved'),
|
|
182
|
+
});
|
|
243
183
|
print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
|
|
244
|
-
...results, store: output
|
|
184
|
+
...results, store: output });
|
|
245
185
|
return interrupted ? 130 : results.failed.length || results.partial.length ? 2 : 0;
|
|
246
186
|
}
|
|
247
|
-
async function analyzeCommits(commits, inspectCommit, skip) {
|
|
248
|
-
const analyzed = [], partial = [], skipped = [];
|
|
249
|
-
const failed = [];
|
|
250
|
-
let interrupted = false;
|
|
251
|
-
const stop = () => { interrupted = true; process.stderr.write('Stopping after the current commit.\n'); };
|
|
252
|
-
process.once('SIGINT', stop);
|
|
253
|
-
const width = String(commits.length).length;
|
|
254
|
-
const progress = (index, id, state) => process.stderr.write(`[${String(index + 1).padStart(width)}/${commits.length}] ${id.slice(0, 7)} ${state}\n`);
|
|
255
|
-
try {
|
|
256
|
-
for (const [index, id] of commits.entries()) {
|
|
257
|
-
if (interrupted)
|
|
258
|
-
break;
|
|
259
|
-
if (skip !== undefined && await skip(id)) {
|
|
260
|
-
skipped.push(id);
|
|
261
|
-
progress(index, id, 'skipped');
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
try {
|
|
265
|
-
const report = await inspectCommit(id);
|
|
266
|
-
analyzed.push(id);
|
|
267
|
-
if (report.status === 'partial')
|
|
268
|
-
partial.push(id);
|
|
269
|
-
progress(index, id, report.status === 'partial' ? 'partial' : 'analyzed');
|
|
270
|
-
}
|
|
271
|
-
catch (error) {
|
|
272
|
-
if (interrupted)
|
|
273
|
-
break;
|
|
274
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
275
|
-
failed.push({ commit: id, error: message });
|
|
276
|
-
progress(index, id, `failed: ${message}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
finally {
|
|
281
|
-
process.removeListener('SIGINT', stop);
|
|
282
|
-
}
|
|
283
|
-
return { analyzed, partial, skipped, failed, interrupted };
|
|
284
|
-
}
|
|
285
|
-
function analysisExecutor(input, plugins) {
|
|
286
|
-
const worker = input.text('worker');
|
|
287
|
-
if (worker === undefined)
|
|
288
|
-
return undefined;
|
|
289
|
-
if (plugins.length)
|
|
290
|
-
throw new Error('Configured process plugins require local analysis. Use --no-config with --worker.');
|
|
291
|
-
return remoteExecutor(worker, workerToken(), languageRegistry([]).isSource);
|
|
292
|
-
}
|
|
293
|
-
async function isSaved(store, id) {
|
|
294
|
-
try {
|
|
295
|
-
return (await lstat(join(store, 'commits', id, 'report.json'))).isFile();
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
|
|
299
|
-
return false;
|
|
300
|
-
throw error;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
187
|
async function show(input) {
|
|
304
188
|
const { root, store } = await context(input);
|
|
305
189
|
const ref = input.args[0];
|
|
@@ -316,48 +200,23 @@ async function show(input) {
|
|
|
316
200
|
}
|
|
317
201
|
print(input.flag('files') ? fileMetrics(report, defaultLanguages) : report);
|
|
318
202
|
}
|
|
319
|
-
async function compare(input) {
|
|
320
|
-
const { directory, root, store } = await context(input);
|
|
321
|
-
const baselinePath = input.text('baseline-store');
|
|
322
|
-
const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
|
|
323
|
-
const [base, head] = await Promise.all([commitId(root, input.args[0]), commitId(root, input.args[1] ?? 'HEAD')]);
|
|
324
|
-
const current = store.reader.read({ kind: 'commit', id: head });
|
|
325
|
-
const before = base === head && baseline === store ? current : baseline.reader.read({ kind: 'commit', id: base });
|
|
326
|
-
print(compareInspections(await before, await current));
|
|
327
|
-
}
|
|
328
|
-
async function diffCoverage(input) {
|
|
329
|
-
const { directory, root } = await context(input);
|
|
330
|
-
const config = await readConfig(root, input);
|
|
331
|
-
const imports = input.many('import');
|
|
332
|
-
const { lcov, goCover, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
333
|
-
if ((!lcov && !goCover) || (imports.length && findings.length))
|
|
334
|
-
throw new Error('diff-coverage requires --import lcov=PATH or go-cover=PATH');
|
|
335
|
-
const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, goCover, plugins: config.plugins,
|
|
336
|
-
exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
|
|
337
|
-
if (useGitHub(input))
|
|
338
|
-
await writeGitHubDiffCoverage(report);
|
|
339
|
-
print(report);
|
|
340
|
-
return report.status === 'partial' ? 2 : report.decision?.status === 'failed' ? 3 : 0;
|
|
341
|
-
}
|
|
342
203
|
async function review(input) {
|
|
343
|
-
const { directory, root } = await
|
|
204
|
+
const { directory, root } = await repositoryContext(input);
|
|
344
205
|
const github = useGitHub(input);
|
|
345
206
|
const config = await readConfig(root, input);
|
|
346
207
|
const imports = input.many('import');
|
|
347
|
-
const {
|
|
208
|
+
const { findings, ...coverage } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
348
209
|
if (findings.length && imports.length)
|
|
349
210
|
throw new Error('review compares both sides of a change; scanner imports apply to full inspections only');
|
|
350
211
|
if (findings.length)
|
|
351
212
|
process.stderr.write('Scanner imports from the config are skipped: review compares both sides of a change.\n');
|
|
352
213
|
const settingsPath = configFile(root, input);
|
|
353
214
|
const { plugins, ...settings } = config;
|
|
354
|
-
const report = await reviewChange({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD',
|
|
355
|
-
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,
|
|
356
217
|
settingsPath: settingsPath === undefined ? undefined : relative(root, settingsPath).split(sep).join('/'),
|
|
357
218
|
number: count(input.text('pull'), '--pull', 1) ?? (github ? await gitHubPullRequest() : undefined),
|
|
358
|
-
minimumPercent:
|
|
359
|
-
minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
|
|
360
|
-
maxNewIssues: count(input.text('max-new-issues') ?? config.maxNewIssues, '--max-new-issues') });
|
|
219
|
+
minimumPercent: config.minCoverage, minimumLines: config.minLines, maxNewIssues: config.maxNewIssues });
|
|
361
220
|
const markdown = pullReviewMarkdown(report);
|
|
362
221
|
if (github)
|
|
363
222
|
await writeGitHubReview(report, markdown, await gitRoot(root));
|
|
@@ -379,14 +238,6 @@ function useGitHub(input) {
|
|
|
379
238
|
throw new Error('--ci must be github or none');
|
|
380
239
|
return provider === 'github';
|
|
381
240
|
}
|
|
382
|
-
function percent(value, name) {
|
|
383
|
-
if (value === undefined)
|
|
384
|
-
return undefined;
|
|
385
|
-
const number = Number(value);
|
|
386
|
-
if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || number < 0 || number > 100)
|
|
387
|
-
throw new Error(`${name} must be a percentage from 0 to 100`);
|
|
388
|
-
return number;
|
|
389
|
-
}
|
|
390
241
|
function count(value, name, minimum = 0) {
|
|
391
242
|
if (value === undefined)
|
|
392
243
|
return undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Report } from '../core/model/report.js';
|
|
2
|
+
import type { parseConfig } from './config.js';
|
|
3
|
+
export interface RangeInspection {
|
|
4
|
+
readonly directory: string;
|
|
5
|
+
readonly output: string;
|
|
6
|
+
readonly exclude: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export type CommitOutcome = {
|
|
9
|
+
readonly commit: string;
|
|
10
|
+
readonly state: 'analyzed' | 'partial';
|
|
11
|
+
} | {
|
|
12
|
+
readonly commit: string;
|
|
13
|
+
readonly state: 'failed';
|
|
14
|
+
readonly error: string;
|
|
15
|
+
};
|
|
16
|
+
export type RangeMessage = {
|
|
17
|
+
readonly kind: 'start';
|
|
18
|
+
readonly commits: readonly string[];
|
|
19
|
+
readonly inspection: RangeInspection;
|
|
20
|
+
readonly config: unknown;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: 'stop';
|
|
23
|
+
};
|
|
24
|
+
export declare function rangeInspector(inspection: RangeInspection, config: ReturnType<typeof parseConfig>): (revision: string) => Promise<Report>;
|
|
25
|
+
export declare function inspectCommits(commits: readonly string[], inspectCommit: (id: string) => Promise<Report>, stopped: () => boolean, report: (outcome: CommitOutcome) => void | Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HistoryCache } from '../compose/history-cache.js';
|
|
2
|
+
import { inspectWithOptions } from '../compose/inspect.js';
|
|
3
|
+
export function rangeInspector(inspection, config) {
|
|
4
|
+
const { plugins, ...profile } = config;
|
|
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 });
|
|
9
|
+
}
|
|
10
|
+
export async function inspectCommits(commits, inspectCommit, stopped, report) {
|
|
11
|
+
for (const commit of commits) {
|
|
12
|
+
if (stopped())
|
|
13
|
+
break;
|
|
14
|
+
const outcome = await inspectOne(commit, inspectCommit);
|
|
15
|
+
if (outcome.state === 'failed' && stopped())
|
|
16
|
+
break;
|
|
17
|
+
await report(outcome);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function inspectOne(commit, inspectCommit) {
|
|
21
|
+
try {
|
|
22
|
+
const report = await inspectCommit(commit);
|
|
23
|
+
return { commit, state: report.status === 'partial' ? 'partial' : 'analyzed' };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return { commit, state: 'failed', error: error instanceof Error ? error.message : String(error) };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=range-inspection.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RangeInspection } from './range-inspection.js';
|
|
2
|
+
import type { parseConfig } from './config.js';
|
|
3
|
+
export declare function historyChunks(commits: readonly string[], concurrency: number, memory: number): readonly (readonly string[])[];
|
|
4
|
+
interface RangeOptions {
|
|
5
|
+
readonly inspection: RangeInspection;
|
|
6
|
+
readonly config: ReturnType<typeof parseConfig>;
|
|
7
|
+
readonly configValue: unknown;
|
|
8
|
+
readonly concurrency?: number;
|
|
9
|
+
readonly skipSaved: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function analyzeCommits(commits: readonly string[], options: RangeOptions): Promise<{
|
|
12
|
+
interrupted: boolean;
|
|
13
|
+
analyzed: string[];
|
|
14
|
+
partial: string[];
|
|
15
|
+
skipped: string[];
|
|
16
|
+
failed: {
|
|
17
|
+
commit: string;
|
|
18
|
+
error: string;
|
|
19
|
+
}[];
|
|
20
|
+
}>;
|
|
21
|
+
export declare function isSaved(store: string, id: string): Promise<boolean>;
|
|
22
|
+
export {};
|