@preventive/triage 1.0.0-alpha.9 → 1.0.0-alpha.90
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-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +378 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +80 -0
- package/common/default-scan-models.ts +37 -0
- package/common/dependency-reviews.d.ts +19 -0
- package/common/dependency-reviews.js +67 -0
- package/common/finding-duplicates.js +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +3 -0
- package/common/github-issue-labels.js +42 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +15 -0
- package/common/line-diff.js +188 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +48 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +386 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/npm-token.d.ts +2 -0
- package/common/npm-token.js +14 -0
- package/common/pretty-json.js +123 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +7 -0
- package/common/pretty-print.js +41 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-3DOSBILK.js +4 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5PWEAEA5.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-BZJU5EEV.js +1 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CJVMNJDZ.js +3 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-ESXA7KID.js +1 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-HGWFRZNC.js +267 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JZAROLQT.js +40 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-KP2XM324.js +6 -0
- package/out/chunk-LRWB6QVO.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RAM3GDAD.js +1 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SMNFBOLO.js +10 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZTCJVZJ.js +55 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TKPNRQNN.js +3 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-UTYWTUTC.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-WBK5ZN4K.js +3 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-XRAAYXPR.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +35 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -5
- package/out/index.html +105 -25
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -148
- package/package.json +416 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +354 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +568 -0
- package/risk/files/script.js +420 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +309 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +303 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +401 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +52 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +3 -3
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +56 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +269 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +21 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +176 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +387 -0
- package/server-managed/bundle-build.ts +328 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1950 -0
- package/server-managed/db-neon.ts +401 -0
- package/server-managed/db-schema.ts +271 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +150 -0
- package/server-managed/dependabot-access.ts +85 -0
- package/server-managed/dependabot-alerts.ts +197 -0
- package/server-managed/dependency-review-comments.ts +158 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +169 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +218 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +290 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +53 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +6722 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/known-listings.ts +112 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +203 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +274 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +477 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +457 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +310 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +4 -0
- package/server-managed/pretty-format.js +27 -0
- package/server-managed/pretty-print.ts +444 -0
- package/server-managed/public-workspace.ts +242 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +458 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/pulse-walk.ts +164 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +362 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +220 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +444 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +409 -0
- package/server-managed/repository-risk-assess.ts +179 -0
- package/server-managed/repository-risk-audit.ts +145 -0
- package/server-managed/repository-risk-caches.ts +56 -0
- package/server-managed/repository-risk-kept.ts +86 -0
- package/server-managed/repository-risk-read.ts +296 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +528 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +280 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +57 -0
- package/server-managed/team-app.ts +162 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-icons.ts +50 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-progress.ts +77 -0
- package/server-managed/team-reports.ts +369 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +181 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +275 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
// What an open pull request's lockfiles' versions want of review, in a
|
|
2
|
+
// repository that reviews dependencies (repository-dependency-reviews.ts), as
|
|
3
|
+
// its tile and popup show it: each version it adds, whether it passes, by as
|
|
4
|
+
// many reviewers' reviews as the repository requires (`reviews`) or by the
|
|
5
|
+
// reviewed dependencies the host registers (`reviewed`,
|
|
6
|
+
// reviewed-dependencies.ts), or needs none, being among those the
|
|
7
|
+
// repository's lockfiles locked at the commit it is reviewed since
|
|
8
|
+
// (`baseline`); apart from them, the other versions its lockfiles lock that
|
|
9
|
+
// neither passes nor needs none (`unreviewed`); and those that can't be
|
|
10
|
+
// reviewed (`unsupported`), which fail its review, as a lockfile it changes
|
|
11
|
+
// that isn't read does. Without that commit, every version wants its
|
|
12
|
+
// reviews; registered reviewed dependencies replace it.
|
|
13
|
+
//
|
|
14
|
+
// A version is reviewed as npm's registry has it, by its name, version and
|
|
15
|
+
// integrity: one locked of npm's registry, by its name or its link to its
|
|
16
|
+
// tarball (locked-packages.ts), with an integrity. One from git, another
|
|
17
|
+
// tarball (a mirror's too), or with no integrity can't be; a file of the
|
|
18
|
+
// project's isn't. Its reviews are those of it, of an integrity it is locked
|
|
19
|
+
// with, either whole, compared with any version of another package, or
|
|
20
|
+
// compared with a version of its own: for a version the pull request adds,
|
|
21
|
+
// one it was, or the one the host names (`base`, withBases); for another, any. A patched
|
|
22
|
+
// one's (`patch`) are of it as patched, by its patch's hash, its patch read
|
|
23
|
+
// of the repository at its file, which its lockfile names, or which is found
|
|
24
|
+
// where it names it by its hash alone (npm-patch.ts withPatchFiles):
|
|
25
|
+
// compared with the version it patches, where that is one it was, they
|
|
26
|
+
// review the patch alone. Locked so at that commit, its patch too, it needs
|
|
27
|
+
// none.
|
|
28
|
+
// Which versions the repository's lockfiles locked at that commit never
|
|
29
|
+
// changes: it is read once, every lockfile there of those read here
|
|
30
|
+
// (pull-dependencies.ts), and kept by the commit (`baselines` in this
|
|
31
|
+
// instance, `kept` beyond it), never stored as reviews.
|
|
32
|
+
import { lockedAt, lockedIn } from './commit-lockfiles.ts'
|
|
33
|
+
import { GithubApiError } from './github-errors.ts'
|
|
34
|
+
import type { LockedPackage } from './locked-packages.ts'
|
|
35
|
+
import { EVERY_LOCKFILE, type LockfileScope, heldTo, isEvery, reviewedIn } from './lockfile-scope.ts'
|
|
36
|
+
import { type Lru, lru } from './lru.ts'
|
|
37
|
+
import { type AddedPackage, type DirectoryDependencies, type GithubAsked, type LockfileStore, MAX_ADDED, type PullDependencies, lockedAs, lockedWith } from './pull-dependencies.ts'
|
|
38
|
+
import type { DraftReview, PublishedReview, RepoReviewState, ReviewedVersionKey } from './repository-dependency-reviews.ts'
|
|
39
|
+
import { type ReviewedBase, type ReviewedDependencies, type ReviewedDependency, askBases, askReviewed } from './reviewed-dependencies.ts'
|
|
40
|
+
import { reviewBase } from '../common/managed/npm-packages.js'
|
|
41
|
+
|
|
42
|
+
// The other versions told unreviewed, and those told unsupported, of each
|
|
43
|
+
// directory, those past them counted.
|
|
44
|
+
export const MAX_UNREVIEWED = 200
|
|
45
|
+
|
|
46
|
+
// The versions a commit's lockfiles lock, and the lockfiles there that
|
|
47
|
+
// couldn't be read (`unread`), whose versions want reviews all the same.
|
|
48
|
+
export interface Baseline { versions: Set<string>; unread: string[] }
|
|
49
|
+
export interface ReviewBaselineStore {
|
|
50
|
+
read(key: string): Promise<{ versions: string[]; unread: string[] } | null>
|
|
51
|
+
write(key: string, value: { versions: string[]; unread: string[] }): Promise<void>
|
|
52
|
+
}
|
|
53
|
+
const baselines: Lru<Baseline> = lru(500_000, baseline => baseline.versions.size + baseline.unread.length + 1)
|
|
54
|
+
|
|
55
|
+
// Why a version can't be reviewed: from git, of a tarball not npm's
|
|
56
|
+
// registry's of its version, locked with no integrity, or, a Stasis build's
|
|
57
|
+
// (stasis-dependencies.ts), locked by no lockfile read (`unlocked`).
|
|
58
|
+
export type Unsupported = 'git' | 'tarball' | 'integrity' | 'unlocked'
|
|
59
|
+
// How a version is reviewed: by its name, version and integrity
|
|
60
|
+
// (`version`), not at all (`skip`), or why it can't be.
|
|
61
|
+
function reviewedAs(pkg: LockedPackage): 'version' | 'skip' | Unsupported {
|
|
62
|
+
if (pkg.unlocked) return 'unlocked'
|
|
63
|
+
if (pkg.source === 'file') return 'skip'
|
|
64
|
+
if (pkg.source === 'git') return 'git'
|
|
65
|
+
if (pkg.source !== 'registry' || pkg.version === null) return 'tarball'
|
|
66
|
+
return pkg.integrity ? 'version' : 'integrity'
|
|
67
|
+
}
|
|
68
|
+
// The hashes an integrity names, each of which is npm's of it.
|
|
69
|
+
export const hashesOf = (pkg: LockedPackage) => (pkg.integrity ?? '').split(/\s+/u).filter(Boolean)
|
|
70
|
+
// A version as a baseline holds it: its name and version with each hash,
|
|
71
|
+
// and its patch.
|
|
72
|
+
const baselineKeys = (pkg: LockedPackage) => hashesOf(pkg).map(hash => `${pkg.name}@${pkg.version ?? ''}\0${hash}\0${pkg.patchHash ?? ''}`)
|
|
73
|
+
|
|
74
|
+
// The versions the repository's lockfiles locked at commit `since` that are
|
|
75
|
+
// reviewed (reviewedAs), as kept, else read of GitHub (commit-lockfiles.ts,
|
|
76
|
+
// its lockfiles as `reads` keeps them) and kept; with the lockfiles there its
|
|
77
|
+
// reader refuses, isn't one of, or past those read (`unread`). GitHub having
|
|
78
|
+
// none of a lockfile it lists there is a failure of the whole, as of any
|
|
79
|
+
// file, never kept.
|
|
80
|
+
export async function reviewBaseline(fullName: string, token: string, repoId: number, since: string, kept: ReviewBaselineStore, reads: LockfileStore | null = null,
|
|
81
|
+
asked?: GithubAsked): Promise<Baseline> {
|
|
82
|
+
const key = `${repoId}\0${since}`
|
|
83
|
+
const known = baselines.get(key)
|
|
84
|
+
if (known) return known
|
|
85
|
+
const stored = await kept.read(key)
|
|
86
|
+
if (stored) { const baseline = { versions: new Set(stored.versions), unread: stored.unread }; baselines.set(key, baseline); return baseline }
|
|
87
|
+
const read = await lockedAt(fullName, token, since, reads, () => true, asked)
|
|
88
|
+
const versions = new Set(lockedIn(read).packages.filter(pkg => reviewedAs(pkg) === 'version').flatMap(pkg => baselineKeys(pkg)))
|
|
89
|
+
const baseline = { versions, unread: read.unread }
|
|
90
|
+
baselines.set(key, baseline)
|
|
91
|
+
await kept.write(key, { versions: [...versions], unread: read.unread })
|
|
92
|
+
return baseline
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Passing reviews by the version they are of, its name and version.
|
|
96
|
+
type ReviewsOf = Map<string, PublishedReview[]>
|
|
97
|
+
export const reviewsByVersion = (reviews: PublishedReview[]): ReviewsOf => Map.groupBy(reviews, review => `${review.package}@${review.version}`)
|
|
98
|
+
// Of those, `pkg`'s: of its version, of an integrity it is locked with, and
|
|
99
|
+
// of its patch.
|
|
100
|
+
export function reviewsOf(pkg: LockedPackage, reviews: ReviewsOf): PublishedReview[] {
|
|
101
|
+
const hashes = hashesOf(pkg)
|
|
102
|
+
return (reviews.get(`${pkg.name}@${pkg.version}`) ?? []).filter(review => hashes.includes(review.integrity) && (review.patchHash ?? '') === (pkg.patchHash ?? ''))
|
|
103
|
+
}
|
|
104
|
+
// Whether `review` is of `pkg` whole, compared with a version of another
|
|
105
|
+
// package (any), or compared with one of `bases` of its own package (any,
|
|
106
|
+
// for `any`).
|
|
107
|
+
export const comparedWith = (review: PublishedReview, pkg: LockedPackage, bases: string[] | 'any') => review.basePackage === null
|
|
108
|
+
|| review.basePackage !== pkg.name || bases === 'any' || bases.includes(review.baseVersion ?? '')
|
|
109
|
+
|
|
110
|
+
// The latest of `reviews`, some, the first of those as late.
|
|
111
|
+
export const latestOf = (reviews: PublishedReview[]) => reviews.reduce((one, other) => other.time > one.time ? other : one)
|
|
112
|
+
// What a review compares its version with, as one continued from it in a new
|
|
113
|
+
// review does too: none (whole), or a package's version; one a pull
|
|
114
|
+
// request's comments make, which revises no review here, of its comments.
|
|
115
|
+
const comparisonOf = (review: PublishedReview) => review.comment ? '\0comment' : review.basePackage === null ? '' : `${review.basePackage}@${review.baseVersion ?? ''}`
|
|
116
|
+
|
|
117
|
+
export const ACCEPTING = new Set(['accept', 'accept-with-nits'])
|
|
118
|
+
// Where `pkg`'s reviewers stand on it among `reviews`, those of its version,
|
|
119
|
+
// of an integrity it is locked with, and of its patch: each one's latest
|
|
120
|
+
// telling it, whatever it was compared with, any rejecting it holding it
|
|
121
|
+
// unreviewed (`rejected`), any not accepting it holding each of theirs
|
|
122
|
+
// before it; those accepting it passing it (`passing`), each once, by a
|
|
123
|
+
// full, accepting review of theirs, the latest of its comparison, which
|
|
124
|
+
// revises those of it before, whole, compared with another package's
|
|
125
|
+
// version, or compared with one of `bases` of its own (any, for `any`); and
|
|
126
|
+
// how many review it in its pull request's comments alone (`commented`),
|
|
127
|
+
// which count for it alone: whose reviews passing it, else whose latest, are
|
|
128
|
+
// its comments'. Each reviewer too (`reviewers`), by their login, their
|
|
129
|
+
// latest verdict, whether they pass it, and whether that verdict is its
|
|
130
|
+
// comments' (`comment`), which counts for it alone.
|
|
131
|
+
function stancesOf(pkg: LockedPackage, reviews: ReviewsOf, bases: string[] | 'any') {
|
|
132
|
+
const by = Map.groupBy(reviewsOf(pkg, reviews), review => review.reviewer)
|
|
133
|
+
const qualifies = (review: PublishedReview) => review.full && ACCEPTING.has(review.status) && comparedWith(review, pkg, bases)
|
|
134
|
+
let commented = 0, passing = 0, rejected = false
|
|
135
|
+
const reviewers: Reviewer[] = []
|
|
136
|
+
for (const theirs of by.values()) {
|
|
137
|
+
const latest = latestOf(theirs)
|
|
138
|
+
const current = [...Map.groupBy(theirs, comparisonOf).values()].map(latestOf).filter(qualifies)
|
|
139
|
+
const passes = ACCEPTING.has(latest.status) && current.length > 0
|
|
140
|
+
// In its comments alone where those telling where they stand are: those
|
|
141
|
+
// passing it, where they pass it, else their latest.
|
|
142
|
+
const comment = (passes ? current : [latest]).every(review => review.comment)
|
|
143
|
+
if (comment) commented++
|
|
144
|
+
if (latest.status === 'reject') rejected = true
|
|
145
|
+
else if (passes) passing++
|
|
146
|
+
reviewers.push({ login: latest.login, status: latest.status, ...passes ? { passes: true as const } : {}, ...latest.comment ? { comment: true as const } : {} })
|
|
147
|
+
}
|
|
148
|
+
return { passing, rejected, commented, reviewers }
|
|
149
|
+
}
|
|
150
|
+
type Reviewer = { login: string; status: PublishedReview['status']; passes?: true; comment?: true }
|
|
151
|
+
|
|
152
|
+
// A version as the client is told it: what its reviews are held to left
|
|
153
|
+
// out, but its patch, where it is patched (`patch`): its hash, which its
|
|
154
|
+
// reviews are held to, and its file, where its lockfile names one or it
|
|
155
|
+
// was found, from the repository's root, whence its reviews read it.
|
|
156
|
+
type Patch = { hash: string; path?: string }
|
|
157
|
+
function shown<T extends LockedPackage>(pkg: T): Omit<T, 'integrity' | 'shasum' | 'patchHash' | 'patchPath' | 'patchDir' | 'lockfile' | 'unlocked'> & { patch?: Patch } {
|
|
158
|
+
const copy = { ...pkg }
|
|
159
|
+
for (const field of ['integrity', 'shasum', 'patchHash', 'patchPath', 'patchDir', 'lockfile', 'unlocked'] as const) delete copy[field]
|
|
160
|
+
return { ...copy, ...pkg.patchHash ? { patch: { hash: pkg.patchHash, ...pkg.patchPath ? { path: pkg.patchPath } : {} } } : {} }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// A version as the registered reviewed dependencies are asked of it, by
|
|
164
|
+
// what it is asked.
|
|
165
|
+
export function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
|
|
166
|
+
const dependency: ReviewedDependency = { ecosystem: 'npm', lockfile: pkg.lockfile ?? 'npm', name: pkg.name, version: pkg.version ?? '', ...pkg.integrity ? { integrity: pkg.integrity } : {},
|
|
167
|
+
...pkg.shasum ? { shasum: pkg.shasum } : {}, ...pkg.patchHash ? { patchHash: pkg.patchHash } : {} }
|
|
168
|
+
return [JSON.stringify(dependency), dependency]
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// A version's review, and whether it wants one (`wants`), neither passing
|
|
172
|
+
// nor needing none, as only one that can be reviewed may.
|
|
173
|
+
type Review = { unsupported: Unsupported } | { baseline: true } | { reviewed: true } | { reviews: number; rejected?: true; commented?: number; reviewers?: Reviewer[] }
|
|
174
|
+
| Record<string, never>
|
|
175
|
+
// The reader's own latest published review of a version, whether or not it
|
|
176
|
+
// counts (`yours`): its verdict, and whether it is partial.
|
|
177
|
+
type Yours = { status: PublishedReview['status']; partial?: true }
|
|
178
|
+
interface Judged { review: Review; wants: boolean; yours?: Yours }
|
|
179
|
+
type Judge = (pkg: LockedPackage, bases: string[] | 'any') => Judged
|
|
180
|
+
// One of npm's registry locked with no integrity passes where the host's
|
|
181
|
+
// `lookup` passed it as it is (`vouched`, by what it was asked).
|
|
182
|
+
interface Context { state: RepoReviewState; reviews: ReviewsOf; baseline: Set<string> | null; vouched?: Set<string> }
|
|
183
|
+
function judge(pkg: LockedPackage, bases: string[] | 'any', { state, reviews, baseline, vouched }: Context): Judged {
|
|
184
|
+
const as = reviewedAs(pkg)
|
|
185
|
+
if (as === 'skip') return { review: {}, wants: false }
|
|
186
|
+
if (as === 'integrity' && vouched?.has(askedOf(pkg)[0])) return { review: { reviewed: true }, wants: false }
|
|
187
|
+
if (as !== 'version') return { review: { unsupported: as }, wants: false }
|
|
188
|
+
if (baselineKeys(pkg).some(key => baseline?.has(key))) return { review: { baseline: true }, wants: false }
|
|
189
|
+
const { passing, rejected, commented, reviewers } = stancesOf(pkg, reviews, bases)
|
|
190
|
+
const told = { reviews: passing, ...commented > 0 ? { commented } : {}, ...reviewers.length > 0 ? { reviewers } : {} }
|
|
191
|
+
if (rejected) return { review: { ...told, rejected: true }, wants: true }
|
|
192
|
+
return { review: told, wants: passing < state.required }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// The versions of a directory's rows that want reviews, each way it is locked.
|
|
196
|
+
const wanted = (rows: { wanting: LockedPackage[] }[]) => rows.flatMap(({ wanting }) => wanting.map(shown))
|
|
197
|
+
// The reader's own draft of a version (`pkg`, as it is locked), against the
|
|
198
|
+
// version its row is reviewed against (`base`, reviewBase, null for its whole
|
|
199
|
+
// package's): how many files it gives a verdict; none where they have none.
|
|
200
|
+
type Drafted = (pkg: LockedPackage, base: { name: string; version: string } | null) => { checked: number } | null
|
|
201
|
+
// How a directory is told (reviewedDirectory): read without its base
|
|
202
|
+
// (`baseless`); those of npm's registry locked with no integrity that
|
|
203
|
+
// `lookup` passed (`vouched`); each version it adds with the reader's draft
|
|
204
|
+
// of it (`drafted`), against its base as the host names it (`namedBases`),
|
|
205
|
+
// else as it was; and only those the reader didn't review (`remaining`).
|
|
206
|
+
interface Telling { baseless?: boolean; vouched?: Set<string>; drafted?: Drafted | null; namedBases?: boolean; remaining?: boolean }
|
|
207
|
+
// A directory as the client is told it: what it adds, as many as MAX_ADDED,
|
|
208
|
+
// each version with its review (`review`, as judged), those past them judged
|
|
209
|
+
// as they are, against the versions they were, as is every one its lockfiles
|
|
210
|
+
// lock of them (another integrity of it, say), each told by the least passing
|
|
211
|
+
// of them, and those of all that want one (`toReview`); the others its lockfiles lock that want reviews, and every one
|
|
212
|
+
// that can't be reviewed (as many of each as MAX_UNREVIEWED, how many more,
|
|
213
|
+
// once `capped`); and how many it locks past those read (`moreLocked`), which
|
|
214
|
+
// aren't checked; without `review`, what it adds alone. Read without its
|
|
215
|
+
// base (`baseless`), it tells only those it adds that pass none, or pass by
|
|
216
|
+
// its comments alone, which the host doesn't take in till it is merged.
|
|
217
|
+
// Each it adds is told the reader's draft of it (`draft`, where `drafted`
|
|
218
|
+
// finds one); where `remaining`, those the reader reviewed (`yours`) are
|
|
219
|
+
// left out of what it adds before they are cut to MAX_ADDED, and counted
|
|
220
|
+
// in `more` no more, nor among those its review wants (`remainingToReview`,
|
|
221
|
+
// told in place of `toReview`, which still holds them all for Stasis).
|
|
222
|
+
function reviewedDirectory(dir: DirectoryDependencies, review: Judge | null,
|
|
223
|
+
{ baseless = false, vouched = new Set(), drafted = null, namedBases = false, remaining = false }: Telling = {}) {
|
|
224
|
+
if ('error' in dir) return dir
|
|
225
|
+
const { locked, moreLocked, added, ...told } = dir
|
|
226
|
+
if (!review) return { ...told, added: baseless ? [] : added.slice(0, MAX_ADDED).map(shown), ...baseless ? { more: 0 } : {} }
|
|
227
|
+
const adds = new Map(added.map(pkg => [lockedAs(pkg), { pkg, variants: [pkg] }]))
|
|
228
|
+
for (const pkg of locked) {
|
|
229
|
+
const of = adds.get(lockedAs(pkg))
|
|
230
|
+
if (of && lockedWith(pkg) !== lockedWith(of.pkg)) of.variants.push(pkg)
|
|
231
|
+
}
|
|
232
|
+
const own = [...adds.values()].map(({ pkg, variants }) => {
|
|
233
|
+
const judged = variants.map(variant => ({ variant, ...review(variant, basesOf(pkg, (variant as AddedPackage).base ?? null)) }))
|
|
234
|
+
const least = judged.find(one => 'unsupported' in one.review) ?? judged.find(one => one.wants) ?? judged[0]!
|
|
235
|
+
return { pkg, judged: least, wanting: judged.filter(one => one.wants).map(({ variant }) => variant) }
|
|
236
|
+
})
|
|
237
|
+
const others = locked.filter(pkg => !adds.has(lockedAs(pkg))).map(pkg => ({ pkg, judged: review(pkg, 'any') }))
|
|
238
|
+
const unsupported = locked.flatMap(pkg => {
|
|
239
|
+
const as = reviewedAs(pkg)
|
|
240
|
+
return as === 'version' || as === 'skip' || (as === 'integrity' && vouched.has(askedOf(pkg)[0])) ? [] : [{ ...shown(pkg), unsupported: as }]
|
|
241
|
+
})
|
|
242
|
+
const kept = baseless ? own.filter(({ judged }) => judged.wants || 'unsupported' in judged.review || 'commented' in judged.review) : own
|
|
243
|
+
const listed = remaining ? kept.filter(({ judged }) => !judged.yours) : kept
|
|
244
|
+
// Those it adds past those it holds (as many as MAX_LOCKED), never judged here.
|
|
245
|
+
const past = baseless || told.more === 0 ? 0 : Math.max(0, told.more + MAX_ADDED - added.length)
|
|
246
|
+
// Each row against the base of the way it is locked that it is told by,
|
|
247
|
+
// with the reader's draft of it against that base.
|
|
248
|
+
const row = ({ pkg, judged }: (typeof own)[number]) => {
|
|
249
|
+
const { base: _base, ...rest } = shown(pkg as AddedPackage), { base } = judged.variant as AddedPackage
|
|
250
|
+
const version = { ...rest, ...base ? { base } : {} }
|
|
251
|
+
const draft = drafted?.(judged.variant, reviewBase(version, { reviewedBases: namedBases }))
|
|
252
|
+
return { ...version, ...judged.review, ...judged.yours ? { yours: judged.yours } : {}, ...draft ? { draft } : {} }
|
|
253
|
+
}
|
|
254
|
+
return { ...told, ...baseless || remaining ? { more: Math.max(0, listed.length - MAX_ADDED) + past } : {}, added: listed.slice(0, MAX_ADDED).map(row),
|
|
255
|
+
toReview: wanted(own), ...remaining ? { remainingToReview: wanted(listed) } : {},
|
|
256
|
+
unreviewed: others.filter(({ judged }) => judged.wants).map(({ pkg, judged }) => ({ ...shown(pkg), ...judged.review, ...judged.yours ? { yours: judged.yours } : {} })),
|
|
257
|
+
unsupported, moreLocked }
|
|
258
|
+
}
|
|
259
|
+
function capped<T extends { toReview: unknown[]; remainingToReview?: unknown[]; unreviewed: unknown[]; unsupported: unknown[] }>({ toReview: _toReview,
|
|
260
|
+
remainingToReview: _remaining, ...dir }: T) {
|
|
261
|
+
return { ...dir, unreviewed: dir.unreviewed.slice(0, MAX_UNREVIEWED), moreUnreviewed: Math.max(0, dir.unreviewed.length - MAX_UNREVIEWED),
|
|
262
|
+
unsupported: dir.unsupported.slice(0, MAX_UNREVIEWED), moreUnsupported: Math.max(0, dir.unsupported.length - MAX_UNREVIEWED) }
|
|
263
|
+
}
|
|
264
|
+
// How many versions of `lists` there are, each once across them, by `key`,
|
|
265
|
+
// as the client tells them once: one wanting reviews by its name and
|
|
266
|
+
// version, and its patch's hash, as each patch of it is reviewed apart; one
|
|
267
|
+
// that can't be reviewed by where it is from too.
|
|
268
|
+
type Shown = Pick<LockedPackage, 'name' | 'version' | 'source' | 'from'> & { patch?: Patch }
|
|
269
|
+
const distinct = (lists: Shown[][], key: (pkg: Shown) => string) => new Set(lists.flat().map(key)).size
|
|
270
|
+
const versionKey = (pkg: Shown) => `${pkg.name}@${pkg.version ?? ''}\0${pkg.patch?.hash ?? ''}`
|
|
271
|
+
const sourceKey = (pkg: Shown) => `${pkg.source}\0${pkg.name}@${pkg.version ?? ''}\0${pkg.from ?? ''}`
|
|
272
|
+
|
|
273
|
+
// The versions of its package an added version's reviews may be compared
|
|
274
|
+
// with: those it was, and the base the host names it (null for none).
|
|
275
|
+
export const basesOf = (pkg: AddedPackage, base: ReviewedBase | null | undefined = pkg.base) => [...pkg.was ?? [], ...base?.name === pkg.name ? [base.version] : []]
|
|
276
|
+
// `dirs`, each version of `asking` as it is locked with the version `base`
|
|
277
|
+
// names to review it against (`base`, of its package or another), its row's
|
|
278
|
+
// link and line count then against that one, and its reviews against it
|
|
279
|
+
// passing it; each named onto `named` too, by what it is asked.
|
|
280
|
+
async function withBases(dirs: DirectoryDependencies[], base: NonNullable<ReviewedDependencies['base']>, asking: Map<string, ReviewedDependency>,
|
|
281
|
+
named: Map<string, ReviewedBase>): Promise<DirectoryDependencies[]> {
|
|
282
|
+
for (const [key, one] of asking.size > 0 ? await askBases(base, asking) : []) named.set(key, one)
|
|
283
|
+
const based = <P extends LockedPackage>(pkg: P) => { const one = named.get(askedOf(pkg)[0]); return one ? { ...pkg, base: one } : pkg }
|
|
284
|
+
return dirs.map(dir => 'error' in dir ? dir : { ...dir, added: dir.added.map(based), locked: dir.locked.map(based) })
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// The reviews an open pull request's comments make of `wanting`, the
|
|
288
|
+
// versions still wanting one (pull-comment-reviews.ts): those that count,
|
|
289
|
+
// and whether they couldn't be read.
|
|
290
|
+
export type CommentReviews = (wanting: ReviewedDependency[]) => Promise<{ reviews: PublishedReview[]; failed: boolean }>
|
|
291
|
+
|
|
292
|
+
// What a pull request's lockfiles lock, but in directories none of whose
|
|
293
|
+
// lockfiles `scope` holds to, as they aren't reviewed: left out, as lockfiles
|
|
294
|
+
// left unread are where it holds to none of them (`omitted`, told to none).
|
|
295
|
+
export function heldDependencies<T extends PullDependencies>(told: T, scope: LockfileScope): Omit<T, 'omitted'> {
|
|
296
|
+
const { omitted, ...answered } = told
|
|
297
|
+
if (isEvery(scope)) return answered
|
|
298
|
+
return { ...answered, cut: told.cut && !(omitted && !omitted.some(path => heldTo(scope, path))), lockfiles: told.lockfiles.filter(dir => reviewedIn(scope, dir.paths)) }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// A pull request's dependencies as the client is told them: without the
|
|
302
|
+
// versions its directories lock; with `state`, a repository's review in
|
|
303
|
+
// effect, each version's review (reviewedDirectory), with `user`'s own
|
|
304
|
+
// latest published review of it, whether it counts or not (`yours`), those wanting one asked
|
|
305
|
+
// of the registered reviewed dependencies (`reviewed`), those they don't pass
|
|
306
|
+
// of their `base` (onto `namedBases`), and those still
|
|
307
|
+
// wanting one of the reviews its comments make (`commentReviews`, where the
|
|
308
|
+
// host reads them), and the review's terms (`review`), with how many
|
|
309
|
+
// reviewers' its comments count (`commentReviews`), or that they couldn't be
|
|
310
|
+
// read (`commentsFailed`), and that reviews count by comments alone, those
|
|
311
|
+
// published here not (`byComments`, where the host reads them), and that
|
|
312
|
+
// they name bases (`reviewedBases`), and how many versions across its directories want
|
|
313
|
+
// reviews, of those it adds (`toReview`, and onto `wantedIn`, each
|
|
314
|
+
// directory's by its paths, all of them, not those told alone) and the rest
|
|
315
|
+
// (`unreviewed`), and can't be reviewed (`unsupported`), each once; how many the reviewed dependencies failed to
|
|
316
|
+
// answer (`unasked`), and whether they are registered (`reviewedDependencies`,
|
|
317
|
+
// the commit reviewed since then none); and where the baseline couldn't be
|
|
318
|
+
// read, why (`baselineError`), every version then wanting its reviews, or
|
|
319
|
+
// the lockfiles there left unread (`baselineUnread`), whose versions do. It
|
|
320
|
+
// fails where a version can't be reviewed, a directory's lockfiles couldn't
|
|
321
|
+
// be read or lock more than are checked, or the pull request changes more
|
|
322
|
+
// lockfiles than are read (`cut`). Those of directories none of whose
|
|
323
|
+
// lockfiles the review holds to (`lockfiles`, lockfile-scope.ts, told in its
|
|
324
|
+
// terms where not every one) are left out (heldDependencies).
|
|
325
|
+
// Where `drafts` reads `user`'s own drafts (listOwnDraftReviews), and they
|
|
326
|
+
// publish to a team counting for the repository, each version it adds is
|
|
327
|
+
// told theirs against the version its row reviews it against (`draft`,
|
|
328
|
+
// reviewBase), as a page reviewing them together continues it, all read
|
|
329
|
+
// at once rather than as each version opens. Where `remaining`, those it
|
|
330
|
+
// adds that `user` reviewed (`yours`) are left out (reviewedDirectory), and
|
|
331
|
+
// of how many want reviews (`toReview`), as that page tells what is left.
|
|
332
|
+
export async function reviewedDependencies(told: PullDependencies, state: RepoReviewState | null,
|
|
333
|
+
{ baseline = null, baselineUnread = [], baselineError = null, reviewed = null, commentReviews = null, namedBases = new Map(), wantedIn = new Map(), user = null,
|
|
334
|
+
drafts = null, remaining = false }: {
|
|
335
|
+
baseline?: Set<string> | null; baselineUnread?: string[]; baselineError?: string | null; reviewed?: ReviewedDependencies | null; commentReviews?: CommentReviews | null
|
|
336
|
+
namedBases?: Map<string, ReviewedBase>; wantedIn?: Map<string[], number>; user?: string | null
|
|
337
|
+
drafts?: ((versions: ReviewedVersionKey[]) => Promise<DraftReview[]>) | null; remaining?: boolean } = {}) {
|
|
338
|
+
const scope = state?.lockfiles ?? EVERY_LOCKFILE
|
|
339
|
+
const answered = heldDependencies(told, scope)
|
|
340
|
+
const baseless = told.baseless === true
|
|
341
|
+
if (!state) return { ...answered, lockfiles: answered.lockfiles.map(dir => reviewedDirectory(dir, null, { baseless })) }
|
|
342
|
+
const { cut } = answered
|
|
343
|
+
let held = answered.lockfiles
|
|
344
|
+
// Reviews published here count but where the host reads those pull
|
|
345
|
+
// requests' comments make (`parseComments`): what is reviewed is then the
|
|
346
|
+
// host's to tell, by those and its `lookup`, and one published here counts
|
|
347
|
+
// for nothing, whatever it was compared with: of a pull request's versions,
|
|
348
|
+
// a default branch's or a bundle's. Its author still copies it as a comment.
|
|
349
|
+
const published = reviewed?.parseComments ? [] : state.reviews
|
|
350
|
+
// Each of npm's registry locked with no integrity, which can't be reviewed
|
|
351
|
+
// here, asked of `lookup` as it is, which may pass it all the same.
|
|
352
|
+
const integrityless = new Map(reviewed ? held.flatMap(dir => 'error' in dir ? [] : [...dir.added, ...dir.locked]).filter(pkg => reviewedAs(pkg) === 'integrity').map(askedOf) : [])
|
|
353
|
+
const vouching = integrityless.size > 0 && reviewed ? await askReviewed(reviewed.lookup, integrityless) : { passed: new Set<string>(), unasked: 0 }
|
|
354
|
+
let context = { state, reviews: reviewsByVersion(published), baseline: reviewed ? null : baseline, vouched: vouching.passed }
|
|
355
|
+
// What wants a review, as `lookup` is asked of, each once.
|
|
356
|
+
const wanting = () => {
|
|
357
|
+
const asked = new Map<string, ReviewedDependency>()
|
|
358
|
+
const asking: Judge = (pkg, bases) => {
|
|
359
|
+
const judged = judge(pkg, bases, context)
|
|
360
|
+
if (judged.wants) asked.set(...askedOf(pkg))
|
|
361
|
+
return judged
|
|
362
|
+
}
|
|
363
|
+
for (const dir of held) reviewedDirectory(dir, asking)
|
|
364
|
+
return asked
|
|
365
|
+
}
|
|
366
|
+
const passed = new Set<string>()
|
|
367
|
+
let unasked = vouching.unasked
|
|
368
|
+
const ask = async (asked: Map<string, ReviewedDependency>) => {
|
|
369
|
+
const answer = asked.size > 0 && reviewed ? await askReviewed(reviewed.lookup, asked) : { passed: new Set<string>(), unasked: 0 }
|
|
370
|
+
for (const key of answer.passed) passed.add(key)
|
|
371
|
+
unasked += answer.unasked
|
|
372
|
+
}
|
|
373
|
+
const asked = wanting()
|
|
374
|
+
await ask(asked)
|
|
375
|
+
const parsing = new Map([...asked].filter(([key]) => !passed.has(key)))
|
|
376
|
+
// Those `lookup` doesn't pass against the bases the host names them.
|
|
377
|
+
if (reviewed?.base) held = await withBases(held, reviewed.base, parsing, namedBases)
|
|
378
|
+
// Of those still wanting one, and every other one the lockfiles it holds
|
|
379
|
+
// to add that its teams' reviews pass, telling other pull requests those
|
|
380
|
+
// it reviews (`commented`), but those `lookup` passes, reviewed, the
|
|
381
|
+
// reviews its comments make, an open one's alone (pull-comment-reviews.ts),
|
|
382
|
+
// which count as its teams' do; those their rejects hold asked of `lookup`
|
|
383
|
+
// too.
|
|
384
|
+
if (commentReviews) {
|
|
385
|
+
const others = new Map<string, ReviewedDependency>()
|
|
386
|
+
for (const pkg of held.flatMap(dir => 'added' in dir ? dir.added : [])) {
|
|
387
|
+
const [key, dependency] = askedOf(pkg)
|
|
388
|
+
if (!asked.has(key) && 'reviews' in judge(pkg, basesOf(pkg), context).review) others.set(key, dependency)
|
|
389
|
+
}
|
|
390
|
+
const vouched = others.size > 0 && reviewed ? (await askReviewed(reviewed.lookup, others)).passed : new Set<string>()
|
|
391
|
+
for (const [key, dependency] of others) if (!vouched.has(key)) parsing.set(key, dependency)
|
|
392
|
+
}
|
|
393
|
+
const comments = parsing.size > 0 && commentReviews ? await commentReviews([...parsing.values()]) : { reviews: [], failed: false }
|
|
394
|
+
if (comments.reviews.length > 0) {
|
|
395
|
+
context = { ...context, reviews: reviewsByVersion([...published, ...comments.reviews.map(review => ({ ...review, comment: true as const }))]) }
|
|
396
|
+
await ask(new Map([...wanting()].filter(([key]) => !asked.has(key))))
|
|
397
|
+
}
|
|
398
|
+
// `user`'s own published reviews, each version told its latest of them
|
|
399
|
+
// whatever it was compared with, and whether or not it counts: one they
|
|
400
|
+
// reviewed that wants reviews still, others' or the host's, is labelled
|
|
401
|
+
// theirs.
|
|
402
|
+
const mine = reviewsByVersion(user ? state.reviews.filter(review => review.id !== undefined && review.reviewer === user) : [])
|
|
403
|
+
const yours = (pkg: LockedPackage) => {
|
|
404
|
+
const latest = reviewsOf(pkg, mine).reduce<PublishedReview | null>((one, other) => one && one.time >= other.time ? one : other, null)
|
|
405
|
+
return latest ? { yours: { status: latest.status, ...latest.full ? {} : { partial: true as const } } } : {}
|
|
406
|
+
}
|
|
407
|
+
const drafted = await draftedIn(held, user && state.canReview ? drafts : null)
|
|
408
|
+
const dirs = held.map(dir => reviewedDirectory(dir, (pkg, bases) => {
|
|
409
|
+
const judged = judge(pkg, bases, context)
|
|
410
|
+
return { ...judged.wants && passed.has(askedOf(pkg)[0]) ? { review: { reviewed: true as const }, wants: false } : judged, ...yours(pkg) }
|
|
411
|
+
}, { baseless, vouched: vouching.passed, drafted, namedBases: Boolean(reviewed?.base), remaining }))
|
|
412
|
+
const unread = baselineUnread.filter(path => heldTo(scope, path))
|
|
413
|
+
const listed = dirs.filter(dir => 'unreviewed' in dir)
|
|
414
|
+
for (const dir of listed) wantedIn.set(dir.paths, distinct([dir.toReview], versionKey))
|
|
415
|
+
return { ...answered, cut, lockfiles: dirs.map(dir => 'unreviewed' in dir ? capped(dir) : dir), review: { required: state.required,
|
|
416
|
+
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {}, ...reviewed?.base ? { reviewedBases: true } : {},
|
|
417
|
+
...reviewed?.parseComments ? { byComments: true } : {},
|
|
418
|
+
toReview: distinct(listed.map(dir => dir.remainingToReview ?? dir.toReview), versionKey), unreviewed: distinct(listed.map(dir => dir.unreviewed), versionKey),
|
|
419
|
+
unsupported: distinct(listed.map(dir => dir.unsupported), sourceKey),
|
|
420
|
+
...unasked > 0 ? { unasked } : {}, ...baselineError && !reviewed ? { baselineError } : {},
|
|
421
|
+
...comments.reviews.length > 0 ? { commentReviews: new Set(comments.reviews.map(review => review.reviewer)).size } : {}, ...comments.failed ? { commentsFailed: true } : {},
|
|
422
|
+
...unread.length > 0 && !reviewed ? { baselineUnread: unread.slice(0, MAX_UNREVIEWED) } : {}, ...isEvery(scope) ? {} : { lockfiles: scope } } }
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// The reader's own drafts of the versions `dirs` add, as `drafts` reads them
|
|
426
|
+
// (none where it is none), all at once: each version's of its integrity and
|
|
427
|
+
// patch, against the base its row reviews it against (Drafted).
|
|
428
|
+
async function draftedIn(dirs: DirectoryDependencies[], drafts: ((versions: ReviewedVersionKey[]) => Promise<DraftReview[]>) | null): Promise<Drafted> {
|
|
429
|
+
const adding = dirs.flatMap(dir => 'error' in dir ? [] : dir.added.filter(pkg => reviewedAs(pkg) === 'version'))
|
|
430
|
+
const asked = [...new Map(adding.map(pkg => [`${pkg.name}@${pkg.version}`, { name: pkg.name, version: pkg.version! }])).values()]
|
|
431
|
+
const own = Map.groupBy(drafts && asked.length > 0 ? await drafts(asked) : [], draft => `${draft.package}@${draft.version}`)
|
|
432
|
+
return (pkg, base) => {
|
|
433
|
+
const hashes = hashesOf(pkg)
|
|
434
|
+
const draft = own.get(`${pkg.name}@${pkg.version}`)?.find(one => hashes.includes(one.integrity) && (one.patchHash ?? '') === (pkg.patchHash ?? '')
|
|
435
|
+
&& one.basePackage === (base?.name ?? null) && one.baseVersion === (base?.version ?? null))
|
|
436
|
+
return draft ? { checked: draft.checked } : null
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// The package versions a pull request's lockfiles lock that its reviews here
|
|
441
|
+
// may pass, whose reviews are asked: those that can be reviewed.
|
|
442
|
+
export const reviewedPackages = (told: PullDependencies) => told.lockfiles
|
|
443
|
+
.flatMap(dir => 'error' in dir ? [] : dir.locked.filter(pkg => reviewedAs(pkg) === 'version').map(pkg => ({ name: pkg.name, version: pkg.version! })))
|
|
444
|
+
|
|
445
|
+
// A repository's baseline as read for a pull request: its versions and the
|
|
446
|
+
// lockfiles there left unread; none where it reviews since no commit; and
|
|
447
|
+
// where GitHub doesn't read it, none and why.
|
|
448
|
+
export async function baselineFor(fullName: string, token: string, repoId: number, state: RepoReviewState, kept: ReviewBaselineStore, reads: LockfileStore | null,
|
|
449
|
+
asked?: GithubAsked) {
|
|
450
|
+
if (!state.since) return { baseline: null, unread: [], error: null }
|
|
451
|
+
try {
|
|
452
|
+
const { versions, unread } = await reviewBaseline(fullName, token, repoId, state.since, kept, reads, asked)
|
|
453
|
+
return { baseline: versions, unread, error: null }
|
|
454
|
+
} catch (err) {
|
|
455
|
+
if (err instanceof GithubApiError && err.status !== 429 && err.status !== 401) return { baseline: null, unread: [], error: err.message }
|
|
456
|
+
throw err
|
|
457
|
+
}
|
|
458
|
+
}
|