@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,204 @@
|
|
|
1
|
+
// GitHub accounts a user links to their own on the profile page. A linked
|
|
2
|
+
// account's identity is reserved for that user: it can neither sign in nor
|
|
3
|
+
// register (upsertUser refuses it in the transaction that would create the
|
|
4
|
+
// user), and an account that has registered cannot be linked. The user's
|
|
5
|
+
// login and GitHub id stay the sign-in account's; the displayed name and
|
|
6
|
+
// avatar may come from any of their accounts.
|
|
7
|
+
import { randomUUID } from 'node:crypto'
|
|
8
|
+
import type { ManagedUser } from './db-methods.ts'
|
|
9
|
+
import { ManagedMutationError } from './management.ts'
|
|
10
|
+
import type { ManagedSql } from './sql.ts'
|
|
11
|
+
|
|
12
|
+
// login/name are snapshots of the account as it was last linked; linking it
|
|
13
|
+
// again refreshes them. Its avatar is cached under the link id (avatar-store.ts).
|
|
14
|
+
export const GITHUB_LINK_SCHEMA = `
|
|
15
|
+
CREATE TABLE IF NOT EXISTS managed_github_link (
|
|
16
|
+
id TEXT PRIMARY KEY,
|
|
17
|
+
user_id TEXT NOT NULL REFERENCES managed_user(id) ON DELETE CASCADE,
|
|
18
|
+
github_user_id INTEGER NOT NULL UNIQUE,
|
|
19
|
+
login TEXT NOT NULL,
|
|
20
|
+
name TEXT,
|
|
21
|
+
linked_at INTEGER NOT NULL
|
|
22
|
+
) STRICT;
|
|
23
|
+
|
|
24
|
+
CREATE INDEX IF NOT EXISTS managed_github_link_user_idx ON managed_github_link(user_id);
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
// managed_user columns added with the table. managed_user.name is the
|
|
28
|
+
// displayed name; github_name keeps the sign-in account's own. name_link and
|
|
29
|
+
// avatar_link name the linked account each comes from, NULL the sign-in one.
|
|
30
|
+
export const GITHUB_LINK_USER_COLUMNS: readonly (readonly [string, string])[] = [
|
|
31
|
+
['github_name', 'TEXT'],
|
|
32
|
+
['name_link', 'TEXT REFERENCES managed_github_link(id) ON DELETE SET NULL'],
|
|
33
|
+
['avatar_link', 'TEXT REFERENCES managed_github_link(id) ON DELETE SET NULL'],
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
export interface LinkedGithubAccount {
|
|
37
|
+
id: string
|
|
38
|
+
// Its GitHub account's numeric id, which GitHub never gives another.
|
|
39
|
+
githubId: number
|
|
40
|
+
login: string
|
|
41
|
+
name: string | null
|
|
42
|
+
linkedAt: number
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ManagedProfile {
|
|
46
|
+
// Always the sign-in account's.
|
|
47
|
+
login: string
|
|
48
|
+
// The displayed name, and the sign-in account's own GitHub name.
|
|
49
|
+
name: string | null
|
|
50
|
+
githubName: string | null
|
|
51
|
+
// The linked account the displayed name or avatar comes from, null the sign-in one.
|
|
52
|
+
nameAccount: string | null
|
|
53
|
+
avatarAccount: string | null
|
|
54
|
+
accounts: LinkedGithubAccount[]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A user as the app shows them where a GitHub login of theirs is named: by
|
|
58
|
+
// their id, whose avatar /api/avatar/<id> serves (the one they chose), their
|
|
59
|
+
// sign-in login and the name they chose.
|
|
60
|
+
export interface AppUser {
|
|
61
|
+
id: string
|
|
62
|
+
login: string
|
|
63
|
+
name: string | null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Which account the displayed name and avatar each come from: a linked
|
|
67
|
+
// account's id, or null for the sign-in account. An absent key is unchanged.
|
|
68
|
+
export interface ProfileChoice {
|
|
69
|
+
name?: string | null
|
|
70
|
+
avatar?: string | null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface GithubLinkStore {
|
|
74
|
+
getProfile(userId: string): Promise<ManagedProfile | null>
|
|
75
|
+
// Link `account` to the session's own user, or refresh the snapshot of one
|
|
76
|
+
// they linked before. Refused for the sign-in account itself, an account
|
|
77
|
+
// another user linked, and any account that has registered.
|
|
78
|
+
linkGithubAccount(sessionId: string, account: ManagedUser, now: number): Promise<{ id: string; created: boolean }>
|
|
79
|
+
// Unlink one of the session user's accounts, which may then sign in or
|
|
80
|
+
// register again; a name or avatar it gave falls back to the sign-in
|
|
81
|
+
// account's. Null when the user has no such link.
|
|
82
|
+
unlinkGithubAccount(sessionId: string, id: string, now: number): Promise<LinkedGithubAccount | null>
|
|
83
|
+
setProfileChoice(sessionId: string, choice: ProfileChoice, now: number): Promise<void>
|
|
84
|
+
// The avatar to serve for `id`: a user's chosen linked account's, else `id`'s own.
|
|
85
|
+
getAvatarKey(id: string): Promise<string>
|
|
86
|
+
// The approved users signing in with, or having linked, each of
|
|
87
|
+
// `accounts`, by the login as asked: by the account's numeric id where it
|
|
88
|
+
// is known, which GitHub never gives another; else by its login (matched
|
|
89
|
+
// regardless of case, as GitHub matches them), one more than one user
|
|
90
|
+
// claims, renamed on GitHub since another signed in with it or linked it,
|
|
91
|
+
// left out. No access users are left out.
|
|
92
|
+
listUsersByAccount(accounts: readonly GithubAccount[]): Promise<Record<string, AppUser>>
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A GitHub account a repository's activity names: by its login, and its
|
|
96
|
+
// numeric id where GitHub told it.
|
|
97
|
+
export interface GithubAccount { login: string; githubId: number | null }
|
|
98
|
+
|
|
99
|
+
type LinkRow = { id: string; githubId: number; login: string; name: string | null; linkedAt: number }
|
|
100
|
+
const accountOf = (row: LinkRow): LinkedGithubAccount => ({ id: row.id, githubId: row.githubId, login: row.login, name: row.name, linkedAt: row.linkedAt })
|
|
101
|
+
|
|
102
|
+
// GithubLinkStore.listUsersByAccount.
|
|
103
|
+
async function usersByAccount(db: ManagedSql, accounts: readonly GithubAccount[]): Promise<Record<string, AppUser>> {
|
|
104
|
+
if (accounts.length === 0) return {}
|
|
105
|
+
const ids = accounts.flatMap(account => account.githubId ?? [])
|
|
106
|
+
const logins = accounts.flatMap(account => account.githubId === null ? [account.login] : [])
|
|
107
|
+
const rows = await db.prepare(`SELECT a.login, a.githubId, u.id, u.login AS appLogin, u.name, u.role FROM (
|
|
108
|
+
SELECT login, github_user_id AS githubId, id AS claimant FROM managed_user
|
|
109
|
+
UNION ALL SELECT login, github_user_id AS githubId, user_id AS claimant FROM managed_github_link
|
|
110
|
+
) a JOIN managed_user u ON u.id = a.claimant
|
|
111
|
+
WHERE a.githubId IN (SELECT CAST(value AS BIGINT) FROM json_each(?)) OR lower(a.login) IN (SELECT lower(value) FROM json_each(?))`)
|
|
112
|
+
.all(JSON.stringify(ids), JSON.stringify(logins)) as { login: string; githubId: number; id: string; appLogin: string; name: string | null; role: string }[]
|
|
113
|
+
const byId = new Map(rows.map(row => [row.githubId, row]))
|
|
114
|
+
const claims = new Map<string, typeof rows>()
|
|
115
|
+
for (const row of rows) claims.set(row.login.toLowerCase(), [...claims.get(row.login.toLowerCase()) ?? [], row])
|
|
116
|
+
const users: Record<string, AppUser> = {}
|
|
117
|
+
for (const { login, githubId } of accounts) {
|
|
118
|
+
const [user, ...others] = githubId === null ? claims.get(login.toLowerCase()) ?? [] : byId.has(githubId) ? [byId.get(githubId)!] : []
|
|
119
|
+
if (!user || user.role === 'none' || others.some(other => other.id !== user.id)) continue
|
|
120
|
+
users[login] = { id: user.id, login: user.appLogin, name: user.name }
|
|
121
|
+
}
|
|
122
|
+
return users
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function githubLinkMethods(db: ManagedSql): GithubLinkStore {
|
|
126
|
+
// Linking is the session user's own act: never an admin's view as them,
|
|
127
|
+
// nor an account that has not been approved for the workspace.
|
|
128
|
+
async function sessionUser(sessionId: string, now: number): Promise<{ id: string; githubId: number }> {
|
|
129
|
+
const row = await db.prepare(`SELECT u.id, u.github_user_id AS githubId, u.role FROM managed_session s JOIN managed_user u ON u.id = s.user_id
|
|
130
|
+
WHERE s.id = ? AND s.expires_at > ? AND s.viewer_session IS NULL`).get(sessionId, now) as { id: string; githubId: number; role: string } | undefined
|
|
131
|
+
if (!row) throw new ManagedMutationError(401, 'unauthenticated')
|
|
132
|
+
if (row.role === 'none') throw new ManagedMutationError(403, 'forbidden')
|
|
133
|
+
return row
|
|
134
|
+
}
|
|
135
|
+
const linkOf = (userId: string, id: string) => db.prepare(`SELECT id, github_user_id AS githubId, login, name, linked_at AS linkedAt FROM managed_github_link
|
|
136
|
+
WHERE id = ? AND user_id = ?`).get(id, userId) as Promise<LinkRow | undefined>
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
async getProfile(userId) {
|
|
140
|
+
const user = await db.prepare(`SELECT login, name, github_name AS githubName, name_link AS nameAccount, avatar_link AS avatarAccount
|
|
141
|
+
FROM managed_user WHERE id = ?`).get(userId) as Omit<ManagedProfile, 'accounts'> | undefined
|
|
142
|
+
if (!user) return null
|
|
143
|
+
const accounts = await db.prepare(`SELECT id, github_user_id AS githubId, login, name, linked_at AS linkedAt FROM managed_github_link
|
|
144
|
+
WHERE user_id = ? ORDER BY linked_at, id`).all(userId) as LinkRow[]
|
|
145
|
+
return { ...user, accounts: accounts.map(accountOf) }
|
|
146
|
+
},
|
|
147
|
+
async linkGithubAccount(sessionId, account, now) {
|
|
148
|
+
const user = await sessionUser(sessionId, now)
|
|
149
|
+
if (account.githubUserId === user.githubId) throw new ManagedMutationError(409, 'github-account-own')
|
|
150
|
+
if (await db.prepare('SELECT 1 AS found FROM managed_user WHERE github_user_id = ?').get(account.githubUserId)) {
|
|
151
|
+
throw new ManagedMutationError(409, 'github-account-registered')
|
|
152
|
+
}
|
|
153
|
+
const existing = await db.prepare('SELECT id, user_id AS userId FROM managed_github_link WHERE github_user_id = ?')
|
|
154
|
+
.get(account.githubUserId) as { id: string; userId: string } | undefined
|
|
155
|
+
if (existing && existing.userId !== user.id) throw new ManagedMutationError(409, 'github-account-linked')
|
|
156
|
+
if (existing) {
|
|
157
|
+
await db.prepare('UPDATE managed_github_link SET login = ?, name = ? WHERE id = ?').run(account.login, account.name, existing.id)
|
|
158
|
+
await db.prepare('UPDATE managed_user SET name = ?, updated_at = ? WHERE id = ? AND name_link = ?').run(account.name, now, user.id, existing.id)
|
|
159
|
+
return { id: existing.id, created: false }
|
|
160
|
+
}
|
|
161
|
+
const id = randomUUID()
|
|
162
|
+
await db.prepare(`INSERT INTO managed_github_link (id, user_id, github_user_id, login, name, linked_at)
|
|
163
|
+
VALUES (?, ?, ?, ?, ?, ?)`).run(id, user.id, account.githubUserId, account.login, account.name, now)
|
|
164
|
+
return { id, created: true }
|
|
165
|
+
},
|
|
166
|
+
async unlinkGithubAccount(sessionId, id, now) {
|
|
167
|
+
const user = await sessionUser(sessionId, now)
|
|
168
|
+
const link = await linkOf(user.id, id)
|
|
169
|
+
if (!link) return null
|
|
170
|
+
await db.prepare(`UPDATE managed_user SET
|
|
171
|
+
name = CASE WHEN name_link = :link THEN github_name ELSE name END,
|
|
172
|
+
name_link = CASE WHEN name_link = :link THEN NULL ELSE name_link END,
|
|
173
|
+
avatar_link = CASE WHEN avatar_link = :link THEN NULL ELSE avatar_link END,
|
|
174
|
+
updated_at = :now
|
|
175
|
+
WHERE id = :user`).run({ link: id, now, user: user.id })
|
|
176
|
+
await db.prepare('DELETE FROM managed_github_link WHERE id = ?').run(id)
|
|
177
|
+
return accountOf(link)
|
|
178
|
+
},
|
|
179
|
+
async setProfileChoice(sessionId, choice, now) {
|
|
180
|
+
const user = await sessionUser(sessionId, now)
|
|
181
|
+
const links = new Map<string, LinkRow>()
|
|
182
|
+
for (const id of [choice.name, choice.avatar]) {
|
|
183
|
+
if (id == null || links.has(id)) continue
|
|
184
|
+
const link = await linkOf(user.id, id)
|
|
185
|
+
if (!link) throw new ManagedMutationError(404, 'no-account')
|
|
186
|
+
links.set(id, link)
|
|
187
|
+
}
|
|
188
|
+
if (choice.name !== undefined) {
|
|
189
|
+
// A linked account without a name leaves the user without one too.
|
|
190
|
+
await db.prepare(`UPDATE managed_user SET name_link = :link,
|
|
191
|
+
name = CASE WHEN :link IS NULL THEN github_name ELSE :name END, updated_at = :now
|
|
192
|
+
WHERE id = :user`).run({ link: choice.name, name: choice.name === null ? null : links.get(choice.name)!.name, now, user: user.id })
|
|
193
|
+
}
|
|
194
|
+
if (choice.avatar !== undefined) {
|
|
195
|
+
await db.prepare('UPDATE managed_user SET avatar_link = ?, updated_at = ? WHERE id = ?').run(choice.avatar, now, user.id)
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
async getAvatarKey(id) {
|
|
199
|
+
const row = await db.prepare('SELECT avatar_link AS link FROM managed_user WHERE id = ?').get(id) as { link: string | null } | undefined
|
|
200
|
+
return row?.link ?? id
|
|
201
|
+
},
|
|
202
|
+
listUsersByAccount: accounts => usersByAccount(db, accounts),
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { GithubFixRef, GithubFixStatus, GithubIssueClosedReason } from '../common/github-pr.ts'
|
|
2
|
+
import type { ManagedSql } from './sql.ts'
|
|
3
|
+
|
|
4
|
+
export interface GithubMetadata {
|
|
5
|
+
key: string
|
|
6
|
+
title: string
|
|
7
|
+
description: string | null
|
|
8
|
+
status: GithubFixStatus
|
|
9
|
+
// NULL on legacy entries; 'unknown' means a closed issue was checked but
|
|
10
|
+
// GitHub supplied no recognized reason, so it needs no further backfill.
|
|
11
|
+
stateReason: GithubIssueClosedReason | null
|
|
12
|
+
fetchedAt: number
|
|
13
|
+
attemptedAt: number | null
|
|
14
|
+
}
|
|
15
|
+
export interface GithubRepositoryVisibility {
|
|
16
|
+
repoId: number
|
|
17
|
+
github: string
|
|
18
|
+
public: boolean
|
|
19
|
+
checkedAt: number
|
|
20
|
+
}
|
|
21
|
+
// A commit's details, keyed by githubCommitKey. Commits never change, so an
|
|
22
|
+
// entry is never refreshed or evicted.
|
|
23
|
+
export interface GithubCommit {
|
|
24
|
+
key: string
|
|
25
|
+
message: string
|
|
26
|
+
authorName: string | null
|
|
27
|
+
authorLogin: string | null
|
|
28
|
+
authoredAt: number | null
|
|
29
|
+
committedAt: number | null
|
|
30
|
+
fetchedAt: number
|
|
31
|
+
}
|
|
32
|
+
export interface GithubTag { name: string; sha: string }
|
|
33
|
+
export interface GithubMetadataStore {
|
|
34
|
+
listGithubMetadata(keys: readonly string[]): Promise<GithubMetadata[]>
|
|
35
|
+
setGithubMetadata(entries: readonly Omit<GithubMetadata, 'attemptedAt'>[]): Promise<void>
|
|
36
|
+
recordGithubMetadataAttempts(keys: readonly string[], attemptedAt: number): Promise<void>
|
|
37
|
+
listGithubRepositoryVisibility(repoIds: readonly number[]): Promise<GithubRepositoryVisibility[]>
|
|
38
|
+
setGithubRepositoryVisibility(entries: readonly GithubRepositoryVisibility[]): Promise<void>
|
|
39
|
+
}
|
|
40
|
+
export interface GithubCommitStore {
|
|
41
|
+
listGithubCommits(keys: readonly string[]): Promise<GithubCommit[]>
|
|
42
|
+
setGithubCommits(entries: readonly GithubCommit[]): Promise<void>
|
|
43
|
+
// The cached tags that point to each commit, by githubCommitKey.
|
|
44
|
+
listGithubCommitTags(keys: readonly string[]): Promise<{ key: string; name: string }[]>
|
|
45
|
+
// `complete` is a listing of every tag the repository has: tags it leaves
|
|
46
|
+
// out were deleted. Otherwise only the listed tags are updated. `observedUs`
|
|
47
|
+
// orders overlapping refreshes (see githubCommitMethods).
|
|
48
|
+
refreshGithubTags(repoId: number, tags: readonly GithubTag[], complete: boolean, observedUs: number): Promise<void>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A stable repository ID survives renames, as in the PR metadata keys.
|
|
52
|
+
export function githubCommitKey(repoId: number, sha: string): string {
|
|
53
|
+
return `${repoId}:${sha}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// An issue's or pull request's metadata key, by its repository's stable ID.
|
|
57
|
+
export function githubFixKey(repoId: number, kind: GithubFixRef['kind'], number: number): string {
|
|
58
|
+
return `${repoId}:${kind}:${number}`
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Successful GitHub reads are shared and retained without eviction. The stable
|
|
62
|
+
// repository ID in the key survives renames, but is never an access grant.
|
|
63
|
+
// Callers must verify current user -> team -> repo grants plus either recently
|
|
64
|
+
// verified public visibility or the viewer's live GitHub access with their token.
|
|
65
|
+
export const GITHUB_STATE_REASON_COLUMN = "TEXT CHECK (state_reason IN ('completed', 'not_planned', 'duplicate', 'unknown'))"
|
|
66
|
+
export const GITHUB_METADATA_SCHEMA = `
|
|
67
|
+
CREATE TABLE IF NOT EXISTS managed_github_metadata (
|
|
68
|
+
cache_key TEXT PRIMARY KEY,
|
|
69
|
+
title TEXT NOT NULL,
|
|
70
|
+
description TEXT,
|
|
71
|
+
status TEXT NOT NULL CHECK (status IN ('open', 'draft', 'closed', 'merged')),
|
|
72
|
+
state_reason ${GITHUB_STATE_REASON_COLUMN},
|
|
73
|
+
fetched_at INTEGER NOT NULL,
|
|
74
|
+
attempted_at INTEGER
|
|
75
|
+
) STRICT;
|
|
76
|
+
CREATE TABLE IF NOT EXISTS managed_github_repository_visibility (
|
|
77
|
+
repo_id INTEGER PRIMARY KEY,
|
|
78
|
+
github TEXT NOT NULL,
|
|
79
|
+
is_public INTEGER NOT NULL CHECK (is_public IN (0, 1)),
|
|
80
|
+
checked_at INTEGER NOT NULL
|
|
81
|
+
) STRICT;
|
|
82
|
+
`
|
|
83
|
+
// Bundles show their commit's details and tags from these tables. Readers rely
|
|
84
|
+
// on bundle access alone; only a GitHub read made with access fills them.
|
|
85
|
+
// Commits are retained without eviction. Every refs read of a repository
|
|
86
|
+
// (Create a bundle's, the code viewer's) refreshes its tags, which go with it.
|
|
87
|
+
export const GITHUB_COMMIT_SCHEMA = `
|
|
88
|
+
CREATE TABLE IF NOT EXISTS managed_github_commit (
|
|
89
|
+
cache_key TEXT PRIMARY KEY,
|
|
90
|
+
message TEXT NOT NULL,
|
|
91
|
+
author_name TEXT,
|
|
92
|
+
author_login TEXT,
|
|
93
|
+
authored_at INTEGER,
|
|
94
|
+
committed_at INTEGER,
|
|
95
|
+
fetched_at INTEGER NOT NULL
|
|
96
|
+
) STRICT;
|
|
97
|
+
CREATE TABLE IF NOT EXISTS managed_github_tag (
|
|
98
|
+
repo_id INTEGER NOT NULL REFERENCES managed_selected_repo(repo_id) ON DELETE CASCADE,
|
|
99
|
+
name TEXT NOT NULL,
|
|
100
|
+
commit_key TEXT NOT NULL,
|
|
101
|
+
observed_us INTEGER NOT NULL,
|
|
102
|
+
PRIMARY KEY (repo_id, name)
|
|
103
|
+
) STRICT;
|
|
104
|
+
CREATE INDEX IF NOT EXISTS managed_github_tag_commit_idx ON managed_github_tag(commit_key);
|
|
105
|
+
CREATE TABLE IF NOT EXISTS managed_github_tag_listing (
|
|
106
|
+
repo_id INTEGER PRIMARY KEY REFERENCES managed_selected_repo(repo_id) ON DELETE CASCADE,
|
|
107
|
+
observed_us INTEGER NOT NULL
|
|
108
|
+
) STRICT;
|
|
109
|
+
`
|
|
110
|
+
|
|
111
|
+
export function githubMetadataMethods(db: ManagedSql): GithubMetadataStore {
|
|
112
|
+
const list = db.prepare(`SELECT cache_key AS key, title, description, status, state_reason AS stateReason, fetched_at AS fetchedAt, attempted_at AS attemptedAt
|
|
113
|
+
FROM managed_github_metadata WHERE cache_key IN (SELECT value FROM json_each(?))`)
|
|
114
|
+
const set = db.prepare(`INSERT INTO managed_github_metadata (cache_key, title, description, status, state_reason, fetched_at)
|
|
115
|
+
SELECT json_extract(e.value, '$.key'), json_extract(e.value, '$.title'),
|
|
116
|
+
json_extract(e.value, '$.description'), json_extract(e.value, '$.status'), json_extract(e.value, '$.stateReason'),
|
|
117
|
+
CAST(json_extract(e.value, '$.fetchedAt') AS BIGINT)
|
|
118
|
+
FROM json_each(:contexts) e WHERE 1 = 1
|
|
119
|
+
ON CONFLICT (cache_key) DO UPDATE SET title = excluded.title, description = excluded.description,
|
|
120
|
+
status = excluded.status, state_reason = excluded.state_reason, fetched_at = excluded.fetched_at
|
|
121
|
+
WHERE managed_github_metadata.status != 'merged' AND managed_github_metadata.fetched_at <= excluded.fetched_at`)
|
|
122
|
+
// Scheduling attempts never overwrite metadata or make stale data fresh.
|
|
123
|
+
// The monotonic guard preserves a newer attempt recorded by another reader.
|
|
124
|
+
const attempt = db.prepare(`UPDATE managed_github_metadata SET attempted_at = ?
|
|
125
|
+
WHERE cache_key IN (SELECT value FROM json_each(?)) AND (attempted_at IS NULL OR attempted_at < ?)`)
|
|
126
|
+
const visibility = db.prepare(`SELECT repo_id AS repoId, github, is_public AS public, checked_at AS checkedAt
|
|
127
|
+
FROM managed_github_repository_visibility WHERE repo_id IN (SELECT CAST(value AS BIGINT) FROM json_each(?))`)
|
|
128
|
+
const setVisibility = db.prepare(`INSERT INTO managed_github_repository_visibility (repo_id, github, is_public, checked_at)
|
|
129
|
+
SELECT CAST(json_extract(e.value, '$.repoId') AS BIGINT), json_extract(e.value, '$.github'),
|
|
130
|
+
CAST(json_extract(e.value, '$.public') AS BIGINT), CAST(json_extract(e.value, '$.checkedAt') AS BIGINT)
|
|
131
|
+
FROM json_each(:contexts) e WHERE 1 = 1
|
|
132
|
+
ON CONFLICT (repo_id) DO UPDATE SET github = excluded.github, is_public = excluded.is_public, checked_at = excluded.checked_at
|
|
133
|
+
WHERE managed_github_repository_visibility.checked_at < excluded.checked_at
|
|
134
|
+
OR (managed_github_repository_visibility.checked_at = excluded.checked_at
|
|
135
|
+
AND (managed_github_repository_visibility.is_public = 1 OR excluded.is_public = 0))`)
|
|
136
|
+
return {
|
|
137
|
+
async listGithubMetadata(keys) {
|
|
138
|
+
if (keys.length === 0) return []
|
|
139
|
+
const rows = await list.all(JSON.stringify(keys)) as GithubMetadata[]
|
|
140
|
+
return rows.map(row => ({ ...row }))
|
|
141
|
+
},
|
|
142
|
+
async setGithubMetadata(entries) {
|
|
143
|
+
if (entries.length > 0) await set.run({ contexts: JSON.stringify(entries) })
|
|
144
|
+
},
|
|
145
|
+
async recordGithubMetadataAttempts(keys, attemptedAt) {
|
|
146
|
+
if (keys.length > 0) await attempt.run(attemptedAt, JSON.stringify(keys), attemptedAt)
|
|
147
|
+
},
|
|
148
|
+
async listGithubRepositoryVisibility(repoIds) {
|
|
149
|
+
if (repoIds.length === 0) return []
|
|
150
|
+
const rows = await visibility.all(JSON.stringify(repoIds)) as (Omit<GithubRepositoryVisibility, 'public'> & { public: number })[]
|
|
151
|
+
return rows.map(row => ({ ...row, public: row.public === 1 }))
|
|
152
|
+
},
|
|
153
|
+
async setGithubRepositoryVisibility(entries) {
|
|
154
|
+
if (entries.length > 0) await setVisibility.run({ contexts: JSON.stringify(entries.map(entry => ({ ...entry, public: entry.public ? 1 : 0 }))) })
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function githubCommitMethods(db: ManagedSql): GithubCommitStore {
|
|
160
|
+
const commits = db.prepare(`SELECT cache_key AS key, message, author_name AS authorName, author_login AS authorLogin,
|
|
161
|
+
authored_at AS authoredAt, committed_at AS committedAt, fetched_at AS fetchedAt
|
|
162
|
+
FROM managed_github_commit WHERE cache_key IN (SELECT value FROM json_each(?))`)
|
|
163
|
+
// Concurrent reads of one commit store the same details; the first stays.
|
|
164
|
+
const setCommits = db.prepare(`INSERT INTO managed_github_commit (cache_key, message, author_name, author_login, authored_at, committed_at, fetched_at)
|
|
165
|
+
SELECT json_extract(e.value, '$.key'), json_extract(e.value, '$.message'), json_extract(e.value, '$.authorName'),
|
|
166
|
+
json_extract(e.value, '$.authorLogin'), CAST(json_extract(e.value, '$.authoredAt') AS BIGINT),
|
|
167
|
+
CAST(json_extract(e.value, '$.committedAt') AS BIGINT), CAST(json_extract(e.value, '$.fetchedAt') AS BIGINT)
|
|
168
|
+
FROM json_each(:contexts) e WHERE 1 = 1
|
|
169
|
+
ON CONFLICT (cache_key) DO NOTHING`)
|
|
170
|
+
const commitTags = db.prepare(`SELECT commit_key AS key, name FROM managed_github_tag
|
|
171
|
+
WHERE commit_key IN (SELECT value FROM json_each(?)) ORDER BY commit_key, name`)
|
|
172
|
+
// Overlapping browses can finish out of order, so every refresh carries
|
|
173
|
+
// when it was observed (in microseconds). Each tag keeps the time it was
|
|
174
|
+
// last observed and only a later observation moves it; a complete listing
|
|
175
|
+
// deletes only the tags observed before it. The listing table holds the
|
|
176
|
+
// last complete listing applied: one observed no later knew whether every
|
|
177
|
+
// tag existed, so a refresh it supersedes is skipped (a tie keeps the first).
|
|
178
|
+
const lastListing = db.prepare('SELECT observed_us AS observedUs FROM managed_github_tag_listing WHERE repo_id = ?')
|
|
179
|
+
const setListing = db.prepare(`INSERT INTO managed_github_tag_listing (repo_id, observed_us) VALUES (?, ?)
|
|
180
|
+
ON CONFLICT (repo_id) DO UPDATE SET observed_us = excluded.observed_us`)
|
|
181
|
+
const deleteTags = db.prepare(`DELETE FROM managed_github_tag WHERE repo_id = ? AND observed_us < ?
|
|
182
|
+
AND name NOT IN (SELECT value FROM json_each(?))`)
|
|
183
|
+
const setTags = db.prepare(`INSERT INTO managed_github_tag (repo_id, name, commit_key, observed_us)
|
|
184
|
+
SELECT CAST(json_extract(e.value, '$.repoId') AS BIGINT), json_extract(e.value, '$.name'), json_extract(e.value, '$.key'),
|
|
185
|
+
CAST(json_extract(e.value, '$.observedUs') AS BIGINT)
|
|
186
|
+
FROM json_each(:contexts) e WHERE 1 = 1
|
|
187
|
+
ON CONFLICT (repo_id, name) DO UPDATE SET commit_key = excluded.commit_key, observed_us = excluded.observed_us
|
|
188
|
+
WHERE managed_github_tag.observed_us < excluded.observed_us`)
|
|
189
|
+
return {
|
|
190
|
+
async listGithubCommits(keys) {
|
|
191
|
+
if (keys.length === 0) return []
|
|
192
|
+
const rows = await commits.all(JSON.stringify(keys)) as GithubCommit[]
|
|
193
|
+
return rows.map(row => ({ ...row }))
|
|
194
|
+
},
|
|
195
|
+
async setGithubCommits(entries) {
|
|
196
|
+
if (entries.length > 0) await setCommits.run({ contexts: JSON.stringify(entries) })
|
|
197
|
+
},
|
|
198
|
+
async listGithubCommitTags(keys) {
|
|
199
|
+
if (keys.length === 0) return []
|
|
200
|
+
const rows = await commitTags.all(JSON.stringify(keys)) as { key: string; name: string }[]
|
|
201
|
+
return rows.map(row => ({ ...row }))
|
|
202
|
+
},
|
|
203
|
+
async refreshGithubTags(repoId, tags, complete, observedUs) {
|
|
204
|
+
// Writes hold the store's writer lock: the listing read stays current.
|
|
205
|
+
const last = (await lastListing.get(repoId) as { observedUs: number } | undefined)?.observedUs
|
|
206
|
+
if (last !== undefined && last >= observedUs) return
|
|
207
|
+
// Postgres refuses an upsert that names one row twice.
|
|
208
|
+
const unique = [...new Map(tags.map(tag => [tag.name, tag])).values()]
|
|
209
|
+
if (complete) {
|
|
210
|
+
await setListing.run(repoId, observedUs)
|
|
211
|
+
await deleteTags.run(repoId, observedUs, JSON.stringify(unique.map(tag => tag.name)))
|
|
212
|
+
}
|
|
213
|
+
if (unique.length > 0) {
|
|
214
|
+
await setTags.run({ contexts: JSON.stringify(unique.map(tag => ({ repoId, name: tag.name, key: githubCommitKey(repoId, tag.sha), observedUs }))) })
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
}
|