@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80
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 +377 -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 +66 -0
- package/common/default-scan-models.ts +36 -0
- package/common/dependency-reviews.d.ts +18 -0
- package/common/dependency-reviews.js +64 -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 +1 -0
- package/common/github-issue-labels.js +11 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +14 -0
- package/common/line-diff.js +181 -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 +41 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +385 -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/pretty-json.js +98 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +6 -0
- package/common/pretty-print.js +36 -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/save-error-reason.ts +20 -7
- 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-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5CJKUV53.js +1 -0
- package/out/chunk-5EAVJAD2.js +3 -0
- package/out/chunk-5M2X3QPK.js +6 -0
- package/out/chunk-5QWPKTCE.js +40 -0
- package/out/chunk-6CCSTJWB.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-7YO4QV5P.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-C4Z6ZBXV.js +10 -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-DUS5ARE2.js +53 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GBMAXAYK.js +3 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-ITUKKCCK.js +10 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JXBRWLMA.js +4 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-LBD3M3J6.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-MV66NL3G.js +3 -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-OWSEQOL5.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-PTFYDJUP.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-RPNO56H2.js +1 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZWPYLPC.js +1 -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-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-VZPPX6MV.js +1 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-YKCRCNYZ.js +266 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +37 -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 -4
- package/out/index.html +104 -24
- 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 -147
- package/package.json +409 -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 +341 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +563 -0
- package/risk/files/script.js +402 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +294 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +285 -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 +393 -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 +50 -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 +60 -33
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +247 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +13 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +79 -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 +380 -0
- package/server-managed/bundle-build.ts +326 -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 +1914 -0
- package/server-managed/db-neon.ts +398 -0
- package/server-managed/db-schema.ts +263 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +149 -0
- package/server-managed/dependabot-access.ts +61 -0
- package/server-managed/dependabot-alerts.ts +180 -0
- package/server-managed/dependency-review-comments.ts +143 -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 +157 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +257 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +30 -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 +6324 -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/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 +142 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +265 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +469 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +455 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +287 -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 +3 -0
- package/server-managed/pretty-format.js +13 -0
- package/server-managed/pretty-print.ts +442 -0
- package/server-managed/public-workspace.ts +243 -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 +407 -0
- package/server-managed/pull-reviews.ts +202 -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 +361 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +182 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +428 -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 +477 -0
- package/server-managed/repository-risk-assess.ts +108 -0
- package/server-managed/repository-risk-audit.ts +78 -0
- package/server-managed/repository-risk-caches.ts +37 -0
- package/server-managed/repository-risk-read.ts +260 -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 +516 -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 +221 -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 +56 -0
- package/server-managed/team-app.ts +156 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-reports.ts +368 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +161 -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 +256 -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,407 @@
|
|
|
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 { PublishedReview, RepoReviewState } from './repository-dependency-reviews.ts'
|
|
39
|
+
import { type ReviewedBase, type ReviewedDependencies, type ReviewedDependency, askBases, askReviewed } from './reviewed-dependencies.ts'
|
|
40
|
+
|
|
41
|
+
// The other versions told unreviewed, and those told unsupported, of each
|
|
42
|
+
// directory, those past them counted.
|
|
43
|
+
export const MAX_UNREVIEWED = 200
|
|
44
|
+
|
|
45
|
+
// The versions a commit's lockfiles lock, and the lockfiles there that
|
|
46
|
+
// couldn't be read (`unread`), whose versions want reviews all the same.
|
|
47
|
+
export interface Baseline { versions: Set<string>; unread: string[] }
|
|
48
|
+
export interface ReviewBaselineStore {
|
|
49
|
+
read(key: string): Promise<{ versions: string[]; unread: string[] } | null>
|
|
50
|
+
write(key: string, value: { versions: string[]; unread: string[] }): Promise<void>
|
|
51
|
+
}
|
|
52
|
+
const baselines: Lru<Baseline> = lru(500_000, baseline => baseline.versions.size + baseline.unread.length + 1)
|
|
53
|
+
|
|
54
|
+
// Why a version can't be reviewed: from git, of a tarball not npm's
|
|
55
|
+
// registry's of its version, locked with no integrity, or, a Stasis build's
|
|
56
|
+
// (stasis-dependencies.ts), locked by no lockfile read (`unlocked`).
|
|
57
|
+
export type Unsupported = 'git' | 'tarball' | 'integrity' | 'unlocked'
|
|
58
|
+
// How a version is reviewed: by its name, version and integrity
|
|
59
|
+
// (`version`), not at all (`skip`), or why it can't be.
|
|
60
|
+
function reviewedAs(pkg: LockedPackage): 'version' | 'skip' | Unsupported {
|
|
61
|
+
if (pkg.unlocked) return 'unlocked'
|
|
62
|
+
if (pkg.source === 'file') return 'skip'
|
|
63
|
+
if (pkg.source === 'git') return 'git'
|
|
64
|
+
if (pkg.source !== 'registry' || pkg.version === null) return 'tarball'
|
|
65
|
+
return pkg.integrity ? 'version' : 'integrity'
|
|
66
|
+
}
|
|
67
|
+
// The hashes an integrity names, each of which is npm's of it.
|
|
68
|
+
export const hashesOf = (pkg: LockedPackage) => (pkg.integrity ?? '').split(/\s+/u).filter(Boolean)
|
|
69
|
+
// A version as a baseline holds it: its name and version with each hash,
|
|
70
|
+
// and its patch.
|
|
71
|
+
const baselineKeys = (pkg: LockedPackage) => hashesOf(pkg).map(hash => `${pkg.name}@${pkg.version ?? ''}\0${hash}\0${pkg.patchHash ?? ''}`)
|
|
72
|
+
|
|
73
|
+
// The versions the repository's lockfiles locked at commit `since` that are
|
|
74
|
+
// reviewed (reviewedAs), as kept, else read of GitHub (commit-lockfiles.ts,
|
|
75
|
+
// its lockfiles as `reads` keeps them) and kept; with the lockfiles there its
|
|
76
|
+
// reader refuses, isn't one of, or past those read (`unread`). GitHub having
|
|
77
|
+
// none of a lockfile it lists there is a failure of the whole, as of any
|
|
78
|
+
// file, never kept.
|
|
79
|
+
export async function reviewBaseline(fullName: string, token: string, repoId: number, since: string, kept: ReviewBaselineStore, reads: LockfileStore | null = null,
|
|
80
|
+
asked?: GithubAsked): Promise<Baseline> {
|
|
81
|
+
const key = `${repoId}\0${since}`
|
|
82
|
+
const known = baselines.get(key)
|
|
83
|
+
if (known) return known
|
|
84
|
+
const stored = await kept.read(key)
|
|
85
|
+
if (stored) { const baseline = { versions: new Set(stored.versions), unread: stored.unread }; baselines.set(key, baseline); return baseline }
|
|
86
|
+
const read = await lockedAt(fullName, token, since, reads, () => true, asked)
|
|
87
|
+
const versions = new Set(lockedIn(read).packages.filter(pkg => reviewedAs(pkg) === 'version').flatMap(pkg => baselineKeys(pkg)))
|
|
88
|
+
const baseline = { versions, unread: read.unread }
|
|
89
|
+
baselines.set(key, baseline)
|
|
90
|
+
await kept.write(key, { versions: [...versions], unread: read.unread })
|
|
91
|
+
return baseline
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Passing reviews by the version they are of, its name and version.
|
|
95
|
+
type ReviewsOf = Map<string, PublishedReview[]>
|
|
96
|
+
export const reviewsByVersion = (reviews: PublishedReview[]): ReviewsOf => Map.groupBy(reviews, review => `${review.package}@${review.version}`)
|
|
97
|
+
// Of those, `pkg`'s: of its version, of an integrity it is locked with, and
|
|
98
|
+
// of its patch.
|
|
99
|
+
export function reviewsOf(pkg: LockedPackage, reviews: ReviewsOf): PublishedReview[] {
|
|
100
|
+
const hashes = hashesOf(pkg)
|
|
101
|
+
return (reviews.get(`${pkg.name}@${pkg.version}`) ?? []).filter(review => hashes.includes(review.integrity) && (review.patchHash ?? '') === (pkg.patchHash ?? ''))
|
|
102
|
+
}
|
|
103
|
+
// Whether `review` is of `pkg` whole, compared with a version of another
|
|
104
|
+
// package (any), or compared with one of `bases` of its own package (any,
|
|
105
|
+
// for `any`).
|
|
106
|
+
export const comparedWith = (review: PublishedReview, pkg: LockedPackage, bases: string[] | 'any') => review.basePackage === null
|
|
107
|
+
|| review.basePackage !== pkg.name || bases === 'any' || bases.includes(review.baseVersion ?? '')
|
|
108
|
+
|
|
109
|
+
// The latest of `reviews`, some, the first of those as late.
|
|
110
|
+
export const latestOf = (reviews: PublishedReview[]) => reviews.reduce((one, other) => other.time > one.time ? other : one)
|
|
111
|
+
// What a review compares its version with, as one continued from it in a new
|
|
112
|
+
// review does too: none (whole), or a package's version; one a pull
|
|
113
|
+
// request's comments make, which revises no review here, of its comments.
|
|
114
|
+
const comparisonOf = (review: PublishedReview) => review.comment ? '\0comment' : review.basePackage === null ? '' : `${review.basePackage}@${review.baseVersion ?? ''}`
|
|
115
|
+
|
|
116
|
+
export const ACCEPTING = new Set(['accept', 'accept-with-nits'])
|
|
117
|
+
// Where `pkg`'s reviewers stand on it among `reviews`, those of its version,
|
|
118
|
+
// of an integrity it is locked with, and of its patch: each one's latest
|
|
119
|
+
// telling it, whatever it was compared with, any rejecting it holding it
|
|
120
|
+
// unreviewed (`rejected`), any not accepting it holding each of theirs
|
|
121
|
+
// before it; those accepting it passing it (`passing`), each once, by a
|
|
122
|
+
// full, accepting review of theirs, the latest of its comparison, which
|
|
123
|
+
// revises those of it before, whole, compared with another package's
|
|
124
|
+
// version, or compared with one of `bases` of its own (any, for `any`); and
|
|
125
|
+
// how many review it in its pull request's comments alone (`commented`),
|
|
126
|
+
// which count for it alone: whose reviews passing it, else whose latest, are
|
|
127
|
+
// its comments'. Each reviewer too (`reviewers`), by their login, their
|
|
128
|
+
// latest verdict, whether they pass it, and whether that verdict is its
|
|
129
|
+
// comments' (`comment`), which counts for it alone.
|
|
130
|
+
function stancesOf(pkg: LockedPackage, reviews: ReviewsOf, bases: string[] | 'any') {
|
|
131
|
+
const by = Map.groupBy(reviewsOf(pkg, reviews), review => review.reviewer)
|
|
132
|
+
const qualifies = (review: PublishedReview) => review.full && ACCEPTING.has(review.status) && comparedWith(review, pkg, bases)
|
|
133
|
+
let commented = 0, passing = 0, rejected = false
|
|
134
|
+
const reviewers: Reviewer[] = []
|
|
135
|
+
for (const theirs of by.values()) {
|
|
136
|
+
const latest = latestOf(theirs)
|
|
137
|
+
const current = [...Map.groupBy(theirs, comparisonOf).values()].map(latestOf).filter(qualifies)
|
|
138
|
+
const passes = ACCEPTING.has(latest.status) && current.length > 0
|
|
139
|
+
// In its comments alone where those telling where they stand are: those
|
|
140
|
+
// passing it, where they pass it, else their latest.
|
|
141
|
+
const comment = (passes ? current : [latest]).every(review => review.comment)
|
|
142
|
+
if (comment) commented++
|
|
143
|
+
if (latest.status === 'reject') rejected = true
|
|
144
|
+
else if (passes) passing++
|
|
145
|
+
reviewers.push({ login: latest.login, status: latest.status, ...passes ? { passes: true as const } : {}, ...latest.comment ? { comment: true as const } : {} })
|
|
146
|
+
}
|
|
147
|
+
return { passing, rejected, commented, reviewers }
|
|
148
|
+
}
|
|
149
|
+
type Reviewer = { login: string; status: PublishedReview['status']; passes?: true; comment?: true }
|
|
150
|
+
|
|
151
|
+
// A version as the client is told it: what its reviews are held to left
|
|
152
|
+
// out, but its patch, where it is patched (`patch`): its hash, which its
|
|
153
|
+
// reviews are held to, and its file, where its lockfile names one or it
|
|
154
|
+
// was found, from the repository's root, whence its reviews read it.
|
|
155
|
+
type Patch = { hash: string; path?: string }
|
|
156
|
+
function shown<T extends LockedPackage>(pkg: T): Omit<T, 'integrity' | 'shasum' | 'patchHash' | 'patchPath' | 'patchDir' | 'lockfile' | 'unlocked'> & { patch?: Patch } {
|
|
157
|
+
const copy = { ...pkg }
|
|
158
|
+
for (const field of ['integrity', 'shasum', 'patchHash', 'patchPath', 'patchDir', 'lockfile', 'unlocked'] as const) delete copy[field]
|
|
159
|
+
return { ...copy, ...pkg.patchHash ? { patch: { hash: pkg.patchHash, ...pkg.patchPath ? { path: pkg.patchPath } : {} } } : {} }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// A version as the registered reviewed dependencies are asked of it, by
|
|
163
|
+
// what it is asked.
|
|
164
|
+
export function askedOf(pkg: LockedPackage): [string, ReviewedDependency] {
|
|
165
|
+
const dependency: ReviewedDependency = { ecosystem: 'npm', lockfile: pkg.lockfile ?? 'npm', name: pkg.name, version: pkg.version ?? '', ...pkg.integrity ? { integrity: pkg.integrity } : {},
|
|
166
|
+
...pkg.shasum ? { shasum: pkg.shasum } : {}, ...pkg.patchHash ? { patchHash: pkg.patchHash } : {} }
|
|
167
|
+
return [JSON.stringify(dependency), dependency]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// A version's review, and whether it wants one (`wants`), neither passing
|
|
171
|
+
// nor needing none, as only one that can be reviewed may.
|
|
172
|
+
type Review = { unsupported: Unsupported } | { baseline: true } | { reviewed: true } | { reviews: number; rejected?: true; commented?: number; reviewers?: Reviewer[] }
|
|
173
|
+
| Record<string, never>
|
|
174
|
+
// The reader's own latest published review of a version, whether or not it
|
|
175
|
+
// counts (`yours`): its verdict, and whether it is partial.
|
|
176
|
+
type Yours = { status: PublishedReview['status']; partial?: true }
|
|
177
|
+
interface Judged { review: Review; wants: boolean; yours?: Yours }
|
|
178
|
+
type Judge = (pkg: LockedPackage, bases: string[] | 'any') => Judged
|
|
179
|
+
// One of npm's registry locked with no integrity passes where the host's
|
|
180
|
+
// `lookup` passed it as it is (`vouched`, by what it was asked).
|
|
181
|
+
interface Context { state: RepoReviewState; reviews: ReviewsOf; baseline: Set<string> | null; vouched?: Set<string> }
|
|
182
|
+
function judge(pkg: LockedPackage, bases: string[] | 'any', { state, reviews, baseline, vouched }: Context): Judged {
|
|
183
|
+
const as = reviewedAs(pkg)
|
|
184
|
+
if (as === 'skip') return { review: {}, wants: false }
|
|
185
|
+
if (as === 'integrity' && vouched?.has(askedOf(pkg)[0])) return { review: { reviewed: true }, wants: false }
|
|
186
|
+
if (as !== 'version') return { review: { unsupported: as }, wants: false }
|
|
187
|
+
if (baselineKeys(pkg).some(key => baseline?.has(key))) return { review: { baseline: true }, wants: false }
|
|
188
|
+
const { passing, rejected, commented, reviewers } = stancesOf(pkg, reviews, bases)
|
|
189
|
+
const told = { reviews: passing, ...commented > 0 ? { commented } : {}, ...reviewers.length > 0 ? { reviewers } : {} }
|
|
190
|
+
if (rejected) return { review: { ...told, rejected: true }, wants: true }
|
|
191
|
+
return { review: told, wants: passing < state.required }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// A directory as the client is told it: what it adds, as many as MAX_ADDED,
|
|
195
|
+
// each version with its review (`review`, as judged), those past them judged
|
|
196
|
+
// as they are, against the versions they were, as is every one its lockfiles
|
|
197
|
+
// lock of them (another integrity of it, say), each told by the least passing
|
|
198
|
+
// of them, and those of all that want one (`toReview`); the others its lockfiles lock that want reviews, and every one
|
|
199
|
+
// that can't be reviewed (as many of each as MAX_UNREVIEWED, how many more,
|
|
200
|
+
// once `capped`); and how many it locks past those read (`moreLocked`), which
|
|
201
|
+
// aren't checked; without `review`, what it adds alone. Read without its
|
|
202
|
+
// base (`baseless`), it tells only those it adds that pass none, or pass by
|
|
203
|
+
// its comments alone, which the host doesn't take in till it is merged.
|
|
204
|
+
function reviewedDirectory(dir: DirectoryDependencies, review: Judge | null, baseless = false, vouched: Set<string> = new Set()) {
|
|
205
|
+
if ('error' in dir) return dir
|
|
206
|
+
const { locked, moreLocked, added, ...told } = dir
|
|
207
|
+
if (!review) return { ...told, added: baseless ? [] : added.slice(0, MAX_ADDED).map(shown), ...baseless ? { more: 0 } : {} }
|
|
208
|
+
const adds = new Map(added.map(pkg => [lockedAs(pkg), { pkg, variants: [pkg] }]))
|
|
209
|
+
for (const pkg of locked) {
|
|
210
|
+
const of = adds.get(lockedAs(pkg))
|
|
211
|
+
if (of && lockedWith(pkg) !== lockedWith(of.pkg)) of.variants.push(pkg)
|
|
212
|
+
}
|
|
213
|
+
const own = [...adds.values()].map(({ pkg, variants }) => {
|
|
214
|
+
const judged = variants.map(variant => ({ variant, ...review(variant, basesOf(pkg, (variant as AddedPackage).base ?? null)) }))
|
|
215
|
+
const least = judged.find(one => 'unsupported' in one.review) ?? judged.find(one => one.wants) ?? judged[0]!
|
|
216
|
+
return { pkg, judged: least, wanting: judged.filter(one => one.wants).map(({ variant }) => variant) }
|
|
217
|
+
})
|
|
218
|
+
const others = locked.filter(pkg => !adds.has(lockedAs(pkg))).map(pkg => ({ pkg, judged: review(pkg, 'any') }))
|
|
219
|
+
const unsupported = locked.flatMap(pkg => {
|
|
220
|
+
const as = reviewedAs(pkg)
|
|
221
|
+
return as === 'version' || as === 'skip' || (as === 'integrity' && vouched.has(askedOf(pkg)[0])) ? [] : [{ ...shown(pkg), unsupported: as }]
|
|
222
|
+
})
|
|
223
|
+
const listed = baseless ? own.filter(({ judged }) => judged.wants || 'unsupported' in judged.review || 'commented' in judged.review) : own
|
|
224
|
+
// Each row against the base of the way it is locked that it is told by.
|
|
225
|
+
const row = ({ pkg, judged }: (typeof own)[number]) => {
|
|
226
|
+
const { base: _base, ...rest } = shown(pkg as AddedPackage), { base } = judged.variant as AddedPackage
|
|
227
|
+
return { ...rest, ...base ? { base } : {}, ...judged.review, ...judged.yours ? { yours: judged.yours } : {} }
|
|
228
|
+
}
|
|
229
|
+
return { ...told, ...baseless ? { more: Math.max(0, listed.length - MAX_ADDED) } : {}, added: listed.slice(0, MAX_ADDED).map(row),
|
|
230
|
+
toReview: own.flatMap(({ wanting }) => wanting.map(shown)),
|
|
231
|
+
unreviewed: others.filter(({ judged }) => judged.wants).map(({ pkg, judged }) => ({ ...shown(pkg), ...judged.review, ...judged.yours ? { yours: judged.yours } : {} })),
|
|
232
|
+
unsupported, moreLocked }
|
|
233
|
+
}
|
|
234
|
+
function capped<T extends { toReview: unknown[]; unreviewed: unknown[]; unsupported: unknown[] }>({ toReview: _toReview, ...dir }: T) {
|
|
235
|
+
return { ...dir, unreviewed: dir.unreviewed.slice(0, MAX_UNREVIEWED), moreUnreviewed: Math.max(0, dir.unreviewed.length - MAX_UNREVIEWED),
|
|
236
|
+
unsupported: dir.unsupported.slice(0, MAX_UNREVIEWED), moreUnsupported: Math.max(0, dir.unsupported.length - MAX_UNREVIEWED) }
|
|
237
|
+
}
|
|
238
|
+
// How many versions of `lists` there are, each once across them, by `key`,
|
|
239
|
+
// as the client tells them once: one wanting reviews by its name and
|
|
240
|
+
// version, and its patch's hash, as each patch of it is reviewed apart; one
|
|
241
|
+
// that can't be reviewed by where it is from too.
|
|
242
|
+
type Shown = Pick<LockedPackage, 'name' | 'version' | 'source' | 'from'> & { patch?: Patch }
|
|
243
|
+
const distinct = (lists: Shown[][], key: (pkg: Shown) => string) => new Set(lists.flat().map(key)).size
|
|
244
|
+
const versionKey = (pkg: Shown) => `${pkg.name}@${pkg.version ?? ''}\0${pkg.patch?.hash ?? ''}`
|
|
245
|
+
const sourceKey = (pkg: Shown) => `${pkg.source}\0${pkg.name}@${pkg.version ?? ''}\0${pkg.from ?? ''}`
|
|
246
|
+
|
|
247
|
+
// The versions of its package an added version's reviews may be compared
|
|
248
|
+
// with: those it was, and the base the host names it (null for none).
|
|
249
|
+
export const basesOf = (pkg: AddedPackage, base: ReviewedBase | null | undefined = pkg.base) => [...pkg.was ?? [], ...base?.name === pkg.name ? [base.version] : []]
|
|
250
|
+
// `dirs`, each version of `asking` as it is locked with the version `base`
|
|
251
|
+
// names to review it against (`base`, of its package or another), its row's
|
|
252
|
+
// link and line count then against that one, and its reviews against it
|
|
253
|
+
// passing it; each named onto `named` too, by what it is asked.
|
|
254
|
+
async function withBases(dirs: DirectoryDependencies[], base: NonNullable<ReviewedDependencies['base']>, asking: Map<string, ReviewedDependency>,
|
|
255
|
+
named: Map<string, ReviewedBase>): Promise<DirectoryDependencies[]> {
|
|
256
|
+
for (const [key, one] of asking.size > 0 ? await askBases(base, asking) : []) named.set(key, one)
|
|
257
|
+
const based = <P extends LockedPackage>(pkg: P) => { const one = named.get(askedOf(pkg)[0]); return one ? { ...pkg, base: one } : pkg }
|
|
258
|
+
return dirs.map(dir => 'error' in dir ? dir : { ...dir, added: dir.added.map(based), locked: dir.locked.map(based) })
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// The reviews an open pull request's comments make of `wanting`, the
|
|
262
|
+
// versions still wanting one (pull-comment-reviews.ts): those that count,
|
|
263
|
+
// and whether they couldn't be read.
|
|
264
|
+
export type CommentReviews = (wanting: ReviewedDependency[]) => Promise<{ reviews: PublishedReview[]; failed: boolean }>
|
|
265
|
+
|
|
266
|
+
// What a pull request's lockfiles lock, but in directories none of whose
|
|
267
|
+
// lockfiles `scope` holds to, as they aren't reviewed: left out, as lockfiles
|
|
268
|
+
// left unread are where it holds to none of them (`omitted`, told to none).
|
|
269
|
+
export function heldDependencies<T extends PullDependencies>(told: T, scope: LockfileScope): Omit<T, 'omitted'> {
|
|
270
|
+
const { omitted, ...answered } = told
|
|
271
|
+
if (isEvery(scope)) return answered
|
|
272
|
+
return { ...answered, cut: told.cut && !(omitted && !omitted.some(path => heldTo(scope, path))), lockfiles: told.lockfiles.filter(dir => reviewedIn(scope, dir.paths)) }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// A pull request's dependencies as the client is told them: without the
|
|
276
|
+
// versions its directories lock; with `state`, a repository's review in
|
|
277
|
+
// effect, each version's review (reviewedDirectory), with `user`'s own
|
|
278
|
+
// latest published review of it, whether it counts or not (`yours`), those wanting one asked
|
|
279
|
+
// of the registered reviewed dependencies (`reviewed`), those they don't pass
|
|
280
|
+
// of their `base` (onto `namedBases`), and those still
|
|
281
|
+
// wanting one of the reviews its comments make (`commentReviews`, where the
|
|
282
|
+
// host reads them), and the review's terms (`review`), with how many
|
|
283
|
+
// reviewers' its comments count (`commentReviews`), or that they couldn't be
|
|
284
|
+
// read (`commentsFailed`), and that reviews count by comments alone, those
|
|
285
|
+
// published here not (`byComments`, where the host reads them), and that
|
|
286
|
+
// they name bases (`reviewedBases`), and how many versions across its directories want
|
|
287
|
+
// reviews, of those it adds (`toReview`, and onto `wantedIn`, each
|
|
288
|
+
// directory's by its paths, all of them, not those told alone) and the rest
|
|
289
|
+
// (`unreviewed`), and can't be reviewed (`unsupported`), each once; how many the reviewed dependencies failed to
|
|
290
|
+
// answer (`unasked`), and whether they are registered (`reviewedDependencies`,
|
|
291
|
+
// the commit reviewed since then none); and where the baseline couldn't be
|
|
292
|
+
// read, why (`baselineError`), every version then wanting its reviews, or
|
|
293
|
+
// the lockfiles there left unread (`baselineUnread`), whose versions do. It
|
|
294
|
+
// fails where a version can't be reviewed, a directory's lockfiles couldn't
|
|
295
|
+
// be read or lock more than are checked, or the pull request changes more
|
|
296
|
+
// lockfiles than are read (`cut`). Those of directories none of whose
|
|
297
|
+
// lockfiles the review holds to (`lockfiles`, lockfile-scope.ts, told in its
|
|
298
|
+
// terms where not every one) are left out (heldDependencies).
|
|
299
|
+
export async function reviewedDependencies(told: PullDependencies, state: RepoReviewState | null,
|
|
300
|
+
{ baseline = null, baselineUnread = [], baselineError = null, reviewed = null, commentReviews = null, namedBases = new Map(), wantedIn = new Map(), user = null }: {
|
|
301
|
+
baseline?: Set<string> | null; baselineUnread?: string[]; baselineError?: string | null; reviewed?: ReviewedDependencies | null; commentReviews?: CommentReviews | null
|
|
302
|
+
namedBases?: Map<string, ReviewedBase>; wantedIn?: Map<string[], number>; user?: string | null } = {}) {
|
|
303
|
+
const scope = state?.lockfiles ?? EVERY_LOCKFILE
|
|
304
|
+
const answered = heldDependencies(told, scope)
|
|
305
|
+
const baseless = told.baseless === true
|
|
306
|
+
if (!state) return { ...answered, lockfiles: answered.lockfiles.map(dir => reviewedDirectory(dir, null, baseless)) }
|
|
307
|
+
const { cut } = answered
|
|
308
|
+
let held = answered.lockfiles
|
|
309
|
+
// Reviews published here count but where the host reads those pull
|
|
310
|
+
// requests' comments make (`parseComments`): what is reviewed is then the
|
|
311
|
+
// host's to tell, by those and its `lookup`, and one published here counts
|
|
312
|
+
// for nothing, whatever it was compared with: of a pull request's versions,
|
|
313
|
+
// a default branch's or a bundle's. Its author still copies it as a comment.
|
|
314
|
+
const published = reviewed?.parseComments ? [] : state.reviews
|
|
315
|
+
// Each of npm's registry locked with no integrity, which can't be reviewed
|
|
316
|
+
// here, asked of `lookup` as it is, which may pass it all the same.
|
|
317
|
+
const integrityless = new Map(reviewed ? held.flatMap(dir => 'error' in dir ? [] : [...dir.added, ...dir.locked]).filter(pkg => reviewedAs(pkg) === 'integrity').map(askedOf) : [])
|
|
318
|
+
const vouching = integrityless.size > 0 && reviewed ? await askReviewed(reviewed.lookup, integrityless) : { passed: new Set<string>(), unasked: 0 }
|
|
319
|
+
let context = { state, reviews: reviewsByVersion(published), baseline: reviewed ? null : baseline, vouched: vouching.passed }
|
|
320
|
+
// What wants a review, as `lookup` is asked of, each once.
|
|
321
|
+
const wanting = () => {
|
|
322
|
+
const asked = new Map<string, ReviewedDependency>()
|
|
323
|
+
const asking: Judge = (pkg, bases) => {
|
|
324
|
+
const judged = judge(pkg, bases, context)
|
|
325
|
+
if (judged.wants) asked.set(...askedOf(pkg))
|
|
326
|
+
return judged
|
|
327
|
+
}
|
|
328
|
+
for (const dir of held) reviewedDirectory(dir, asking)
|
|
329
|
+
return asked
|
|
330
|
+
}
|
|
331
|
+
const passed = new Set<string>()
|
|
332
|
+
let unasked = vouching.unasked
|
|
333
|
+
const ask = async (asked: Map<string, ReviewedDependency>) => {
|
|
334
|
+
const answer = asked.size > 0 && reviewed ? await askReviewed(reviewed.lookup, asked) : { passed: new Set<string>(), unasked: 0 }
|
|
335
|
+
for (const key of answer.passed) passed.add(key)
|
|
336
|
+
unasked += answer.unasked
|
|
337
|
+
}
|
|
338
|
+
const asked = wanting()
|
|
339
|
+
await ask(asked)
|
|
340
|
+
const parsing = new Map([...asked].filter(([key]) => !passed.has(key)))
|
|
341
|
+
// Those `lookup` doesn't pass against the bases the host names them.
|
|
342
|
+
if (reviewed?.base) held = await withBases(held, reviewed.base, parsing, namedBases)
|
|
343
|
+
// Of those still wanting one, and every other one the lockfiles it holds
|
|
344
|
+
// to add that its teams' reviews pass, telling other pull requests those
|
|
345
|
+
// it reviews (`commented`), but those `lookup` passes, reviewed, the
|
|
346
|
+
// reviews its comments make, an open one's alone (pull-comment-reviews.ts),
|
|
347
|
+
// which count as its teams' do; those their rejects hold asked of `lookup`
|
|
348
|
+
// too.
|
|
349
|
+
if (commentReviews) {
|
|
350
|
+
const others = new Map<string, ReviewedDependency>()
|
|
351
|
+
for (const pkg of held.flatMap(dir => 'added' in dir ? dir.added : [])) {
|
|
352
|
+
const [key, dependency] = askedOf(pkg)
|
|
353
|
+
if (!asked.has(key) && 'reviews' in judge(pkg, basesOf(pkg), context).review) others.set(key, dependency)
|
|
354
|
+
}
|
|
355
|
+
const vouched = others.size > 0 && reviewed ? (await askReviewed(reviewed.lookup, others)).passed : new Set<string>()
|
|
356
|
+
for (const [key, dependency] of others) if (!vouched.has(key)) parsing.set(key, dependency)
|
|
357
|
+
}
|
|
358
|
+
const comments = parsing.size > 0 && commentReviews ? await commentReviews([...parsing.values()]) : { reviews: [], failed: false }
|
|
359
|
+
if (comments.reviews.length > 0) {
|
|
360
|
+
context = { ...context, reviews: reviewsByVersion([...published, ...comments.reviews.map(review => ({ ...review, comment: true as const }))]) }
|
|
361
|
+
await ask(new Map([...wanting()].filter(([key]) => !asked.has(key))))
|
|
362
|
+
}
|
|
363
|
+
// `user`'s own published reviews, each version told its latest of them
|
|
364
|
+
// whatever it was compared with, and whether or not it counts: one they
|
|
365
|
+
// reviewed that wants reviews still, others' or the host's, is labelled
|
|
366
|
+
// theirs.
|
|
367
|
+
const mine = reviewsByVersion(user ? state.reviews.filter(review => review.id !== undefined && review.reviewer === user) : [])
|
|
368
|
+
const yours = (pkg: LockedPackage) => {
|
|
369
|
+
const latest = reviewsOf(pkg, mine).reduce<PublishedReview | null>((one, other) => one && one.time >= other.time ? one : other, null)
|
|
370
|
+
return latest ? { yours: { status: latest.status, ...latest.full ? {} : { partial: true as const } } } : {}
|
|
371
|
+
}
|
|
372
|
+
const dirs = held.map(dir => reviewedDirectory(dir, (pkg, bases) => {
|
|
373
|
+
const judged = judge(pkg, bases, context)
|
|
374
|
+
return { ...judged.wants && passed.has(askedOf(pkg)[0]) ? { review: { reviewed: true as const }, wants: false } : judged, ...yours(pkg) }
|
|
375
|
+
}, baseless, vouching.passed))
|
|
376
|
+
const unread = baselineUnread.filter(path => heldTo(scope, path))
|
|
377
|
+
const listed = dirs.filter(dir => 'unreviewed' in dir)
|
|
378
|
+
for (const dir of listed) wantedIn.set(dir.paths, distinct([dir.toReview], versionKey))
|
|
379
|
+
return { ...answered, cut, lockfiles: dirs.map(dir => 'unreviewed' in dir ? capped(dir) : dir), review: { required: state.required,
|
|
380
|
+
since: reviewed ? null : state.since, canReview: state.canReview, ...reviewed ? { reviewedDependencies: true } : {}, ...reviewed?.base ? { reviewedBases: true } : {},
|
|
381
|
+
...reviewed?.parseComments ? { byComments: true } : {},
|
|
382
|
+
toReview: distinct(listed.map(dir => dir.toReview), versionKey), unreviewed: distinct(listed.map(dir => dir.unreviewed), versionKey),
|
|
383
|
+
unsupported: distinct(listed.map(dir => dir.unsupported), sourceKey),
|
|
384
|
+
...unasked > 0 ? { unasked } : {}, ...baselineError && !reviewed ? { baselineError } : {},
|
|
385
|
+
...comments.reviews.length > 0 ? { commentReviews: new Set(comments.reviews.map(review => review.reviewer)).size } : {}, ...comments.failed ? { commentsFailed: true } : {},
|
|
386
|
+
...unread.length > 0 && !reviewed ? { baselineUnread: unread.slice(0, MAX_UNREVIEWED) } : {}, ...isEvery(scope) ? {} : { lockfiles: scope } } }
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// The package versions a pull request's lockfiles lock that its reviews here
|
|
390
|
+
// may pass, whose reviews are asked: those that can be reviewed.
|
|
391
|
+
export const reviewedPackages = (told: PullDependencies) => told.lockfiles
|
|
392
|
+
.flatMap(dir => 'error' in dir ? [] : dir.locked.filter(pkg => reviewedAs(pkg) === 'version').map(pkg => ({ name: pkg.name, version: pkg.version! })))
|
|
393
|
+
|
|
394
|
+
// A repository's baseline as read for a pull request: its versions and the
|
|
395
|
+
// lockfiles there left unread; none where it reviews since no commit; and
|
|
396
|
+
// where GitHub doesn't read it, none and why.
|
|
397
|
+
export async function baselineFor(fullName: string, token: string, repoId: number, state: RepoReviewState, kept: ReviewBaselineStore, reads: LockfileStore | null,
|
|
398
|
+
asked?: GithubAsked) {
|
|
399
|
+
if (!state.since) return { baseline: null, unread: [], error: null }
|
|
400
|
+
try {
|
|
401
|
+
const { versions, unread } = await reviewBaseline(fullName, token, repoId, state.since, kept, reads, asked)
|
|
402
|
+
return { baseline: versions, unread, error: null }
|
|
403
|
+
} catch (err) {
|
|
404
|
+
if (err instanceof GithubApiError && err.status !== 429 && err.status !== 401) return { baseline: null, unread: [], error: err.message }
|
|
405
|
+
throw err
|
|
406
|
+
}
|
|
407
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// What an open pull request's reviews say, as the code viewer's Pull requests
|
|
2
|
+
// tab and a pull request's popup show it (repository-issues.ts): who
|
|
3
|
+
// reviewed it and how, each by their latest review and the commit it was on,
|
|
4
|
+
// its author's own aside (the replies GitHub makes reviews of in a thread);
|
|
5
|
+
// whose review is requested, and how many more than those read; its review
|
|
6
|
+
// threads open and resolved, the latest read (open ones are, mostly, those
|
|
7
|
+
// lately opened), the gravest open one by the P0–P3 badge Codex marks a
|
|
8
|
+
// finding with; and
|
|
9
|
+
// Codex's own, which it keeps in a comment of its own (its summary, edited in
|
|
10
|
+
// place) rather than in reviews, reviewing only where it finds something:
|
|
11
|
+
// the commit its code review and its security review were last on, either
|
|
12
|
+
// one still running, asked for again since, or failed since. A review an
|
|
13
|
+
// agentic workflow (gh-aw) posted, as GitHub Actions' bot, names its
|
|
14
|
+
// workflow by the marker gh-aw leaves (`<!-- gh-aw-workflow-id: NAME -->`), in
|
|
15
|
+
// the popup, which reads reviews' bodies.
|
|
16
|
+
import { githubAgent } from '../common/managed/github-agents.ts'
|
|
17
|
+
import { ACTOR, type GraphAccount, actorOf } from './github-accounts.ts'
|
|
18
|
+
import type { GraphqlError } from './github-graphql.ts'
|
|
19
|
+
import { SHA, timeOf } from './github-values.ts'
|
|
20
|
+
|
|
21
|
+
const REVIEWERS = 20
|
|
22
|
+
const REQUESTS = 10
|
|
23
|
+
// The threads the Pull requests tab counts, and those a popup lists.
|
|
24
|
+
export const TILE_THREADS = 50
|
|
25
|
+
export const ITEM_THREADS = 100
|
|
26
|
+
// The comments read for Codex's: its summary among the first, posted as the
|
|
27
|
+
// pull request opens, or among the last, where it was first asked later;
|
|
28
|
+
// asking it again, and its failures, among the last.
|
|
29
|
+
const FIRST_COMMENTS = 5
|
|
30
|
+
const LAST_COMMENTS = 20
|
|
31
|
+
const MAX_TITLE = 200
|
|
32
|
+
const MAX_PATH = 1000
|
|
33
|
+
|
|
34
|
+
// The fields a pull request's reviews are read by, its threads' places and
|
|
35
|
+
// links with them for its popup (`detail`). A team requested is no reviewer
|
|
36
|
+
// read, but one of those requested GitHub names no one for: reading a team
|
|
37
|
+
// needs its organization's Members permission, and a query reading one
|
|
38
|
+
// without it fails whole (as one naming an EnterpriseTeam, which GitHub's
|
|
39
|
+
// docs name and its API knows none of, does).
|
|
40
|
+
export const reviewFields = (threads: number, detail: boolean) => `headRefOid
|
|
41
|
+
latestReviews(first: ${REVIEWERS}) { totalCount nodes { author { ${ACTOR} } state submittedAt commit { oid }${detail ? ' body' : ''} } }
|
|
42
|
+
reviewRequests(first: ${REQUESTS}) { totalCount nodes { requestedReviewer { __typename ... on User { login databaseId } ... on Bot { login databaseId }
|
|
43
|
+
... on Mannequin { login databaseId } } } }
|
|
44
|
+
reviewThreads(last: ${threads}) { totalCount nodes { isResolved isOutdated${detail ? ' path line originalLine' : ''}
|
|
45
|
+
comments(first: 1) { nodes { author { ${ACTOR} } body${detail ? ' url' : ''} } } } }
|
|
46
|
+
firstComments: comments(first: ${FIRST_COMMENTS}) { nodes { author { ${ACTOR} } body updatedAt } }
|
|
47
|
+
lastComments: comments(last: ${LAST_COMMENTS}) { nodes { author { ${ACTOR} } body createdAt updatedAt } }`
|
|
48
|
+
|
|
49
|
+
// The fields read for reviews that GitHub may refuse alone, as it refuses an
|
|
50
|
+
// App a pull request's checks: their pull request then shows no reviews.
|
|
51
|
+
const REVIEW_PATHS = new Set(['latestReviews', 'reviewRequests', 'reviewThreads', 'firstComments', 'lastComments'])
|
|
52
|
+
export const reviewsRefused = (error: GraphqlError) => error?.type === 'FORBIDDEN' && Array.isArray(error.path)
|
|
53
|
+
&& error.path.some(part => REVIEW_PATHS.has(part as string))
|
|
54
|
+
|
|
55
|
+
type Comment = { author?: GraphAccount; body?: unknown; updatedAt?: unknown; createdAt?: unknown } | null
|
|
56
|
+
type Thread = { isResolved?: unknown; isOutdated?: unknown; path?: unknown; line?: unknown; originalLine?: unknown
|
|
57
|
+
comments?: { nodes?: (Comment & { url?: unknown })[] } | null } | null
|
|
58
|
+
export type ReviewNode = {
|
|
59
|
+
headRefOid?: unknown
|
|
60
|
+
latestReviews?: { totalCount?: unknown; nodes?: ({ author?: GraphAccount; state?: unknown; submittedAt?: unknown; commit?: { oid?: unknown } | null; body?: unknown } | null)[] } | null
|
|
61
|
+
reviewRequests?: { totalCount?: unknown; nodes?: ({ requestedReviewer?: { __typename?: unknown; login?: unknown; databaseId?: unknown } | null } | null)[] } | null
|
|
62
|
+
reviewThreads?: { totalCount?: unknown; nodes?: Thread[] } | null
|
|
63
|
+
firstComments?: { nodes?: Comment[] } | null
|
|
64
|
+
lastComments?: { nodes?: Comment[] } | null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const STATES: Record<string, string> = { APPROVED: 'approved', CHANGES_REQUESTED: 'changes', COMMENTED: 'commented', DISMISSED: 'dismissed' }
|
|
68
|
+
const CODEX_STATES: Record<string, string> = { completed: 'done', running: 'running', queued: 'running', pending: 'running', in_progress: 'running', failed: 'failed', error: 'failed' }
|
|
69
|
+
const SEVERITY = /!\[(P[0-3]) Badge\]/u
|
|
70
|
+
const SUMMARY = /<!--\s*codex-review-state:v1\s+(\{[^]*?\})\s*-->/u
|
|
71
|
+
// Asking it to review again reruns its code review alone, never its security review.
|
|
72
|
+
const ASKED = /^@codex\s+review\b/iu
|
|
73
|
+
const FAILED = /^Codex Review: Something went wrong/u
|
|
74
|
+
const WORKFLOW = /<!--\s*gh-aw-workflow-id:\s*([\w.-]{1,100})\s*-->/u
|
|
75
|
+
|
|
76
|
+
const commitOf = (value: unknown) => typeof value === 'string' && SHA.test(value.toLowerCase()) ? value.toLowerCase() : null
|
|
77
|
+
const textOf = (value: unknown) => typeof value === 'string' ? value : ''
|
|
78
|
+
const isCodex = (account: GraphAccount) => {
|
|
79
|
+
const { login, id } = actorOf(account)
|
|
80
|
+
return login !== null && githubAgent(login, id) === 'codex'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// A finding's gravity, by its badge, `p0` the gravest; null for none.
|
|
84
|
+
const severityOf = (body: string) => SEVERITY.exec(body.slice(0, 500))?.[1]?.toLowerCase() ?? null
|
|
85
|
+
// A thread's title: its first comment's first line with words, as written,
|
|
86
|
+
// but for Codex's badge and emphasis.
|
|
87
|
+
function titleOf(body: string) {
|
|
88
|
+
for (const line of body.split('\n', 6)) {
|
|
89
|
+
const words = line.replaceAll(/!\[[^\]]*\]\([^)]*\)|<\/?sub>|\*\*|__/gu, '').trim()
|
|
90
|
+
if (words) return words.slice(0, MAX_TITLE)
|
|
91
|
+
}
|
|
92
|
+
return ''
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Codex's review of one kind, as its summary names it: the commit it was
|
|
96
|
+
// last on and how it stands.
|
|
97
|
+
function codexReview(value: unknown) {
|
|
98
|
+
const review = value && typeof value === 'object' ? value as { commit_sha?: unknown; status?: unknown } : null
|
|
99
|
+
if (!review) return null
|
|
100
|
+
return { commit: commitOf(review.commit_sha), status: CODEX_STATES[String(review.status)] ?? null }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// What Codex's summary says of its reviews, else null.
|
|
104
|
+
function summaryState(body: string): { code_review?: unknown; security_review?: unknown } | null {
|
|
105
|
+
try {
|
|
106
|
+
const value: unknown = JSON.parse(SUMMARY.exec(body)?.[1] ?? 'null')
|
|
107
|
+
return value && typeof value === 'object' ? value : null
|
|
108
|
+
} catch { return null }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Codex's reviews, from its summary, else none: its account, as the summary
|
|
112
|
+
// names it; whether it was asked again since the summary last changed
|
|
113
|
+
// (`@codex review`), and whether it failed since it was last asked.
|
|
114
|
+
function codexOf(node: ReviewNode) {
|
|
115
|
+
const summary = [...node.firstComments?.nodes ?? [], ...node.lastComments?.nodes ?? []]
|
|
116
|
+
.find(comment => comment && isCodex(comment.author) && SUMMARY.test(textOf(comment.body)))
|
|
117
|
+
if (!summary) return null
|
|
118
|
+
const state = summaryState(textOf(summary.body))
|
|
119
|
+
if (!state) return null
|
|
120
|
+
const since = timeOf(summary.updatedAt) ?? 0
|
|
121
|
+
const later = (node.lastComments?.nodes ?? []).filter(comment => comment && (timeOf(comment.createdAt) ?? 0) > since) as NonNullable<Comment>[]
|
|
122
|
+
const at = (comment: NonNullable<Comment> | undefined) => comment ? timeOf(comment.createdAt) ?? 0 : null
|
|
123
|
+
const asked = at(later.findLast(comment => !isCodex(comment.author) && ASKED.test(textOf(comment.body).trim())))
|
|
124
|
+
const failed = at(later.findLast(comment => isCodex(comment.author) && FAILED.test(textOf(comment.body).trim())))
|
|
125
|
+
const { login, id } = actorOf(summary.author)
|
|
126
|
+
return { login, id, code: codexReview(state.code_review), security: codexReview(state.security_review),
|
|
127
|
+
requested: asked !== null && !(failed !== null && failed > asked), failed: failed !== null && (asked === null || failed > asked) }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type Reviewer = { login: string | null; id: number | null; workflow?: string; state: string | null; requested: boolean; commit: string | null; at: number | null }
|
|
131
|
+
|
|
132
|
+
// The reviewers, each once: by their latest review, its state and commit;
|
|
133
|
+
// whose is requested (again, for one who reviewed), a user, a bot (Copilot's
|
|
134
|
+
// code review, asked for, is its bot's) or an imported account's mannequin.
|
|
135
|
+
// Codex's reviews are its summary's where it has one (`codex`). How many
|
|
136
|
+
// requested GitHub named no one for, a team among them, as `unnamed`,
|
|
137
|
+
// counted with those past the ones read.
|
|
138
|
+
function reviewersOf(node: ReviewNode, author: string | null, codex: boolean) {
|
|
139
|
+
const own = author?.toLowerCase()
|
|
140
|
+
const reviewers: Reviewer[] = (node.latestReviews?.nodes ?? []).flatMap(review => {
|
|
141
|
+
const { login, id } = actorOf(review?.author)
|
|
142
|
+
const state = STATES[String(review?.state)]
|
|
143
|
+
if (!state || (login !== null && login.toLowerCase() === own) || (codex && isCodex(review?.author))) return []
|
|
144
|
+
const workflow = WORKFLOW.exec(textOf(review?.body))?.[1]
|
|
145
|
+
return [{ login, id, ...workflow ? { workflow } : {}, state, requested: false, commit: commitOf(review?.commit?.oid), at: timeOf(review?.submittedAt) }]
|
|
146
|
+
})
|
|
147
|
+
let unnamed = 0
|
|
148
|
+
for (const request of node.reviewRequests?.nodes ?? []) {
|
|
149
|
+
const reviewer = request?.requestedReviewer
|
|
150
|
+
const { login, id } = actorOf(reviewer)
|
|
151
|
+
if (login === null) {
|
|
152
|
+
unnamed++
|
|
153
|
+
continue
|
|
154
|
+
}
|
|
155
|
+
// By their account where both name it, as GitHub may name one account
|
|
156
|
+
// otherwise on its reviews than on its requests (Copilot's code review's
|
|
157
|
+
// bot); else by their login.
|
|
158
|
+
const reviewed = reviewers.find(item => id !== null && item.id !== null ? item.id === id : item.login?.toLowerCase() === login.toLowerCase())
|
|
159
|
+
if (reviewed) reviewed.requested = true
|
|
160
|
+
else reviewers.push({ login, id, state: null, requested: true, commit: null, at: null })
|
|
161
|
+
}
|
|
162
|
+
return { reviewers, unnamed }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Its review threads, the latest read: how many are open and resolved,
|
|
166
|
+
// whether more than those read are, the gravest open one; and, for its popup (`detail`), each
|
|
167
|
+
// open one: its gravity, title, file and line, whether its code changed
|
|
168
|
+
// since, who opened it and where it is on GitHub.
|
|
169
|
+
function threadsOf(node: ReviewNode, detail: boolean) {
|
|
170
|
+
const threads = (node.reviewThreads?.nodes ?? []).filter(Boolean) as NonNullable<Thread>[]
|
|
171
|
+
const open = threads.filter(thread => thread.isResolved !== true)
|
|
172
|
+
const severities = open.map(thread => severityOf(textOf(thread.comments?.nodes?.[0]?.body))).filter(Boolean) as string[]
|
|
173
|
+
const total = node.reviewThreads?.totalCount
|
|
174
|
+
const counted = { open: open.length, resolved: threads.length - open.length,
|
|
175
|
+
more: Number.isSafeInteger(total) && (total as number) > threads.length, severity: severities.toSorted()[0] ?? null }
|
|
176
|
+
if (!detail) return counted
|
|
177
|
+
return { ...counted, list: open.map(thread => {
|
|
178
|
+
const first = thread.comments?.nodes?.[0]
|
|
179
|
+
const body = textOf(first?.body)
|
|
180
|
+
const opener = actorOf(first?.author)
|
|
181
|
+
const line = Number.isSafeInteger(thread.line) ? thread.line : Number.isSafeInteger(thread.originalLine) ? thread.originalLine : null
|
|
182
|
+
const url = typeof first?.url === 'string' && first.url.startsWith('https://github.com/') ? first.url : null
|
|
183
|
+
return { severity: severityOf(body), title: titleOf(body), path: typeof thread.path === 'string' ? thread.path.slice(0, MAX_PATH) : null, line,
|
|
184
|
+
outdated: thread.isOutdated === true, author: opener.login, authorId: opener.id, url }
|
|
185
|
+
}) }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// A pull request's reviews (`author` its author's login), for its tile or,
|
|
189
|
+
// with its threads listed, its popup (`detail`); null where none was read, or
|
|
190
|
+
// GitHub refused its reviews, requests or threads (reviewsRefused), rather
|
|
191
|
+
// than none.
|
|
192
|
+
export function pullReviews(node: ReviewNode, author: string | null, detail = false) {
|
|
193
|
+
if (node.headRefOid === undefined || node.latestReviews === null || node.reviewRequests === null || node.reviewThreads === null) return null
|
|
194
|
+
const codex = codexOf(node)
|
|
195
|
+
// Those past the reviews and the requests read, as many as GitHub counts,
|
|
196
|
+
// apart: a review unread may be on the latest commit, a request never is.
|
|
197
|
+
const past = (connection: { totalCount?: unknown; nodes?: unknown[] } | null | undefined) => Number.isSafeInteger(connection?.totalCount)
|
|
198
|
+
? Math.max(0, (connection!.totalCount as number) - (connection!.nodes?.length ?? 0)) : 0
|
|
199
|
+
const { reviewers, unnamed } = reviewersOf(node, author, codex !== null)
|
|
200
|
+
return { head: commitOf(node.headRefOid), reviewers, moreReviews: past(node.latestReviews), moreRequests: past(node.reviewRequests) + unnamed,
|
|
201
|
+
threads: threadsOf(node, detail), codex }
|
|
202
|
+
}
|