repometry 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -2
- package/package.json +64 -4
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +33 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +252 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +120 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +560 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +92 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +106 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +108 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +53 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +71 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +74 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +153 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +31 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +47 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +36 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +35 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +57 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +227 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +14 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +17 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +46 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +102 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +86 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +111 -0
- package/target/main/ts/cli/config.d.ts +13 -0
- package/target/main/ts/cli/config.js +58 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +30 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +379 -0
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +104 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +16 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +39 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +164 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +50 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +45 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +10 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +17 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +39 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +30 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +50 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +105 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +107 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +86 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +2 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +15 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +32 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +36 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +33 -0
- package/target/main/ts/core/model/measurement.js +30 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +40 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +29 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +51 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +2 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +5 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +58 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +10 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +11 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +146 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +16 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +42 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +129 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +18 -0
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +6 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
- package/target/main/ts/plugins/coverage/coverage.js +199 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +94 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +36 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +61 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +80 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +38 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2104 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
- package/target/main/ts/report/html/app/viewer-trends.js +423 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +735 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +40 -0
- package/target/main/ts/report/html/site/export-site.d.ts +22 -0
- package/target/main/ts/report/html/site/export-site.js +150 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +71 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +65 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +80 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +65 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +23 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
- package/target/main/ts/report/json/projections/commit-summary.js +124 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +30 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +244 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +93 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +70 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +58 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +17 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +32 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +180 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +52 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +8 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +65 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +28 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +6 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { QualitySummary } from '../../../core/model/quality-summary.js';
|
|
2
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
3
|
+
export interface SecurityCounts {
|
|
4
|
+
readonly critical?: number;
|
|
5
|
+
readonly high: number;
|
|
6
|
+
readonly medium: number;
|
|
7
|
+
readonly low: number;
|
|
8
|
+
readonly unknown: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The README badges. Security joins coverage and maintainability only where the export may carry scanner counts:
|
|
12
|
+
* the public export leaves them out, and so leaves the badge out.
|
|
13
|
+
*/
|
|
14
|
+
export declare function badges(report: PublicHistoryEntry | undefined, quality: QualitySummary | undefined, security?: SecurityCounts): Map<string, Buffer>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { coverageGrade, securityGrade } from '../../../core/model/quality-summary.js';
|
|
2
|
+
/** The report's own grade colours, so a badge in a README reads as the report does. */
|
|
3
|
+
const colors = { A: '#1f9d5a', B: '#74a83a', C: '#d9a400', D: '#ec8a2c', F: '#db4a3f' };
|
|
4
|
+
const unavailable = '#6b7684';
|
|
5
|
+
const label = '#0f1720';
|
|
6
|
+
/**
|
|
7
|
+
* The README badges. Security joins coverage and maintainability only where the export may carry scanner counts:
|
|
8
|
+
* the public export leaves them out, and so leaves the badge out.
|
|
9
|
+
*/
|
|
10
|
+
export function badges(report, quality, security) {
|
|
11
|
+
const lines = report?.lineCoverage;
|
|
12
|
+
const ratio = lines && lines.total > 0 ? lines.covered / lines.total : null;
|
|
13
|
+
const grade = quality?.maintainability?.grade ?? null;
|
|
14
|
+
// A missing measurement is one mark, not a word.
|
|
15
|
+
const coverage = ratio === null ? '—'
|
|
16
|
+
: new Intl.NumberFormat('en', { style: 'percent', maximumFractionDigits: 1 }).format(ratio);
|
|
17
|
+
const files = new Map([
|
|
18
|
+
['coverage.svg', badge('coverage', coverage, ratio === null ? null : coverageGrade(ratio), 68)],
|
|
19
|
+
['maintainability.svg', badge('maintainability', grade ?? '—', grade, 112)],
|
|
20
|
+
]);
|
|
21
|
+
if (security) {
|
|
22
|
+
const grade = securityGrade(security);
|
|
23
|
+
files.set('security.svg', badge('security', grade, grade, 64));
|
|
24
|
+
}
|
|
25
|
+
return files;
|
|
26
|
+
}
|
|
27
|
+
function badge(name, value, grade, labelWidth) {
|
|
28
|
+
const fill = grade ? colors[grade] : unavailable;
|
|
29
|
+
const valueWidth = Math.max(30, value.length * 8 + 14);
|
|
30
|
+
const width = labelWidth + valueWidth;
|
|
31
|
+
return Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="26" viewBox="0 0 ${width} 26" role="img" aria-label="${name}: ${value}">
|
|
32
|
+
<rect width="${width}" height="26" rx="5" fill="${fill}"/>
|
|
33
|
+
<path d="M0 5a5 5 0 0 1 5-5h${labelWidth - 5}v26H5a5 5 0 0 1-5-5Z" fill="${label}"/>
|
|
34
|
+
<g fill="#fff" font-family="system-ui,sans-serif" font-size="12" font-weight="600" text-anchor="middle">
|
|
35
|
+
<text x="${labelWidth / 2}" y="17">${name}</text>
|
|
36
|
+
<text x="${labelWidth + valueWidth / 2}" y="17">${value}</text>
|
|
37
|
+
</g>
|
|
38
|
+
</svg>\n`);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=badges.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReadCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
2
|
+
import type { CommitSummary, SourceLocator } from '../../json/wire/summary-model.js';
|
|
3
|
+
import type { Report, ReportReader } from '../../json/validation/report.js';
|
|
4
|
+
import type { PullReview } from '../../json/wire/pull-review-model.js';
|
|
5
|
+
import type { Component } from '../../json/projections/components.js';
|
|
6
|
+
export interface SiteOptions {
|
|
7
|
+
readonly title?: string;
|
|
8
|
+
/** `local` for `repometry view`, which serves details live; an export writes them as files. */
|
|
9
|
+
readonly mode?: 'local' | 'private';
|
|
10
|
+
readonly components?: readonly Component[];
|
|
11
|
+
readonly pulls?: readonly PullReview[];
|
|
12
|
+
readonly sources?: SourceLocator;
|
|
13
|
+
readonly branch?: string;
|
|
14
|
+
readonly readCommitMetadata?: ReadCommitMetadata;
|
|
15
|
+
/** The page footer with the project link and license; --no-footer leaves it out. */
|
|
16
|
+
readonly footer?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A page without its footer, for reports published under someone else's name. */
|
|
19
|
+
export declare function withoutFooter(html: string): string;
|
|
20
|
+
export declare function siteFiles(reports: readonly Report[], { title, mode, components, pulls, sources, branch, readCommitMetadata, footer }?: SiteOptions, indexed?: readonly CommitSummary[]): Promise<Map<string, Buffer>>;
|
|
21
|
+
export declare function siteSummary(rows: readonly CommitSummary[], { mode, components, pulls, sources, branch }: SiteOptions, details?: Map<string, string>): Buffer;
|
|
22
|
+
export declare function exportSite(reader: ReportReader, destination: string, options?: SiteOptions): Promise<void>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { historySchema } from '../../json/wire/public-history-model.js';
|
|
5
|
+
import { inspectionAsset } from '../../json/projections/inspection-details.js';
|
|
6
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
7
|
+
import { commitSummary, orderSummaries, repositorySummary, withCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
8
|
+
import { packJson } from '../../json/wire/compact-json.js';
|
|
9
|
+
import { comparePaths, digest } from '../../../core/model/snapshot.js';
|
|
10
|
+
import { pullReviewsSchema } from '../../json/wire/pull-review-model.js';
|
|
11
|
+
import { badges } from './badges.js';
|
|
12
|
+
const appDirectory = new URL('../app/', import.meta.url);
|
|
13
|
+
const wireDirectory = new URL('../../json/wire/', import.meta.url);
|
|
14
|
+
const resourceDirectory = new URL('../../../../resources/viewer/', import.meta.url);
|
|
15
|
+
async function listViewerAssets() {
|
|
16
|
+
const groups = await Promise.all([
|
|
17
|
+
listAssets(appDirectory, name => name.endsWith('.js')),
|
|
18
|
+
listAssets(wireDirectory, name => name.endsWith('.js')),
|
|
19
|
+
listAssets(resourceDirectory, name => name.endsWith('.css') || name === 'index.html'),
|
|
20
|
+
]);
|
|
21
|
+
const assets = groups.flat().sort(([left], [right]) => comparePaths(left, right));
|
|
22
|
+
if (new Set(assets.map(([name]) => name)).size !== assets.length) {
|
|
23
|
+
throw new Error('The build contains duplicate viewer asset names');
|
|
24
|
+
}
|
|
25
|
+
return assets;
|
|
26
|
+
}
|
|
27
|
+
async function listAssets(directory, include) {
|
|
28
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
29
|
+
return entries.filter(entry => entry.isFile() && include(entry.name))
|
|
30
|
+
.map(({ name }) => [name, new URL(encodeURIComponent(name), directory)]);
|
|
31
|
+
}
|
|
32
|
+
/** A page without its footer, for reports published under someone else's name. */
|
|
33
|
+
export function withoutFooter(html) {
|
|
34
|
+
return html.replace(/\n[ \t]*<footer class="site-footer">[\s\S]*?<\/footer>/, '');
|
|
35
|
+
}
|
|
36
|
+
export async function siteFiles(reports, { title = '', mode = 'private', components, pulls = [], sources, branch, readCommitMetadata, footer = true } = {}, indexed) {
|
|
37
|
+
const files = new Map(await Promise.all((await listViewerAssets()).map(async ([name, source]) => {
|
|
38
|
+
const bytes = await readFile(source);
|
|
39
|
+
// The published viewer keeps its existing flat URLs for static hosts and open tabs.
|
|
40
|
+
const contents = source.href.startsWith(appDirectory.href)
|
|
41
|
+
? Buffer.from(bytes.toString('utf8').replace(/(\b(?:from|import)\s*['"]|\bimport\(\s*['"])\.\.\/\.\.\/json\/wire\//g, '$1./'))
|
|
42
|
+
: bytes;
|
|
43
|
+
return [name, contents];
|
|
44
|
+
})));
|
|
45
|
+
const index = files.get('index.html').toString('utf8')
|
|
46
|
+
.replace('name="repometry-view" content="private"', `name="repometry-view" content="${mode}"`)
|
|
47
|
+
.replace('name="repometry-project" content=""', () => `name="repometry-project" content="${escapeAttribute(title)}"`);
|
|
48
|
+
files.set('index.html', Buffer.from(footer ? index : withoutFooter(index)));
|
|
49
|
+
const commits = reports.filter(report => report.subject.kind === 'commit');
|
|
50
|
+
const rows = orderSummaries(await withCommitMetadata(indexed ?? commits.map(commitSummary), readCommitMetadata));
|
|
51
|
+
const publicRows = rows.map(({ quality, counts, detail, revision, profileDigest, profileBoundary, subject, author, tags, metrics, values, privateMetrics, ...history }) => ({ ...history, subject, author, tags }));
|
|
52
|
+
const history = { schema: historySchema, reports: publicRows };
|
|
53
|
+
const quality = { schema: 'urn:repometry:schema:quality-history:1',
|
|
54
|
+
reports: Object.fromEntries(rows.map(row => [row.sha, row.quality])) };
|
|
55
|
+
files.set('history.json', Buffer.from(`${JSON.stringify(history)}\n`));
|
|
56
|
+
files.set('quality-history.json', Buffer.from(`${JSON.stringify(quality)}\n`));
|
|
57
|
+
const latest = rows[0];
|
|
58
|
+
for (const [name, data] of badges(latest, latest?.quality, latest?.counts?.security))
|
|
59
|
+
files.set(name, data);
|
|
60
|
+
files.set('pulls.json', Buffer.from(`${JSON.stringify({ schema: pullReviewsSchema, reviews: pulls })}\n`));
|
|
61
|
+
const details = new Map();
|
|
62
|
+
if (mode === 'private') {
|
|
63
|
+
for (const report of commits) {
|
|
64
|
+
const sha = report.subject.id;
|
|
65
|
+
const data = JSON.stringify(packJson(inspectionAsset(report, components))) + '\n';
|
|
66
|
+
const name = `details/${sha}-${digest(data)}.json`;
|
|
67
|
+
details.set(sha, name);
|
|
68
|
+
files.set(name, Buffer.from(data));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
files.set('summary.json', siteSummary(rows, { mode, components, pulls, sources, branch }, details));
|
|
72
|
+
return files;
|
|
73
|
+
}
|
|
74
|
+
export function siteSummary(rows, { mode = 'private', components, pulls = [], sources, branch }, details = new Map()) {
|
|
75
|
+
const ordered = orderSummaries(rows);
|
|
76
|
+
const commits = ordered.map(({ counts, detail, revision, profileDigest, profileBoundary, subject, author, tags, ...row }, index) => {
|
|
77
|
+
const previous = ordered[index + 1];
|
|
78
|
+
const boundary = !previous ? undefined : !profileDigest || !previous.profileDigest ? 'unavailable'
|
|
79
|
+
: profileDigest === previous.profileDigest ? undefined : 'changed';
|
|
80
|
+
return {
|
|
81
|
+
...row, subject, author, tags, detail: mode === 'local' && revision ? `inspection/${row.sha}-${revision}.json` : details.get(row.sha),
|
|
82
|
+
counts: counts && { ...counts, componentCount: components?.length ?? 0 },
|
|
83
|
+
...(boundary === undefined ? {} : { profileBoundary: boundary }),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const summary = repositorySummary(commits, pulls.length, true);
|
|
87
|
+
return Buffer.from(`${JSON.stringify({ ...summary, ...(branch === undefined ? {} : { source: { branch } }),
|
|
88
|
+
...(sources ? { sources } : {}) })}\n`);
|
|
89
|
+
}
|
|
90
|
+
export async function exportSite(reader, destination, options = {}) {
|
|
91
|
+
const files = await siteFiles(await reader.list(), options);
|
|
92
|
+
await mkdir(destination, { recursive: true, mode: 0o755 });
|
|
93
|
+
if (!(await lstat(destination)).isDirectory())
|
|
94
|
+
throw new Error('The viewer destination must be a directory');
|
|
95
|
+
const entries = await readdir(destination, { withFileTypes: true });
|
|
96
|
+
const oldDetails = entries.some(entry => entry.name === 'details.json' && entry.isFile());
|
|
97
|
+
const detailDirectory = entries.some(entry => entry.name === 'details' && entry.isDirectory());
|
|
98
|
+
if (entries.some(entry => !(entry.isFile() && files.has(entry.name))
|
|
99
|
+
&& !(entry.name === 'details' && entry.isDirectory())
|
|
100
|
+
&& !(oldDetails && entry.name === 'details.json' && entry.isFile()))) {
|
|
101
|
+
throw new Error('Use a dedicated viewer destination containing only Repometry export files');
|
|
102
|
+
}
|
|
103
|
+
if (oldDetails) {
|
|
104
|
+
const legacy = JSON.parse(await readFile(join(destination, 'details.json'), 'utf8'));
|
|
105
|
+
if (!isRecord(legacy) || legacy.schema !== 'urn:repometry:schema:viewer-details:1') {
|
|
106
|
+
throw new Error('Existing details.json is not a Repometry export');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (detailDirectory) {
|
|
110
|
+
const existing = await readdir(join(destination, 'details'), { withFileTypes: true });
|
|
111
|
+
if (existing.some(entry => !entry.isFile() || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})-[a-f0-9]{64}\.json$/.test(entry.name))) {
|
|
112
|
+
throw new Error('The viewer details directory contains files outside the export');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (entries.length > 0) {
|
|
116
|
+
const existing = entries.some(entry => entry.name === 'history.json')
|
|
117
|
+
? JSON.parse(await readFile(join(destination, 'history.json'), 'utf8')) : undefined;
|
|
118
|
+
if (!isRecord(existing) || existing.schema !== historySchema)
|
|
119
|
+
throw new Error('Choose an empty viewer directory or an existing Repometry export');
|
|
120
|
+
}
|
|
121
|
+
const staging = join(destination, `.export-${randomUUID()}`);
|
|
122
|
+
await mkdir(staging);
|
|
123
|
+
try {
|
|
124
|
+
const hasDetails = [...files.keys()].some(name => name.startsWith('details/'));
|
|
125
|
+
if (hasDetails)
|
|
126
|
+
await mkdir(join(staging, 'details'));
|
|
127
|
+
for (const [name, bytes] of files)
|
|
128
|
+
await writeFile(join(staging, name), bytes, { mode: 0o644 });
|
|
129
|
+
const afterDependencies = ['viewer.js', 'summary.json', 'index.html'];
|
|
130
|
+
const install = (name) => rename(join(staging, name), join(destination, name));
|
|
131
|
+
await install('history.json');
|
|
132
|
+
if (hasDetails && !detailDirectory)
|
|
133
|
+
await mkdir(join(destination, 'details'));
|
|
134
|
+
for (const name of files.keys()) {
|
|
135
|
+
if (name !== 'history.json' && !afterDependencies.includes(name))
|
|
136
|
+
await install(name);
|
|
137
|
+
}
|
|
138
|
+
for (const name of afterDependencies)
|
|
139
|
+
await install(name);
|
|
140
|
+
if (oldDetails)
|
|
141
|
+
await rm(join(destination, 'details.json'));
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
await rm(staging, { recursive: true, force: true });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function escapeAttribute(value) {
|
|
148
|
+
return value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=export-site.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceAccess } from './source-route.js';
|
|
2
|
+
export declare function readExportedSummary(directory: string): Promise<import("../../../report.js").RepositorySummary | undefined>;
|
|
3
|
+
export declare function serveExportedSite(directory: string, port: number, access?: SourceAccess): Promise<{
|
|
4
|
+
url: string;
|
|
5
|
+
close: () => void;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { lstat, readFile, realpath } from 'node:fs/promises';
|
|
2
|
+
import { join, sep } from 'node:path';
|
|
3
|
+
import { isRecord } from '../../../core/engine/plugin.js';
|
|
4
|
+
import { unpackJson } from '../../json/wire/compact-json.js';
|
|
5
|
+
import { validateSummaryIndex } from '../../json/validation/summary-validation.js';
|
|
6
|
+
import { serveAssets } from './server.js';
|
|
7
|
+
import { sourceResponse } from './source-route.js';
|
|
8
|
+
export async function readExportedSummary(directory) {
|
|
9
|
+
const path = join(directory, 'summary.json');
|
|
10
|
+
const index = join(directory, 'index.html');
|
|
11
|
+
try {
|
|
12
|
+
if (!(await lstat(index)).isFile() || !(await lstat(path)).isFile())
|
|
13
|
+
return undefined;
|
|
14
|
+
const value = JSON.parse(await readFile(path, 'utf8'));
|
|
15
|
+
return validateSummaryIndex(value) ? value : undefined;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof SyntaxError || missing(error))
|
|
19
|
+
return undefined;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function serveExportedSite(directory, port, access) {
|
|
24
|
+
const root = await realpath(directory);
|
|
25
|
+
const summary = await readExportedSummary(root);
|
|
26
|
+
if (!summary)
|
|
27
|
+
throw new Error(`No exported report at ${directory}`);
|
|
28
|
+
const details = new Map(summary.commits.map(row => [row.sha, row.detail]));
|
|
29
|
+
const local = summary.sources?.provider === 'local' && summary.sources.url === './sources/{revision}/{path}' ? access : undefined;
|
|
30
|
+
async function file(name) {
|
|
31
|
+
if (!/^[A-Za-z0-9_-]+\.(?:html|css|js|json|svg)$/.test(name) && !/^details\/[a-f0-9]+-[a-f0-9]{64}\.json$/.test(name)) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const path = join(root, name);
|
|
35
|
+
try {
|
|
36
|
+
if (!(await lstat(path)).isFile() || !((await realpath(path)).startsWith(root + sep)))
|
|
37
|
+
return undefined;
|
|
38
|
+
return readFile(path);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (missing(error))
|
|
42
|
+
return undefined;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return serveAssets(port, async (name) => {
|
|
47
|
+
if (!name.startsWith('sources/'))
|
|
48
|
+
return file(name);
|
|
49
|
+
return sourceResponse(name, local, async (revision, path) => {
|
|
50
|
+
const detail = details.get(revision);
|
|
51
|
+
if (!detail?.startsWith(`details/${revision}-`))
|
|
52
|
+
return false;
|
|
53
|
+
const bytes = await file(detail);
|
|
54
|
+
if (!bytes)
|
|
55
|
+
return false;
|
|
56
|
+
const asset = unpackJson(JSON.parse(bytes.toString('utf8')));
|
|
57
|
+
if (!isRecord(asset) || asset.schema !== 'urn:repometry:schema:viewer-inspection:1'
|
|
58
|
+
|| asset.sha !== revision || !isRecord(asset.inspection))
|
|
59
|
+
return false;
|
|
60
|
+
const { metrics, findings, diagnostics } = asset.inspection;
|
|
61
|
+
return (isRecord(metrics) && listsPath(metrics.files, path)) || listsPath(findings, path) || listsPath(diagnostics, path);
|
|
62
|
+
});
|
|
63
|
+
}, access?.close);
|
|
64
|
+
}
|
|
65
|
+
function listsPath(rows, path) {
|
|
66
|
+
return Array.isArray(rows) && rows.some(row => isRecord(row) && row.path === path);
|
|
67
|
+
}
|
|
68
|
+
function missing(error) {
|
|
69
|
+
return error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR');
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=exported-server.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReportReader } from '../../json/validation/report.js';
|
|
2
|
+
import type { SiteOptions } from './export-site.js';
|
|
3
|
+
import type { SourceAccess } from './source-route.js';
|
|
4
|
+
export declare function serveSite(reader: ReportReader, port: number, options?: Omit<SiteOptions, 'mode'>, source?: SourceAccess): Promise<{
|
|
5
|
+
url: string;
|
|
6
|
+
close: () => void;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { reportRevision, validSubjectId } from '../../json/validation/report.js';
|
|
2
|
+
import { siteFiles, siteSummary } from './export-site.js';
|
|
3
|
+
import { fileMetrics } from '../../json/projections/file-metrics.js';
|
|
4
|
+
import { inspectionHistory } from '../../json/projections/inspection-context.js';
|
|
5
|
+
import { complexFunctions, inspectionAsset, inspectionDetails } from '../../json/projections/inspection-details.js';
|
|
6
|
+
import { packJson } from '../../json/wire/compact-json.js';
|
|
7
|
+
import { withCommitMetadata } from '../../json/projections/commit-summary.js';
|
|
8
|
+
import { serveAssets } from './server.js';
|
|
9
|
+
import { sourceResponse } from './source-route.js';
|
|
10
|
+
export async function serveSite(reader, port, options = {}, source) {
|
|
11
|
+
const indexed = await reader.listSummaries?.();
|
|
12
|
+
const reports = indexed ? [] : await reader.list();
|
|
13
|
+
const siteOptions = { ...options, mode: 'local' };
|
|
14
|
+
const files = await siteFiles(reports, siteOptions, indexed);
|
|
15
|
+
const commits = new Map(reports.filter(report => report.subject.kind === 'commit').map(report => [report.subject.id, report]));
|
|
16
|
+
async function read(sha) {
|
|
17
|
+
if (!validSubjectId('commit', sha))
|
|
18
|
+
return undefined;
|
|
19
|
+
if (!indexed)
|
|
20
|
+
return commits.get(sha);
|
|
21
|
+
try {
|
|
22
|
+
return await reader.read({ kind: 'commit', id: sha });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
26
|
+
return undefined;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function asset(name) {
|
|
31
|
+
if (name.startsWith('sources/'))
|
|
32
|
+
return sourceResponse(name, source, async (revision, path) => {
|
|
33
|
+
const report = await read(revision);
|
|
34
|
+
return report !== undefined && sourceListed(report, path);
|
|
35
|
+
});
|
|
36
|
+
if (name === 'summary.json' && reader.listSummaries) {
|
|
37
|
+
return siteSummary(await withCommitMetadata(await reader.listSummaries(), options.readCommitMetadata), siteOptions);
|
|
38
|
+
}
|
|
39
|
+
if (name === 'inspection-context.json')
|
|
40
|
+
return Buffer.from(JSON.stringify(inspectionHistory(indexed ? await reader.list() : reports)));
|
|
41
|
+
const versioned = /^inspection\/([a-f0-9]+)-([a-f0-9]{64})\.json$/.exec(name);
|
|
42
|
+
if (versioned) {
|
|
43
|
+
const inspection = await read(versioned[1]);
|
|
44
|
+
return inspection && reportRevision(inspection) === versioned[2]
|
|
45
|
+
? Buffer.from(JSON.stringify(packJson(inspectionAsset(inspection, options.components)))) : undefined;
|
|
46
|
+
}
|
|
47
|
+
const resource = /^(files|details|functions)\/([a-f0-9]+)\.json$/.exec(name);
|
|
48
|
+
if (!resource)
|
|
49
|
+
return files.get(name);
|
|
50
|
+
const inspection = await read(resource[2]);
|
|
51
|
+
if (!inspection)
|
|
52
|
+
return undefined;
|
|
53
|
+
const value = resource[1] === 'files' ? fileMetrics(inspection)
|
|
54
|
+
: resource[1] === 'functions' ? complexFunctions(inspection).slice(0, 5) : inspectionDetails(inspection, options.components);
|
|
55
|
+
return Buffer.from(JSON.stringify(value));
|
|
56
|
+
}
|
|
57
|
+
return serveAssets(port, asset, source?.close);
|
|
58
|
+
}
|
|
59
|
+
function sourceListed(report, path) {
|
|
60
|
+
return (report.pluginData?.inventory ?? []).some(file => file.path === path)
|
|
61
|
+
|| report.measurements.some(row => row.path === path)
|
|
62
|
+
|| report.diagnostics.some(row => row.path === path)
|
|
63
|
+
|| (report.findings ?? []).some(row => row.path === path || row.related?.some(location => location.path === path));
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=local-server.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
5
|
+
import historyContract from '../../../../resources/report/json/public-history-v1.schema.json' with { type: 'json' };
|
|
6
|
+
import qualityContract from '../../../../resources/report/json/quality-history-v1.schema.json' with { type: 'json' };
|
|
7
|
+
import { withoutFooter } from './export-site.js';
|
|
8
|
+
const indexMarker = '<meta name="repometry-projects" content="1">';
|
|
9
|
+
const resources = '../../../../resources/viewer/';
|
|
10
|
+
const validator = new Ajv2020();
|
|
11
|
+
const validHistory = validator.compile(historyContract);
|
|
12
|
+
const validQuality = validator.compile(qualityContract);
|
|
13
|
+
export async function exportProjects(directory, { footer = true } = {}) {
|
|
14
|
+
const folders = await readdir(directory, { withFileTypes: true });
|
|
15
|
+
const candidates = folders.filter(entry => (entry.isDirectory() || entry.isSymbolicLink()) && !entry.name.startsWith('.'));
|
|
16
|
+
const entries = (await Promise.all(candidates.map(({ name }) => readProject(directory, name))))
|
|
17
|
+
.filter(entry => entry !== null);
|
|
18
|
+
entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
19
|
+
const marker = await readOptional(join(directory, 'index.html'));
|
|
20
|
+
const files = new Map([
|
|
21
|
+
['styles.css', await readFile(new URL(resources + 'styles.css', import.meta.url))],
|
|
22
|
+
['projects.js', await readFile(new URL('../app/viewer-projects.js', import.meta.url))],
|
|
23
|
+
['projects.json', JSON.stringify({ schema: 'urn:repometry:schema:projects:1', projects: entries }) + '\n'],
|
|
24
|
+
['index.html', await readFile(new URL(resources + 'projects.html', import.meta.url))
|
|
25
|
+
.then(page => footer ? page : Buffer.from(withoutFooter(page.toString('utf8'))))],
|
|
26
|
+
]);
|
|
27
|
+
if (marker !== null && !marker.includes(indexMarker))
|
|
28
|
+
throw new Error('Directory already contains another site index');
|
|
29
|
+
for (const name of files.keys()) {
|
|
30
|
+
try {
|
|
31
|
+
const file = await lstat(join(directory, name));
|
|
32
|
+
if (!file.isFile() || marker === null)
|
|
33
|
+
throw new Error(`Project index would overwrite ${name}`);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!hasCode(error, 'ENOENT'))
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const staging = join(directory, `.projects-${randomUUID()}`);
|
|
41
|
+
await mkdir(staging);
|
|
42
|
+
try {
|
|
43
|
+
for (const [name, contents] of files)
|
|
44
|
+
await writeFile(join(staging, name), contents);
|
|
45
|
+
for (const name of files.keys())
|
|
46
|
+
await rename(join(staging, name), join(directory, name));
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await rm(staging, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
return entries.length;
|
|
52
|
+
}
|
|
53
|
+
async function readProject(directory, name) {
|
|
54
|
+
const path = join(directory, name);
|
|
55
|
+
const text = await readOptional(join(path, 'history.json'));
|
|
56
|
+
if (text === null)
|
|
57
|
+
return null;
|
|
58
|
+
const history = JSON.parse(text);
|
|
59
|
+
if (!validHistory(history))
|
|
60
|
+
return null;
|
|
61
|
+
const inspection = history.reports[0] ?? null;
|
|
62
|
+
const qualityText = inspection && await readOptional(join(path, 'quality-history.json'));
|
|
63
|
+
const quality = qualityText ? JSON.parse(qualityText) : null;
|
|
64
|
+
return { name, inspection, quality: inspection && validQuality(quality)
|
|
65
|
+
? quality.reports[inspection.sha] ?? null : null };
|
|
66
|
+
}
|
|
67
|
+
async function readOptional(path) {
|
|
68
|
+
try {
|
|
69
|
+
return await readFile(path, 'utf8');
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (hasCode(error, 'ENOENT') || hasCode(error, 'ENOTDIR'))
|
|
73
|
+
return null;
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function hasCode(error, code) {
|
|
78
|
+
return error instanceof Error && 'code' in error && error.code === code;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { extname } from 'node:path';
|
|
3
|
+
const contentTypes = new Map([
|
|
4
|
+
['.html', 'text/html; charset=utf-8'], ['.css', 'text/css; charset=utf-8'],
|
|
5
|
+
['.js', 'text/javascript; charset=utf-8'], ['.json', 'application/json; charset=utf-8'],
|
|
6
|
+
['.svg', 'image/svg+xml'],
|
|
7
|
+
]);
|
|
8
|
+
export async function serveAssets(port, asset, cleanup) {
|
|
9
|
+
const handle = async (request, response) => {
|
|
10
|
+
const port = request.socket.localPort;
|
|
11
|
+
const host = request.headers.host?.toLowerCase();
|
|
12
|
+
if (port === undefined || (host !== `127.0.0.1:${port}` && host !== `localhost:${port}` && host !== `[::1]:${port}`)) {
|
|
13
|
+
response.writeHead(403).end();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
17
|
+
response.writeHead(405, { Allow: 'GET, HEAD' }).end();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const path = request.url?.split('?', 1)[0];
|
|
21
|
+
const name = path === '/' ? 'index.html' : path?.startsWith('/') ? path.slice(1) : '';
|
|
22
|
+
let data;
|
|
23
|
+
try {
|
|
24
|
+
data = await asset(name);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
response.writeHead(500).end();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!data) {
|
|
31
|
+
response.writeHead(404).end();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const contentType = name.startsWith('sources/') ? 'text/plain; charset=utf-8'
|
|
35
|
+
: contentTypes.get(extname(name)) ?? 'application/octet-stream';
|
|
36
|
+
response.writeHead(200, {
|
|
37
|
+
'Content-Type': contentType, 'Content-Length': data.length,
|
|
38
|
+
'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff',
|
|
39
|
+
});
|
|
40
|
+
response.end(request.method === 'HEAD' ? undefined : data);
|
|
41
|
+
};
|
|
42
|
+
const server = await listen('127.0.0.1', port, handle);
|
|
43
|
+
const address = server.address();
|
|
44
|
+
if (!address || typeof address === 'string') {
|
|
45
|
+
server.close();
|
|
46
|
+
throw new Error('Cannot determine the viewer address');
|
|
47
|
+
}
|
|
48
|
+
const ipv6 = await listen('::1', address.port, handle).catch((error) => {
|
|
49
|
+
if (error instanceof Error && 'code' in error &&
|
|
50
|
+
(error.code === 'EAFNOSUPPORT' || error.code === 'EADDRNOTAVAIL' || error.code === 'EADDRINUSE'))
|
|
51
|
+
return undefined;
|
|
52
|
+
server.close();
|
|
53
|
+
throw error;
|
|
54
|
+
});
|
|
55
|
+
return { url: `http://127.0.0.1:${address.port}/`, close: () => { cleanup?.(); server.close(); ipv6?.close(); } };
|
|
56
|
+
}
|
|
57
|
+
async function listen(host, port, handle) {
|
|
58
|
+
const server = createServer(handle);
|
|
59
|
+
await new Promise((resolve, reject) => {
|
|
60
|
+
server.once('error', reject);
|
|
61
|
+
server.listen(port, host, () => { server.removeListener('error', reject); resolve(); });
|
|
62
|
+
});
|
|
63
|
+
return server;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceProvider } from '../../../core/ports/source-provider.js';
|
|
2
|
+
export interface SourceAccess {
|
|
3
|
+
readonly read: NonNullable<SourceProvider['read']>;
|
|
4
|
+
readonly close?: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function sourceResponse(name: string, access: SourceAccess | undefined, listed: (revision: string, path: string) => Promise<boolean>): Promise<Uint8Array | undefined>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { validSubjectId } from '../../../core/model/report.js';
|
|
2
|
+
import { isSourcePathname } from '../../../core/ports/source-provider.js';
|
|
3
|
+
export async function sourceResponse(name, access, listed) {
|
|
4
|
+
if (!access)
|
|
5
|
+
return undefined;
|
|
6
|
+
const [prefix, revision, ...segments] = name.split('/');
|
|
7
|
+
if (prefix !== 'sources' || revision === undefined || !validSubjectId('commit', revision))
|
|
8
|
+
return undefined;
|
|
9
|
+
let path;
|
|
10
|
+
try {
|
|
11
|
+
const decoded = segments.map(decodeURIComponent);
|
|
12
|
+
if (decoded.some(part => part.includes('/')))
|
|
13
|
+
return undefined;
|
|
14
|
+
path = decoded.join('/');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
if (!isSourcePathname(path) || !await listed(revision, path))
|
|
20
|
+
return undefined;
|
|
21
|
+
return access.read(revision, path);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=source-route.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PublicHistoryEntry } from '../wire/public-history-model.js';
|
|
2
|
+
import type { Report } from '../validation/report.js';
|
|
3
|
+
import type { CommitSummary, RepositorySummary } from '../wire/summary-model.js';
|
|
4
|
+
export declare function commitSummary(report: Report): CommitSummary;
|
|
5
|
+
export declare function orderSummaries(rows: readonly CommitSummary[]): CommitSummary[];
|
|
6
|
+
export type CommitMetadata = Pick<PublicHistoryEntry, 'subject' | 'author' | 'tags'>;
|
|
7
|
+
export type ReadCommitMetadata = (revisions: readonly string[]) => Promise<ReadonlyMap<string, CommitMetadata>>;
|
|
8
|
+
/** Values recorded at analysis win; Git fills in older inspections and adds tags, which can land after analysis. */
|
|
9
|
+
export declare function withCommitMetadata(rows: readonly CommitSummary[], read?: ReadCommitMetadata): Promise<readonly CommitSummary[]>;
|
|
10
|
+
export declare function expandSummaryCatalog(summary: RepositorySummary): CommitSummary[];
|
|
11
|
+
export declare function repositorySummary(rows: readonly CommitSummary[], pullReviewCount?: number, includePrivateMetrics?: boolean): RepositorySummary;
|
|
12
|
+
export declare function historyEntry(report: Report): PublicHistoryEntry;
|