@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,293 @@
|
|
|
1
|
+
// The issues and pull requests the code viewer's Issues and Pull requests
|
|
2
|
+
// tabs show (GET /api/admin/repositories/issues): those open, or those
|
|
3
|
+
// closed (a pull request's merged among them), the most recently updated
|
|
4
|
+
// first, a page at a time, each as one tile has room for, with how many are
|
|
5
|
+
// open and closed. A pull request's tile names its branches, its size, its
|
|
6
|
+
// review and its checks, which GraphQL alone gives, so it needs a token; an
|
|
7
|
+
// open one's, and its popup's, whether it changes a lockfile whose new
|
|
8
|
+
// packages are told (pull-dependencies.ts touchesLockfile), and its reviews
|
|
9
|
+
// (pull-reviews.ts), each reviewer's; and an open one's base's and head's
|
|
10
|
+
// commits, kept with its page but never told, by which what its lockfiles
|
|
11
|
+
// add is read for its tile (http.ts keptPullCommits). A team's Dependencies
|
|
12
|
+
// reads the open ones in pages of its own, of less each (repositoryOpenPulls).
|
|
13
|
+
// A nonpublic repository's
|
|
14
|
+
// are read with its GitHub App's installation, which reads pull requests only
|
|
15
|
+
// with their own permission (doc/code-viewer.md).
|
|
16
|
+
import { ACTOR, type GraphAccount, actorOf } from './github-accounts.ts'
|
|
17
|
+
import { GithubApiError } from './github-errors.ts'
|
|
18
|
+
import { type GraphqlError, githubGraphql } from './github-graphql.ts'
|
|
19
|
+
import { SHA, count, nameOf, timeOf } from './github-values.ts'
|
|
20
|
+
import { pullRefs, touchesLockfile } from './pull-dependencies.ts'
|
|
21
|
+
import { ITEM_THREADS, type ReviewNode, TILE_THREADS, pullReviews, reviewFields, reviewsRefused } from './pull-reviews.ts'
|
|
22
|
+
import type { Connection } from './repository-history.ts'
|
|
23
|
+
|
|
24
|
+
const ISSUES_PAGE = 50
|
|
25
|
+
// What a kept page or item was read as: kept ones read before differ.
|
|
26
|
+
export const ISSUES_READ_VERSION = 4
|
|
27
|
+
const MAX_LABELS = 20
|
|
28
|
+
const MAX_TITLE = 1000
|
|
29
|
+
const COLOR = /^[a-f\d]{6}$/iu
|
|
30
|
+
// A page's cursor as GitHub gives it, to read on from: opaque, base64 or
|
|
31
|
+
// base64url as it is now (`…rOrK_u7Q==`), passed back to GitHub alone, so any
|
|
32
|
+
// printable one is, but none with spaces or control characters.
|
|
33
|
+
export const ISSUES_CURSOR = /^[!-~]{1,256}$/u
|
|
34
|
+
|
|
35
|
+
type IssuesKind = 'issues' | 'pulls'
|
|
36
|
+
type IssuesState = 'open' | 'closed'
|
|
37
|
+
|
|
38
|
+
const shared = `number title createdAt updatedAt closedAt author { ${ACTOR} } comments { totalCount } labels(first: ${MAX_LABELS}) { totalCount nodes { name color } }`
|
|
39
|
+
const fields = {
|
|
40
|
+
issues: `${shared} state stateReason`,
|
|
41
|
+
pulls: `${shared} state isDraft mergedAt reviewDecision additions deletions headRefName baseRefName
|
|
42
|
+
commits(last: 1) { nodes { commit { statusCheckRollup { state } } } }`,
|
|
43
|
+
}
|
|
44
|
+
// The files a pull request changes, as many as LISTED_FILES, as an open one's
|
|
45
|
+
// tile and its popup tell whether it changes a lockfile by them.
|
|
46
|
+
const LISTED_FILES = 100
|
|
47
|
+
const files = `files(first: ${LISTED_FILES}) { totalCount nodes { path } }`
|
|
48
|
+
const connection = { issues: 'issues', pulls: 'pullRequests' }
|
|
49
|
+
const states = { issues: { open: '[OPEN]', closed: '[CLOSED]' }, pulls: { open: '[OPEN]', closed: '[CLOSED, MERGED]' } }
|
|
50
|
+
|
|
51
|
+
// A page of `kind`, those in `state`, after the page `after` ends, and how
|
|
52
|
+
// many of each state there are; open pull requests with their commits and
|
|
53
|
+
// their reviews.
|
|
54
|
+
const pageQuery = (kind: IssuesKind, state: IssuesState) => `query($owner: String!, $name: String!, $after: String) {
|
|
55
|
+
repository(owner: $owner, name: $name) {
|
|
56
|
+
open: ${connection[kind]}(states: ${states[kind].open}) { totalCount }
|
|
57
|
+
closed: ${connection[kind]}(states: ${states[kind].closed}) { totalCount }
|
|
58
|
+
page: ${connection[kind]}(states: ${states[kind][state]}, first: ${ISSUES_PAGE}, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
59
|
+
pageInfo { hasNextPage endCursor }
|
|
60
|
+
nodes { ${fields[kind]}${kind === 'pulls' && state === 'open' ? ` baseRefOid headRefOid isCrossRepository ${files} ${reviewFields(TILE_THREADS, false)}` : ''} }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}`
|
|
64
|
+
|
|
65
|
+
type Node = ReviewNode & { number?: unknown; title?: unknown; createdAt?: unknown; updatedAt?: unknown; closedAt?: unknown; mergedAt?: unknown; author?: GraphAccount
|
|
66
|
+
comments?: { totalCount?: unknown }; labels?: { totalCount?: unknown; nodes?: { name?: unknown; color?: unknown }[] }; state?: unknown; stateReason?: unknown
|
|
67
|
+
isDraft?: unknown; reviewDecision?: unknown; additions?: unknown; deletions?: unknown; headRefName?: unknown; baseRefName?: unknown; baseRefOid?: unknown; isCrossRepository?: unknown
|
|
68
|
+
commits?: { nodes?: { commit?: { statusCheckRollup?: { state?: unknown } | null } | null }[] }
|
|
69
|
+
files?: { totalCount?: unknown; nodes?: ({ path?: unknown } | null)[] } | null }
|
|
70
|
+
type Page = { repository?: { open?: { totalCount?: unknown }; closed?: { totalCount?: unknown }; page?: Connection<Node>; defaultBranchRef?: { name?: unknown } | null } | null }
|
|
71
|
+
|
|
72
|
+
const REVIEWS: Record<string, string> = { APPROVED: 'approved', CHANGES_REQUESTED: 'changes', REVIEW_REQUIRED: 'required' }
|
|
73
|
+
const CHECKS: Record<string, string> = { SUCCESS: 'success', FAILURE: 'failure', ERROR: 'failure', PENDING: 'pending', EXPECTED: 'pending' }
|
|
74
|
+
// Why an issue was closed, as GitHub tells it: completed, not planned or a duplicate.
|
|
75
|
+
export type IssueReason = 'completed' | 'not-planned' | 'duplicate'
|
|
76
|
+
export const ISSUE_REASONS: Record<string, IssueReason> = { COMPLETED: 'completed', NOT_PLANNED: 'not-planned', DUPLICATE: 'duplicate' }
|
|
77
|
+
|
|
78
|
+
// An issue or pull request by its number, title and author, as its tile and
|
|
79
|
+
// the Pulse's lists (repository-pulse.ts) name it; null for one GitHub names
|
|
80
|
+
// no number for.
|
|
81
|
+
export function itemOf(node: { number?: unknown; title?: unknown; author?: GraphAccount } | null) {
|
|
82
|
+
if (!node || !Number.isSafeInteger(node.number) || (node.number as number) <= 0) return null
|
|
83
|
+
const author = actorOf(node.author)
|
|
84
|
+
return { number: node.number as number, title: nameOf(node.title, MAX_TITLE) ?? '', author: author.login, authorId: author.id }
|
|
85
|
+
}
|
|
86
|
+
// An issue's state as a tile tells it, and why it was closed; a pull
|
|
87
|
+
// request's, and whether it is a draft.
|
|
88
|
+
export const issueState = (state: unknown, reason: unknown) => ({ state: state === 'OPEN' ? 'open' : 'closed', reason: ISSUE_REASONS[String(reason)] ?? null })
|
|
89
|
+
export const pullState = (state: unknown, draft: unknown) => ({ state: state === 'MERGED' ? 'merged' : state === 'OPEN' ? 'open' : 'closed', draft: draft === true })
|
|
90
|
+
|
|
91
|
+
// An issue or pull request as a tile shows it; null for one GitHub names no
|
|
92
|
+
// number for.
|
|
93
|
+
function item(kind: IssuesKind, node: Node | null) {
|
|
94
|
+
const named = itemOf(node)
|
|
95
|
+
if (!node || !named) return null
|
|
96
|
+
const labels = (node.labels?.nodes ?? []).flatMap(label => {
|
|
97
|
+
const name = nameOf(label?.name)
|
|
98
|
+
return name ? [{ name, color: typeof label?.color === 'string' && COLOR.test(label.color) ? label.color.toLowerCase() : null }] : []
|
|
99
|
+
})
|
|
100
|
+
const common = { ...named, createdAt: timeOf(node.createdAt), updatedAt: timeOf(node.updatedAt),
|
|
101
|
+
closedAt: timeOf(node.closedAt), comments: count(node.comments?.totalCount), labels, moreLabels: Math.max(0, count(node.labels?.totalCount) - labels.length) }
|
|
102
|
+
if (kind === 'issues') return { ...common, ...issueState(node.state, node.stateReason) }
|
|
103
|
+
const checks = node.commits?.nodes?.[0]?.commit?.statusCheckRollup?.state
|
|
104
|
+
return { ...common, ...pullState(node.state, node.isDraft), mergedAt: timeOf(node.mergedAt),
|
|
105
|
+
review: REVIEWS[String(node.reviewDecision)] ?? null, checks: CHECKS[String(checks)] ?? null, additions: count(node.additions), deletions: count(node.deletions),
|
|
106
|
+
head: nameOf(node.headRefName), base: nameOf(node.baseRefName), ...lockfileTouched(node) }
|
|
107
|
+
}
|
|
108
|
+
// Whether a pull request changes a lockfile read (touchesLockfile), by the
|
|
109
|
+
// files of it listed; untold where GitHub lists none of them.
|
|
110
|
+
function lockfileTouched(node: Node) {
|
|
111
|
+
const listed = node.files?.nodes
|
|
112
|
+
const paths = Array.isArray(listed) ? listed.flatMap(file => typeof file?.path === 'string' ? [file.path] : []) : null
|
|
113
|
+
return paths ? { touchesLockfile: touchesLockfile(paths, count(node.files?.totalCount)) } : {}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// A pull request's checks, which a GitHub App reads only with the Checks and
|
|
117
|
+
// Commit statuses permissions, refused: its tile then shows none; or its
|
|
118
|
+
// files, whose lockfiles' new packages it then tells none of. Any other
|
|
119
|
+
// field refused, the list is, as one without Pull requests: read is.
|
|
120
|
+
const checksRefused = (error: GraphqlError) => error?.type === 'FORBIDDEN' && Array.isArray(error.path)
|
|
121
|
+
&& (error.path.includes('statusCheckRollup') || error.path.includes('files'))
|
|
122
|
+
const partRefused = (error: GraphqlError) => checksRefused(error) || reviewsRefused(error)
|
|
123
|
+
|
|
124
|
+
// One issue or pull request, as its popup shows it (GET
|
|
125
|
+
// /api/admin/repositories/item): as its tile does, with its description, its
|
|
126
|
+
// Markdown as written (never GitHub's HTML of it); an issue's pull requests closing
|
|
127
|
+
// it, a pull request's issues it closes, its commits and files changed, and
|
|
128
|
+
// who merged it. Its state, of a different type each, named apart. A
|
|
129
|
+
// description longer than MAX_BODY is shortened (`bodyShortened`), and the
|
|
130
|
+
// linked past the first LINKED counted (`moreLinked`), the rest on GitHub.
|
|
131
|
+
const MAX_BODY = 20_000
|
|
132
|
+
const LINKED = 10
|
|
133
|
+
const ITEM_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
|
|
134
|
+
repository(owner: $owner, name: $name) {
|
|
135
|
+
item: issueOrPullRequest(number: $number) {
|
|
136
|
+
__typename
|
|
137
|
+
... on Issue { ${shared} issueState: state stateReason body
|
|
138
|
+
closedByPullRequestsReferences(first: ${LINKED}, includeClosedPrs: true) { totalCount nodes { number title pullState: state isDraft } } }
|
|
139
|
+
... on PullRequest { ${shared} pullState: state isDraft mergedAt reviewDecision additions deletions headRefName baseRefName body changedFiles ${files}
|
|
140
|
+
commits(last: 1) { totalCount nodes { commit { statusCheckRollup { state } } } } mergedBy { ${ACTOR} }
|
|
141
|
+
closingIssuesReferences(first: ${LINKED}) { totalCount nodes { number title issueState: state stateReason } }
|
|
142
|
+
${reviewFields(ITEM_THREADS, true)} }
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}`
|
|
146
|
+
type Linked = { number?: unknown; title?: unknown; issueState?: unknown; pullState?: unknown; stateReason?: unknown; isDraft?: unknown } | null
|
|
147
|
+
type ItemNode = Node & { __typename?: unknown; issueState?: unknown; pullState?: unknown; body?: unknown; changedFiles?: unknown
|
|
148
|
+
commits?: Node['commits'] & { totalCount?: unknown }; mergedBy?: GraphAccount
|
|
149
|
+
closedByPullRequestsReferences?: Links; closingIssuesReferences?: Links }
|
|
150
|
+
type Links = { totalCount?: unknown; nodes?: Linked[] } | null
|
|
151
|
+
|
|
152
|
+
// The issues or pull requests an item names, each by its number, title and
|
|
153
|
+
// state, as `kind`'s tile names one.
|
|
154
|
+
const linked = (kind: IssuesKind, nodes: Linked[] | undefined) => (nodes ?? []).flatMap(node => {
|
|
155
|
+
const tile = item(kind, node ? { number: node.number, title: node.title, state: node.issueState ?? node.pullState, stateReason: node.stateReason, isDraft: node.isDraft } : null)
|
|
156
|
+
return tile ? [{ number: tile.number, title: tile.title, state: tile.state, ...'reason' in tile ? { reason: tile.reason } : { draft: tile.draft } }] : []
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
// The issue or pull request numbered `number`, its `kind` with it.
|
|
160
|
+
export async function repositoryItem(fullName: string, token: string, number: number, fetchImpl: typeof fetch = globalThis.fetch) {
|
|
161
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
162
|
+
const data = await githubGraphql(ITEM_QUERY, { owner, name, number }, token, fetchImpl, partRefused) as { repository?: { item?: ItemNode | null } | null }
|
|
163
|
+
const node = data?.repository?.item
|
|
164
|
+
const kind: IssuesKind | null = node?.__typename === 'Issue' ? 'issues' : node?.__typename === 'PullRequest' ? 'pulls' : null
|
|
165
|
+
const tile = kind && node ? item(kind, { ...node, state: kind === 'issues' ? node.issueState : node.pullState }) : null
|
|
166
|
+
if (!kind || !node || !tile) throw new GithubApiError(404, 'github-not-found')
|
|
167
|
+
// As written, but for blank lines before it and spaces after: a first
|
|
168
|
+
// line's indent, an indented code block's, kept.
|
|
169
|
+
const written = typeof node.body === 'string' ? node.body.replace(/^(?:[ \t]*\r?\n)+/u, '').trimEnd() : ''
|
|
170
|
+
const links = kind === 'issues' ? node.closedByPullRequestsReferences : node.closingIssuesReferences
|
|
171
|
+
const named = linked(kind === 'issues' ? 'pulls' : 'issues', links?.nodes)
|
|
172
|
+
const described = { body: written.slice(0, MAX_BODY), bodyShortened: written.length > MAX_BODY, moreLinked: Math.max(0, count(links?.totalCount) - named.length) }
|
|
173
|
+
const merger = actorOf(node.mergedBy)
|
|
174
|
+
return kind === 'issues' ? { kind, ...tile, ...described, closedBy: named }
|
|
175
|
+
: { kind, ...tile, ...described, closes: named, commits: count(node.commits?.totalCount), files: count(node.changedFiles),
|
|
176
|
+
mergedBy: merger.login, mergedById: merger.id, reviews: pullReviews(node, tile.author, true) }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// An open pull request's base's and head's commits, by its number, as GitHub
|
|
180
|
+
// has them now: those its REST API names `base.sha` and `head.sha`
|
|
181
|
+
// (pull-dependencies.ts pullCommits), with the branches they are of
|
|
182
|
+
// (pullRefs), its head's where it is no fork's, and that it is one's where
|
|
183
|
+
// it is. None where either isn't a commit's id.
|
|
184
|
+
const commitsOf = (number: number, { baseRefOid: base, headRefOid: head, baseRefName, headRefName, isCrossRepository }: Node) =>
|
|
185
|
+
typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)
|
|
186
|
+
? [{ number, base, head, ...pullRefs(baseRefName, isCrossRepository === false ? headRefName : undefined, isCrossRepository) }] : []
|
|
187
|
+
|
|
188
|
+
// The label the pull requests changing a repository's dependencies carry,
|
|
189
|
+
// as Dependabot's do: where it has one, a team's Dependencies reads its open
|
|
190
|
+
// pull requests carrying it alone (http.ts teamOpenPulls).
|
|
191
|
+
export const DEPENDENCIES_LABEL = 'dependencies'
|
|
192
|
+
const LABEL_QUERY = `query($owner: String!, $name: String!, $label: String!) { repository(owner: $owner, name: $name) { label(name: $label) { name } } }`
|
|
193
|
+
const labelRefused = (error: GraphqlError) => error?.type === 'FORBIDDEN' && Array.isArray(error.path) && error.path.includes('label')
|
|
194
|
+
|
|
195
|
+
// The repository's label named `label`, by its name as the repository has
|
|
196
|
+
// it, which its pull requests are read by; null where it has none, or GitHub
|
|
197
|
+
// refuses to tell.
|
|
198
|
+
export async function repositoryLabel(fullName: string, token: string, label: string, fetchImpl: typeof fetch = globalThis.fetch) {
|
|
199
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
200
|
+
const data = await githubGraphql(LABEL_QUERY, { owner, name, label }, token, fetchImpl, labelRefused) as { repository?: { label?: { name?: unknown } | null } | null }
|
|
201
|
+
const named = data?.repository?.label?.name
|
|
202
|
+
return { label: typeof named === 'string' && named !== '' ? named : null }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// A page of the repository's issues or pull requests in `state`, after the
|
|
206
|
+
// page `after` ended (null for the first): its `items`, how many are open and
|
|
207
|
+
// closed (`counts`), and, where more follow, the cursor reading them
|
|
208
|
+
// (`after`); open pull requests' commits (`commits`, commitsOf) too, which
|
|
209
|
+
// the code viewer is never told (http.ts handleRepositoryIssues).
|
|
210
|
+
export async function repositoryIssues(fullName: string, token: string, kind: IssuesKind, state: IssuesState, after: string | null, fetchImpl: typeof fetch = globalThis.fetch) {
|
|
211
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
212
|
+
const data = await githubGraphql(pageQuery(kind, state), { owner, name, after }, token, fetchImpl, partRefused) as Page
|
|
213
|
+
const repository = data?.repository
|
|
214
|
+
if (!repository) throw new GithubApiError(404, 'github-not-found')
|
|
215
|
+
const info = repository.page?.pageInfo
|
|
216
|
+
const next = info?.hasNextPage === true && typeof info.endCursor === 'string' && ISSUES_CURSOR.test(info.endCursor) ? info.endCursor : null
|
|
217
|
+
const open = kind === 'pulls' && state === 'open'
|
|
218
|
+
const tiles = (repository.page?.nodes ?? []).flatMap(node => {
|
|
219
|
+
const tile = item(kind, node)
|
|
220
|
+
return tile && node ? [{ node, tile }] : []
|
|
221
|
+
})
|
|
222
|
+
return {
|
|
223
|
+
items: tiles.map(({ node, tile }) => open ? { ...tile, reviews: pullReviews(node, tile.author) } : tile),
|
|
224
|
+
counts: { open: count(repository.open?.totalCount), closed: count(repository.closed?.totalCount) },
|
|
225
|
+
more: next !== null, after: next,
|
|
226
|
+
...open ? { commits: tiles.flatMap(({ node, tile }) => commitsOf(tile.number, node)) } : {},
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// A page of the open pull requests a team's Dependencies reads (http.ts
|
|
231
|
+
// teamOpenPulls), those carrying `$labels` alone where it names some: each by
|
|
232
|
+
// what its card there and its popup's heading tell (its number, title and
|
|
233
|
+
// author, when it was opened and last updated, whether it is a draft, the
|
|
234
|
+
// branch it is to merge into), the files by which whether it changes a
|
|
235
|
+
// lockfile is told, and its base's and head's commits, by which what its
|
|
236
|
+
// lockfiles add is read, with the branches they are of (commitsOf); and the
|
|
237
|
+
// repository's default branch, by its name. Nothing else a tile shows (its labels, comments,
|
|
238
|
+
// size, checks, reviews, threads and comments), which GitHub is slow enough
|
|
239
|
+
// to gather for fifty of a large repository's to fail the page.
|
|
240
|
+
const openPullsQuery = (labelled: boolean) => `query($owner: String!, $name: String!, $first: Int!, $after: String${labelled ? ', $labels: [String!]' : ''}) {
|
|
241
|
+
repository(owner: $owner, name: $name) {
|
|
242
|
+
defaultBranchRef { name }
|
|
243
|
+
page: pullRequests(states: [OPEN], first: $first, after: $after, ${labelled ? 'labels: $labels, ' : ''}orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
244
|
+
pageInfo { hasNextPage endCursor }
|
|
245
|
+
nodes { number title createdAt updatedAt author { ${ACTOR} } state isDraft baseRefOid headRefOid baseRefName headRefName isCrossRepository ${files} }
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}`
|
|
249
|
+
// What a kept page of them was read as: kept ones read before differ.
|
|
250
|
+
export const OPEN_PULLS_READ = 2
|
|
251
|
+
// How many a page asks for: ISSUES_PAGE, then, where GitHub fails to answer
|
|
252
|
+
// that many in its time, fewer, and fewer again.
|
|
253
|
+
export const OPEN_PULLS_SIZES = [ISSUES_PAGE, 20, 5]
|
|
254
|
+
// GitHub not answering a query in its time: its gateway's 502 or 504, the
|
|
255
|
+
// timeout it tells of itself, or ours of it. Fewer asked for may be answered.
|
|
256
|
+
const SLOW = new Set(['github-status-502', 'github-status-504', 'github-timeout', 'github-unreachable'])
|
|
257
|
+
const tooSlow = (err: unknown) => err instanceof GithubApiError && SLOW.has(err.message)
|
|
258
|
+
|
|
259
|
+
// A page of the repository's open pull requests, the latest updated first,
|
|
260
|
+
// after the page `after` ended (null for the first), those carrying `label`
|
|
261
|
+
// alone where it names one: its `items`, their commits (`commits`, commitsOf),
|
|
262
|
+
// the repository's default branch (`defaultBranch`, null where it tells none)
|
|
263
|
+
// and, where more follow, the cursor reading them (`after`). As many as
|
|
264
|
+
// `size` asked for, then, GitHub too slow to answer, as many as each smaller
|
|
265
|
+
// of OPEN_PULLS_SIZES, the last one's failure the read's; how many were
|
|
266
|
+
// asked for (`size`) told, for the pages after it to ask no more.
|
|
267
|
+
export async function repositoryOpenPulls(fullName: string, token: string, after: string | null, label: string | null, size: number = ISSUES_PAGE,
|
|
268
|
+
fetchImpl: typeof fetch = globalThis.fetch) {
|
|
269
|
+
const fitting = OPEN_PULLS_SIZES.filter(one => one <= size)
|
|
270
|
+
const sizes = fitting.length > 0 ? fitting : OPEN_PULLS_SIZES.slice(-1)
|
|
271
|
+
for (const first of sizes.slice(0, -1)) {
|
|
272
|
+
try { return await openPullsPage(fullName, token, after, label, first, fetchImpl) } catch (err) {
|
|
273
|
+
if (!tooSlow(err)) throw err
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return openPullsPage(fullName, token, after, label, sizes.at(-1)!, fetchImpl)
|
|
277
|
+
}
|
|
278
|
+
async function openPullsPage(fullName: string, token: string, after: string | null, label: string | null, first: number, fetchImpl: typeof fetch) {
|
|
279
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
280
|
+
const data = await githubGraphql(openPullsQuery(label !== null), { owner, name, first, after, ...label === null ? {} : { labels: [label] } }, token, fetchImpl, checksRefused) as Page
|
|
281
|
+
const repository = data?.repository
|
|
282
|
+
if (!repository) throw new GithubApiError(404, 'github-not-found')
|
|
283
|
+
const info = repository.page?.pageInfo
|
|
284
|
+
const next = info?.hasNextPage === true && typeof info.endCursor === 'string' && ISSUES_CURSOR.test(info.endCursor) ? info.endCursor : null
|
|
285
|
+
const pulls = (repository.page?.nodes ?? []).flatMap(node => {
|
|
286
|
+
const named = itemOf(node)
|
|
287
|
+
const base = nameOf(node?.baseRefName)
|
|
288
|
+
return node && named ? [{ node, tile: { ...named, createdAt: timeOf(node.createdAt), updatedAt: timeOf(node.updatedAt), ...pullState(node.state, node.isDraft),
|
|
289
|
+
...base ? { base } : {}, ...lockfileTouched(node) } }] : []
|
|
290
|
+
})
|
|
291
|
+
return { items: pulls.map(({ tile }) => tile), commits: pulls.flatMap(({ node, tile }) => commitsOf(tile.number, node)), defaultBranch: nameOf(repository.defaultBranchRef?.name),
|
|
292
|
+
more: next !== null, after: next, size: first }
|
|
293
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { StoredUser } from './db.ts'
|
|
2
|
+
|
|
3
|
+
const WHITEHAT = [
|
|
4
|
+
291301, // ChALkeR
|
|
5
|
+
259122746, // exo-nikita
|
|
6
|
+
247161625, // ex0sec
|
|
7
|
+
]
|
|
8
|
+
const whitehatIds = new Set(WHITEHAT)
|
|
9
|
+
|
|
10
|
+
// (1) Server permission to add repositories. Keep this independent of GitHub
|
|
11
|
+
// identity and ecosystem exceptions if other install modes broaden it later.
|
|
12
|
+
export function canAddRepositories(user: StoredUser): boolean {
|
|
13
|
+
return user.role === 'admin'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// (3b) Only the ecosystem safeguard for public repositories is bypassed by
|
|
17
|
+
// WHITEHAT. Callers must separately establish (0) server readability, (1) add
|
|
18
|
+
// permission, and (2) server admin or GitHub access to this repository.
|
|
19
|
+
export function passesPublicRepositorySafeguard(githubUserId: number | null, involved: boolean): boolean {
|
|
20
|
+
return involved || (githubUserId != null && whitehatIds.has(githubUserId))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Arbitrary public repositories have no involvement evidence, so (2) requires
|
|
24
|
+
// admin even if (1) expands in the future. This capability is also the UI gate.
|
|
25
|
+
export function canAddAnyPublicRepository(user: StoredUser, githubUserId: number | null): boolean {
|
|
26
|
+
return canAddRepositories(user) && user.role === 'admin' && passesPublicRepositorySafeguard(githubUserId, false)
|
|
27
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// A repository's pull requests and its issues, the most recently updated
|
|
2
|
+
// first, each kept once for all of those that read them so (http.ts
|
|
3
|
+
// keptList): the Pulse, telling whose its year's commits are by the pull
|
|
4
|
+
// requests merged (agent-merges.ts agentMerges) and counting those of a
|
|
5
|
+
// period (repository-pulse.ts listedActivity), and the Agents tab, its pages
|
|
6
|
+
// of pull requests (repository-agents.ts agentPulls) and its latest issues.
|
|
7
|
+
// Those updated since the Pulse's year's start, a few queries an answer, the
|
|
8
|
+
// rest read by the next, and those updated since read as they are. An issue
|
|
9
|
+
// kept as both show it; a pull request as the Agents tab shows it
|
|
10
|
+
// (repository-agents.ts pull: the marks an agent left in its texts, never
|
|
11
|
+
// the texts) and, one merged, what it brought the default branch, as the
|
|
12
|
+
// Pulse tells it: an agent that
|
|
13
|
+
// commits as whoever ran it (Codex's own) leaves its commits no mark, its
|
|
14
|
+
// pull request's branch alone naming it (app-agents.ts
|
|
15
|
+
// AGENT_BRANCH_PREFIXES), or a label one who ran it gave it naming the agent
|
|
16
|
+
// (agent-tasks.ts labelAgents), as the Agents tab tells an agent's work; or
|
|
17
|
+
// its author, an account agents work as (github-agents.ts AGENT_OPERATED),
|
|
18
|
+
// or any GitHub App's bot.
|
|
19
|
+
import { type AgentIssue, type AgentPull, labelAgents } from '../common/managed/agent-tasks.ts'
|
|
20
|
+
import { GITHUB_AGENTS, agentOperated } from '../common/managed/github-agents.ts'
|
|
21
|
+
import { AGENT_BRANCH_PREFIXES } from './app-agents.ts'
|
|
22
|
+
import { AGENT_ISSUE_FIELDS, AGENT_PULL_FIELDS, type IssueNode, type PullNode, issue, pull } from './repository-agents.ts'
|
|
23
|
+
import { githubGraphql } from './github-graphql.ts'
|
|
24
|
+
import { SHA, count, timeOf } from './github-values.ts'
|
|
25
|
+
import { type Connection, nextCursor } from './repository-history.ts'
|
|
26
|
+
import { ISSUE_REASONS, type IssueReason } from './repository-issues.ts'
|
|
27
|
+
|
|
28
|
+
// What the pull requests kept are read by, its version: bumped as what a
|
|
29
|
+
// page reads, or how one is told, changes, its pull requests read again
|
|
30
|
+
// (http.ts keptList keys them by AGENTS_READ_VERSION and the Pulse's
|
|
31
|
+
// PULSE_YEAR_VERSION too, as either changes how it tells an agent's); and
|
|
32
|
+
// the issues kept.
|
|
33
|
+
export const PULLS_READ_VERSION = 2
|
|
34
|
+
export const ISSUES_LIST_READ_VERSION = 1
|
|
35
|
+
// The pull requests or issues read an answer, a page a query, as many
|
|
36
|
+
// queries as LIST_QUERIES, the rest left for the next to ask; of each pull
|
|
37
|
+
// request merged, as many of its latest commits as MERGED_COMMITS. Those
|
|
38
|
+
// updated since the newest read, few as they mostly are, read TOP_UP_PAGE
|
|
39
|
+
// first, the rest LIST_PAGE a page (GitHub reading on from a page's end
|
|
40
|
+
// whatever its size).
|
|
41
|
+
const LIST_PAGE = 100
|
|
42
|
+
const TOP_UP_PAGE = 10
|
|
43
|
+
const LIST_QUERIES = 5
|
|
44
|
+
const MERGED_COMMITS = 100
|
|
45
|
+
const LABEL_AGENTS = Object.keys(GITHUB_AGENTS)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// A pull request as read: its row on the Agents tab, whether a GitHub App's
|
|
49
|
+
// bot opened it (`bot`, GitHub's GraphQL API naming one by its app's login
|
|
50
|
+
// alone), and one merged, what it brought the default branch (`merged`).
|
|
51
|
+
export type KeptPull = AgentPull & { bot?: true; merged?: Merged }
|
|
52
|
+
// What a merged pull request brought: its merge commit (`sha`), when it was
|
|
53
|
+
// merged (`at`) and whether it was an agent's (agentPull); an agent's merged
|
|
54
|
+
// with a merge commit, which a year counts none of, its own commits too
|
|
55
|
+
// (`own`, its latest MERGED_COMMITS); and of one of more commits whose merge
|
|
56
|
+
// commit has one parent, its commits' subjects, the oldest first, for those
|
|
57
|
+
// it was rebased as to be told by (agent-merges.ts agentCommits), those of
|
|
58
|
+
// its empty commits left out, as a rebase leaves them, and how many more it
|
|
59
|
+
// had than those read (`more`).
|
|
60
|
+
export interface Merged { sha: string; at: number; agent: boolean; own?: string[]; subjects?: string[]; more?: number }
|
|
61
|
+
// An issue as read: as the Agents tab shows it, whether a bot opened it
|
|
62
|
+
// (`bot`, as a pull request's), when it was closed, and why (`reason`, as
|
|
63
|
+
// GitHub tells it: completed, not planned or a duplicate).
|
|
64
|
+
export type KeptIssue = AgentIssue & { bot?: true; closedAt: number | null; reason: IssueReason | null }
|
|
65
|
+
// The pull requests or issues updated since a year's start (`since`) as
|
|
66
|
+
// read so far (readList), the most recently updated first (`rows`); when the
|
|
67
|
+
// newest read was last updated, those updated since read again (`through`,
|
|
68
|
+
// null till all are read once), and where those read reach back no further
|
|
69
|
+
// than was needed, when the oldest of them was updated (`reach`); whether
|
|
70
|
+
// every one the repository has is read (`all`); and a read not finished:
|
|
71
|
+
// where it goes on (`after`), when the newest it began with was updated
|
|
72
|
+
// (`from`), the oldest it reads to (`stop`), how many it has read (`read`)
|
|
73
|
+
// and when the oldest of them was updated (`to`).
|
|
74
|
+
export interface Listed<Row> { rows: Row[]; since: number; through: number | null; reach?: number; all?: true
|
|
75
|
+
next: { after: string; from: number; stop: number; read: number; to?: number } | null }
|
|
76
|
+
export type PullList = Listed<KeptPull>
|
|
77
|
+
export type IssueList = Listed<KeptIssue>
|
|
78
|
+
|
|
79
|
+
// Since when every one updated is read: all of them since the year's
|
|
80
|
+
// start, -∞; none yet, ∞.
|
|
81
|
+
export const pullsReadTo = (list: Pick<Listed<unknown>, 'next' | 'reach'>) => list.next ? list.next.to ?? Number.POSITIVE_INFINITY : list.reach ?? Number.NEGATIVE_INFINITY
|
|
82
|
+
|
|
83
|
+
const PULLS_QUERY = `query($owner: String!, $name: String!, $after: String, $first: Int!) {
|
|
84
|
+
repository(owner: $owner, name: $name) {
|
|
85
|
+
pullRequests(first: $first, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
86
|
+
pageInfo { hasNextPage endCursor }
|
|
87
|
+
nodes { ${AGENT_PULL_FIELDS} mergedAt mergeCommit { oid parents { totalCount } }
|
|
88
|
+
commits(last: ${MERGED_COMMITS}) { totalCount nodes { commit { oid messageHeadline changedFilesIfAvailable } } } }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}`
|
|
92
|
+
type MergedNode = PullNode & { mergedAt?: unknown; mergeCommit?: { oid?: unknown; message?: unknown; parents?: { totalCount?: unknown } | null } | null
|
|
93
|
+
author?: PullNode['author'] & { __typename?: unknown }
|
|
94
|
+
commits?: { totalCount?: unknown; nodes?: ({ commit?: { oid?: unknown; messageHeadline?: unknown; changedFilesIfAvailable?: unknown } | null } | null)[] } | null }
|
|
95
|
+
const ISSUES_QUERY = `query($owner: String!, $name: String!, $after: String, $first: Int!) {
|
|
96
|
+
repository(owner: $owner, name: $name) {
|
|
97
|
+
issues(first: $first, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }) {
|
|
98
|
+
pageInfo { hasNextPage endCursor }
|
|
99
|
+
nodes { ${AGENT_ISSUE_FIELDS} stateReason closedAt }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}`
|
|
103
|
+
type ClosedNode = IssueNode & { stateReason?: unknown; closedAt?: unknown; author?: IssueNode['author'] & { __typename?: unknown } }
|
|
104
|
+
const botOf = (author: { __typename?: unknown } | null | undefined) => author?.__typename === 'Bot' ? { bot: true as const } : {}
|
|
105
|
+
type ListPage<Node> = { repository?: Record<string, Connection<Node> | null> | null }
|
|
106
|
+
|
|
107
|
+
const agentBranch = (name: unknown) => typeof name === 'string' && AGENT_BRANCH_PREFIXES.some(prefix => name.startsWith(prefix))
|
|
108
|
+
// Whether a pull request is an agent's: by its branch, a label naming one,
|
|
109
|
+
// or its author, an account agents work as or a bot (GitHub's GraphQL API
|
|
110
|
+
// naming a bot by its app's login alone, its type telling it).
|
|
111
|
+
const agentPull = ({ headRefName, labels, author }: MergedNode) => agentBranch(headRefName)
|
|
112
|
+
|| labelAgents((labels?.nodes ?? []).map(label => label?.name), LABEL_AGENTS).length > 0 || author?.__typename === 'Bot'
|
|
113
|
+
|| agentOperated(typeof author?.login === 'string' ? author.login : null, Number.isSafeInteger(author?.databaseId) ? author!.databaseId as number : null)
|
|
114
|
+
|
|
115
|
+
// What a pull request merged brought (Merged); null for one not merged.
|
|
116
|
+
function mergedOf(node: MergedNode): Merged | null {
|
|
117
|
+
const [at, sha] = [timeOf(node.mergedAt), node.mergeCommit?.oid]
|
|
118
|
+
if (at === null || typeof sha !== 'string' || !SHA.test(sha)) return null
|
|
119
|
+
const commits = (node.commits?.nodes ?? []).map(item => item?.commit)
|
|
120
|
+
const merging = count(node.mergeCommit?.parents?.totalCount) > 1
|
|
121
|
+
const copied = commits.filter(commit => commit?.changedFilesIfAvailable !== 0)
|
|
122
|
+
// Of one of more commits than its latest read, how many more it had.
|
|
123
|
+
const more = Math.max(0, count(node.commits?.totalCount) - commits.length)
|
|
124
|
+
const subjects = !merging && (copied.length > 1 || more > 0) && copied.length > 0 && copied.every(commit => typeof commit?.messageHeadline === 'string')
|
|
125
|
+
? copied.map(commit => commit!.messageHeadline as string) : null
|
|
126
|
+
const agent = agentPull(node)
|
|
127
|
+
const own = agent && merging ? commits.flatMap(commit => typeof commit?.oid === 'string' && SHA.test(commit.oid) ? [commit.oid] : []) : []
|
|
128
|
+
return { sha, at, agent, ...own.length > 0 ? { own } : {}, ...subjects ? { subjects, ...more > 0 ? { more } : {} } : {} }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// What an issue closed tells beside its row (KeptIssue).
|
|
132
|
+
function closedOf(node: ClosedNode): KeptIssue | null {
|
|
133
|
+
const row = issue(node)
|
|
134
|
+
return row ? { ...row, ...botOf(node.author), closedAt: timeOf(node.closedAt), reason: ISSUE_REASONS[String(node.stateReason)] ?? null } : null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The most recently updated first, the higher number first of those
|
|
138
|
+
// updated together.
|
|
139
|
+
const newestFirst = (a: { number: number; updatedAt: number | null }, b: { number: number; updatedAt: number | null }) =>
|
|
140
|
+
(b.updatedAt ?? 0) - (a.updatedAt ?? 0) || b.number - a.number
|
|
141
|
+
|
|
142
|
+
// How a list is read: the query of its pages, the repository's connection
|
|
143
|
+
// they are of, and what each of them is kept as.
|
|
144
|
+
interface ListSpec<Node, Row> { query: string; connection: 'pullRequests' | 'issues'; row(node: Node): Row | null }
|
|
145
|
+
const PULLS: ListSpec<MergedNode, KeptPull> = { query: PULLS_QUERY, connection: 'pullRequests', row: node => {
|
|
146
|
+
const row = pull(node)
|
|
147
|
+
const merged = mergedOf(node)
|
|
148
|
+
return row ? { ...row, ...botOf(node.author), ...merged ? { merged } : {} } : null
|
|
149
|
+
} }
|
|
150
|
+
const ISSUES: ListSpec<ClosedNode, KeptIssue> = { query: ISSUES_QUERY, connection: 'issues', row: closedOf }
|
|
151
|
+
|
|
152
|
+
// The pull requests updated since `since` (readList), and what each merged
|
|
153
|
+
// brought.
|
|
154
|
+
export const readPulls = (fullName: string, token: string, since: number, kept: PullList | null, fetchImpl: typeof fetch = globalThis.fetch, need = since) =>
|
|
155
|
+
readList(PULLS, fullName, token, since, kept, fetchImpl, need)
|
|
156
|
+
// The issues updated since `since` (readList), and when and why each closed was.
|
|
157
|
+
export const readIssues = (fullName: string, token: string, since: number, kept: IssueList | null, fetchImpl: typeof fetch = globalThis.fetch, need = since) =>
|
|
158
|
+
readList(ISSUES, fullName, token, since, kept, fetchImpl, need)
|
|
159
|
+
|
|
160
|
+
// Those of a list (`spec`) updated since `since`, read the most recently
|
|
161
|
+
// updated first (a pull request is updated when merged, or after, an issue
|
|
162
|
+
// when closed), on from what was `kept`: till one updated before the year,
|
|
163
|
+
// or before the newest read before was, as many queries an answer as
|
|
164
|
+
// LIST_QUERIES, a read not finished going on from where it was left by the
|
|
165
|
+
// next, or once those updated since `need` are all read; where those read
|
|
166
|
+
// reached no further back than they needed, and `need` is further, read
|
|
167
|
+
// again from the newest on, as far back as it needs. Each kept as last read,
|
|
168
|
+
// one updated before the year forgotten.
|
|
169
|
+
async function readList<Node extends { updatedAt?: unknown }, Row extends { number: number; updatedAt: number | null }>(spec: ListSpec<Node, Row>,
|
|
170
|
+
fullName: string, token: string, since: number, kept: Listed<Row> | null, fetchImpl: typeof fetch, need: number): Promise<Listed<Row>> {
|
|
171
|
+
const [owner, name] = fullName.split('/') as [string, string]
|
|
172
|
+
const rows = new Map((kept?.rows ?? []).filter(item => (item.updatedAt ?? 0) >= since).map(item => [item.number, item]))
|
|
173
|
+
// Every one read, as long as none was forgotten, the year begun since.
|
|
174
|
+
const whole = kept?.all === true && rows.size === kept.rows.length
|
|
175
|
+
const further = !kept?.next && kept?.reach !== undefined && kept.reach > need
|
|
176
|
+
const stop = kept?.next?.stop ?? (further ? since : Math.max(since, kept?.through ?? since))
|
|
177
|
+
const result = (through: number | null, next: Listed<Row>['next'], reach: number | undefined, all = whole): Listed<Row> => ({
|
|
178
|
+
rows: [...rows.values()].toSorted(newestFirst), since, through, ...reach === undefined ? {} : { reach }, ...all ? { all: true as const } : {}, next })
|
|
179
|
+
// A read of those updated since the newest read alone.
|
|
180
|
+
const topping = !kept?.next && !further && kept?.through !== null && kept?.through !== undefined
|
|
181
|
+
let { after = null, from = null, read = 0, to = null }: { after?: string | null; from?: number | null; read?: number; to?: number | null } = kept?.next ?? {}
|
|
182
|
+
for (let queries = 0; queries < LIST_QUERIES; queries++) {
|
|
183
|
+
const first = topping && queries === 0 ? TOP_UP_PAGE : LIST_PAGE
|
|
184
|
+
const page = (await githubGraphql(spec.query, { owner, name, after, first }, token, fetchImpl) as ListPage<Node> | null)?.repository?.[spec.connection]
|
|
185
|
+
const cursor = nextCursor(page?.pageInfo), end = cursor === null
|
|
186
|
+
let crossed = false
|
|
187
|
+
for (const node of page?.nodes ?? []) {
|
|
188
|
+
const updated = timeOf(node?.updatedAt)
|
|
189
|
+
if (!node || updated === null) continue
|
|
190
|
+
if (updated < stop) { crossed = true; break }
|
|
191
|
+
from ??= updated
|
|
192
|
+
to = updated
|
|
193
|
+
read++
|
|
194
|
+
const row = spec.row(node)
|
|
195
|
+
if (row) rows.set(row.number, row)
|
|
196
|
+
}
|
|
197
|
+
// Read as far back as it reads to: the year's start, every one since
|
|
198
|
+
// read; else as far as those read before reached. Read to the last
|
|
199
|
+
// the repository has, every one of them.
|
|
200
|
+
if (crossed || end) return result(from ?? stop, null, stop > since ? kept?.reach : undefined, (end && !crossed) || (whole && stop > since))
|
|
201
|
+
after = cursor
|
|
202
|
+
// Read as far back as `need`: finished, so far back, those updated
|
|
203
|
+
// since read by the next as ever.
|
|
204
|
+
if (need > since && to !== null && to < need) return result(Math.max(from ?? stop, kept?.through ?? Number.NEGATIVE_INFINITY), null, to)
|
|
205
|
+
}
|
|
206
|
+
return result(kept?.through ?? null, { after: after!, from: from ?? stop, stop, read, ...to === null ? {} : { to } }, kept?.reach)
|
|
207
|
+
}
|