@myrialabs/clopen 0.4.49 → 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/background-wait.test.ts +28 -0
- package/backend/chat/engine-handoff.ts +42 -6
- package/backend/chat/message-pages.test.ts +17 -0
- package/backend/chat/message-pages.ts +6 -2
- package/backend/chat/stream-manager.ts +114 -19
- 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/088_create_messages_fts_map.ts +52 -0
- package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
- package/backend/database/migrations/090_create_storage_tables.ts +83 -0
- package/backend/database/migrations/index.ts +25 -2
- package/backend/database/queries/graph-queries.ts +392 -135
- package/backend/database/queries/integration-queries.ts +10 -0
- package/backend/database/queries/memory-queue-queries.ts +11 -0
- package/backend/database/queries/message-fts.test.ts +120 -0
- package/backend/database/queries/message-queries.ts +45 -9
- package/backend/database/queries/project-queries.ts +6 -0
- package/backend/database/queries/session-queries.ts +6 -2
- package/backend/database/queries/utils-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/environment.ts +4 -0
- package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
- package/backend/engine/adapters/claude/input-gate.ts +74 -0
- package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
- package/backend/engine/adapters/claude/message-converter.ts +8 -0
- package/backend/engine/adapters/claude/stream.ts +20 -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.test.ts +7 -4
- 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 +84 -17
- 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/memory/README.md +7 -4
- package/backend/memory/layout.test.ts +377 -0
- package/backend/memory/layout.ts +1029 -265
- package/backend/memory/view.ts +257 -386
- 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/project/status-manager.ts +4 -2
- 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/chat/stream.ts +19 -10
- 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/memory/crud.ts +118 -81
- package/backend/ws/mentions/index.ts +81 -0
- package/backend/ws/messages/crud.ts +3 -1
- 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 +18 -18
- package/dist/assets/{index-DD0-3EWg.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-CrVWZH_D.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 +8 -9
- 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/memory.ts +96 -73
- 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 +2 -0
- package/shared/types/unified/message.ts +26 -1
- package/shared/types/unified/stream.ts +22 -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 +88 -1
- package/shared/utils/process-supervisor.ts +123 -29
- package/shared/utils/process-tree.ts +99 -0
- 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/graph-layout.worker-CRFqN7ZQ.js +0 -1
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
- package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
- package/dist/assets/index-CrVWZH_D.js.br +0 -0
- package/dist/assets/index-CrVWZH_D.js.gz +0 -0
- package/dist/assets/index-DD0-3EWg.js.br +0 -0
- package/dist/assets/index-DD0-3EWg.js.gz +0 -0
- package/dist/assets/main-D2_TmcwQ.js +0 -1240
- package/dist/assets/main-D2_TmcwQ.js.br +0 -0
- package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
- package/dist/assets/main-Yucigcmf.css +0 -1
- package/dist/assets/main-Yucigcmf.css.br +0 -0
- package/dist/assets/main-Yucigcmf.css.gz +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hosting adapters, keyed by integration provider id.
|
|
3
|
+
*
|
|
4
|
+
* The provider id IS the host kind — `github`, `gitlab`, `gitea`, `bitbucket`
|
|
5
|
+
* — so an account row says which adapter serves it without a lookup table.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GitHostKind } from '$shared/types/git-hosting';
|
|
9
|
+
import { GIT_HOST_KINDS } from '$shared/types/git-hosting';
|
|
10
|
+
import type { GitHostAdapter } from './types';
|
|
11
|
+
import { githubHost } from './providers/github';
|
|
12
|
+
import { gitlabHost } from './providers/gitlab';
|
|
13
|
+
import { giteaHost } from './providers/gitea';
|
|
14
|
+
import { bitbucketHost } from './providers/bitbucket';
|
|
15
|
+
|
|
16
|
+
const adapters: Record<GitHostKind, GitHostAdapter> = {
|
|
17
|
+
github: githubHost,
|
|
18
|
+
gitlab: gitlabHost,
|
|
19
|
+
gitea: giteaHost,
|
|
20
|
+
bitbucket: bitbucketHost
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function isGitHostKind(value: string): value is GitHostKind {
|
|
24
|
+
return (GIT_HOST_KINDS as readonly string[]).includes(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getHostAdapter(provider: string): GitHostAdapter | null {
|
|
28
|
+
return isGitHostKind(provider) ? adapters[provider] : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Which service a bare hostname belongs to, for a remote no account serves.
|
|
33
|
+
*
|
|
34
|
+
* Only the cloud hosts can be named from a hostname. A self-hosted server is
|
|
35
|
+
* recognised by the account that points at it, never by guessing from its name.
|
|
36
|
+
*/
|
|
37
|
+
export function cloudHostKind(host: string): GitHostKind | null {
|
|
38
|
+
switch (host) {
|
|
39
|
+
case 'github.com':
|
|
40
|
+
return 'github';
|
|
41
|
+
case 'gitlab.com':
|
|
42
|
+
return 'gitlab';
|
|
43
|
+
case 'bitbucket.org':
|
|
44
|
+
return 'bitbucket';
|
|
45
|
+
case 'codeberg.org':
|
|
46
|
+
return 'gitea';
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Git panel asks the hosting layer, provider-agnostic.
|
|
3
|
+
*
|
|
4
|
+
* Every function resolves the account first, hands the adapter a credential
|
|
5
|
+
* that is current (`credentialsForUse`), and returns shapes with no secret in
|
|
6
|
+
* them. Writes to the local repository (templates, the first commit, remotes,
|
|
7
|
+
* the push) happen here too, so publishing and forking are each ONE call the
|
|
8
|
+
* route can run under the repository lock.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { existsSync } from 'node:fs';
|
|
12
|
+
import { writeFile } from 'node:fs/promises';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { integrationAccountQueries } from '$backend/database/queries';
|
|
15
|
+
import { getProvider } from '$backend/integrations';
|
|
16
|
+
import { gitService } from '$backend/git/git-service';
|
|
17
|
+
import { execGit } from '$backend/git/git-executor';
|
|
18
|
+
import { resolveGitEnv } from '$backend/git/identity';
|
|
19
|
+
import { getWorkAdapter } from '$backend/work/registry';
|
|
20
|
+
import type {
|
|
21
|
+
CommitCiStatus,
|
|
22
|
+
ForkResult,
|
|
23
|
+
HostAccount,
|
|
24
|
+
HostedRepo,
|
|
25
|
+
HostingContext,
|
|
26
|
+
HostOwner,
|
|
27
|
+
HostRemote,
|
|
28
|
+
HostRepoPage,
|
|
29
|
+
HostTemplates,
|
|
30
|
+
HostViewer,
|
|
31
|
+
PublishRepoInput,
|
|
32
|
+
PublishRepoResult
|
|
33
|
+
} from '$shared/types/git-hosting';
|
|
34
|
+
import { debug } from '$shared/utils/logger';
|
|
35
|
+
import { accountForRemote, hostAccountById, hostAccounts, rememberOwners, type HostAccountRef } from './accounts';
|
|
36
|
+
import { credentialsForUse } from './credentials';
|
|
37
|
+
import { cloudHostKind, getHostAdapter } from './registry';
|
|
38
|
+
import { parseRemoteUrl } from './urls';
|
|
39
|
+
|
|
40
|
+
function requireAccount(accountId: string, projectId: string | null): HostAccountRef {
|
|
41
|
+
const ref = hostAccountById(accountId);
|
|
42
|
+
if (!ref) throw new Error('That account is not connected or is switched off');
|
|
43
|
+
if (projectId && ref.account.project_id && ref.account.project_id !== projectId) {
|
|
44
|
+
throw new Error('That account belongs to another project');
|
|
45
|
+
}
|
|
46
|
+
return ref;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function toHostAccount(ref: HostAccountRef): HostAccount {
|
|
50
|
+
const capabilities = integrationAccountQueries.capabilitiesOf(ref.account);
|
|
51
|
+
return {
|
|
52
|
+
accountId: ref.account.id,
|
|
53
|
+
provider: ref.provider,
|
|
54
|
+
providerName: getProvider(ref.provider)?.name ?? ref.adapter.serviceName,
|
|
55
|
+
label: ref.account.label,
|
|
56
|
+
host: ref.host,
|
|
57
|
+
login: ref.credentials.login || null,
|
|
58
|
+
offersWork: capabilities.includes('work') && getWorkAdapter(ref.provider) !== null,
|
|
59
|
+
status: ref.account.status,
|
|
60
|
+
statusDetail: ref.account.status_detail
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** `owner/name` off a URL for a service no account serves — enough for web links. */
|
|
65
|
+
function bareLocator(path: string): string | null {
|
|
66
|
+
const parts = path.split('/').filter(Boolean);
|
|
67
|
+
return parts.length >= 2 ? parts.join('/') : null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const REMOTE_RANK = (name: string) => (name === 'origin' ? 0 : name === 'upstream' ? 1 : 2);
|
|
71
|
+
|
|
72
|
+
/** Remote names git accepts and that will not be read as an option. */
|
|
73
|
+
const REMOTE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
74
|
+
/** What every service accepts as a repository name. */
|
|
75
|
+
const REPO_NAME = /^[A-Za-z0-9._-]{1,100}$/;
|
|
76
|
+
|
|
77
|
+
async function hasCommits(root: string): Promise<boolean> {
|
|
78
|
+
const result = await execGit(['rev-parse', '--verify', '--quiet', 'HEAD'], root);
|
|
79
|
+
return result.exitCode === 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The branch HEAD points at, including an unborn one in a repository with no commits. */
|
|
83
|
+
async function currentBranch(root: string): Promise<string | null> {
|
|
84
|
+
const result = await execGit(['symbolic-ref', '--short', '-q', 'HEAD'], root);
|
|
85
|
+
const name = result.stdout.trim();
|
|
86
|
+
return result.exitCode === 0 && name ? name : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function pushBranch(
|
|
90
|
+
projectId: string,
|
|
91
|
+
root: string,
|
|
92
|
+
remoteName: string,
|
|
93
|
+
url: string
|
|
94
|
+
): Promise<{ pushed: boolean; message: string | null }> {
|
|
95
|
+
if (!(await hasCommits(root))) {
|
|
96
|
+
return { pushed: false, message: 'Nothing to push yet — commit something, then push.' };
|
|
97
|
+
}
|
|
98
|
+
const branch = await currentBranch(root);
|
|
99
|
+
if (!branch) return { pushed: false, message: 'HEAD is detached, so there is no branch to push.' };
|
|
100
|
+
|
|
101
|
+
const result = await gitService.push(root, remoteName, branch, false, { useUpstream: false }, resolveGitEnv(projectId, url));
|
|
102
|
+
return result.success ? { pushed: true, message: null } : { pushed: false, message: result.message };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// CI status cache. A finished commit's CI never changes, so it is kept; a
|
|
107
|
+
// running one is re-asked after a short while.
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
const ciCache = new Map<string, { status: CommitCiStatus; at: number }>();
|
|
111
|
+
const CI_PENDING_TTL_MS = 30_000;
|
|
112
|
+
const CI_NONE_TTL_MS = 120_000;
|
|
113
|
+
const CI_CACHE_MAX = 4000;
|
|
114
|
+
|
|
115
|
+
function cachedCi(key: string): CommitCiStatus | null {
|
|
116
|
+
const entry = ciCache.get(key);
|
|
117
|
+
if (!entry) return null;
|
|
118
|
+
const age = Date.now() - entry.at;
|
|
119
|
+
if (entry.status.state === 'pending' && age > CI_PENDING_TTL_MS) return null;
|
|
120
|
+
if (entry.status.state === 'none' && age > CI_NONE_TTL_MS) return null;
|
|
121
|
+
return entry.status;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function storeCi(key: string, status: CommitCiStatus): void {
|
|
125
|
+
if (ciCache.size >= CI_CACHE_MAX) {
|
|
126
|
+
const oldest = ciCache.keys().next();
|
|
127
|
+
if (!oldest.done) ciCache.delete(oldest.value);
|
|
128
|
+
}
|
|
129
|
+
ciCache.set(key, { status, at: Date.now() });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// Templates
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The .gitignore template a project's own files point at.
|
|
138
|
+
*
|
|
139
|
+
* Read from marker files, not from anything the user said: a `package.json`
|
|
140
|
+
* means Node whatever else is in the folder. Names are the ones the services'
|
|
141
|
+
* template lists use; the caller matches them case-insensitively.
|
|
142
|
+
*/
|
|
143
|
+
const STACK_MARKERS: { files: string[]; template: string }[] = [
|
|
144
|
+
{ files: ['package.json', 'bun.lock', 'bun.lockb'], template: 'Node' },
|
|
145
|
+
{ files: ['Cargo.toml'], template: 'Rust' },
|
|
146
|
+
{ files: ['go.mod'], template: 'Go' },
|
|
147
|
+
{ files: ['pyproject.toml', 'requirements.txt', 'setup.py', 'Pipfile'], template: 'Python' },
|
|
148
|
+
{ files: ['Gemfile'], template: 'Ruby' },
|
|
149
|
+
{ files: ['composer.json'], template: 'Composer' },
|
|
150
|
+
{ files: ['pom.xml'], template: 'Maven' },
|
|
151
|
+
{ files: ['build.gradle', 'build.gradle.kts'], template: 'Gradle' },
|
|
152
|
+
{ files: ['pubspec.yaml'], template: 'Dart' },
|
|
153
|
+
{ files: ['Package.swift'], template: 'Swift' },
|
|
154
|
+
{ files: ['mix.exs'], template: 'Elixir' },
|
|
155
|
+
{ files: ['CMakeLists.txt'], template: 'CMake' },
|
|
156
|
+
{ files: ['deno.json', 'deno.jsonc'], template: 'Node' }
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
export function suggestGitignore(root: string, available: string[]): string | null {
|
|
160
|
+
const byName = new Map(available.map((name) => [name.toLowerCase(), name]));
|
|
161
|
+
for (const marker of STACK_MARKERS) {
|
|
162
|
+
if (marker.files.some((file) => existsSync(join(root, file)))) {
|
|
163
|
+
const match = byName.get(marker.template.toLowerCase());
|
|
164
|
+
if (match) return match;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const LICENSE_FILES = ['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'COPYING'];
|
|
171
|
+
const README_FILES = ['README.md', 'README', 'README.txt', 'readme.md'];
|
|
172
|
+
|
|
173
|
+
export const hostingService = {
|
|
174
|
+
accounts(projectId: string | null): HostAccount[] {
|
|
175
|
+
return hostAccounts(projectId).map(toHostAccount);
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Remotes matched against accounts, in one pass. Cheap — no network — so the
|
|
180
|
+
* panel can ask on every remote change.
|
|
181
|
+
*/
|
|
182
|
+
async context(projectId: string, root: string): Promise<HostingContext> {
|
|
183
|
+
let remotes: { name: string; fetchUrl: string; pushUrl: string }[] = [];
|
|
184
|
+
try {
|
|
185
|
+
remotes = await gitService.getRemotes(root);
|
|
186
|
+
} catch {
|
|
187
|
+
remotes = [];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const sorted = [...remotes].sort((a, b) => REMOTE_RANK(a.name) - REMOTE_RANK(b.name));
|
|
191
|
+
const defaults = await Promise.all(sorted.map((remote) =>
|
|
192
|
+
gitService.getDefaultBranch(root, remote.name).catch(() => null)));
|
|
193
|
+
|
|
194
|
+
const matched: HostRemote[] = sorted
|
|
195
|
+
.map((remote, index) => {
|
|
196
|
+
const defaultBranch = defaults[index] ?? null;
|
|
197
|
+
const url = remote.pushUrl || remote.fetchUrl;
|
|
198
|
+
const parsed = parseRemoteUrl(url);
|
|
199
|
+
const match = accountForRemote(url, projectId, { strict: false });
|
|
200
|
+
if (match) {
|
|
201
|
+
return {
|
|
202
|
+
name: remote.name,
|
|
203
|
+
url,
|
|
204
|
+
host: parsed?.host ?? null,
|
|
205
|
+
provider: match.ref.provider,
|
|
206
|
+
locator: match.locator,
|
|
207
|
+
accountId: match.ref.account.id,
|
|
208
|
+
links: match.ref.adapter.links(match.ref.credentials, match.locator),
|
|
209
|
+
defaultBranch
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const provider = parsed ? cloudHostKind(parsed.host) : null;
|
|
213
|
+
const locator = parsed && provider ? bareLocator(parsed.path) : null;
|
|
214
|
+
const adapter = provider ? getHostAdapter(provider) : null;
|
|
215
|
+
return {
|
|
216
|
+
name: remote.name,
|
|
217
|
+
url,
|
|
218
|
+
host: parsed?.host ?? null,
|
|
219
|
+
provider,
|
|
220
|
+
locator,
|
|
221
|
+
accountId: null,
|
|
222
|
+
// The cloud services' links need no account — a link to a
|
|
223
|
+
// public page works signed in or not.
|
|
224
|
+
links: adapter && locator && provider !== 'gitea' ? adapter.links({}, locator) : null,
|
|
225
|
+
defaultBranch
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const primary = matched.find((remote) => remote.accountId) ?? matched.find((remote) => remote.provider) ?? matched[0];
|
|
230
|
+
const unserved = matched.find((remote) => remote.provider && !remote.accountId);
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
remotes: matched,
|
|
234
|
+
accounts: this.accounts(projectId),
|
|
235
|
+
primaryRemote: primary?.name ?? null,
|
|
236
|
+
unservedProvider: unserved?.provider && unserved.host ? { provider: unserved.provider, host: unserved.host } : null
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
async viewer(accountId: string): Promise<HostViewer> {
|
|
241
|
+
const ref = requireAccount(accountId, null);
|
|
242
|
+
return ref.adapter.viewer(await credentialsForUse(ref.account));
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
async owners(accountId: string, projectId: string | null): Promise<HostOwner[]> {
|
|
246
|
+
const ref = requireAccount(accountId, projectId);
|
|
247
|
+
const owners = await ref.adapter.listOwners(await credentialsForUse(ref.account));
|
|
248
|
+
rememberOwners(accountId, owners.map((owner) => owner.login));
|
|
249
|
+
return owners;
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
async repos(
|
|
253
|
+
accountId: string,
|
|
254
|
+
projectId: string | null,
|
|
255
|
+
query: { search?: string; owner?: string; page: number }
|
|
256
|
+
): Promise<HostRepoPage> {
|
|
257
|
+
const ref = requireAccount(accountId, projectId);
|
|
258
|
+
return ref.adapter.listRepos(await credentialsForUse(ref.account), query);
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
async templates(accountId: string, projectId: string, root: string): Promise<HostTemplates> {
|
|
262
|
+
const ref = requireAccount(accountId, projectId);
|
|
263
|
+
const credentials = await credentialsForUse(ref.account);
|
|
264
|
+
const [gitignore, licenses] = ref.adapter.templates
|
|
265
|
+
? await Promise.all([
|
|
266
|
+
ref.adapter.templates.gitignoreList(credentials).catch(() => []),
|
|
267
|
+
ref.adapter.templates.licenseList(credentials).catch(() => [])
|
|
268
|
+
])
|
|
269
|
+
: [[], []];
|
|
270
|
+
|
|
271
|
+
let pendingFiles = 0;
|
|
272
|
+
try {
|
|
273
|
+
const status = await gitService.getStatus(root);
|
|
274
|
+
pendingFiles = new Set([
|
|
275
|
+
...status.staged.map((file) => file.path),
|
|
276
|
+
...status.unstaged.map((file) => file.path),
|
|
277
|
+
...status.untracked.map((file) => file.path)
|
|
278
|
+
]).size;
|
|
279
|
+
} catch {
|
|
280
|
+
pendingFiles = 0;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
gitignore,
|
|
285
|
+
licenses,
|
|
286
|
+
suggestedGitignore: suggestGitignore(root, gitignore.map((entry) => entry.key)),
|
|
287
|
+
existing: {
|
|
288
|
+
gitignore: existsSync(join(root, '.gitignore')),
|
|
289
|
+
license: LICENSE_FILES.some((file) => existsSync(join(root, file))),
|
|
290
|
+
readme: README_FILES.some((file) => existsSync(join(root, file)))
|
|
291
|
+
},
|
|
292
|
+
needsFirstCommit: !(await hasCommits(root)),
|
|
293
|
+
pendingFiles
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Create the repository on the service, connect it as a remote, push.
|
|
299
|
+
*
|
|
300
|
+
* Local files first, remote last: a template that cannot be fetched fails
|
|
301
|
+
* the publish before anything exists on the service, so a retry does not
|
|
302
|
+
* meet "name already taken" from a half-finished first attempt.
|
|
303
|
+
*/
|
|
304
|
+
async publish(projectId: string, root: string, input: PublishRepoInput): Promise<PublishRepoResult> {
|
|
305
|
+
const ref = requireAccount(input.accountId, projectId);
|
|
306
|
+
const credentials = await credentialsForUse(ref.account);
|
|
307
|
+
|
|
308
|
+
const name = input.name.trim();
|
|
309
|
+
if (!REPO_NAME.test(name)) throw new Error('Use letters, numbers, dots, dashes and underscores for the name');
|
|
310
|
+
const remoteName = input.remoteName.trim() || 'origin';
|
|
311
|
+
if (!REMOTE_NAME.test(remoteName)) throw new Error('That is not a valid remote name');
|
|
312
|
+
|
|
313
|
+
const existingRemotes = await gitService.getRemotes(root).catch(() => []);
|
|
314
|
+
if (existingRemotes.some((remote) => remote.name === remoteName)) {
|
|
315
|
+
throw new Error(`A remote called "${remoteName}" already exists`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const owners = await ref.adapter.listOwners(credentials);
|
|
319
|
+
const owner = owners.find((candidate) => candidate.login === input.owner);
|
|
320
|
+
if (!owner) throw new Error(`${input.owner} is not an owner this account can create repositories under`);
|
|
321
|
+
|
|
322
|
+
// --- local files ---
|
|
323
|
+
const holder = { year: String(new Date().getFullYear()), fullname: owner.name || owner.login };
|
|
324
|
+
if (input.gitignore && ref.adapter.templates && !existsSync(join(root, '.gitignore'))) {
|
|
325
|
+
await writeFile(join(root, '.gitignore'), await ref.adapter.templates.gitignore(credentials, input.gitignore));
|
|
326
|
+
}
|
|
327
|
+
if (input.license && ref.adapter.templates && !LICENSE_FILES.some((file) => existsSync(join(root, file)))) {
|
|
328
|
+
await writeFile(join(root, 'LICENSE'), await ref.adapter.templates.license(credentials, input.license, holder));
|
|
329
|
+
}
|
|
330
|
+
if (input.readme && !README_FILES.some((file) => existsSync(join(root, file)))) {
|
|
331
|
+
const description = input.description.trim();
|
|
332
|
+
await writeFile(join(root, 'README.md'), `# ${name}\n${description ? `\n${description}\n` : ''}`);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (input.createFirstCommit && !(await hasCommits(root))) {
|
|
336
|
+
await gitService.stageAll(root);
|
|
337
|
+
await gitService.commit(root, 'Initial commit', resolveGitEnv(projectId));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// --- the service ---
|
|
341
|
+
const repo = await ref.adapter.createRepo(credentials, {
|
|
342
|
+
owner,
|
|
343
|
+
name,
|
|
344
|
+
description: input.description.trim(),
|
|
345
|
+
isPrivate: input.isPrivate
|
|
346
|
+
});
|
|
347
|
+
debug.log('git-hosts', `Created ${repo.fullName} on ${ref.adapter.serviceName}`);
|
|
348
|
+
|
|
349
|
+
const url = input.protocol === 'ssh' && repo.cloneUrlSsh ? repo.cloneUrlSsh : repo.cloneUrlHttps;
|
|
350
|
+
await gitService.addRemote(root, remoteName, url);
|
|
351
|
+
|
|
352
|
+
const push = await pushBranch(projectId, root, remoteName, url);
|
|
353
|
+
return { repo, remoteName, pushed: push.pushed, pushMessage: push.message };
|
|
354
|
+
},
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Fork the repository a remote points at, and push the current branch there.
|
|
358
|
+
*
|
|
359
|
+
* When the forked remote is `origin` and there is no `upstream` yet, the
|
|
360
|
+
* remotes are rearranged the way `gh repo fork` does it — the original
|
|
361
|
+
* becomes `upstream`, the fork becomes `origin` — because that is the layout
|
|
362
|
+
* every contributor guide assumes. Otherwise the fork is added alongside,
|
|
363
|
+
* named after the account, and nothing existing is renamed.
|
|
364
|
+
*/
|
|
365
|
+
async fork(projectId: string, root: string, input: { accountId: string; remote: string }): Promise<ForkResult> {
|
|
366
|
+
const ref = requireAccount(input.accountId, projectId);
|
|
367
|
+
const credentials = await credentialsForUse(ref.account);
|
|
368
|
+
|
|
369
|
+
const remotes = await gitService.getRemotes(root);
|
|
370
|
+
const source = remotes.find((remote) => remote.name === input.remote);
|
|
371
|
+
if (!source) throw new Error(`There is no remote called "${input.remote}"`);
|
|
372
|
+
const sourceUrl = source.pushUrl || source.fetchUrl;
|
|
373
|
+
const locator = ref.adapter.locatorFromRemote(sourceUrl, credentials);
|
|
374
|
+
if (!locator) throw new Error(`${input.remote} does not point at ${ref.adapter.serviceName}`);
|
|
375
|
+
|
|
376
|
+
const fork = await ref.adapter.fork(credentials, locator);
|
|
377
|
+
const usesSsh = !/^https?:\/\//i.test(sourceUrl);
|
|
378
|
+
const forkUrl = usesSsh && fork.cloneUrlSsh ? fork.cloneUrlSsh : fork.cloneUrlHttps;
|
|
379
|
+
|
|
380
|
+
const names = new Set(remotes.map((remote) => remote.name));
|
|
381
|
+
let forkRemote: string;
|
|
382
|
+
let upstreamRemote: string | null = null;
|
|
383
|
+
if (input.remote === 'origin' && !names.has('upstream')) {
|
|
384
|
+
await gitService.renameRemote(root, 'origin', 'upstream');
|
|
385
|
+
forkRemote = 'origin';
|
|
386
|
+
upstreamRemote = 'upstream';
|
|
387
|
+
} else {
|
|
388
|
+
const login = (credentials.login || 'fork').replace(/[^A-Za-z0-9._-]/g, '-');
|
|
389
|
+
forkRemote = !names.has(login) ? login : !names.has('fork') ? 'fork' : `fork-${Date.now().toString(36)}`;
|
|
390
|
+
}
|
|
391
|
+
await gitService.addRemote(root, forkRemote, forkUrl);
|
|
392
|
+
|
|
393
|
+
const push = await pushBranch(projectId, root, forkRemote, forkUrl);
|
|
394
|
+
return { fork, forkRemote, upstreamRemote, pushed: push.pushed, pushMessage: push.message };
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Whether pushing to a remote is refused for permission — the question the
|
|
399
|
+
* fork offer hangs on. Null when the account cannot say.
|
|
400
|
+
*/
|
|
401
|
+
async canPush(projectId: string, root: string, remote: string): Promise<{ canPush: boolean | null; accountId: string | null; repo: HostedRepo | null }> {
|
|
402
|
+
const remotes = await gitService.getRemotes(root).catch(() => []);
|
|
403
|
+
const target = remotes.find((entry) => entry.name === remote);
|
|
404
|
+
if (!target) return { canPush: null, accountId: null, repo: null };
|
|
405
|
+
const match = accountForRemote(target.pushUrl || target.fetchUrl, projectId, { strict: false });
|
|
406
|
+
if (!match) return { canPush: null, accountId: null, repo: null };
|
|
407
|
+
try {
|
|
408
|
+
const repo = await match.ref.adapter.getRepo(await credentialsForUse(match.ref.account), match.locator);
|
|
409
|
+
return { canPush: repo.canPush, accountId: match.ref.account.id, repo };
|
|
410
|
+
} catch {
|
|
411
|
+
return { canPush: null, accountId: match.ref.account.id, repo: null };
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
|
|
415
|
+
async commitStatuses(projectId: string, root: string, remote: string | null, shas: string[]): Promise<CommitCiStatus[]> {
|
|
416
|
+
const remotes = await gitService.getRemotes(root).catch(() => []);
|
|
417
|
+
const ordered = [...remotes].sort((a, b) => REMOTE_RANK(a.name) - REMOTE_RANK(b.name));
|
|
418
|
+
const target = remote ? ordered.find((entry) => entry.name === remote) : ordered[0];
|
|
419
|
+
if (!target) return [];
|
|
420
|
+
const match = accountForRemote(target.pushUrl || target.fetchUrl, projectId, { strict: false });
|
|
421
|
+
if (!match) return [];
|
|
422
|
+
|
|
423
|
+
const prefix = `${match.ref.account.id}:${match.locator}:`;
|
|
424
|
+
const missing = shas.filter((sha) => !cachedCi(prefix + sha));
|
|
425
|
+
if (missing.length > 0) {
|
|
426
|
+
const credentials = await credentialsForUse(match.ref.account);
|
|
427
|
+
const fresh = await match.ref.adapter.commitStatuses(credentials, match.locator, missing);
|
|
428
|
+
for (const status of fresh) storeCi(prefix + status.sha, status);
|
|
429
|
+
}
|
|
430
|
+
return shas.map((sha) => cachedCi(prefix + sha) ?? { sha, state: 'none', url: null, summary: 'No checks' });
|
|
431
|
+
}
|
|
432
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hosting adapter contract.
|
|
3
|
+
*
|
|
4
|
+
* One per service. Where `backend/work/types.ts` is about the WORK on a
|
|
5
|
+
* repository (issues, pull requests, CI runs), this is about the repository
|
|
6
|
+
* itself and the account that owns it: who am I, where can I create a
|
|
7
|
+
* repository, which repositories can I pick, make one, fork one, what does CI
|
|
8
|
+
* say about these commits, and where on the web is all of it.
|
|
9
|
+
*
|
|
10
|
+
* `credentials` is the account's decoded credential object, already refreshed
|
|
11
|
+
* (see `credentials.ts`). An adapter reads `token`, `baseUrl` and whatever its
|
|
12
|
+
* service needs, and never returns any of it.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
CommitCiStatus,
|
|
17
|
+
GitHostKind,
|
|
18
|
+
HostedRepo,
|
|
19
|
+
HostLinks,
|
|
20
|
+
HostOwner,
|
|
21
|
+
HostRepoPage,
|
|
22
|
+
HostTemplateOption,
|
|
23
|
+
HostViewer
|
|
24
|
+
} from '$shared/types/git-hosting';
|
|
25
|
+
|
|
26
|
+
export type HostCredentials = Record<string, string>;
|
|
27
|
+
|
|
28
|
+
export interface CreateRepoInput {
|
|
29
|
+
owner: HostOwner;
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
isPrivate: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RepoQuery {
|
|
36
|
+
search?: string;
|
|
37
|
+
/** Only repositories under this owner. */
|
|
38
|
+
owner?: string;
|
|
39
|
+
page: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface GitHostAdapter {
|
|
43
|
+
kind: GitHostKind;
|
|
44
|
+
/** The service's display name, for messages. */
|
|
45
|
+
serviceName: string;
|
|
46
|
+
|
|
47
|
+
/** `https://github.com`, or the self-hosted root. */
|
|
48
|
+
webBase(credentials: HostCredentials): string;
|
|
49
|
+
/** Hostname git remotes on this account point at. */
|
|
50
|
+
host(credentials: HostCredentials): string;
|
|
51
|
+
/** `owner/name` for a remote on this account's host, or null when it is not. */
|
|
52
|
+
locatorFromRemote(url: string, credentials: HostCredentials): string | null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The username git should send alongside the token over HTTPS. Services
|
|
56
|
+
* disagree — GitHub ignores it, GitLab wants `oauth2`, Bitbucket a fixed
|
|
57
|
+
* marker — and a wrong one is a 401 that looks like a bad token.
|
|
58
|
+
*/
|
|
59
|
+
gitUsername(credentials: HostCredentials): string;
|
|
60
|
+
|
|
61
|
+
viewer(credentials: HostCredentials): Promise<HostViewer>;
|
|
62
|
+
/** The signed-in user first, then every organisation/group/workspace they can create in. */
|
|
63
|
+
listOwners(credentials: HostCredentials): Promise<HostOwner[]>;
|
|
64
|
+
listRepos(credentials: HostCredentials, query: RepoQuery): Promise<HostRepoPage>;
|
|
65
|
+
getRepo(credentials: HostCredentials, locator: string): Promise<HostedRepo>;
|
|
66
|
+
createRepo(credentials: HostCredentials, input: CreateRepoInput): Promise<HostedRepo>;
|
|
67
|
+
/** Fork into the signed-in user's namespace. Resolves once the fork is usable. */
|
|
68
|
+
fork(credentials: HostCredentials, locator: string): Promise<HostedRepo>;
|
|
69
|
+
|
|
70
|
+
/** CI roll-up per commit, in the order asked. Commits the service never saw report `none`. */
|
|
71
|
+
commitStatuses(credentials: HostCredentials, locator: string, shas: string[]): Promise<CommitCiStatus[]>;
|
|
72
|
+
|
|
73
|
+
links(credentials: HostCredentials, locator: string): HostLinks;
|
|
74
|
+
|
|
75
|
+
/** Optional: services that can generate a .gitignore and a license text. */
|
|
76
|
+
templates?: {
|
|
77
|
+
gitignoreList(credentials: HostCredentials): Promise<HostTemplateOption[]>;
|
|
78
|
+
gitignore(credentials: HostCredentials, key: string): Promise<string>;
|
|
79
|
+
licenseList(credentials: HostCredentials): Promise<HostTemplateOption[]>;
|
|
80
|
+
license(credentials: HostCredentials, key: string, holder: { year: string; fullname: string }): Promise<string>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { normaliseBaseUrl, parseRemoteUrl, withoutUserInfo } from './urls';
|
|
3
|
+
|
|
4
|
+
describe('parseRemoteUrl', () => {
|
|
5
|
+
test('scp-style', () => {
|
|
6
|
+
expect(parseRemoteUrl('git@github.com:acme/web.git')).toEqual({ host: 'github.com', path: 'acme/web' });
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test('https with credentials and a trailing slash', () => {
|
|
10
|
+
expect(parseRemoteUrl('https://user@GitLab.com/group/sub/project.git/')).toEqual({ host: 'gitlab.com', path: 'group/sub/project' });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('ssh:// with a port keeps only the hostname', () => {
|
|
14
|
+
expect(parseRemoteUrl('ssh://git@git.example.com:2222/acme/web.git')).toEqual({ host: 'git.example.com', path: 'acme/web' });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('a local path has no host', () => {
|
|
18
|
+
expect(parseRemoteUrl('/srv/repos/web.git')).toBeNull();
|
|
19
|
+
expect(parseRemoteUrl('file:///srv/repos/web.git')).toBeNull();
|
|
20
|
+
expect(parseRemoteUrl('')).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('normaliseBaseUrl', () => {
|
|
25
|
+
test('adds a scheme and drops trailing slashes and API suffixes', () => {
|
|
26
|
+
expect(normaliseBaseUrl('git.example.com/')).toBe('https://git.example.com');
|
|
27
|
+
expect(normaliseBaseUrl('https://ghe.example.com/api/v3')).toBe('https://ghe.example.com');
|
|
28
|
+
expect(normaliseBaseUrl('https://gitlab.example.com/api/v4/')).toBe('https://gitlab.example.com');
|
|
29
|
+
expect(normaliseBaseUrl('http://localhost:3000/gitea')).toBe('http://localhost:3000/gitea');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('empty stays empty — it means the cloud host', () => {
|
|
33
|
+
expect(normaliseBaseUrl(' ')).toBe('');
|
|
34
|
+
expect(normaliseBaseUrl(undefined)).toBe('');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('withoutUserInfo', () => {
|
|
39
|
+
test('a clone link never carries a username into .git/config', () => {
|
|
40
|
+
expect(withoutUserInfo('https://octocat@bitbucket.org/acme/web.git')).toBe('https://bitbucket.org/acme/web.git');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote URLs and server roots.
|
|
3
|
+
*
|
|
4
|
+
* Every adapter answers "is this remote mine, and which repository is it" the
|
|
5
|
+
* same way: compare the remote's hostname with the account's, then read the
|
|
6
|
+
* path. Kept in one place so `git@host:owner/repo.git`, `ssh://git@host:22/…`
|
|
7
|
+
* and `https://user@host/…` are parsed identically by all four services.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Host and path of a git remote URL, or null for a local path. */
|
|
11
|
+
export function parseRemoteUrl(url: string): { host: string; path: string } | null {
|
|
12
|
+
const trimmed = (url ?? '').trim();
|
|
13
|
+
if (!trimmed) return null;
|
|
14
|
+
|
|
15
|
+
// scp-like: [user@]host:path — not a URL, the part after the colon is a path.
|
|
16
|
+
const scp = /^(?:[^@/]+@)?([^/:]+):(?!\/\/)(.+)$/.exec(trimmed);
|
|
17
|
+
if (scp) return { host: scp[1]!.toLowerCase(), path: cleanPath(scp[2]!) };
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const parsed = new URL(trimmed);
|
|
21
|
+
if (parsed.protocol === 'file:' || !parsed.hostname) return null;
|
|
22
|
+
return { host: parsed.hostname.toLowerCase(), path: cleanPath(decodeURIComponent(parsed.pathname)) };
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function cleanPath(path: string): string {
|
|
29
|
+
return path.replace(/^\/+/, '').replace(/\/+$/, '').replace(/\.git$/, '');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A server root as the user typed it, normalised: scheme added when missing,
|
|
34
|
+
* trailing slashes and any API suffix removed. Empty in, empty out.
|
|
35
|
+
*/
|
|
36
|
+
export function normaliseBaseUrl(raw: string | undefined | null): string {
|
|
37
|
+
let value = (raw ?? '').trim();
|
|
38
|
+
if (!value) return '';
|
|
39
|
+
if (!/^https?:\/\//i.test(value)) value = `https://${value}`;
|
|
40
|
+
value = value.replace(/\/+$/, '');
|
|
41
|
+
value = value.replace(/\/(api\/v3|api\/v4|api\/v1)$/i, '');
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Hostname of a server root, lowercased. */
|
|
46
|
+
export function hostOfBase(base: string): string {
|
|
47
|
+
try {
|
|
48
|
+
return new URL(base).hostname.toLowerCase();
|
|
49
|
+
} catch {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Fill `{name}` placeholders. Values are URL-encoded except where a path is expected. */
|
|
55
|
+
export function fillTemplate(template: string, values: Record<string, string>): string {
|
|
56
|
+
return template.replace(/\{(\w+)\}/g, (_, key: string) => values[key] ?? `{${key}}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Strip any `user[:password]@` from an https clone URL — a token must never end up in `.git/config`. */
|
|
60
|
+
export function withoutUserInfo(url: string): string {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = new URL(url);
|
|
63
|
+
parsed.username = '';
|
|
64
|
+
parsed.password = '';
|
|
65
|
+
return parsed.toString();
|
|
66
|
+
} catch {
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
}
|