@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,409 @@
|
|
|
1
|
+
// What the code viewer's Pulse tab shows of a repository
|
|
2
|
+
// (GET /api/admin/repositories/pulse): how its default branch moves, week by
|
|
3
|
+
// week over the last year: its commits each day, the lines they add and
|
|
4
|
+
// remove, those an agent made or co-authored, who made them and when in the
|
|
5
|
+
// week, counted from its commits as the Commits tab reads and keeps them
|
|
6
|
+
// (repository-history.ts historyFrom), so that only those not kept yet are
|
|
7
|
+
// read of GitHub, a few queries a part, each going on from what the last
|
|
8
|
+
// walked (pulse-walk.ts); a year past YEAR_COMMITS is counted by GitHub's statistics instead,
|
|
9
|
+
// which GitHub computes when first asked and again once the default branch
|
|
10
|
+
// moves, answering 202 till they are (told pending, StatsPending, for the
|
|
11
|
+
// client to ask again). And, since
|
|
12
|
+
// the start of the week `weeks` weeks back, and over the same days of the
|
|
13
|
+
// week `weeks` weeks earlier, the pull requests merged and opened and the
|
|
14
|
+
// issues closed and opened, how many and the latest of each.
|
|
15
|
+
import { agentOperated, githubAgent } from '../common/managed/github-agents.ts'
|
|
16
|
+
import { ACTOR, type GraphAccount, accountOf } from './github-accounts.ts'
|
|
17
|
+
import { GithubApiError } from './github-errors.ts'
|
|
18
|
+
import { githubGraphql } from './github-graphql.ts'
|
|
19
|
+
import { githubJson, repoApi, shareGithubRead } from './github-requests.ts'
|
|
20
|
+
import { SHA, count, timeOf } from './github-values.ts'
|
|
21
|
+
import { coauthorsOf } from './commit-coauthors.ts'
|
|
22
|
+
import type { HistoryCommit } from './repository-history.ts'
|
|
23
|
+
import { issueState, itemOf, pullState } from './repository-issues.ts'
|
|
24
|
+
|
|
25
|
+
export { YEAR_COMMITS, yearCommits } from './pulse-walk.ts'
|
|
26
|
+
|
|
27
|
+
export const PULSE_WEEKS = [1, 4, 13, 52]
|
|
28
|
+
// What a year counted from its commits holds, its version: kept years of
|
|
29
|
+
// another are counted again.
|
|
30
|
+
export const PULSE_YEAR_VERSION = 12
|
|
31
|
+
const WEEK_MS = 7 * 24 * 60 * 60_000
|
|
32
|
+
const DAY_MS = 24 * 60 * 60_000
|
|
33
|
+
const MAX_CONTRIBUTORS = 100
|
|
34
|
+
const DIRECT_LISTED = 500
|
|
35
|
+
export const LISTED = 10
|
|
36
|
+
// Merged pull requests and closed issues are searched by when each was last
|
|
37
|
+
// updated, GitHub sorting by no merge or close: as many as this are read, and
|
|
38
|
+
// the latest merged or closed of them listed.
|
|
39
|
+
const SEARCHED = 50
|
|
40
|
+
// GitHub still computing a statistic.
|
|
41
|
+
export class StatsPending extends Error {
|
|
42
|
+
constructor() { super('github-stats-pending') }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A week: its commits each day (Sunday first) and in all, the lines they
|
|
46
|
+
// added and removed, and, counted from its commits, each day's lines
|
|
47
|
+
// (`dayLines`, `[added, removed]`), the commits that release the repository
|
|
48
|
+
// each day (`releaseDays`, release-commits.ts) and, of the rest, those an
|
|
49
|
+
// agent made or co-authored (`agentDays`), and those pushed to the branch
|
|
50
|
+
// directly (`directDays`, agent-merges.ts directCommits), which GitHub's
|
|
51
|
+
// statistics don't count.
|
|
52
|
+
interface PulseWeek { week: number; days: number[]; commits: number; additions: number | null; deletions: number | null; dayLines?: [number, number][]
|
|
53
|
+
agentDays?: number[]; releaseDays?: number[]; directDays?: number[] }
|
|
54
|
+
// A contributor, by their login and their account's numeric id (`id`, where
|
|
55
|
+
// GitHub named it), else by the name their commits carry, and their weeks,
|
|
56
|
+
// each `[week, commits, additions, deletions]`, those with any; counted from
|
|
57
|
+
// their commits, their days too, each `[day, commits, additions, deletions,
|
|
58
|
+
// agents, releases, direct]`, `releases` those that release the repository,
|
|
59
|
+
// `agents`, of the rest, those an agent took part in (withAgent), and
|
|
60
|
+
// `direct` those pushed to the branch directly.
|
|
61
|
+
interface PulseContributor { login: string | null; id?: number | null; name: string | null; weeks: [number, number, number, number][]
|
|
62
|
+
days?: [number, number, number, number, number, number, number][] }
|
|
63
|
+
// A commit pushed to the branch directly, as Pulse lists it: its id, when it
|
|
64
|
+
// was committed, its subject, its author, by account, else name, and what it
|
|
65
|
+
// is: a release, else one an agent took part in, else one without.
|
|
66
|
+
interface PulseCommit { sha: string; at: number; subject: string; login: string | null; id: number | null; name: string | null
|
|
67
|
+
kind: 'agent' | 'without' | 'release' }
|
|
68
|
+
// Commits by day of the week and hour (`punch[day][hour]`, Sunday first), in
|
|
69
|
+
// each commit's own time zone, and, counted from its commits, each period's
|
|
70
|
+
// (`punches`, by its weeks); `lines` false where GitHub counts none, null
|
|
71
|
+
// while it is counting them; counted from its commits, the latest pushed to
|
|
72
|
+
// the branch directly (`directCommits`, as many as DIRECT_LISTED); and,
|
|
73
|
+
// counted from its commits read no further back than a period needed, when
|
|
74
|
+
// from it is counted whole (`from`), absent for the year whole.
|
|
75
|
+
export interface PulseStats { weeks: PulseWeek[]; contributors: PulseContributor[]; punch: number[][]; punches?: Record<number, number[][]>; lines: boolean | null
|
|
76
|
+
directCommits?: PulseCommit[]; from?: number }
|
|
77
|
+
// The lines added and removed a week, and each contributor's, as GitHub's
|
|
78
|
+
// statistics count them, `lines` false where it counts none.
|
|
79
|
+
interface PulseLines { weeks: [number, number, number][]; contributors: { login: string; weeks: [number, number, number][] }[]; lines: boolean }
|
|
80
|
+
// The days (`from`, `to`, both days, UTC; `to` none, on) and the authors (GitHub
|
|
81
|
+
// logins, any of them) a period's pull requests and issues are narrowed to.
|
|
82
|
+
export interface PulseNarrowing { from: number; to: number | null; authors: string[] }
|
|
83
|
+
const emptyPunch = () => Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0))
|
|
84
|
+
|
|
85
|
+
// One statistic: its rows once GitHub has computed it, 'pending' while it
|
|
86
|
+
// computes them (202), none for a repository with no commits (204, no body),
|
|
87
|
+
// 'too-large' where it counts none (lines past 10,000 commits, 422).
|
|
88
|
+
function statistic(fullName: string, token: string | null, kind: string, fetchImpl: typeof fetch) {
|
|
89
|
+
// Stats and lines both need contributors. Share by the original transport;
|
|
90
|
+
// the per-call status wrapper below would otherwise give each its own read.
|
|
91
|
+
return shareGithubRead(fetchImpl, JSON.stringify(['statistic', fullName, token, kind]), () => readStatistic(fullName, token, kind, fetchImpl))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function readStatistic(fullName: string, token: string | null, kind: string, fetchImpl: typeof fetch): Promise<unknown[] | 'pending' | 'too-large'> {
|
|
95
|
+
let status = 0
|
|
96
|
+
const answered: typeof fetch = async (input, init) => {
|
|
97
|
+
const res = await fetchImpl(input, init)
|
|
98
|
+
status = res.status
|
|
99
|
+
return res
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const data = await githubJson(`${repoApi(fullName)}/stats/${kind}`, token, answered)
|
|
103
|
+
if (status === 202) return 'pending'
|
|
104
|
+
if (!Array.isArray(data)) throw new GithubApiError(502, 'github-malformed')
|
|
105
|
+
return data
|
|
106
|
+
} catch (err) {
|
|
107
|
+
if (status === 202) return 'pending'
|
|
108
|
+
if (status === 204) return []
|
|
109
|
+
if (err instanceof GithubApiError && err.message === 'github-status-422') return 'too-large'
|
|
110
|
+
throw err
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// `kinds` of GitHub's statistics, each asked once, together; any still
|
|
115
|
+
// computed, StatsPending.
|
|
116
|
+
async function statistics(fullName: string, token: string | null, kinds: string[], fetchImpl: typeof fetch) {
|
|
117
|
+
const read = await Promise.all(kinds.map(kind => statistic(fullName, token, kind, fetchImpl)))
|
|
118
|
+
if (read.includes('pending')) throw new StatsPending()
|
|
119
|
+
return read.map(rows => rows === 'too-large' ? null : rows as unknown[])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type ActivityRow = { week?: unknown; days?: unknown; total?: unknown }
|
|
123
|
+
type ContributorRow = { author?: { login?: unknown; id?: unknown } | null; weeks?: { w?: unknown; a?: unknown; d?: unknown; c?: unknown }[] }
|
|
124
|
+
|
|
125
|
+
// The default branch's commits over the last year as GitHub's statistics
|
|
126
|
+
// count them, for a year past YEAR_COMMITS: a week a row, the oldest first,
|
|
127
|
+
// its commits each day (Sunday first) and in all; its contributors (as many
|
|
128
|
+
// as MAX_CONTRIBUTORS, the most commits that year first) and their weeks;
|
|
129
|
+
// and its commits by day of the week and hour, in each commit's own time
|
|
130
|
+
// zone. Lines are GitHub's to count apart (repositoryLines).
|
|
131
|
+
export async function repositoryStats(fullName: string, token: string | null, fetchImpl: typeof fetch = globalThis.fetch): Promise<PulseStats> {
|
|
132
|
+
const [activityRows = null, contributorRows = null, punchRows = null] = await statistics(fullName, token, ['commit_activity', 'contributors', 'punch_card'], fetchImpl)
|
|
133
|
+
const weeks = ((activityRows ?? []) as ActivityRow[]).flatMap(row => {
|
|
134
|
+
if (!Number.isSafeInteger(row?.week)) return []
|
|
135
|
+
const days = Array.from({ length: 7 }, (_, day) => count(Array.isArray(row.days) ? row.days[day] : 0))
|
|
136
|
+
return [{ week: (row.week as number) * 1000, days, commits: count(row.total), additions: null, deletions: null }]
|
|
137
|
+
}).toSorted((a, b) => a.week - b.week)
|
|
138
|
+
const first = weeks[0]?.week ?? Number.POSITIVE_INFINITY
|
|
139
|
+
const contributors = ((contributorRows ?? []) as ContributorRow[]).flatMap(row => {
|
|
140
|
+
const { login, id } = accountOf(row?.author)
|
|
141
|
+
const theirs = (row?.weeks ?? []).flatMap(item => {
|
|
142
|
+
const week = count(item?.w) * 1000
|
|
143
|
+
return week >= first && count(item?.c) > 0 ? [[week, count(item?.c), 0, 0] as [number, number, number, number]] : []
|
|
144
|
+
})
|
|
145
|
+
return login && theirs.length > 0 ? [{ login, id, name: null, weeks: theirs, commits: theirs.reduce((sum, item) => sum + item[1], 0) }] : []
|
|
146
|
+
}).toSorted((a, b) => b.commits - a.commits).slice(0, MAX_CONTRIBUTORS).map(({ login, id, name, weeks: theirs }) => ({ login, id, name, weeks: theirs }))
|
|
147
|
+
const punch = emptyPunch()
|
|
148
|
+
for (const row of (punchRows ?? []) as unknown[][]) {
|
|
149
|
+
if (Array.isArray(row) && Number.isSafeInteger(row[0]) && Number.isSafeInteger(row[1]) && punch[row[0] as number]?.[row[1] as number] !== undefined) {
|
|
150
|
+
punch[row[0] as number]![row[1] as number] = count(row[2])
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { weeks, contributors, punch, lines: null }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// The lines added and removed each week since `since`, and each
|
|
157
|
+
// contributor's, as GitHub's statistics count them; none, `lines` false,
|
|
158
|
+
// where it counts none (past 10,000 commits, where it counts each
|
|
159
|
+
// contributor's as none too).
|
|
160
|
+
export async function repositoryLines(fullName: string, token: string | null, since: number, fetchImpl: typeof fetch = globalThis.fetch): Promise<PulseLines> {
|
|
161
|
+
const [frequency = null, contributorRows = null] = await statistics(fullName, token, ['code_frequency', 'contributors'], fetchImpl)
|
|
162
|
+
if (frequency === null) return { weeks: [], contributors: [], lines: false }
|
|
163
|
+
const weeks = frequency.flatMap(row => Array.isArray(row) && Number.isSafeInteger(row[0]) && (row[0] as number) * 1000 >= since
|
|
164
|
+
? [[(row[0] as number) * 1000, count(row[1]), count(Math.abs(Number(row[2])))] as [number, number, number]] : [])
|
|
165
|
+
const contributors = ((contributorRows ?? []) as ContributorRow[]).flatMap(row => {
|
|
166
|
+
const { login } = accountOf(row?.author)
|
|
167
|
+
const theirs = (row?.weeks ?? []).flatMap(item => count(item?.w) * 1000 >= since && count(item?.a) + count(item?.d) > 0
|
|
168
|
+
? [[count(item?.w) * 1000, count(item?.a), count(item?.d)] as [number, number, number]] : [])
|
|
169
|
+
return login && theirs.length > 0 ? [{ login, weeks: theirs }] : []
|
|
170
|
+
})
|
|
171
|
+
return { weeks, contributors, lines: true }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The default branch's head, null for a repository with none.
|
|
175
|
+
export async function defaultHead(fullName: string, token: string, fetchImpl: typeof fetch = globalThis.fetch): Promise<string | null> {
|
|
176
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
177
|
+
const data = await githubGraphql('query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { defaultBranchRef { target { oid } } } }',
|
|
178
|
+
{ owner, name }, token, fetchImpl) as { repository?: { defaultBranchRef?: { target?: { oid?: unknown } | null } | null } | null } | null
|
|
179
|
+
if (!data?.repository) throw new GithubApiError(404, 'github-not-found')
|
|
180
|
+
const oid = data.repository.defaultBranchRef?.target?.oid
|
|
181
|
+
return typeof oid === 'string' && SHA.test(oid) ? oid : null
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Whether an author is a GitHub App's bot: by its login (`<app>[bot]`, as a
|
|
185
|
+
// commit's no-reply address names it, github-accounts.ts commitAccount),
|
|
186
|
+
// else, for one GitHub names no account for, by the name it commits as.
|
|
187
|
+
const bot = (login: string | null | undefined, name: string | null | undefined) => /\[bot\]$/iu.test(login ?? name ?? '')
|
|
188
|
+
|
|
189
|
+
// Whether an agent made `commit` or co-authored it: its author one of
|
|
190
|
+
// GitHub's agents (common/managed/github-agents.ts githubAgent), or any of
|
|
191
|
+
// its co-authors an agent (commit-coauthors.ts coauthorsOf), as Commits
|
|
192
|
+
// marks them, or any bot, whichever GitHub App's; or one an agent's pull request brought (`merges`,
|
|
193
|
+
// agent-merges.ts agentCommits); or one an account agents work as pushed to
|
|
194
|
+
// the branch directly (`direct`, github-agents.ts agentOperated).
|
|
195
|
+
const withAgent = (commit: HistoryCommit, merges: ReadonlySet<string>, direct: ReadonlySet<string>) => merges.has(commit.sha)
|
|
196
|
+
|| (direct.has(commit.sha) && agentOperated(commit.authorLogin, commit.authorId ?? null))
|
|
197
|
+
|| githubAgent(commit.authorLogin, commit.authorId ?? null, commit.authorName) !== null || bot(commit.authorLogin, commit.authorName)
|
|
198
|
+
|| coauthorsOf(commit).some(coauthor => Boolean(coauthor.agent) || bot(coauthor.login, coauthor.name))
|
|
199
|
+
|
|
200
|
+
// A contributor as commitStats counts them: by the login, id and name the
|
|
201
|
+
// first of their commits listed names, every login they committed as
|
|
202
|
+
// (`logins`), and their commits' counts, by week and by day, to which
|
|
203
|
+
// addCounts adds those `made` at `at`.
|
|
204
|
+
type Counts = Map<number, number[]>
|
|
205
|
+
type Person = { login: string | null; logins: Set<string>; id: number | null; name: string | null; weeks: Counts; days: Counts; commits: number }
|
|
206
|
+
const addCounts = (counts: Counts, at: number, made: number[]) => counts.set(at, made.map((value, index) => (counts.get(at)?.[index] ?? 0) + value))
|
|
207
|
+
|
|
208
|
+
// A login one account committed as, those of its commits read before ids
|
|
209
|
+
// were that account's; one more did, theirs apart, no one's. Those of
|
|
210
|
+
// `people` counted so, out of it, each by its key the account it is.
|
|
211
|
+
function mergedLogins(people: Map<string, Person>) {
|
|
212
|
+
const merged = new Map<string, Person>()
|
|
213
|
+
const accounts = Map.groupBy([...people.values()].filter(person => person.id !== null).flatMap(person => [...person.logins].map(login => ({ login, person }))),
|
|
214
|
+
({ login }) => login)
|
|
215
|
+
for (const [key, person] of people) {
|
|
216
|
+
const [owner, ...others] = person.login !== null && person.id === null ? accounts.get(person.login.toLowerCase()) ?? [] : []
|
|
217
|
+
if (!owner || others.length > 0) continue
|
|
218
|
+
const account = owner.person
|
|
219
|
+
for (const [week, counts] of person.weeks) addCounts(account.weeks, week, counts)
|
|
220
|
+
for (const [day, counts] of person.days) addCounts(account.days, day, counts)
|
|
221
|
+
account.commits += person.commits
|
|
222
|
+
people.delete(key)
|
|
223
|
+
merged.set(key, account)
|
|
224
|
+
}
|
|
225
|
+
return merged
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// The year from `first` (pulseSince(52, …)) of `commits`, as GitHub's
|
|
229
|
+
// statistics count them, merges left out: a week a row, its commits each day
|
|
230
|
+
// (UTC) and in all and the lines they added and removed, in all and each day,
|
|
231
|
+
// those that release the repository (`releases`, release-commits.ts) and,
|
|
232
|
+
// of the rest, those an agent made or co-authored, merged from an agent's
|
|
233
|
+
// pull request (`merges`) or pushed directly as an account agents work as
|
|
234
|
+
// (`direct`, withAgent), each day;
|
|
235
|
+
// its contributors,
|
|
236
|
+
// by account (its id, by the login it committed as first listed, the newest,
|
|
237
|
+
// whatever it was renamed from; a login's commits read before ids were, the
|
|
238
|
+
// one account's that committed as it, where only one did), else login, each
|
|
239
|
+
// matched as GitHub matches logins, regardless of case, else name (as many
|
|
240
|
+
// as MAX_CONTRIBUTORS, the most commits first),
|
|
241
|
+
// and their weeks and days, each day's releases and commits with agents too;
|
|
242
|
+
// and its commits by day of the week and hour, in each author's own time
|
|
243
|
+
// zone (else UTC, where GitHub told none), the year's and each period's
|
|
244
|
+
// (PULSE_WEEKS, its last weeks).
|
|
245
|
+
export function commitStats(commits: HistoryCommit[], first: number, merges: ReadonlySet<string> = new Set(), releases: ReadonlySet<string> = new Set(),
|
|
246
|
+
direct: ReadonlySet<string> = new Set()): PulseStats {
|
|
247
|
+
const weeks = Array.from({ length: 52 }, (_, at) => ({ week: first + at * WEEK_MS, days: Array.from({ length: 7 }, () => 0), commits: 0, additions: 0, deletions: 0,
|
|
248
|
+
dayLines: Array.from({ length: 7 }, () => [0, 0] as [number, number]), agentDays: Array.from({ length: 7 }, () => 0), releaseDays: Array.from({ length: 7 }, () => 0),
|
|
249
|
+
directDays: Array.from({ length: 7 }, () => 0) }))
|
|
250
|
+
const people = new Map<string, Person>()
|
|
251
|
+
const punches = Object.fromEntries(PULSE_WEEKS.map(span => [span, emptyPunch()]))
|
|
252
|
+
// Each commit's author, by the key their commits are counted by.
|
|
253
|
+
const keys = new Map<string, string>()
|
|
254
|
+
for (const commit of commits) {
|
|
255
|
+
if (commit.parents.length > 1 || commit.committedAt === null || commit.committedAt < first) continue
|
|
256
|
+
const at = Math.floor((commit.committedAt - first) / WEEK_MS)
|
|
257
|
+
const week = weeks[at]
|
|
258
|
+
if (!week) continue
|
|
259
|
+
const [additions, deletions] = [commit.additions ?? 0, commit.deletions ?? 0]
|
|
260
|
+
const weekday = new Date(commit.committedAt).getUTCDay()
|
|
261
|
+
week.days[weekday]!++
|
|
262
|
+
week.dayLines[weekday]![0] += additions
|
|
263
|
+
week.dayLines[weekday]![1] += deletions
|
|
264
|
+
week.commits++
|
|
265
|
+
week.additions += additions
|
|
266
|
+
week.deletions += deletions
|
|
267
|
+
const release = releases.has(commit.sha)
|
|
268
|
+
const agent = !release && withAgent(commit, merges, direct)
|
|
269
|
+
if (release) week.releaseDays[weekday]!++
|
|
270
|
+
if (direct.has(commit.sha)) week.directDays[weekday]!++
|
|
271
|
+
if (agent) week.agentDays[weekday]!++
|
|
272
|
+
const local = new Date(commit.authoredAt != null && commit.authorZone != null ? commit.authoredAt + commit.authorZone * 60_000 : commit.committedAt)
|
|
273
|
+
for (const span of PULSE_WEEKS) if (at >= 52 - span) punches[span]![local.getUTCDay()]![local.getUTCHours()]!++
|
|
274
|
+
const key = commit.authorLogin && commit.authorId != null ? `#${commit.authorId}` : commit.authorLogin ? `@${commit.authorLogin.toLowerCase()}`
|
|
275
|
+
: commit.authorName ? `=${commit.authorName}` : null
|
|
276
|
+
if (!key) continue
|
|
277
|
+
keys.set(commit.sha, key)
|
|
278
|
+
const person = people.get(key) ?? { login: commit.authorLogin, logins: new Set<string>(), id: commit.authorId ?? null, name: commit.authorName,
|
|
279
|
+
weeks: new Map(), days: new Map(), commits: 0 }
|
|
280
|
+
if (commit.authorLogin) person.logins.add(commit.authorLogin.toLowerCase())
|
|
281
|
+
addCounts(person.weeks, week.week, [1, additions, deletions])
|
|
282
|
+
addCounts(person.days, Math.floor(commit.committedAt / DAY_MS) * DAY_MS, [1, additions, deletions, agent ? 1 : 0, release ? 1 : 0, direct.has(commit.sha) ? 1 : 0])
|
|
283
|
+
person.commits++
|
|
284
|
+
people.set(key, person)
|
|
285
|
+
}
|
|
286
|
+
// Of a login an account took on, that account.
|
|
287
|
+
const merged = mergedLogins(people)
|
|
288
|
+
const rows = (counts: Counts) => [...counts].toSorted(([a], [b]) => a - b).map(([at, made]) => [at, ...made])
|
|
289
|
+
const contributors = [...people.values()].toSorted((a, b) => b.commits - a.commits).slice(0, MAX_CONTRIBUTORS).map(({ login, id, name, weeks: theirs, days }) => ({
|
|
290
|
+
login, id, name, weeks: rows(theirs) as [number, number, number, number][], days: rows(days) as [number, number, number, number, number, number, number][] }))
|
|
291
|
+
// Each pushed directly by the contributor its author's commits are counted
|
|
292
|
+
// as, whatever account it named.
|
|
293
|
+
const directCommits = commits.filter(commit => direct.has(commit.sha) && commit.committedAt !== null && commit.committedAt >= first)
|
|
294
|
+
.toSorted((a, b) => b.committedAt! - a.committedAt!).slice(0, DIRECT_LISTED).map((commit): PulseCommit => {
|
|
295
|
+
const { sha, committedAt, subject, authorLogin, authorId, authorName } = commit
|
|
296
|
+
const author = people.get(keys.get(sha) ?? '') ?? merged.get(keys.get(sha) ?? '') ?? { login: authorLogin, id: authorId ?? null, name: authorName }
|
|
297
|
+
const kind = releases.has(sha) ? 'release' : withAgent(commit, merges, direct) ? 'agent' : 'without'
|
|
298
|
+
return { sha, at: committedAt!, subject, login: author.login, id: author.id, name: author.name, kind }
|
|
299
|
+
})
|
|
300
|
+
return { weeks, contributors, punch: punches[52]!, punches, lines: true, directCommits }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// The year's statistics as a period of `weeks` weeks shows them: when its
|
|
304
|
+
// commits are made, the period's where they were counted from its commits
|
|
305
|
+
// (`periodPunch`), else the year's or more, as GitHub's statistics count it;
|
|
306
|
+
// the commits pushed to the branch directly, the period's alone.
|
|
307
|
+
export function periodStats(stats: PulseStats, weeks: number) {
|
|
308
|
+
const { punches, directCommits, ...rest } = stats
|
|
309
|
+
const punch = punches?.[weeks]
|
|
310
|
+
const since = stats.weeks.at(-weeks)?.week ?? Number.NEGATIVE_INFINITY
|
|
311
|
+
return { ...rest, punch: punch ?? rest.punch, periodPunch: Boolean(punch), ...directCommits ? { directCommits: directCommits.filter(commit => commit.at >= since) } : {} }
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// GitHub's statistics of a year past YEAR_COMMITS (repositoryStats) with
|
|
315
|
+
// its `lines` added in, each week's and each contributor's, by login; null
|
|
316
|
+
// while GitHub is counting them, `lines` null.
|
|
317
|
+
export function withLines(stats: PulseStats, lines: PulseLines | null): PulseStats {
|
|
318
|
+
if (!lines) return { ...stats, lines: null }
|
|
319
|
+
if (!lines.lines) return { ...stats, lines: false }
|
|
320
|
+
const weekly = new Map(lines.weeks.map(([week, additions, deletions]) => [week, [additions, deletions]]))
|
|
321
|
+
const theirs = new Map(lines.contributors.map(person => [person.login, new Map(person.weeks.map(([week, additions, deletions]) => [week, [additions, deletions]]))]))
|
|
322
|
+
return {
|
|
323
|
+
...stats,
|
|
324
|
+
weeks: stats.weeks.map(week => ({ ...week, additions: weekly.get(week.week)?.[0] ?? 0, deletions: weekly.get(week.week)?.[1] ?? 0 })),
|
|
325
|
+
contributors: stats.contributors.map(person => ({ ...person, weeks: person.weeks.map(([week, made]) => {
|
|
326
|
+
const added = person.login ? theirs.get(person.login)?.get(week) : undefined
|
|
327
|
+
return [week, made, added?.[0] ?? 0, added?.[1] ?? 0] as [number, number, number, number]
|
|
328
|
+
}) })),
|
|
329
|
+
lines: true,
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Where a period of `weeks` weeks starts, as GitHub's statistics count weeks:
|
|
334
|
+
// the Sunday (UTC) that many weeks back, this week the last of them.
|
|
335
|
+
export function pulseSince(weeks: number, now: number) {
|
|
336
|
+
const today = Math.floor(now / DAY_MS) * DAY_MS
|
|
337
|
+
const sunday = today - new Date(today).getUTCDay() * DAY_MS
|
|
338
|
+
return sunday - (weeks - 1) * WEEK_MS
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const SEARCH = (name: string, fragment: string, first = 0) => `${name}: search(type: ISSUE, query: $${name}, first: ${Math.max(first, 1)}) {
|
|
342
|
+
issueCount${first > 0 ? ` nodes { ...${fragment} }` : ''}
|
|
343
|
+
}`
|
|
344
|
+
const ACTIVITY_QUERY = `query($merged: String!, $mergedBefore: String!, $opened: String!, $openedBefore: String!,
|
|
345
|
+
$closed: String!, $closedBefore: String!, $created: String!, $createdBefore: String!) {
|
|
346
|
+
${SEARCH('merged', 'pull', SEARCHED)}
|
|
347
|
+
${SEARCH('mergedBefore', 'pull')}
|
|
348
|
+
${SEARCH('opened', 'pull', LISTED)}
|
|
349
|
+
${SEARCH('openedBefore', 'pull')}
|
|
350
|
+
${SEARCH('closed', 'issue', SEARCHED)}
|
|
351
|
+
${SEARCH('closedBefore', 'issue')}
|
|
352
|
+
${SEARCH('created', 'issue', LISTED)}
|
|
353
|
+
${SEARCH('createdBefore', 'issue')}
|
|
354
|
+
}
|
|
355
|
+
fragment pull on PullRequest { number title pullState: state isDraft createdAt mergedAt author { ${ACTOR} } }
|
|
356
|
+
fragment issue on Issue { number title issueState: state stateReason createdAt closedAt author { ${ACTOR} } }`
|
|
357
|
+
|
|
358
|
+
type SearchNode = { number?: unknown; title?: unknown; pullState?: unknown; issueState?: unknown; isDraft?: unknown; stateReason?: unknown
|
|
359
|
+
createdAt?: unknown; mergedAt?: unknown; closedAt?: unknown; author?: GraphAccount } | null
|
|
360
|
+
type Search = { issueCount?: unknown; nodes?: SearchNode[] } | null | undefined
|
|
361
|
+
|
|
362
|
+
// An issue or pull request a search lists, as the popup's preview of it
|
|
363
|
+
// takes one, `at` when it was merged, opened or closed.
|
|
364
|
+
function listed(node: SearchNode, at: unknown) {
|
|
365
|
+
const named = itemOf(node)
|
|
366
|
+
if (!node || !named) return null
|
|
367
|
+
const common = { ...named, at: timeOf(at), createdAt: timeOf(node.createdAt) }
|
|
368
|
+
return node.pullState === undefined
|
|
369
|
+
? { ...common, kind: 'issues', ...issueState(node.issueState, node.stateReason) }
|
|
370
|
+
: { ...common, kind: 'pulls', ...pullState(node.pullState, node.isDraft) }
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// The pull requests merged and opened and the issues closed and opened since
|
|
374
|
+
// the start of the week `weeks` weeks back (`since`), and over the same days
|
|
375
|
+
// of the week `weeks` weeks earlier (`previous`, its count: a week's Sunday to
|
|
376
|
+
// Thursday beside the week before's, not the days just before, whose days of
|
|
377
|
+
// the week differ), the latest of each listed, as many as LISTED: those
|
|
378
|
+
// opened as GitHub sorts them, those merged or closed the latest of the
|
|
379
|
+
// SEARCHED most recently updated, which are the latest of all where the
|
|
380
|
+
// period holds no more, or the last listed was merged or closed after the
|
|
381
|
+
// SEARCHED-th was last updated. A search counts by the day (UTC). Narrowed
|
|
382
|
+
// (`narrowing`), those of its days from `from` to `to` (both days, UTC;
|
|
383
|
+
// none, on), and those its `authors` (GitHub logins) opened, any of them.
|
|
384
|
+
export async function repositoryActivity(fullName: string, token: string, weeks: number, now: number = Date.now(), fetchImpl: typeof fetch = globalThis.fetch,
|
|
385
|
+
narrowing: PulseNarrowing | null = null) {
|
|
386
|
+
const since = pulseSince(weeks, now)
|
|
387
|
+
const back = weeks * WEEK_MS
|
|
388
|
+
const day = (at: number) => new Date(at).toISOString().slice(0, 10)
|
|
389
|
+
const current = narrowing?.to == null ? `>=${day(narrowing?.from ?? since)}` : `${day(narrowing.from)}..${day(narrowing.to)}`
|
|
390
|
+
const previous = `${day(since - back)}..${day(now - back)}`
|
|
391
|
+
const repo = `repo:${fullName}`
|
|
392
|
+
// An app's login (`name[bot]`) is searched for as GitHub names its app.
|
|
393
|
+
const by = (narrowing?.authors ?? []).map(login => ` author:${login.endsWith('[bot]') ? `app/${login.slice(0, -5)}` : login}`).join('')
|
|
394
|
+
const asked = (what: string, range: string, sort: string) => `${repo} ${what}${range}${by} sort:${sort}`
|
|
395
|
+
const kinds = {
|
|
396
|
+
merged: ['is:pr is:merged merged:', 'updated-desc'], opened: ['is:pr created:', 'created-desc'],
|
|
397
|
+
closed: ['is:issue is:closed closed:', 'updated-desc'], created: ['is:issue created:', 'created-desc'],
|
|
398
|
+
} as const
|
|
399
|
+
const variables = Object.fromEntries(Object.entries(kinds).flatMap(([name, [what, sort]]) => [[name, asked(what, current, sort)],
|
|
400
|
+
[`${name}Before`, asked(what, previous, sort)]]))
|
|
401
|
+
const data = await githubGraphql(ACTIVITY_QUERY, variables, token, fetchImpl) as Record<string, Search> | null
|
|
402
|
+
const at = { merged: 'mergedAt', opened: 'createdAt', closed: 'closedAt', created: 'createdAt' } as const
|
|
403
|
+
const told = Object.fromEntries((Object.keys(kinds) as (keyof typeof kinds)[]).map(name => [name, {
|
|
404
|
+
count: count(data?.[name]?.issueCount),
|
|
405
|
+
previous: count(data?.[`${name}Before`]?.issueCount),
|
|
406
|
+
items: (data?.[name]?.nodes ?? []).flatMap(node => listed(node, node?.[at[name]]) ?? []).toSorted((a, b) => (b.at ?? 0) - (a.at ?? 0)).slice(0, LISTED),
|
|
407
|
+
}]))
|
|
408
|
+
return { since, previousSince: since - back, ...told }
|
|
409
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// A package's risk line, as a repository risk scan tells it
|
|
2
|
+
// (repository-risk.ts): its version's document read and assessed, as risk
|
|
3
|
+
// tells one npm removed where npm has none; and how a failure is told.
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises'
|
|
5
|
+
import { NpmRiskError, SEVERITIES, type Severity } from '../risk/index.js'
|
|
6
|
+
import { GithubApiError } from './github-errors.ts'
|
|
7
|
+
import { NpmPackageError, type NpmVersionDocument } from './npm-packages.ts'
|
|
8
|
+
import type { RiskLine } from './repository-risk.ts'
|
|
9
|
+
|
|
10
|
+
// An assessment refused as busy (`npm-busy`, by npm-risk.ts or the npm reads
|
|
11
|
+
// beneath it), or that npm asked to ask later (risk's `upstream-busy`, as its
|
|
12
|
+
// downloads API answers past a burst of requests), is asked again after a
|
|
13
|
+
// wait, up to this many times.
|
|
14
|
+
export const BUSY_RETRIES = 20
|
|
15
|
+
export const BUSY_WAIT_MS = 1000
|
|
16
|
+
|
|
17
|
+
// How long a package's risk line, or a lockfile's advisories, is told as it
|
|
18
|
+
// is: after it, a risk line is told stale and assessed again, as risk tells
|
|
19
|
+
// again what of a package changes in time, and advisories asked again, as npm
|
|
20
|
+
// publishes them (repository-risk.ts).
|
|
21
|
+
export const RISK_KEPT_MS = 60 * 60_000
|
|
22
|
+
|
|
23
|
+
// The most severe of `findings`, or null for none.
|
|
24
|
+
export function highestSeverity(findings: readonly { severity: Severity }[]): Severity | null {
|
|
25
|
+
return SEVERITIES.find(severity => findings.some(finding => finding.severity === severity)) ?? null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Why a step failed, as a line says it: an error's code, and for a lockfile
|
|
29
|
+
// refused, what of it its reader refused.
|
|
30
|
+
export type RiskFailure = { error: string; detail?: string }
|
|
31
|
+
|
|
32
|
+
// What an error is known by: a GitHub or npm failure's code, or `failed`;
|
|
33
|
+
// GitHub not reached with what failed (githubUnreachable), while `doing` what
|
|
34
|
+
// of a repository, and risk's with what it asked of npm and how that failed,
|
|
35
|
+
// where they say.
|
|
36
|
+
export function failureOf(error: unknown, doing?: string): RiskFailure {
|
|
37
|
+
if (error instanceof GithubApiError && error.detail) return { error: error.message, detail: doing ? `${doing}: ${error.detail}` : error.detail }
|
|
38
|
+
if (error instanceof GithubApiError || error instanceof NpmPackageError) return { error: error.message }
|
|
39
|
+
if (!(error instanceof NpmRiskError)) return { error: 'failed' }
|
|
40
|
+
return error.message === error.code ? { error: error.code } : { error: error.code, detail: error.message }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const isBusy = (error: unknown) => (error instanceof NpmPackageError && error.status === 429) || (error instanceof NpmRiskError && error.code === 'upstream-busy')
|
|
44
|
+
// `work` done, asked again a while after where it is refused as busy, as
|
|
45
|
+
// many times as `retries`, the wait given up with `signal`.
|
|
46
|
+
export async function notBusy<T>(work: () => Promise<T>, signal: AbortSignal, retries = BUSY_RETRIES): Promise<T> {
|
|
47
|
+
for (let attempt = 0; ; attempt++) {
|
|
48
|
+
try { return await work() } catch (error) {
|
|
49
|
+
if (!isBusy(error) || attempt >= retries) throw error
|
|
50
|
+
await delay(BUSY_WAIT_MS * Math.min(attempt + 1, 5), undefined, { signal })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A package to assess: npm's of its name and version, or, with an
|
|
56
|
+
// `integrity`, a mirror's held to it.
|
|
57
|
+
export interface AssessedPackage { name: string; version: string; integrity?: string }
|
|
58
|
+
|
|
59
|
+
export type Assessment = { published: string | null; findings: ({ id: string; severity: Severity } & Record<string, unknown>)[]; score: { score: number } }
|
|
60
|
+
|
|
61
|
+
// How many of what a finding found a risk line keeps, the first (its files,
|
|
62
|
+
// dependencies or scripts; the hosts it names anew, short as each is, up to
|
|
63
|
+
// TOLD_HOSTS), with how many there are (`count`), for the Packages tab's
|
|
64
|
+
// tooltips (repository-risk.js); and how long a text of it (npm's
|
|
65
|
+
// deprecation message, a script's command) may be.
|
|
66
|
+
export const TOLD_ROWS = 5
|
|
67
|
+
export const TOLD_HOSTS = 10
|
|
68
|
+
const TOLD_TEXT = 300
|
|
69
|
+
|
|
70
|
+
// What a risk line tells of a finding: its id and severity, whether npm took
|
|
71
|
+
// its package down, and of what it found (assessNpm's, risk/npm/held.js,
|
|
72
|
+
// combined.js), what its tooltip says, bounded (TOLD_ROWS, TOLD_TEXT): npm's
|
|
73
|
+
// deprecation message; its package's tier by downloads, and the known
|
|
74
|
+
// account or scope that lowers it; the accounts that published it and the
|
|
75
|
+
// one before; the scripts npm runs installing it; its files, each with what
|
|
76
|
+
// it runs or reaches for (their kinds), the services it names, how it is
|
|
77
|
+
// obfuscated, where it links, its size, or its longest line before and now;
|
|
78
|
+
// the dependencies it takes from elsewhere than npm or imports none of, by
|
|
79
|
+
// their specs; and the hosts it names anew, each where first.
|
|
80
|
+
export type ToldFinding = { id: string; severity: Severity; takenDown?: true } & Record<string, unknown>
|
|
81
|
+
type Row = Record<string, unknown>
|
|
82
|
+
const cut = (text: unknown) => typeof text === 'string' && text.length > TOLD_TEXT ? `${text.slice(0, TOLD_TEXT - 1)}…` : typeof text === 'string' ? text : undefined
|
|
83
|
+
const keysOf = (found: unknown) => found && typeof found === 'object' ? Object.keys(found) : []
|
|
84
|
+
const first = (key: string, rows: unknown, pick: (row: Row) => Row, most = TOLD_ROWS) => Array.isArray(rows)
|
|
85
|
+
? { [key]: (rows as Row[]).slice(0, most).map(pick), count: rows.length } : {}
|
|
86
|
+
const FILES: Partial<Record<string, (row: Row) => Row>> = {
|
|
87
|
+
'held-runs-code': row => ({ path: row['path'], kinds: keysOf(row['found']) }),
|
|
88
|
+
'held-credentials': row => ({ path: row['path'], kinds: keysOf(row['found']) }),
|
|
89
|
+
'held-exfiltration': row => ({ path: row['path'], services: keysOf(row['found']) }),
|
|
90
|
+
'held-remote': row => ({ path: row['path'], services: keysOf(row['found']) }),
|
|
91
|
+
'held-ip-lookup': row => ({ path: row['path'], services: keysOf(row['found']) }),
|
|
92
|
+
'held-obfuscated': row => ({ path: row['path'], ...row['found'] as Row }),
|
|
93
|
+
'held-symlinks': row => ({ path: row['path'], link: row['link'], ...row['outside'] === true ? { outside: true } : {} }),
|
|
94
|
+
'large-code': row => ({ path: row['path'], bytes: row['bytes'] }),
|
|
95
|
+
'binary-code': row => ({ path: row['path'], bytes: row['bytes'] }),
|
|
96
|
+
'now-unreadable': row => ({ path: row['path'], was: row['was'], now: row['now'] }),
|
|
97
|
+
}
|
|
98
|
+
export function toldFinding({ id, severity, ...found }: { id: string; severity: Severity } & Record<string, unknown>): ToldFinding {
|
|
99
|
+
const told: ToldFinding = { id, severity, ...found['takenDown'] === true ? { takenDown: true as const } : {} }
|
|
100
|
+
const files = FILES[id]
|
|
101
|
+
if (files) return { ...told, ...first('files', found['files'], files) }
|
|
102
|
+
switch (id) {
|
|
103
|
+
case 'deprecated': return { ...told, message: cut(found['message']) }
|
|
104
|
+
case 'popularity': return { ...told, tier: typeof found['tier'] === 'number' && Number.isFinite(found['tier']) ? found['tier'] : null,
|
|
105
|
+
...found['known'] ? { known: true } : {}, ...typeof found['scope'] === 'string' ? { scope: found['scope'] } : {}, ...typeof found['account'] === 'string' ? { account: found['account'] } : {} }
|
|
106
|
+
case 'publisher': return { ...told, was: found['was'], now: found['now'], wasStanding: found['wasStanding'] ?? (found['wasKnown'] ? 'known' : 'unknown'),
|
|
107
|
+
nowStanding: found['nowStanding'] ?? (found['nowKnown'] ? 'known' : 'unknown'), ...found['major'] ? { major: true } : {} }
|
|
108
|
+
case 'held-install-scripts': {
|
|
109
|
+
const scripts = Array.isArray(found['scripts']) ? found['scripts'] as [string, unknown][] : []
|
|
110
|
+
return { ...told, scripts: scripts.slice(0, TOLD_ROWS).map(([script, command]) => [script, cut(command) ?? '']), count: scripts.length }
|
|
111
|
+
}
|
|
112
|
+
case 'held-non-registry-deps': return { ...told, ...first('dependencies', found['dependencies'], row => ({ name: row['name'], spec: row['now'] })) }
|
|
113
|
+
case 'held-unused-deps': return { ...told, ...first('dependencies', found['dependencies'], row => ({ name: row['name'], spec: row['range'] })) }
|
|
114
|
+
case 'new-hosts': return { ...told, ...first('hosts', found['hosts'], row => {
|
|
115
|
+
const [place] = Array.isArray(row['places']) ? row['places'] as Row[] : []
|
|
116
|
+
return { host: row['host'], ...place ? { path: place['path'], line: place['line'] } : {} }
|
|
117
|
+
}, TOLD_HOSTS) }
|
|
118
|
+
default: return told
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// What of a scan's source assessing a package asks (RepositoryRiskSource).
|
|
123
|
+
export interface AssessingSource {
|
|
124
|
+
// npm's document of a version; an NpmPackageError where npm has none.
|
|
125
|
+
version(name: string, version: string, signal: AbortSignal): Promise<NpmVersionDocument>
|
|
126
|
+
assess(doc: NpmVersionDocument, teamScoped: boolean, signal: AbortSignal): Promise<Assessment>
|
|
127
|
+
// A version npm has no document of, as risk tells one npm removed: its
|
|
128
|
+
// malware alone, its package taken down by npm; an NpmRiskError where
|
|
129
|
+
// nothing tells of it (npm-risk.ts npmRiskRemoved).
|
|
130
|
+
removed(name: string, version: string, teamScoped: boolean, signal: AbortSignal): Promise<Assessment>
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// A package's risk line, its version's document kept and the assessment asked
|
|
134
|
+
// again after a wait while the server is busy; null once the scan stops. A
|
|
135
|
+
// version npm has no document of is told as risk tells one npm removed
|
|
136
|
+
// (removedOf), its malware keeping whether its package was taken down.
|
|
137
|
+
export async function assessPackage(source: AssessingSource, signal: AbortSignal, pkg: AssessedPackage, teamScoped: boolean): Promise<RiskLine | null> {
|
|
138
|
+
const at = { type: 'risk', ...pkg } as const
|
|
139
|
+
let doc: NpmVersionDocument | NpmPackageError | undefined
|
|
140
|
+
for (let attempt = 0; ; attempt++) {
|
|
141
|
+
try {
|
|
142
|
+
const read = doc ??= await documentOf(source, pkg, signal)
|
|
143
|
+
if (!(read instanceof NpmPackageError) && pkg.integrity !== undefined && !pkg.integrity.split(/\s+/u).includes(read.dist.integrity)) return { ...at, error: 'integrity-mismatch' }
|
|
144
|
+
const { published, findings, score } = read instanceof NpmPackageError ? await removedOf(source, pkg, teamScoped, signal, read) : await assessedOf(source, pkg, teamScoped, signal, read)
|
|
145
|
+
const told = findings.map(toldFinding)
|
|
146
|
+
return { ...at, published, severity: highestSeverity(told), score: score.score, findings: told }
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (signal.aborted) return null
|
|
149
|
+
if (!isBusy(error) || attempt >= BUSY_RETRIES) return { ...at, ...failureOf(error) }
|
|
150
|
+
try { await delay(BUSY_WAIT_MS * Math.min(attempt + 1, 5), undefined, { signal }) } catch { return null }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// npm's document of a version, or its answer that it has none (a 404).
|
|
156
|
+
async function documentOf(source: AssessingSource, pkg: AssessedPackage, signal: AbortSignal): Promise<NpmVersionDocument | NpmPackageError> {
|
|
157
|
+
try { return await source.version(pkg.name, pkg.version, signal) } catch (error) {
|
|
158
|
+
if (error instanceof NpmPackageError && error.status === 404) return error
|
|
159
|
+
throw error
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// A version's assessment; where risk finds npm no longer has it, as a document
|
|
164
|
+
// read from where versions' are kept doesn't tell, as one npm removed.
|
|
165
|
+
async function assessedOf(source: AssessingSource, pkg: AssessedPackage, teamScoped: boolean, signal: AbortSignal, doc: NpmVersionDocument): Promise<Assessment> {
|
|
166
|
+
try { return await source.assess(doc, teamScoped, signal) } catch (error) {
|
|
167
|
+
if (!(error instanceof NpmRiskError && error.code === 'version-not-found')) throw error
|
|
168
|
+
return removedOf(source, pkg, teamScoped, signal, new NpmPackageError(404, 'package-not-found'))
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// A version npm has no document of, as risk tells one npm removed, as it
|
|
173
|
+
// removes every one it finds malware in (`removed`): `gone`, npm's answer of
|
|
174
|
+
// none, thrown where nothing tells of it.
|
|
175
|
+
async function removedOf(source: AssessingSource, pkg: AssessedPackage, teamScoped: boolean, signal: AbortSignal, gone: NpmPackageError): Promise<Assessment> {
|
|
176
|
+
try { return await source.removed(pkg.name, pkg.version, teamScoped, signal) } catch (error) {
|
|
177
|
+
throw error instanceof NpmRiskError && (error.code === 'version-not-found' || error.code === 'package-not-found') ? gone : error
|
|
178
|
+
}
|
|
179
|
+
}
|