Configure a default API base URL per git provider (github/gitlab/gitea) in settings.json gitProviders, with GitHub Enterprise support (Octokit baseUrl + device-flow web origin derived from the API base), and replace the client-side custom-domains list with server-persisted detection URL chips (SSH/HTTPS forms normalized to hosts). The configured API base host auto-counts as a detection host. Settings round-trip through the existing /api/config/settings sanitizer; the UI store hydrates from server settings with a one-time localStorage migration.
3.5 KiB
3.5 KiB
Git Providers Configuration Module
Purpose
- This module owns the per-provider git hosting configuration (
gitProvidersin the user settings file): API base URLs and provider-detection hostnames for GitHub, GitLab, and Gitea. - It is the single source of truth for the effective provider defaults consumed by
packages/web/server/lib/{github,gitlab,gitea}and is validated end-to-end through the settings GET/PUT routes (thegitProviderskey round-trips viasanitizeSettingsUpdateinpackages/web/server/lib/opencode/settings-helpers.js).
Entrypoints
packages/web/server/lib/git-providers/config.js: the single module file, exporting the helpers directly.
Public exports
GIT_PROVIDER_DEFAULTS:{ github: 'https://api.github.com', gitlab: 'https://gitlab.com', gitea: null }. Built-in defaults are not persisted; they are applied at read time by getters.normalizeBaseUrl(raw): normalize an API base URL (addhttps://when the scheme is missing, strip trailing slashes, preserve subpaths like/gitlab),nullfor empty/unparseable input.normalizeDetectionHost(raw): extract the bare lowercase hostname from any git remote/URL form (https://,ssh://, scp-likegit@host:path, IPv6); mirrorspackages/ui/src/lib/gitHost.tsparseGitHost.sanitizeGitProviders(payload): validate/normalize thegitProvidersshape — onlygithub|gitlab|giteakeys survive;apiBaseUrlvianormalizeBaseUrl,detectUrlsdeduped bare hostnames; empty/absent values dropped; returnsundefinedwhen nothing valid remains.readGitProvidersConfig(): read thegitProviderssection fromsettings.json(OPENCHAMBER_DATA_DIRenv override, else~/.config/openchamber); never throws, returns{}on missing/invalid data.getProviderApiBaseUrl(provider): configured value ->GIT_PROVIDER_DEFAULTS[provider]->null(gitea).githubWebOriginFromApiBase(apiBase): GitHub web origin from an API base —https://api.github.com->https://github.com; Enterprisehttps://host/api[/v3]->https://host(trailing/api//api/v3stripped, subpath prefixes kept); otherwise the URL origin; never throws, falls back tohttps://github.com.
Settings shape
~/.config/openchamber/settings.json:
"gitProviders": {
"github": { "apiBaseUrl": "https://github.example.com/api/v3", "detectUrls": ["github.example.com"] },
"gitlab": { "apiBaseUrl": "https://gitlab.example.com", "detectUrls": [] },
"gitea": { "apiBaseUrl": "", "detectUrls": ["gitea.example.com"] }
}
apiBaseUrl: API base URL; the per-account baseUrl (gitlab/gitea accounts) still wins when set; this is the default/fallback plus connect-form prefill.detectUrls: SSH/HTTPS URLs normalized to bare hostnames for provider autodetection (client-side; the server only persists/validates them).- The whole
gitProviderskey is omitted when empty.
Consumers
packages/web/server/lib/github/octokit.js,device-flow.js,routes.js,repo/index.js,pr-status.js,repo/fork-detection.js: GitHub Enterprise support (OctokitbaseUrl, device-flow web origin, remote parsing, fallback URLs).packages/web/server/lib/gitlab/auth.js,client.js,routes.js: effective default base URL.packages/web/server/lib/gitea/auth.js,routes.js: connect-form default / statusdefaultBaseUrl.packages/web/server/lib/opencode/settings-helpers.js:gitProviderspersistence whitelist.
Notes for contributors
- Readers must never throw:
readGitProvidersConfigandgithubWebOriginFromApiBasefail closed. - No new dependencies.