@myrialabs/clopen 0.4.50 → 0.4.51
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/README.md +2 -1
- package/backend/chat/attachments.test.ts +106 -17
- package/backend/chat/attachments.ts +131 -34
- package/backend/chat/engine-handoff.ts +42 -6
- package/backend/chat/stream-manager.ts +41 -5
- package/backend/containers/actions.ts +22 -0
- package/backend/control/actions/projects.ts +93 -37
- package/backend/control/folders.test.ts +27 -2
- package/backend/control/index.ts +2 -1
- package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
- package/backend/database/migrations/086_single_owner.ts +66 -73
- package/backend/database/migrations/090_create_storage_tables.ts +83 -0
- package/backend/database/migrations/index.ts +11 -2
- package/backend/database/queries/integration-queries.ts +10 -0
- package/backend/database/queries/memory-queue-queries.ts +11 -0
- package/backend/database/queries/project-queries.ts +6 -0
- package/backend/database/queries/session-queries.ts +3 -0
- package/backend/database/utils/migration-runner.test.ts +196 -0
- package/backend/database/utils/migration-runner.ts +61 -16
- package/backend/database/utils/seeder-runner.ts +22 -16
- package/backend/engine/adapters/claude/stream.ts +5 -0
- package/backend/engine/adapters/cursor/environment.ts +1 -1
- package/backend/engine/adapters/qwen/session-store.ts +10 -1
- package/backend/engine/types.ts +7 -0
- package/backend/git/identity/cli.ts +35 -0
- package/backend/git/identity/env.test.ts +52 -1
- package/backend/git/identity/env.ts +69 -10
- package/backend/git/identity/index.ts +25 -6
- package/backend/git/identity/resolve.ts +2 -1
- package/backend/git/identity/scope-config.ts +13 -7
- package/backend/git-hosts/accounts.ts +106 -0
- package/backend/git-hosts/auth/client-ids.ts +34 -0
- package/backend/git-hosts/auth/connect.ts +110 -0
- package/backend/git-hosts/auth/endpoints.ts +130 -0
- package/backend/git-hosts/auth/flows.ts +355 -0
- package/backend/git-hosts/auth/local.ts +152 -0
- package/backend/git-hosts/ci.ts +18 -0
- package/backend/git-hosts/cli.test.ts +82 -0
- package/backend/git-hosts/cli.ts +342 -0
- package/backend/git-hosts/credentials.ts +173 -0
- package/backend/git-hosts/git-credential.ts +30 -0
- package/backend/git-hosts/health.ts +39 -0
- package/backend/git-hosts/http.ts +174 -0
- package/backend/git-hosts/index.ts +34 -0
- package/backend/git-hosts/providers/bitbucket.ts +186 -0
- package/backend/git-hosts/providers/gitea.ts +208 -0
- package/backend/git-hosts/providers/github.ts +270 -0
- package/backend/git-hosts/providers/gitlab-client.ts +70 -0
- package/backend/git-hosts/providers/gitlab.ts +285 -0
- package/backend/git-hosts/providers/locators.test.ts +68 -0
- package/backend/git-hosts/registry.ts +50 -0
- package/backend/git-hosts/service.ts +432 -0
- package/backend/git-hosts/types.ts +82 -0
- package/backend/git-hosts/urls.test.ts +42 -0
- package/backend/git-hosts/urls.ts +69 -0
- package/backend/index.ts +50 -10
- package/backend/integrations/accounts.ts +50 -3
- package/backend/integrations/registry/define.ts +9 -0
- package/backend/integrations/registry/index.ts +11 -0
- package/backend/integrations/registry/providers/bitbucket.ts +51 -0
- package/backend/integrations/registry/providers/gitea.ts +53 -0
- package/backend/integrations/registry/providers/github.ts +24 -7
- package/backend/integrations/registry/providers/gitlab.ts +57 -0
- package/backend/integrations/registry/types.ts +13 -1
- package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
- package/backend/mentions/diff.ts +63 -0
- package/backend/mentions/index.ts +109 -0
- package/backend/mentions/mentions.test.ts +27 -0
- package/backend/mentions/shared.ts +82 -0
- package/backend/mentions/sources/ai-changes.ts +140 -0
- package/backend/mentions/sources/chats.ts +122 -0
- package/backend/mentions/sources/database.ts +211 -0
- package/backend/mentions/sources/files.ts +240 -0
- package/backend/mentions/sources/git.ts +308 -0
- package/backend/mentions/sources/notes-memory.ts +121 -0
- package/backend/mentions/sources/ops.ts +125 -0
- package/backend/mentions/sources/preview.ts +153 -0
- package/backend/mentions/sources/projects.ts +114 -0
- package/backend/mentions/sources/system.ts +135 -0
- package/backend/mentions/sources/terminal.ts +50 -0
- package/backend/mentions/types.ts +75 -0
- package/backend/preview/browser/bot-check-frames.test.ts +49 -0
- package/backend/preview/browser/bot-check-frames.ts +66 -0
- package/backend/preview/browser/browser-dialog-handler.ts +6 -5
- package/backend/preview/browser/browser-host-bridge.ts +4 -2
- package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
- package/backend/preview/browser/browser-pool.ts +26 -17
- package/backend/preview/browser/browser-preview-service.ts +164 -2
- package/backend/preview/browser/browser-screenshot.test.ts +113 -0
- package/backend/preview/browser/browser-screenshot.ts +396 -0
- package/backend/preview/browser/browser-tab-manager.ts +35 -186
- package/backend/preview/browser/browser-video-capture.ts +12 -17
- package/backend/preview/browser/element-describe.ts +125 -0
- package/backend/preview/browser/page-binding.ts +141 -0
- package/backend/preview/browser/screenshot-files.test.ts +117 -0
- package/backend/preview/browser/screenshot-files.ts +134 -0
- package/backend/preview/browser/user-agent.test.ts +25 -0
- package/backend/preview/browser/user-agent.ts +100 -0
- package/backend/projects/engine-transcripts.ts +153 -0
- package/backend/projects/folder-guard.ts +55 -0
- package/backend/projects/move.test.ts +208 -0
- package/backend/projects/move.ts +277 -0
- package/backend/projects/project-cleanup.integration.test.ts +3 -1
- package/backend/projects/project-cleanup.ts +10 -0
- package/backend/storage/actions.ts +260 -0
- package/backend/storage/chats.test.ts +57 -0
- package/backend/storage/chats.ts +170 -0
- package/backend/storage/database.ts +105 -0
- package/backend/storage/engine-homes.ts +145 -0
- package/backend/storage/fs-size.ts +111 -0
- package/backend/storage/history.ts +39 -0
- package/backend/storage/policy.ts +156 -0
- package/backend/storage/preview-profiles.ts +169 -0
- package/backend/storage/purge.ts +158 -0
- package/backend/storage/scanner.ts +339 -0
- package/backend/storage/session-index.ts +208 -0
- package/backend/storage/snapshots.ts +99 -0
- package/backend/storage/storage-flow.test.ts +137 -0
- package/backend/storage/transcripts/aliases.ts +75 -0
- package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
- package/backend/storage/transcripts/claude-dedupe.ts +152 -0
- package/backend/storage/transcripts/claude.ts +155 -0
- package/backend/storage/transcripts/cursor.ts +165 -0
- package/backend/storage/transcripts/file-stores.ts +224 -0
- package/backend/storage/transcripts/index.ts +207 -0
- package/backend/storage/transcripts/opencode.ts +124 -0
- package/backend/storage/transcripts/references.ts +42 -0
- package/backend/storage/transcripts/types.ts +58 -0
- package/backend/storage/worktrees.ts +114 -0
- package/backend/terminal/ptykit.ts +25 -0
- package/backend/update/registry.ts +24 -0
- package/backend/update/release-notes.test.ts +110 -0
- package/backend/update/release-notes.ts +132 -0
- package/backend/update/restart.ts +159 -0
- package/backend/utils/env.test.ts +64 -0
- package/backend/utils/env.ts +23 -55
- package/backend/utils/port-utils.ts +13 -0
- package/backend/work/index.ts +13 -2
- package/backend/work/providers/github/actions-logs.ts +1 -1
- package/backend/work/providers/github/adapter.ts +32 -1
- package/backend/work/providers/github/client.ts +7 -3
- package/backend/work/providers/gitlab/adapter.ts +770 -0
- package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
- package/backend/work/service.ts +60 -36
- package/backend/work/start-work.ts +1 -1
- package/backend/work/types.ts +4 -0
- package/backend/worktrees/index.ts +1 -0
- package/backend/worktrees/service.ts +23 -2
- package/backend/ws/chat/composer.ts +47 -6
- package/backend/ws/files/search.ts +1 -1
- package/backend/ws/files/write.ts +27 -0
- package/backend/ws/hosting/index.ts +231 -0
- package/backend/ws/index.ts +12 -2
- package/backend/ws/integrations/crud.ts +31 -5
- package/backend/ws/integrations/hosting-auth.ts +227 -0
- package/backend/ws/integrations/index.ts +2 -0
- package/backend/ws/mentions/index.ts +81 -0
- package/backend/ws/preview/browser/screenshot.ts +184 -0
- package/backend/ws/preview/index.ts +23 -0
- package/backend/ws/projects/crud.ts +66 -58
- package/backend/ws/sessions/crud.ts +7 -95
- package/backend/ws/snapshot/changes.ts +3 -3
- package/backend/ws/storage/index.ts +102 -0
- package/backend/ws/system/index.ts +7 -0
- package/backend/ws/system/operations.ts +125 -69
- package/backend/ws/work/context.ts +3 -4
- package/backend/ws/work/crud.ts +33 -0
- package/backend/ws/work/schemas.ts +4 -1
- package/bin/clopen.ts +15 -16
- package/dist/assets/{index-By6KdSLT.js → index-B9rHDvjg.js} +1 -1
- package/dist/assets/index-B9rHDvjg.js.br +0 -0
- package/dist/assets/index-B9rHDvjg.js.gz +0 -0
- package/dist/assets/{index-DV4TiDn1.js → index-DFlwOd7k.js} +1 -1
- package/dist/assets/index-DFlwOd7k.js.br +0 -0
- package/dist/assets/index-DFlwOd7k.js.gz +0 -0
- package/dist/assets/main-Bz_brxxS.css +1 -0
- package/dist/assets/main-Bz_brxxS.css.br +0 -0
- package/dist/assets/main-Bz_brxxS.css.gz +0 -0
- package/dist/assets/main-DRcX9SHx.js +1273 -0
- package/dist/assets/main-DRcX9SHx.js.br +0 -0
- package/dist/assets/main-DRcX9SHx.js.gz +0 -0
- package/dist/assets/pdf-DfwfQPLy.js +57 -0
- package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
- package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
- package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
- package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
- package/dist/index.html +2 -2
- package/dist/index.html.br +0 -0
- package/dist/index.html.gz +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
- package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
- package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
- package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
- package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
- package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
- package/package.json +6 -7
- package/scripts/start.ts +21 -4
- package/shared/constants/binary-extensions.ts +20 -4
- package/shared/constants/support.test.ts +27 -0
- package/shared/constants/support.ts +79 -0
- package/shared/constants/tool-icons.ts +7 -1
- package/shared/types/database/schema.ts +6 -0
- package/shared/types/git-hosting.ts +241 -0
- package/shared/types/integrations.ts +51 -1
- package/shared/types/mentions.ts +96 -0
- package/shared/types/release-notes.ts +31 -0
- package/shared/types/storage.ts +175 -0
- package/shared/types/stores/settings.ts +16 -0
- package/shared/types/unified/index.ts +1 -0
- package/shared/types/unified/message.ts +26 -1
- package/shared/types/unified/tool.ts +4 -0
- package/shared/types/work.ts +6 -0
- package/shared/utils/attachment-mentions.test.ts +39 -0
- package/shared/utils/attachment-mentions.ts +100 -0
- package/shared/utils/context-document.test.ts +53 -0
- package/shared/utils/context-document.ts +226 -0
- package/shared/utils/device-frame.test.ts +73 -0
- package/shared/utils/device-frame.ts +320 -0
- package/shared/utils/fuzzy.ts +79 -0
- package/shared/utils/launcher-fingerprint.test.ts +73 -0
- package/shared/utils/launcher-fingerprint.ts +108 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/page-colors.test.ts +17 -0
- package/shared/utils/page-colors.ts +24 -0
- package/shared/utils/process-supervisor.test.ts +18 -1
- package/shared/utils/process-supervisor.ts +12 -23
- package/shared/utils/restart-intent.test.ts +57 -0
- package/shared/utils/restart-intent.ts +80 -0
- package/shared/utils/semver.test.ts +33 -0
- package/shared/utils/semver.ts +35 -0
- package/shared/utils/supervised-child.ts +44 -0
- package/shared/utils/supervisor-protocol.ts +20 -0
- package/.env.example +0 -9
- package/dist/assets/index-By6KdSLT.js.br +0 -0
- package/dist/assets/index-By6KdSLT.js.gz +0 -0
- package/dist/assets/index-DV4TiDn1.js.br +0 -0
- package/dist/assets/index-DV4TiDn1.js.gz +0 -0
- package/dist/assets/main-DIESTGTD.css +0 -1
- package/dist/assets/main-DIESTGTD.css.br +0 -0
- package/dist/assets/main-DIESTGTD.css.gz +0 -0
- package/dist/assets/main-Da3JKoua.js +0 -1240
- package/dist/assets/main-Da3JKoua.js.br +0 -0
- package/dist/assets/main-Da3JKoua.js.gz +0 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub (and Enterprise Server) as a repository host.
|
|
3
|
+
*
|
|
4
|
+
* Shares the Issues & PRs client, so both surfaces spend one ETag cache and
|
|
5
|
+
* one rate limit — a 304 on `/user` here is a 304 for the work view too.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CommitCiState, CommitCiStatus, HostedRepo, HostOwner, HostViewer } from '$shared/types/git-hosting';
|
|
9
|
+
import {
|
|
10
|
+
GitHubError,
|
|
11
|
+
githubRequest,
|
|
12
|
+
invalidateGitHubCache,
|
|
13
|
+
webBaseOf,
|
|
14
|
+
type GitHubCredentials
|
|
15
|
+
} from '$backend/work/providers/github/client';
|
|
16
|
+
import { HostApiError, mapLimited, waitFor } from '../http';
|
|
17
|
+
import { rollUp } from '../ci';
|
|
18
|
+
import { hostOfBase, parseRemoteUrl } from '../urls';
|
|
19
|
+
import type { CreateRepoInput, GitHostAdapter, HostCredentials, RepoQuery } from '../types';
|
|
20
|
+
|
|
21
|
+
/** What Clopen needs from a classic or OAuth token. `read:org` is only needed for SAML orgs, so it is not demanded. */
|
|
22
|
+
const REQUIRED_SCOPES = ['repo', 'workflow'];
|
|
23
|
+
|
|
24
|
+
function creds(credentials: HostCredentials): GitHubCredentials {
|
|
25
|
+
return { token: credentials.token ?? '', baseUrl: credentials.baseUrl };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** GitHub's errors, re-thrown in the vocabulary every hosting adapter speaks. */
|
|
29
|
+
async function call<T>(credentials: HostCredentials, path: string, options: Parameters<typeof githubRequest>[2] = {}) {
|
|
30
|
+
try {
|
|
31
|
+
return await githubRequest<T>(creds(credentials), path, options);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error instanceof GitHubError) {
|
|
34
|
+
const kind = error.status === 422 ? 'conflict' : error.kind;
|
|
35
|
+
throw new HostApiError(error.message, error.status, kind);
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface GitHubRepoWire {
|
|
42
|
+
full_name: string;
|
|
43
|
+
name: string;
|
|
44
|
+
owner: { login: string };
|
|
45
|
+
description: string | null;
|
|
46
|
+
private: boolean;
|
|
47
|
+
fork: boolean;
|
|
48
|
+
parent?: { full_name: string };
|
|
49
|
+
default_branch?: string;
|
|
50
|
+
clone_url: string;
|
|
51
|
+
ssh_url?: string;
|
|
52
|
+
html_url: string;
|
|
53
|
+
updated_at?: string;
|
|
54
|
+
pushed_at?: string;
|
|
55
|
+
permissions?: { push?: boolean; admin?: boolean };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function toRepo(raw: GitHubRepoWire): HostedRepo {
|
|
59
|
+
return {
|
|
60
|
+
fullName: raw.full_name,
|
|
61
|
+
owner: raw.owner.login,
|
|
62
|
+
name: raw.name,
|
|
63
|
+
description: raw.description,
|
|
64
|
+
isPrivate: raw.private,
|
|
65
|
+
isFork: raw.fork,
|
|
66
|
+
parentFullName: raw.parent?.full_name ?? null,
|
|
67
|
+
defaultBranch: raw.default_branch ?? null,
|
|
68
|
+
cloneUrlHttps: raw.clone_url,
|
|
69
|
+
cloneUrlSsh: raw.ssh_url ?? null,
|
|
70
|
+
webUrl: raw.html_url,
|
|
71
|
+
updatedAt: raw.pushed_at ?? raw.updated_at ?? null,
|
|
72
|
+
canPush: raw.permissions ? raw.permissions.push === true || raw.permissions.admin === true : null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const REPO_PAGE = 50;
|
|
77
|
+
|
|
78
|
+
/** Pages read when a search is typed. The listing has no search parameter, so it filters what it reads. */
|
|
79
|
+
const SEARCH_PAGES = 6;
|
|
80
|
+
|
|
81
|
+
function matchesSearch(repo: HostedRepo, needle: string): boolean {
|
|
82
|
+
return `${repo.fullName} ${repo.description ?? ''}`.toLowerCase().includes(needle);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function ciFromConclusion(status: string, conclusion: string | null): CommitCiState {
|
|
86
|
+
if (status !== 'completed') return 'pending';
|
|
87
|
+
if (conclusion === 'success' || conclusion === 'neutral' || conclusion === 'skipped') return 'success';
|
|
88
|
+
if (conclusion === 'failure' || conclusion === 'timed_out' || conclusion === 'startup_failure' || conclusion === 'action_required') return 'failure';
|
|
89
|
+
return 'none';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const githubHost: GitHostAdapter = {
|
|
93
|
+
kind: 'github',
|
|
94
|
+
serviceName: 'GitHub',
|
|
95
|
+
|
|
96
|
+
webBase: (credentials) => webBaseOf(creds(credentials)),
|
|
97
|
+
host: (credentials) => hostOfBase(webBaseOf(creds(credentials))),
|
|
98
|
+
|
|
99
|
+
locatorFromRemote(url, credentials) {
|
|
100
|
+
const parsed = parseRemoteUrl(url);
|
|
101
|
+
if (!parsed || parsed.host !== this.host(credentials)) return null;
|
|
102
|
+
const parts = parsed.path.split('/').filter(Boolean);
|
|
103
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : null;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
// GitHub ignores the username for a token; it only has to be non-empty.
|
|
107
|
+
gitUsername: () => 'x-access-token',
|
|
108
|
+
|
|
109
|
+
async viewer(credentials): Promise<HostViewer> {
|
|
110
|
+
const response = await call<{ login: string; name: string | null; avatar_url: string | null }>(
|
|
111
|
+
credentials,
|
|
112
|
+
'/user',
|
|
113
|
+
{ noCache: true }
|
|
114
|
+
);
|
|
115
|
+
const header = response.headers.get('x-oauth-scopes');
|
|
116
|
+
// Fine-grained tokens report no scopes header at all; their permissions
|
|
117
|
+
// are per repository and cannot be read off the token, so nothing is
|
|
118
|
+
// reported missing rather than everything.
|
|
119
|
+
const scopes = header === null ? null : header.split(',').map((scope) => scope.trim()).filter(Boolean);
|
|
120
|
+
return {
|
|
121
|
+
login: response.data.login,
|
|
122
|
+
name: response.data.name,
|
|
123
|
+
avatarUrl: response.data.avatar_url,
|
|
124
|
+
scopes,
|
|
125
|
+
missingScopes: scopes ? REQUIRED_SCOPES.filter((scope) => !scopes.includes(scope)) : []
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
async listOwners(credentials): Promise<HostOwner[]> {
|
|
130
|
+
const [user, orgs] = await Promise.all([
|
|
131
|
+
call<{ login: string; name: string | null; avatar_url: string | null }>(credentials, '/user'),
|
|
132
|
+
call<{ login: string; description: string | null; avatar_url: string | null }[]>(credentials, '/user/orgs?per_page=100')
|
|
133
|
+
]);
|
|
134
|
+
return [
|
|
135
|
+
{ login: user.data.login, kind: 'user', name: user.data.name, avatarUrl: user.data.avatar_url },
|
|
136
|
+
...(orgs.data ?? []).map((org): HostOwner => ({
|
|
137
|
+
login: org.login,
|
|
138
|
+
kind: 'org',
|
|
139
|
+
name: null,
|
|
140
|
+
avatarUrl: org.avatar_url
|
|
141
|
+
}))
|
|
142
|
+
];
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
async listRepos(credentials, query: RepoQuery) {
|
|
146
|
+
const needle = (query.search ?? '').trim().toLowerCase();
|
|
147
|
+
const owner = (query.owner ?? '').trim().toLowerCase();
|
|
148
|
+
// One listing for everything the user can reach. `/users/{org}/repos`
|
|
149
|
+
// would only ever show an organisation's PUBLIC repositories.
|
|
150
|
+
const base = `/user/repos?affiliation=owner,collaborator,organization_member&sort=pushed&per_page=${REPO_PAGE}`;
|
|
151
|
+
|
|
152
|
+
if (!needle && !owner) {
|
|
153
|
+
const response = await call<GitHubRepoWire[]>(credentials, `${base}&page=${query.page}`);
|
|
154
|
+
return { repos: (response.data ?? []).map(toRepo), hasMore: response.nextUrl !== null };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const keep = (repo: HostedRepo) =>
|
|
158
|
+
(!owner || repo.owner.toLowerCase() === owner) && (!needle || matchesSearch(repo, needle));
|
|
159
|
+
const found: HostedRepo[] = [];
|
|
160
|
+
let page = 1;
|
|
161
|
+
let hasMore = true;
|
|
162
|
+
while (hasMore && page <= SEARCH_PAGES && found.length < REPO_PAGE) {
|
|
163
|
+
const response = await call<GitHubRepoWire[]>(credentials, `${base}&page=${page}`);
|
|
164
|
+
found.push(...(response.data ?? []).map(toRepo).filter(keep));
|
|
165
|
+
hasMore = response.nextUrl !== null;
|
|
166
|
+
page += 1;
|
|
167
|
+
}
|
|
168
|
+
return { repos: found, hasMore: false };
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
async getRepo(credentials, locator) {
|
|
172
|
+
const response = await call<GitHubRepoWire>(credentials, `/repos/${locator}`, { noCache: true });
|
|
173
|
+
return toRepo(response.data);
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
async createRepo(credentials, input: CreateRepoInput) {
|
|
177
|
+
const path = input.owner.kind === 'org' ? `/orgs/${encodeURIComponent(input.owner.login)}/repos` : '/user/repos';
|
|
178
|
+
const response = await call<GitHubRepoWire>(credentials, path, {
|
|
179
|
+
method: 'POST',
|
|
180
|
+
body: {
|
|
181
|
+
name: input.name,
|
|
182
|
+
description: input.description || undefined,
|
|
183
|
+
private: input.isPrivate,
|
|
184
|
+
// The local repository already has history (or is about to): an
|
|
185
|
+
// initialised remote would diverge from it on the first push.
|
|
186
|
+
auto_init: false
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
invalidateGitHubCache(credentials.token ?? '');
|
|
190
|
+
return toRepo(response.data);
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
async fork(credentials, locator) {
|
|
194
|
+
const response = await call<GitHubRepoWire>(credentials, `/repos/${locator}/forks`, { method: 'POST', body: {} });
|
|
195
|
+
const forkName = response.data.full_name;
|
|
196
|
+
// GitHub creates the fork asynchronously and answers 202 straight away;
|
|
197
|
+
// pushing before it exists is a 404 from git with no explanation.
|
|
198
|
+
const ready = await waitFor(async () => {
|
|
199
|
+
const check = await call<GitHubRepoWire>(credentials, `/repos/${forkName}`, { noCache: true });
|
|
200
|
+
return check.data?.full_name ? toRepo(check.data) : null;
|
|
201
|
+
}, 60_000);
|
|
202
|
+
if (!ready) throw new HostApiError(`GitHub is still creating ${forkName}. Try again in a minute.`, 0, 'error');
|
|
203
|
+
invalidateGitHubCache(credentials.token ?? '');
|
|
204
|
+
return ready;
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
async commitStatuses(credentials, locator, shas): Promise<CommitCiStatus[]> {
|
|
208
|
+
const web = webBaseOf(creds(credentials));
|
|
209
|
+
return mapLimited(shas, 4, async (sha): Promise<CommitCiStatus> => {
|
|
210
|
+
// Two systems report on a commit: Checks (Actions and most apps) and
|
|
211
|
+
// the older commit statuses (many external CIs). Reading one of them
|
|
212
|
+
// shows a green tick on a commit whose other half is failing.
|
|
213
|
+
const [checks, statuses] = await Promise.all([
|
|
214
|
+
call<{ total_count: number; check_runs: { status: string; conclusion: string | null }[] }>(
|
|
215
|
+
credentials,
|
|
216
|
+
`/repos/${locator}/commits/${sha}/check-runs?per_page=100`
|
|
217
|
+
).catch(() => null),
|
|
218
|
+
call<{ state: string; total_count: number; statuses: { state: string }[] }>(
|
|
219
|
+
credentials,
|
|
220
|
+
`/repos/${locator}/commits/${sha}/status`
|
|
221
|
+
).catch(() => null)
|
|
222
|
+
]);
|
|
223
|
+
|
|
224
|
+
const states: CommitCiState[] = [
|
|
225
|
+
...(checks?.data.check_runs ?? []).map((run) => ciFromConclusion(run.status, run.conclusion)),
|
|
226
|
+
...(statuses?.data.statuses ?? []).map((status): CommitCiState =>
|
|
227
|
+
status.state === 'success' ? 'success'
|
|
228
|
+
: status.state === 'pending' ? 'pending'
|
|
229
|
+
: status.state === 'failure' || status.state === 'error' ? 'failure'
|
|
230
|
+
: 'none')
|
|
231
|
+
].filter((state) => state !== 'none');
|
|
232
|
+
|
|
233
|
+
return rollUp(sha, states, `${web}/${locator}/commit/${sha}`);
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
links(credentials, locator) {
|
|
238
|
+
const repo = `${webBaseOf(creds(credentials))}/${locator}`;
|
|
239
|
+
return {
|
|
240
|
+
repo,
|
|
241
|
+
commit: `${repo}/commit/{sha}`,
|
|
242
|
+
branch: `${repo}/tree/{branch}`,
|
|
243
|
+
file: `${repo}/blob/{ref}/{path}`,
|
|
244
|
+
fileLine: '#L{line}',
|
|
245
|
+
compare: `${repo}/compare/{base}...{head}`,
|
|
246
|
+
newPullRequest: `${repo}/compare/{base}...{head}?expand=1`
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
templates: {
|
|
251
|
+
async gitignoreList(credentials) {
|
|
252
|
+
const response = await call<string[]>(credentials, '/gitignore/templates');
|
|
253
|
+
return (response.data ?? []).map((name) => ({ key: name, name }));
|
|
254
|
+
},
|
|
255
|
+
async gitignore(credentials, key) {
|
|
256
|
+
const response = await call<{ source: string }>(credentials, `/gitignore/templates/${encodeURIComponent(key)}`);
|
|
257
|
+
return response.data.source;
|
|
258
|
+
},
|
|
259
|
+
async licenseList(credentials) {
|
|
260
|
+
const response = await call<{ key: string; name: string }[]>(credentials, '/licenses');
|
|
261
|
+
return (response.data ?? []).map((license) => ({ key: license.key, name: license.name }));
|
|
262
|
+
},
|
|
263
|
+
async license(credentials, key, holder) {
|
|
264
|
+
const response = await call<{ body: string }>(credentials, `/licenses/${encodeURIComponent(key)}`);
|
|
265
|
+
return response.data.body
|
|
266
|
+
.replace(/\[year\]/g, holder.year)
|
|
267
|
+
.replace(/\[fullname\]/g, holder.fullname);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GitLab REST client, shared by the hosting adapter and the Issues & PRs
|
|
3
|
+
* adapter so both read one server root and one error vocabulary.
|
|
4
|
+
*
|
|
5
|
+
* `Authorization: Bearer` works for personal, project, group and OAuth tokens
|
|
6
|
+
* alike, so nothing downstream needs to know how the account signed in.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { WorkRateLimit } from '$shared/types/work';
|
|
10
|
+
import { hostRequest, rateLimitFrom, type HostRequestOptions } from '../http';
|
|
11
|
+
import { normaliseBaseUrl } from '../urls';
|
|
12
|
+
|
|
13
|
+
export const GITLAB_WEB_BASE = 'https://gitlab.com';
|
|
14
|
+
|
|
15
|
+
export function gitlabWebBase(credentials: Record<string, string>): string {
|
|
16
|
+
return normaliseBaseUrl(credentials.baseUrl) || GITLAB_WEB_BASE;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function gitlabApiBase(credentials: Record<string, string>): string {
|
|
20
|
+
return `${gitlabWebBase(credentials)}/api/v4`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A project path as the API wants it in a URL segment: `group%2Fsub%2Fname`. */
|
|
24
|
+
export function projectRef(locator: string): string {
|
|
25
|
+
return encodeURIComponent(locator);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GitLabResponse<T> {
|
|
29
|
+
data: T;
|
|
30
|
+
rateLimit: WorkRateLimit | null;
|
|
31
|
+
nextPage: number | null;
|
|
32
|
+
total: number | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function gitlabRequest<T>(
|
|
36
|
+
credentials: Record<string, string>,
|
|
37
|
+
path: string,
|
|
38
|
+
options: HostRequestOptions = {}
|
|
39
|
+
): Promise<GitLabResponse<T>> {
|
|
40
|
+
const url = path.startsWith('http') ? path : `${gitlabApiBase(credentials)}${path}`;
|
|
41
|
+
const response = await hostRequest<T>('GitLab', url, {
|
|
42
|
+
...options,
|
|
43
|
+
headers: { Authorization: `Bearer ${credentials.token ?? ''}`, ...options.headers }
|
|
44
|
+
});
|
|
45
|
+
const next = response.headers.get('x-next-page');
|
|
46
|
+
const total = response.headers.get('x-total');
|
|
47
|
+
return {
|
|
48
|
+
data: response.data,
|
|
49
|
+
rateLimit: rateLimitFrom(response.headers),
|
|
50
|
+
nextPage: next ? Number(next) : null,
|
|
51
|
+
total: total ? Number(total) : null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Follow `x-next-page` up to `maxPages`. */
|
|
56
|
+
export async function gitlabPaged<T>(
|
|
57
|
+
credentials: Record<string, string>,
|
|
58
|
+
path: string,
|
|
59
|
+
maxPages = 3
|
|
60
|
+
): Promise<T[]> {
|
|
61
|
+
const items: T[] = [];
|
|
62
|
+
const joiner = path.includes('?') ? '&' : '?';
|
|
63
|
+
let page: number | null = 1;
|
|
64
|
+
for (let fetched = 0; fetched < maxPages && page; fetched += 1) {
|
|
65
|
+
const response: GitLabResponse<T[]> = await gitlabRequest<T[]>(credentials, `${path}${joiner}per_page=100&page=${page}`);
|
|
66
|
+
items.push(...(response.data ?? []));
|
|
67
|
+
page = response.nextPage;
|
|
68
|
+
}
|
|
69
|
+
return items;
|
|
70
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitLab (gitlab.com and self-managed) as a repository host.
|
|
3
|
+
*
|
|
4
|
+
* Where GitLab differs from GitHub, it differs here and nowhere else:
|
|
5
|
+
* repositories are "projects", owners are users or (nested) GROUPS, so a
|
|
6
|
+
* locator is a full path of any depth, and a namespace is addressed by id
|
|
7
|
+
* when creating into it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { CommitCiState, CommitCiStatus, HostedRepo, HostOwner, HostViewer } from '$shared/types/git-hosting';
|
|
11
|
+
import { HostApiError, mapLimited, waitFor } from '../http';
|
|
12
|
+
import { hostOfBase, parseRemoteUrl } from '../urls';
|
|
13
|
+
import type { CreateRepoInput, GitHostAdapter, HostCredentials, RepoQuery } from '../types';
|
|
14
|
+
import { gitlabRequest, gitlabWebBase, projectRef } from './gitlab-client';
|
|
15
|
+
|
|
16
|
+
const REQUIRED_SCOPES = ['api', 'write_repository'];
|
|
17
|
+
|
|
18
|
+
interface GitLabProjectWire {
|
|
19
|
+
id: number;
|
|
20
|
+
path_with_namespace: string;
|
|
21
|
+
path: string;
|
|
22
|
+
name: string;
|
|
23
|
+
namespace: { full_path: string; kind?: string };
|
|
24
|
+
description: string | null;
|
|
25
|
+
visibility: 'private' | 'internal' | 'public';
|
|
26
|
+
forked_from_project?: { path_with_namespace: string } | null;
|
|
27
|
+
default_branch?: string | null;
|
|
28
|
+
http_url_to_repo: string;
|
|
29
|
+
ssh_url_to_repo?: string | null;
|
|
30
|
+
web_url: string;
|
|
31
|
+
last_activity_at?: string;
|
|
32
|
+
import_status?: string;
|
|
33
|
+
permissions?: {
|
|
34
|
+
project_access?: { access_level: number } | null;
|
|
35
|
+
group_access?: { access_level: number } | null;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Developer (30) is the lowest role that may push to an unprotected branch. */
|
|
40
|
+
const DEVELOPER = 30;
|
|
41
|
+
|
|
42
|
+
function toRepo(raw: GitLabProjectWire): HostedRepo {
|
|
43
|
+
const access = Math.max(
|
|
44
|
+
raw.permissions?.project_access?.access_level ?? 0,
|
|
45
|
+
raw.permissions?.group_access?.access_level ?? 0
|
|
46
|
+
);
|
|
47
|
+
return {
|
|
48
|
+
fullName: raw.path_with_namespace,
|
|
49
|
+
owner: raw.namespace.full_path,
|
|
50
|
+
name: raw.path,
|
|
51
|
+
description: raw.description,
|
|
52
|
+
// `internal` is visible to every signed-in user of the instance, which is
|
|
53
|
+
// not what anyone means by public.
|
|
54
|
+
isPrivate: raw.visibility !== 'public',
|
|
55
|
+
isFork: !!raw.forked_from_project,
|
|
56
|
+
parentFullName: raw.forked_from_project?.path_with_namespace ?? null,
|
|
57
|
+
defaultBranch: raw.default_branch ?? null,
|
|
58
|
+
cloneUrlHttps: raw.http_url_to_repo,
|
|
59
|
+
cloneUrlSsh: raw.ssh_url_to_repo ?? null,
|
|
60
|
+
webUrl: raw.web_url,
|
|
61
|
+
updatedAt: raw.last_activity_at ?? null,
|
|
62
|
+
canPush: raw.permissions ? access >= DEVELOPER : null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function pipelineState(status: string | undefined): CommitCiState {
|
|
67
|
+
switch (status) {
|
|
68
|
+
case 'success':
|
|
69
|
+
return 'success';
|
|
70
|
+
case 'failed':
|
|
71
|
+
return 'failure';
|
|
72
|
+
case 'running':
|
|
73
|
+
case 'pending':
|
|
74
|
+
case 'created':
|
|
75
|
+
case 'preparing':
|
|
76
|
+
case 'waiting_for_resource':
|
|
77
|
+
case 'waiting_for_callback':
|
|
78
|
+
case 'scheduled':
|
|
79
|
+
case 'manual':
|
|
80
|
+
return 'pending';
|
|
81
|
+
default:
|
|
82
|
+
return 'none';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const REPO_PAGE = 50;
|
|
87
|
+
|
|
88
|
+
export const gitlabHost: GitHostAdapter = {
|
|
89
|
+
kind: 'gitlab',
|
|
90
|
+
serviceName: 'GitLab',
|
|
91
|
+
|
|
92
|
+
webBase: (credentials) => gitlabWebBase(credentials),
|
|
93
|
+
host: (credentials) => hostOfBase(gitlabWebBase(credentials)),
|
|
94
|
+
|
|
95
|
+
locatorFromRemote(url, credentials) {
|
|
96
|
+
const parsed = parseRemoteUrl(url);
|
|
97
|
+
if (!parsed || parsed.host !== this.host(credentials)) return null;
|
|
98
|
+
// Every segment counts: `group/subgroup/project` is one project.
|
|
99
|
+
const parts = parsed.path.split('/').filter(Boolean);
|
|
100
|
+
return parts.length >= 2 ? parts.join('/') : null;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
gitUsername: () => 'oauth2',
|
|
104
|
+
|
|
105
|
+
async viewer(credentials): Promise<HostViewer> {
|
|
106
|
+
const user = await gitlabRequest<{ username: string; name: string | null; avatar_url: string | null }>(credentials, '/user');
|
|
107
|
+
|
|
108
|
+
// A personal access token can describe itself; an OAuth token describes
|
|
109
|
+
// itself through a different endpoint at the server root. Either way the
|
|
110
|
+
// answer is the scope list — and if neither works, the scopes are simply
|
|
111
|
+
// not reported rather than reported as all missing.
|
|
112
|
+
let scopes: string[] | null = null;
|
|
113
|
+
try {
|
|
114
|
+
const self = await gitlabRequest<{ scopes?: string[] }>(credentials, '/personal_access_tokens/self');
|
|
115
|
+
scopes = self.data.scopes ?? null;
|
|
116
|
+
} catch {
|
|
117
|
+
try {
|
|
118
|
+
const info = await gitlabRequest<{ scope?: string[]; scopes?: string[] }>(
|
|
119
|
+
credentials,
|
|
120
|
+
`${gitlabWebBase(credentials)}/oauth/token/info`
|
|
121
|
+
);
|
|
122
|
+
scopes = info.data.scope ?? info.data.scopes ?? null;
|
|
123
|
+
} catch {
|
|
124
|
+
scopes = null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
login: user.data.username,
|
|
130
|
+
name: user.data.name,
|
|
131
|
+
avatarUrl: user.data.avatar_url,
|
|
132
|
+
scopes,
|
|
133
|
+
missingScopes: scopes ? REQUIRED_SCOPES.filter((scope) => !scopes!.includes(scope)) : []
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
async listOwners(credentials): Promise<HostOwner[]> {
|
|
138
|
+
const [user, groups] = await Promise.all([
|
|
139
|
+
gitlabRequest<{ username: string; name: string | null; avatar_url: string | null }>(credentials, '/user'),
|
|
140
|
+
// Developer is the lowest role that can create a project in a group
|
|
141
|
+
// whose settings allow it; anything lower is offered and then refused.
|
|
142
|
+
gitlabRequest<{ full_path: string; full_name: string; avatar_url: string | null }[]>(
|
|
143
|
+
credentials,
|
|
144
|
+
`/groups?min_access_level=${DEVELOPER}&per_page=100&order_by=path`
|
|
145
|
+
)
|
|
146
|
+
]);
|
|
147
|
+
return [
|
|
148
|
+
{ login: user.data.username, kind: 'user', name: user.data.name, avatarUrl: user.data.avatar_url },
|
|
149
|
+
...(groups.data ?? []).map((group): HostOwner => ({
|
|
150
|
+
login: group.full_path,
|
|
151
|
+
kind: 'org',
|
|
152
|
+
name: group.full_name,
|
|
153
|
+
avatarUrl: group.avatar_url
|
|
154
|
+
}))
|
|
155
|
+
];
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
async listRepos(credentials, query: RepoQuery) {
|
|
159
|
+
const params = new URLSearchParams({
|
|
160
|
+
membership: 'true',
|
|
161
|
+
order_by: 'last_activity_at',
|
|
162
|
+
per_page: String(REPO_PAGE),
|
|
163
|
+
page: String(query.page),
|
|
164
|
+
simple: 'false'
|
|
165
|
+
});
|
|
166
|
+
if (query.search?.trim()) params.set('search', query.search.trim());
|
|
167
|
+
|
|
168
|
+
const path = query.owner
|
|
169
|
+
? `/groups/${projectRef(query.owner)}/projects?include_subgroups=true&${params.toString()}`
|
|
170
|
+
: `/projects?${params.toString()}`;
|
|
171
|
+
// A user namespace is not a group; asking the groups endpoint for one is
|
|
172
|
+
// a 404, so a user owner lists their own projects instead.
|
|
173
|
+
const viewer = query.owner
|
|
174
|
+
? await gitlabRequest<{ username: string }>(credentials, '/user').then((r) => r.data.username).catch(() => '')
|
|
175
|
+
: '';
|
|
176
|
+
const resolved = query.owner && query.owner === viewer
|
|
177
|
+
? `/users/${encodeURIComponent(viewer)}/projects?${params.toString()}`
|
|
178
|
+
: path;
|
|
179
|
+
|
|
180
|
+
const response = await gitlabRequest<GitLabProjectWire[]>(credentials, resolved);
|
|
181
|
+
return { repos: (response.data ?? []).map(toRepo), hasMore: response.nextPage !== null };
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
async getRepo(credentials, locator) {
|
|
185
|
+
const response = await gitlabRequest<GitLabProjectWire>(credentials, `/projects/${projectRef(locator)}`);
|
|
186
|
+
return toRepo(response.data);
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
async createRepo(credentials, input: CreateRepoInput) {
|
|
190
|
+
let namespaceId: number | undefined;
|
|
191
|
+
if (input.owner.kind === 'org') {
|
|
192
|
+
const group = await gitlabRequest<{ id: number }>(credentials, `/groups/${projectRef(input.owner.login)}`);
|
|
193
|
+
namespaceId = group.data.id;
|
|
194
|
+
}
|
|
195
|
+
const response = await gitlabRequest<GitLabProjectWire>(credentials, '/projects', {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
body: {
|
|
198
|
+
name: input.name,
|
|
199
|
+
path: input.name,
|
|
200
|
+
description: input.description || undefined,
|
|
201
|
+
visibility: input.isPrivate ? 'private' : 'public',
|
|
202
|
+
...(namespaceId !== undefined && { namespace_id: namespaceId }),
|
|
203
|
+
initialize_with_readme: false
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return toRepo(response.data);
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
async fork(credentials, locator) {
|
|
210
|
+
const response = await gitlabRequest<GitLabProjectWire>(credentials, `/projects/${projectRef(locator)}/fork`, {
|
|
211
|
+
method: 'POST',
|
|
212
|
+
body: {}
|
|
213
|
+
});
|
|
214
|
+
const id = response.data.id;
|
|
215
|
+
// A fork is an import job; until it finishes the repository is empty and
|
|
216
|
+
// a push to it would race the copy.
|
|
217
|
+
const ready = await waitFor(async () => {
|
|
218
|
+
const check = await gitlabRequest<GitLabProjectWire>(credentials, `/projects/${id}`);
|
|
219
|
+
const status = check.data.import_status;
|
|
220
|
+
if (status === 'failed') throw new HostApiError('GitLab could not create the fork', 0, 'error');
|
|
221
|
+
return !status || status === 'finished' || status === 'none' ? toRepo(check.data) : null;
|
|
222
|
+
}, 120_000, 2000);
|
|
223
|
+
if (!ready) throw new HostApiError('GitLab is still creating the fork. Try again in a minute.', 0, 'error');
|
|
224
|
+
return ready;
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
async commitStatuses(credentials, locator, shas): Promise<CommitCiStatus[]> {
|
|
228
|
+
return mapLimited(shas, 4, async (sha): Promise<CommitCiStatus> => {
|
|
229
|
+
try {
|
|
230
|
+
const commit = await gitlabRequest<{ last_pipeline?: { status?: string; web_url?: string } | null }>(
|
|
231
|
+
credentials,
|
|
232
|
+
`/projects/${projectRef(locator)}/repository/commits/${encodeURIComponent(sha)}`
|
|
233
|
+
);
|
|
234
|
+
const pipeline = commit.data.last_pipeline;
|
|
235
|
+
const state = pipelineState(pipeline?.status);
|
|
236
|
+
return {
|
|
237
|
+
sha,
|
|
238
|
+
state,
|
|
239
|
+
url: pipeline?.web_url ?? null,
|
|
240
|
+
summary: pipeline?.status ? `Pipeline ${pipeline.status.replace(/_/g, ' ')}` : 'No pipeline'
|
|
241
|
+
};
|
|
242
|
+
} catch {
|
|
243
|
+
// A commit the server has never seen (not pushed yet) is a 404,
|
|
244
|
+
// which is "no CI", not an error worth showing.
|
|
245
|
+
return { sha, state: 'none', url: null, summary: 'No pipeline' };
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
links(credentials, locator) {
|
|
251
|
+
const repo = `${gitlabWebBase(credentials)}/${locator}`;
|
|
252
|
+
return {
|
|
253
|
+
repo,
|
|
254
|
+
commit: `${repo}/-/commit/{sha}`,
|
|
255
|
+
branch: `${repo}/-/tree/{branch}`,
|
|
256
|
+
file: `${repo}/-/blob/{ref}/{path}`,
|
|
257
|
+
fileLine: '#L{line}',
|
|
258
|
+
compare: `${repo}/-/compare/{base}...{head}`,
|
|
259
|
+
newPullRequest: `${repo}/-/merge_requests/new?merge_request%5Bsource_branch%5D={head}&merge_request%5Btarget_branch%5D={base}`
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
templates: {
|
|
264
|
+
async gitignoreList(credentials) {
|
|
265
|
+
const response = await gitlabRequest<{ key: string; name: string }[]>(credentials, '/templates/gitignores?per_page=100');
|
|
266
|
+
return (response.data ?? []).map((entry) => ({ key: entry.key, name: entry.name }));
|
|
267
|
+
},
|
|
268
|
+
async gitignore(credentials, key) {
|
|
269
|
+
const response = await gitlabRequest<{ content: string }>(credentials, `/templates/gitignores/${encodeURIComponent(key)}`);
|
|
270
|
+
return response.data.content;
|
|
271
|
+
},
|
|
272
|
+
async licenseList(credentials) {
|
|
273
|
+
const response = await gitlabRequest<{ key: string; name: string }[]>(credentials, '/templates/licenses?per_page=100');
|
|
274
|
+
return (response.data ?? []).map((entry) => ({ key: entry.key, name: entry.name }));
|
|
275
|
+
},
|
|
276
|
+
async license(credentials, key, holder) {
|
|
277
|
+
const params = new URLSearchParams({ fullname: holder.fullname });
|
|
278
|
+
const response = await gitlabRequest<{ content: string }>(
|
|
279
|
+
credentials,
|
|
280
|
+
`/templates/licenses/${encodeURIComponent(key)}?${params.toString()}`
|
|
281
|
+
);
|
|
282
|
+
return response.data.content.replace(/\[year\]/g, holder.year);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { githubHost } from './github';
|
|
3
|
+
import { gitlabHost } from './gitlab';
|
|
4
|
+
import { giteaHost } from './gitea';
|
|
5
|
+
import { bitbucketHost } from './bitbucket';
|
|
6
|
+
import { gitlabWorkAdapter } from '$backend/work/providers/gitlab/adapter';
|
|
7
|
+
import { rollUp } from '../ci';
|
|
8
|
+
|
|
9
|
+
describe('locatorFromRemote', () => {
|
|
10
|
+
test('GitHub takes owner/repo and rejects lookalike hosts', () => {
|
|
11
|
+
expect(githubHost.locatorFromRemote('git@github.com:acme/web.git', {})).toBe('acme/web');
|
|
12
|
+
expect(githubHost.locatorFromRemote('https://evilgithub.com/acme/web.git', {})).toBeNull();
|
|
13
|
+
expect(githubHost.locatorFromRemote('git@github.com:acme/web.git', { baseUrl: 'https://ghe.example.com' })).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('GitLab keeps every group level', () => {
|
|
17
|
+
expect(gitlabHost.locatorFromRemote('git@gitlab.com:group/sub/project.git', {})).toBe('group/sub/project');
|
|
18
|
+
expect(gitlabHost.locatorFromRemote('https://gitlab.example.com/a/b.git', { baseUrl: 'gitlab.example.com' })).toBe('a/b');
|
|
19
|
+
expect(gitlabHost.locatorFromRemote('https://gitlab.com/a/b.git', { baseUrl: 'gitlab.example.com' })).toBeNull();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('the GitLab work adapter cuts a web page path back to the project', () => {
|
|
23
|
+
expect(gitlabWorkAdapter.locatorFromRemote('https://gitlab.com/group/project/-/tree/main', {})).toBe('group/project');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Gitea served under a sub-path still yields owner/name', () => {
|
|
27
|
+
expect(giteaHost.locatorFromRemote('https://git.example.com/gitea/acme/web.git', { baseUrl: 'https://git.example.com/gitea' })).toBe('acme/web');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Gitea without a server answers for nothing', () => {
|
|
31
|
+
expect(giteaHost.locatorFromRemote('https://git.example.com/acme/web.git', {})).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('Bitbucket', () => {
|
|
35
|
+
expect(bitbucketHost.locatorFromRemote('git@bitbucket.org:team/repo.git', {})).toBe('team/repo');
|
|
36
|
+
expect(bitbucketHost.locatorFromRemote('git@github.com:team/repo.git', {})).toBeNull();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('links', () => {
|
|
41
|
+
test('each service uses its own URL shapes', () => {
|
|
42
|
+
expect(githubHost.links({}, 'acme/web').commit).toBe('https://github.com/acme/web/commit/{sha}');
|
|
43
|
+
expect(gitlabHost.links({}, 'g/p').branch).toBe('https://gitlab.com/g/p/-/tree/{branch}');
|
|
44
|
+
expect(giteaHost.links({ baseUrl: 'https://git.example.com' }, 'a/b').file).toBe('https://git.example.com/a/b/src/branch/{ref}/{path}');
|
|
45
|
+
expect(bitbucketHost.links({}, 'a/b').fileLine).toBe('#lines-{line}');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('git usernames', () => {
|
|
50
|
+
test('match what each service expects alongside a token', () => {
|
|
51
|
+
expect(githubHost.gitUsername({})).toBe('x-access-token');
|
|
52
|
+
expect(gitlabHost.gitUsername({})).toBe('oauth2');
|
|
53
|
+
expect(giteaHost.gitUsername({ login: 'octocat' })).toBe('octocat');
|
|
54
|
+
expect(bitbucketHost.gitUsername({})).toBe('x-bitbucket-api-token-auth');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('rollUp', () => {
|
|
59
|
+
test('any failure fails, then any pending is pending', () => {
|
|
60
|
+
expect(rollUp('a', ['success', 'failure', 'pending'], null).state).toBe('failure');
|
|
61
|
+
expect(rollUp('a', ['success', 'pending'], null).state).toBe('pending');
|
|
62
|
+
expect(rollUp('a', ['success', 'success'], null)).toMatchObject({ state: 'success', summary: '2 of 2 checks passed' });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('no signals is "none", not a pass', () => {
|
|
66
|
+
expect(rollUp('a', [], 'https://x').state).toBe('none');
|
|
67
|
+
});
|
|
68
|
+
});
|