repometry 0.0.0-dev.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +24 -1
- package/package.json +48 -7
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +34 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +238 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +130 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +586 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
- package/target/main/ts/api/gh/github-pr-comment.js +107 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +91 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +105 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +107 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +54 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +70 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +73 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +152 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +30 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +46 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +35 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +34 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +56 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +226 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +13 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +16 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +45 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +101 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +85 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +110 -0
- package/target/main/ts/cli/config.d.ts +14 -0
- package/target/main/ts/cli/config.js +60 -0
- package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
- package/target/main/ts/cli/github-pr-comment.js +12 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +29 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +343 -284
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +108 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +15 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +38 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +163 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +37 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +56 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +44 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +9 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +16 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +38 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +29 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +49 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +104 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +106 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +85 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +1 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +14 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +31 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +35 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +27 -0
- package/target/main/ts/core/model/measurement.js +24 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +32 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +28 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +50 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +1 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +4 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +57 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +9 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +10 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +145 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +15 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +41 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +128 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +17 -13
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +5 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
- package/target/main/ts/plugins/coverage/coverage.js +120 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +93 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +35 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +60 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +79 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +37 -0
- package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-access.js +25 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2087 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
- package/target/main/ts/report/html/app/viewer-trends.js +413 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +794 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +39 -0
- package/target/main/ts/report/html/site/export-site.d.ts +21 -0
- package/target/main/ts/report/html/site/export-site.js +157 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +70 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +64 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +79 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +64 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +22 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
- package/target/main/ts/report/json/projections/commit-summary.js +118 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +29 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +243 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +92 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +69 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +57 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +16 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +31 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +179 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +51 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +7 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +64 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +27 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +5 -0
- package/index.js +0 -1
|
@@ -1,317 +1,376 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
repometry export --destination DIR [--local-details] [--title NAME] [--components FILE] [--repo DIR] [--output DIR | --meta-ref REF]
|
|
42
|
-
repometry view [--port NUMBER] [--title NAME] [--components FILE] [--repo DIR] [--output DIR | --meta-ref REF]
|
|
43
|
-
repometry projects --destination DIR
|
|
44
|
-
repometry worker [--port NUMBER] [--listen ADDRESS]
|
|
45
|
-
|
|
46
|
-
Inspect reads HEAD by default. Use --working-tree to inspect a directory as it is.
|
|
47
|
-
The output defaults to .repometry inside --repo (the current directory by default).
|
|
48
|
-
Use --working-tree with show to select a working snapshot digest.
|
|
49
|
-
Exit codes: 0 success, 1 command or input error, 2 incomplete result, 3 quality gate failed.
|
|
50
|
-
`;
|
|
51
|
-
const commandOptions = {
|
|
52
|
-
inspect: ['revision', 'profile', 'no-profile', 'exclude', 'lcov', 'working-tree', 'github-summary', 'worker-url',
|
|
53
|
-
'sarif', 'security-sarif', 'secret-sarif', 'eslint-report', 'osv-report', 'finding-root'],
|
|
54
|
-
show: ['working-tree', 'meta-ref'],
|
|
55
|
-
files: ['working-tree', 'meta-ref'],
|
|
56
|
-
history: ['meta-ref'],
|
|
57
|
-
compare: ['meta-ref', 'baseline-output'],
|
|
58
|
-
'diff-coverage': ['revision', 'base', 'lcov', 'profile', 'exclude', 'min-diff-coverage', 'github-summary'],
|
|
59
|
-
review: ['revision', 'base', 'lcov', 'profile', 'exclude', 'number', 'min-diff-coverage', 'min-diff-lines',
|
|
60
|
-
'max-coverage-drop', 'max-new-issues', 'baseline-output', 'github-summary', 'github-annotations'],
|
|
61
|
-
prepare: ['meta-worktree', 'meta-branch'],
|
|
62
|
-
export: ['meta-ref', 'destination', 'local-details', 'title', 'components'],
|
|
63
|
-
view: ['meta-ref', 'port', 'title', 'components'],
|
|
64
|
-
projects: ['destination'],
|
|
65
|
-
worker: ['port', 'listen'],
|
|
2
|
+
import { lstat, readFile } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { firstParentRange, gitRoot, resolveGitCommit } from '../api/git/git.js';
|
|
5
|
+
import { resolveGitBranch } from '../api/git/commit-metadata.js';
|
|
6
|
+
import { clearSourceCache, sourceCacheRoot } from '../api/git/source-cache.js';
|
|
7
|
+
import { writeGitHubDiffCoverage, writeGitHubResult, writeGitHubReview } from '../api/gh/github.js';
|
|
8
|
+
import { remoteExecutor } from '../api/worker/remote-executor.js';
|
|
9
|
+
import { serveWorker } from '../api/worker/worker.js';
|
|
10
|
+
import { workerToken } from '../api/worker/worker-protocol.js';
|
|
11
|
+
import { analyzeSnapshot, attachFindings, inspect } from '../compose/inspect.js';
|
|
12
|
+
import { measureDiffCoverage } from '../compose/diff-coverage.js';
|
|
13
|
+
import { prepareMetabranch } from '../compose/prepare-metabranch.js';
|
|
14
|
+
import { reviewExitCode, reviewPull } from '../compose/review.js';
|
|
15
|
+
import { builtInPlugins } from '../compose/plugin-list.js';
|
|
16
|
+
import { isRecord } from '../core/engine/plugin.js';
|
|
17
|
+
import { validSubjectId } from '../core/model/report.js';
|
|
18
|
+
import { sourceExclusionMatcher } from '../core/profile/exclusions.js';
|
|
19
|
+
import { compareInspections } from '../core/usecases/compare.js';
|
|
20
|
+
import { exportProjects } from '../report/html/site/projects.js';
|
|
21
|
+
import { fileMetrics } from '../report/json/projections/file-metrics.js';
|
|
22
|
+
import { savePullReview } from '../report/json/store/pull-review-store.js';
|
|
23
|
+
import { dispatch, flag, option } from './arguments.js';
|
|
24
|
+
import { readConfig } from './config.js';
|
|
25
|
+
import { importerIds, readInputs } from './imports.js';
|
|
26
|
+
import { outputReports, reporterIds, viewTarget } from './reporting.js';
|
|
27
|
+
import { parseRange } from './revisions.js';
|
|
28
|
+
import { findRepository, selectStore, writableStore } from './store.js';
|
|
29
|
+
const configOptions = { config: option('FILE', 'Read a different JSON configuration.'), 'no-config': flag('Skip configuration.') };
|
|
30
|
+
const importOption = option('FORMAT=PATH', 'Import a report produced by another tool. Repeatable.', { multiple: true });
|
|
31
|
+
const excludeOption = option('PATTERN', 'Exclude a path or glob. Repeatable.', { multiple: true });
|
|
32
|
+
const ciOption = option('PROVIDER', 'Send CI output to github or none.');
|
|
33
|
+
const outputOption = option('PATH', 'Set the report output path.', { short: 'o' });
|
|
34
|
+
const baselineOption = option('PATH|git:REF', 'Select the baseline report store.');
|
|
35
|
+
const branchOption = option('NAME', 'Name the branch represented by the report.');
|
|
36
|
+
const renderOptions = {
|
|
37
|
+
output: outputOption, mode: option('public|private', 'Select the report data to expose.'),
|
|
38
|
+
sources: option('auto|none|ID[:SPEC]', 'Select source navigation for a private report.'),
|
|
39
|
+
title: option('NAME', 'Set the report title.'), components: option('FILE', 'Read component definitions.'),
|
|
40
|
+
'no-footer': flag('Omit the footer.'), branch: branchOption,
|
|
66
41
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
42
|
+
const commands = {
|
|
43
|
+
analyze: {
|
|
44
|
+
description: 'Analyze and save one revision or a range of commits.', parameters: '[REVISION | BASE..[HEAD]]', max: 1,
|
|
45
|
+
options: { ...configOptions, ...renderOptions, 'working-tree': flag('Analyze the working directory.'),
|
|
46
|
+
'skip-saved': flag('Keep commits that already have a saved inspection.'),
|
|
47
|
+
import: importOption, report: option('FORMAT[=PATH]', 'Generate a report after inspection. Repeatable.', { multiple: true }),
|
|
48
|
+
exclude: excludeOption, 'import-root': option('DIR', 'Resolve scanner locations relative to this directory.'),
|
|
49
|
+
worker: option('URL', 'Run analysis on a Repometry worker.'), ci: ciOption },
|
|
50
|
+
run: analyze,
|
|
51
|
+
},
|
|
52
|
+
show: {
|
|
53
|
+
description: 'Print a saved report.', parameters: 'REVISION|DIGEST', min: 1, max: 1,
|
|
54
|
+
options: { files: flag('Print file metrics.') }, run: show,
|
|
55
|
+
},
|
|
56
|
+
history: { description: 'List saved inspections.', async run(input) {
|
|
57
|
+
const { store } = await context(input);
|
|
58
|
+
print({ schema: 'urn:repometry:schema:inspection-history:1', inspections: (await store.reader.list()).map(inspectionSummary) });
|
|
59
|
+
} },
|
|
60
|
+
compare: {
|
|
61
|
+
description: 'Compare two saved reports.', parameters: 'BASE [HEAD]', min: 1, max: 2,
|
|
62
|
+
options: { 'baseline-store': baselineOption }, run: compare,
|
|
63
|
+
},
|
|
64
|
+
'diff-coverage': {
|
|
65
|
+
description: 'Measure coverage of added lines.', parameters: 'BASE [HEAD]', min: 1, max: 2,
|
|
66
|
+
options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
|
|
67
|
+
'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.') }, run: diffCoverage,
|
|
68
|
+
},
|
|
69
|
+
review: {
|
|
70
|
+
description: 'Review coverage and issues introduced by a change.', parameters: 'BASE [HEAD]', min: 1, max: 2,
|
|
71
|
+
options: { ...configOptions, import: importOption, exclude: excludeOption, ci: ciOption,
|
|
72
|
+
'baseline-store': baselineOption, pull: option('NUMBER', 'Store a review for this pull request.'),
|
|
73
|
+
'min-coverage': option('PERCENT', 'Minimum acceptable changed-line coverage.'),
|
|
74
|
+
'min-lines': option('COUNT', 'Minimum measured lines for the changed-line coverage gate.'),
|
|
75
|
+
'max-coverage-drop': option('POINTS', 'Maximum total coverage drop.'),
|
|
76
|
+
'max-new-issues': option('COUNT', 'Maximum count of new quality findings.'),
|
|
77
|
+
annotations: flag('Write GitHub line annotations.') }, run: review,
|
|
78
|
+
},
|
|
79
|
+
report: {
|
|
80
|
+
description: 'Render HTML or JSON from saved reports.', parameters: '[FORMAT[=PATH]]...', max: Infinity,
|
|
81
|
+
options: { ...configOptions, ...renderOptions }, async run(input) {
|
|
82
|
+
const { root, store } = await context(input);
|
|
83
|
+
const config = await readConfig(root, input);
|
|
84
|
+
const requests = input.args.length ? input.args : config.reports.length ? config.reports : ['html'];
|
|
85
|
+
print({ schema: 'urn:repometry:schema:render-result:1', reports: await outputReports(root, store, requests, input, config) });
|
|
95
86
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
87
|
+
},
|
|
88
|
+
view: {
|
|
89
|
+
description: 'Open a repository, store or exported site locally.', parameters: '[TARGET]', max: 1,
|
|
90
|
+
options: { ...configOptions, branch: branchOption, port: option('PORT', 'Listen on this localhost port.'), title: renderOptions.title,
|
|
91
|
+
components: renderOptions.components, 'no-footer': renderOptions['no-footer'] },
|
|
92
|
+
async run(input) { announce(await viewTarget(input, port(input.text('port') ?? '0'))); },
|
|
93
|
+
},
|
|
94
|
+
projects: {
|
|
95
|
+
description: 'Generate a projects index.', options: { output: outputOption, 'no-footer': renderOptions['no-footer'] },
|
|
96
|
+
async run(input) {
|
|
97
|
+
const destination = resolve(input.text('repo') ?? '.', input.text('output') ?? '.');
|
|
98
|
+
print({ schema: 'urn:repometry:schema:projects-result:1', destination,
|
|
99
|
+
projects: await exportProjects(destination, { footer: !input.flag('no-footer') }) });
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
prepare: {
|
|
103
|
+
description: 'Prepare a report for a Git storage branch.', parameters: 'REVISION', min: 1, max: 1,
|
|
104
|
+
options: { worktree: option('DIR', 'Select the storage worktree.'), branch: option('NAME', 'Select the storage branch.') },
|
|
105
|
+
async run(input) {
|
|
106
|
+
const { directory, root, store } = await context(input);
|
|
107
|
+
const path = input.text('worktree');
|
|
108
|
+
if (!path)
|
|
109
|
+
throw new Error('prepare requires --worktree');
|
|
110
|
+
const worktree = resolve(directory, path);
|
|
111
|
+
const id = await commitId(root, input.args[0]);
|
|
112
|
+
const report = await store.reader.read({ kind: 'commit', id });
|
|
113
|
+
const files = await prepareMetabranch({ repository: root, worktree, branch: input.text('branch') ?? 'repometry', report });
|
|
114
|
+
print({ schema: 'urn:repometry:schema:prepare-result:1', subject: report.subject, worktree, files });
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
plugins: { description: 'List plugins and supported formats.', run() {
|
|
118
|
+
print({ schema: 'urn:repometry:schema:plugin-list:1', plugins: builtInPlugins, importers: importerIds,
|
|
119
|
+
reporters: reporterIds, ci: ['github'], stores: ['local', 'git'] });
|
|
120
|
+
} },
|
|
121
|
+
cache: {
|
|
122
|
+
description: 'Find or clear the system cache.', parameters: 'path|clear', min: 1, max: 1,
|
|
123
|
+
options: { sources: flag('Clear only source blobs.') },
|
|
124
|
+
async run(input) {
|
|
125
|
+
const action = input.args[0];
|
|
126
|
+
if (action !== 'path' && action !== 'clear')
|
|
127
|
+
throw new Error('Use cache path or cache clear');
|
|
128
|
+
if (action === 'path' && input.flag('sources'))
|
|
129
|
+
throw new Error('--sources requires cache clear');
|
|
130
|
+
const path = sourceCacheRoot();
|
|
131
|
+
if (action === 'clear')
|
|
132
|
+
await clearSourceCache(path);
|
|
133
|
+
print({ schema: 'urn:repometry:schema:cache-result:1', path, ...(action === 'clear' ? { cleared: ['sources'] } : {}) });
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
worker: { description: 'Run the remote analysis worker.',
|
|
137
|
+
options: { port: option('PORT', 'Listen on this port.'), listen: option('ADDRESS', 'Listen on 127.0.0.1 or 0.0.0.0.') },
|
|
138
|
+
async run(input) {
|
|
139
|
+
const host = input.text('listen') ?? '127.0.0.1';
|
|
140
|
+
if (host !== '127.0.0.1' && host !== '0.0.0.0')
|
|
141
|
+
throw new Error('--listen must be 127.0.0.1 or 0.0.0.0');
|
|
142
|
+
announce(await serveWorker(host, port(input.text('port') ?? '7331'), workerToken(), analyzeSnapshot));
|
|
143
|
+
} },
|
|
144
|
+
};
|
|
145
|
+
async function context(input) {
|
|
146
|
+
const directory = resolve(input.text('repo') ?? '.');
|
|
147
|
+
const root = await findRepository(directory) ?? directory;
|
|
148
|
+
return { directory, root, store: selectStore(root, input.text('store'), directory) };
|
|
149
|
+
}
|
|
150
|
+
async function analyze(input) {
|
|
151
|
+
const range = input.args[0] === undefined ? undefined : parseRange(input.args[0]);
|
|
152
|
+
if (range)
|
|
153
|
+
return analyzeRange(input, range);
|
|
154
|
+
const { directory, root, store } = await context(input);
|
|
155
|
+
const output = writableStore(store);
|
|
156
|
+
if (input.flag('working-tree') && input.args.length)
|
|
157
|
+
throw new Error('Choose a revision or --working-tree');
|
|
158
|
+
if (input.flag('working-tree') && input.flag('skip-saved'))
|
|
159
|
+
throw new Error('--skip-saved applies to commits, not --working-tree');
|
|
160
|
+
const github = useGitHub(input);
|
|
161
|
+
const config = await readConfig(root, input);
|
|
162
|
+
const branch = input.text('branch') ?? config.branch;
|
|
163
|
+
const revision = input.args[0] ?? (!input.flag('working-tree') && branch !== undefined ? await resolveGitBranch(root, branch) : 'HEAD');
|
|
164
|
+
const imports = input.many('import');
|
|
165
|
+
const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
166
|
+
const importRoot = input.text('import-root');
|
|
167
|
+
if (importRoot && findings.length === 0)
|
|
168
|
+
throw new Error('--import-root requires a scanner report');
|
|
169
|
+
const worker = input.text('worker');
|
|
170
|
+
const savedId = input.flag('skip-saved') ? await resolveGitCommit(root, revision) : undefined;
|
|
171
|
+
const skipped = savedId !== undefined && await isSaved(output, savedId);
|
|
172
|
+
const report = skipped ? await store.reader.read({ kind: 'commit', id: savedId })
|
|
173
|
+
: await inspect({ directory, output, source: input.flag('working-tree') ? { workingTree: true } : { revision },
|
|
174
|
+
lcov, exclude: [...config.exclude, ...input.many('exclude')], ignore: config.ignore,
|
|
175
|
+
findingInputs: findings, findingRoot: importRoot ? resolve(directory, importRoot) : undefined }, worker === undefined ? undefined : remoteExecutor(worker, workerToken()));
|
|
176
|
+
if (github)
|
|
177
|
+
await writeGitHubResult(report);
|
|
178
|
+
const requested = input.many('report');
|
|
179
|
+
const reports = await outputReports(root, store, requested.length ? requested : config.reports, input, config);
|
|
180
|
+
print({ schema: 'urn:repometry:schema:analysis-result:1', ...inspectionSummary(report), ...(skipped ? { skipped: true } : {}),
|
|
181
|
+
store: output, reports });
|
|
182
|
+
return report.status === 'partial' ? 2 : 0;
|
|
183
|
+
}
|
|
184
|
+
async function analyzeRange(input, range) {
|
|
185
|
+
const { directory, root, store } = await context(input);
|
|
186
|
+
const output = writableStore(store);
|
|
187
|
+
if (input.flag('working-tree'))
|
|
188
|
+
throw new Error('Choose a range or --working-tree');
|
|
189
|
+
if (input.many('import').length)
|
|
190
|
+
throw new Error('--import describes one checkout and cannot be used with a range');
|
|
191
|
+
if (input.text('import-root'))
|
|
192
|
+
throw new Error('--import-root requires a scanner report');
|
|
193
|
+
if (useGitHub(input))
|
|
194
|
+
throw new Error('--ci github needs a single revision');
|
|
195
|
+
const config = await readConfig(root, input);
|
|
196
|
+
if (config.imports.length)
|
|
197
|
+
process.stderr.write('Imports from the config describe one checkout and are skipped for a range.\n');
|
|
198
|
+
const { base, head, commits } = await firstParentRange(root, range.base, range.head);
|
|
199
|
+
if (!commits.length)
|
|
200
|
+
process.stderr.write(`No commits in ${range.base}..${range.head}.\n`);
|
|
201
|
+
const worker = input.text('worker');
|
|
202
|
+
const executor = worker === undefined ? undefined : remoteExecutor(worker, workerToken());
|
|
203
|
+
const exclude = [...config.exclude, ...input.many('exclude')];
|
|
204
|
+
const analyzed = [], partial = [], skipped = [];
|
|
205
|
+
const failed = [];
|
|
206
|
+
let interrupted = false;
|
|
207
|
+
const stop = () => { interrupted = true; process.stderr.write('Stopping after the current commit.\n'); };
|
|
208
|
+
process.once('SIGINT', stop);
|
|
209
|
+
const width = String(commits.length).length;
|
|
210
|
+
const progress = (index, id, state) => process.stderr.write(`[${String(index + 1).padStart(width)}/${commits.length}] ${id.slice(0, 7)} ${state}\n`);
|
|
211
|
+
try {
|
|
212
|
+
for (const [index, id] of commits.entries()) {
|
|
213
|
+
if (interrupted)
|
|
214
|
+
break;
|
|
215
|
+
if (input.flag('skip-saved') && await isSaved(output, id)) {
|
|
216
|
+
skipped.push(id);
|
|
217
|
+
progress(index, id, 'skipped');
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const report = await inspect({ directory, output, source: { revision: id }, exclude, ignore: config.ignore }, executor);
|
|
222
|
+
analyzed.push(id);
|
|
223
|
+
if (report.status === 'partial')
|
|
224
|
+
partial.push(id);
|
|
225
|
+
progress(index, id, report.status === 'partial' ? 'partial' : 'analyzed');
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
if (interrupted)
|
|
229
|
+
break;
|
|
230
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
231
|
+
failed.push({ commit: id, error: message });
|
|
232
|
+
progress(index, id, `failed: ${message}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
243
235
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return 0;
|
|
236
|
+
finally {
|
|
237
|
+
process.removeListener('SIGINT', stop);
|
|
247
238
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
return 0;
|
|
253
|
-
}
|
|
254
|
-
async function profileExclusions(file, additional = []) {
|
|
255
|
-
const preset = await readProfile(file);
|
|
256
|
-
return [...preset.exclude, ...additional];
|
|
239
|
+
const requested = input.many('report');
|
|
240
|
+
const reports = interrupted ? [] : await outputReports(root, store, requested.length ? requested : config.reports, input, config);
|
|
241
|
+
print({ schema: 'urn:repometry:schema:analyze-range:1', range: `${base}..${head}`,
|
|
242
|
+
analyzed, partial, skipped, failed, store: output, reports });
|
|
243
|
+
return interrupted ? 130 : failed.length || partial.length ? 2 : 0;
|
|
257
244
|
}
|
|
258
|
-
async function
|
|
259
|
-
if (file === undefined)
|
|
260
|
-
return { exclude: [], ignore: [] };
|
|
261
|
-
let text;
|
|
245
|
+
async function isSaved(store, id) {
|
|
262
246
|
try {
|
|
263
|
-
|
|
247
|
+
return (await lstat(join(store, 'commits', id, 'report.json'))).isFile();
|
|
264
248
|
}
|
|
265
249
|
catch (error) {
|
|
266
|
-
if (
|
|
267
|
-
return
|
|
250
|
+
if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR'))
|
|
251
|
+
return false;
|
|
268
252
|
throw error;
|
|
269
253
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
254
|
+
}
|
|
255
|
+
async function show(input) {
|
|
256
|
+
const { root, store } = await context(input);
|
|
257
|
+
const ref = input.args[0];
|
|
258
|
+
const id = await commitId(root, ref);
|
|
259
|
+
let report;
|
|
260
|
+
try {
|
|
261
|
+
report = await store.reader.read({ kind: 'commit', id });
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (!validSubjectId('working-tree', ref) || store.path === undefined || !(error instanceof Error)
|
|
265
|
+
|| !('code' in error) || error.code !== 'ENOENT')
|
|
266
|
+
throw error;
|
|
267
|
+
report = await store.reader.read({ kind: 'working-tree', id: ref });
|
|
273
268
|
}
|
|
274
|
-
|
|
275
|
-
ignore: normalizeFindingIgnore(profile.ignore === undefined ? [] : profile.ignore) };
|
|
269
|
+
print(input.flag('files') ? fileMetrics(report) : report);
|
|
276
270
|
}
|
|
277
|
-
function
|
|
271
|
+
async function compare(input) {
|
|
272
|
+
const { directory, root, store } = await context(input);
|
|
273
|
+
const baselinePath = input.text('baseline-store');
|
|
274
|
+
const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
|
|
275
|
+
const [base, head] = await Promise.all([commitId(root, input.args[0]), commitId(root, input.args[1] ?? 'HEAD')]);
|
|
276
|
+
const current = store.reader.read({ kind: 'commit', id: head });
|
|
277
|
+
const before = base === head && baseline === store ? current : baseline.reader.read({ kind: 'commit', id: base });
|
|
278
|
+
print(compareInspections(await before, await current));
|
|
279
|
+
}
|
|
280
|
+
async function diffCoverage(input) {
|
|
281
|
+
const { directory, root } = await context(input);
|
|
282
|
+
const config = await readConfig(root, input);
|
|
283
|
+
const imports = input.many('import');
|
|
284
|
+
const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
285
|
+
if (!lcov || (imports.length && findings.length))
|
|
286
|
+
throw new Error('diff-coverage requires --import lcov=PATH');
|
|
287
|
+
const report = await measureDiffCoverage({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov,
|
|
288
|
+
exclude: [...config.exclude, ...input.many('exclude')], minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage') });
|
|
289
|
+
if (useGitHub(input))
|
|
290
|
+
await writeGitHubDiffCoverage(report);
|
|
291
|
+
print(report);
|
|
292
|
+
return report.status === 'partial' ? 2 : report.decision?.status === 'failed' ? 3 : 0;
|
|
293
|
+
}
|
|
294
|
+
async function review(input) {
|
|
295
|
+
const { directory, root, store } = await context(input);
|
|
296
|
+
const github = useGitHub(input);
|
|
297
|
+
if (input.flag('annotations') && !github)
|
|
298
|
+
throw new Error('--annotations requires --ci github');
|
|
299
|
+
const config = await readConfig(root, input);
|
|
300
|
+
const imports = input.many('import');
|
|
301
|
+
const { lcov, findings } = imports.length ? readInputs(directory, imports) : readInputs(root, config.imports);
|
|
302
|
+
const baselinePath = input.text('baseline-store');
|
|
303
|
+
const baseline = baselinePath === undefined ? store : selectStore(root, baselinePath, directory);
|
|
304
|
+
const exclude = [...config.exclude, ...input.many('exclude')];
|
|
305
|
+
const current = imports.length && findings.length ? {
|
|
306
|
+
list: () => store.reader.list(),
|
|
307
|
+
read: async (subject) => {
|
|
308
|
+
const report = await store.reader.read(subject);
|
|
309
|
+
const source = report.appliedConfig.source;
|
|
310
|
+
const generated = isRecord(source) && Array.isArray(source.generatedExcluded)
|
|
311
|
+
? source.generatedExcluded.filter((path) => typeof path === 'string') : [];
|
|
312
|
+
return attachFindings(report, findings, root, root, sourceExclusionMatcher(exclude, generated));
|
|
313
|
+
},
|
|
314
|
+
} : store.reader;
|
|
315
|
+
const number = count(input.text('pull'), '--pull', 1);
|
|
316
|
+
const report = await reviewPull({ directory: root, base: input.args[0], revision: input.args[1] ?? 'HEAD', lcov, exclude, number,
|
|
317
|
+
minimumPercent: percent(input.text('min-coverage') ?? config.minCoverage, '--min-coverage'),
|
|
318
|
+
minimumLines: count(input.text('min-lines') ?? config.minLines, '--min-lines'),
|
|
319
|
+
maxCoverageDrop: percent(input.text('max-coverage-drop') ?? config.maxCoverageDrop, '--max-coverage-drop'),
|
|
320
|
+
maxNewIssues: count(input.text('max-new-issues') ?? config.maxNewIssues, '--max-new-issues') }, current, baseline.reader);
|
|
321
|
+
if (number !== undefined)
|
|
322
|
+
await savePullReview(writableStore(store), report);
|
|
323
|
+
if (github)
|
|
324
|
+
await writeGitHubReview(report, input.flag('annotations') ? await gitRoot(root) : undefined);
|
|
325
|
+
print(report);
|
|
326
|
+
return reviewExitCode(report);
|
|
327
|
+
}
|
|
328
|
+
function commitId(root, revision) {
|
|
329
|
+
return validSubjectId('commit', revision) ? Promise.resolve(revision) : resolveGitCommit(root, revision);
|
|
330
|
+
}
|
|
331
|
+
function useGitHub(input) {
|
|
332
|
+
const provider = input.text('ci') ?? 'none';
|
|
333
|
+
if (provider !== 'none' && provider !== 'github')
|
|
334
|
+
throw new Error('--ci must be github or none');
|
|
335
|
+
return provider === 'github';
|
|
336
|
+
}
|
|
337
|
+
function percent(value, name) {
|
|
278
338
|
if (value === undefined)
|
|
279
339
|
return undefined;
|
|
280
|
-
const
|
|
281
|
-
if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) ||
|
|
282
|
-
throw new Error(`${
|
|
283
|
-
|
|
284
|
-
return percent;
|
|
340
|
+
const number = Number(value);
|
|
341
|
+
if (!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(value) || number < 0 || number > 100)
|
|
342
|
+
throw new Error(`${name} must be a percentage from 0 to 100`);
|
|
343
|
+
return number;
|
|
285
344
|
}
|
|
286
|
-
function
|
|
345
|
+
function count(value, name, minimum = 0) {
|
|
287
346
|
if (value === undefined)
|
|
288
347
|
return undefined;
|
|
289
|
-
const
|
|
290
|
-
if (!/^\d+$/.test(value) || !Number.isSafeInteger(
|
|
291
|
-
throw new Error(`${
|
|
292
|
-
|
|
293
|
-
return count;
|
|
348
|
+
const number = Number(value);
|
|
349
|
+
if (!/^\d+$/.test(value) || !Number.isSafeInteger(number) || number < minimum)
|
|
350
|
+
throw new Error(`${name} must be an integer of at least ${minimum}`);
|
|
351
|
+
return number;
|
|
294
352
|
}
|
|
295
|
-
function
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
353
|
+
function port(value) {
|
|
354
|
+
const number = count(value, '--port');
|
|
355
|
+
if (number > 65535)
|
|
298
356
|
throw new Error('--port must be an integer from 0 to 65535');
|
|
299
|
-
return
|
|
357
|
+
return number;
|
|
300
358
|
}
|
|
301
359
|
function announce(server) {
|
|
302
|
-
process.once('SIGINT', server.close);
|
|
360
|
+
process.once('SIGINT', () => { process.exitCode = 130; server.close(); });
|
|
303
361
|
process.once('SIGTERM', server.close);
|
|
304
|
-
process.
|
|
362
|
+
process.stderr.write(`Serving${server.label ? ' ' + server.label : ''} at ${server.url}\n`);
|
|
305
363
|
}
|
|
306
|
-
function
|
|
364
|
+
function inspectionSummary(report) {
|
|
307
365
|
return { subject: report.subject, generatedAt: report.generatedAt, status: report.status, scope: report.scope,
|
|
308
366
|
measurements: report.measurements.length, diagnostics: report.diagnostics.length };
|
|
309
367
|
}
|
|
310
368
|
function print(value) {
|
|
311
|
-
process.stdout.write(
|
|
369
|
+
process.stdout.write(JSON.stringify(value, null, 2) + '\n');
|
|
312
370
|
}
|
|
313
371
|
try {
|
|
314
|
-
|
|
372
|
+
const manifest = JSON.parse(await readFile(new URL('../../../../package.json', import.meta.url), 'utf8'));
|
|
373
|
+
process.exitCode = await dispatch(commands, process.argv.slice(2), manifest.version);
|
|
315
374
|
}
|
|
316
375
|
catch (error) {
|
|
317
376
|
process.stderr.write(`repometry: ${error instanceof Error ? error.message : String(error)}\n`);
|