diff --git a/CHANGELOG.md b/CHANGELOG.md index c57a088c3..6a1b46fdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Added an optional `webUrl` field to the GitLab connection config, used to build links to repositories in the GitLab web UI when the API host differs from the browsable host. [#1457](https://github.com/sourcebot-dev/sourcebot/pull/1457) + ### Fixed - Prevented focus rings in workspace connector dialogs from being clipped. [#1457](https://github.com/sourcebot-dev/sourcebot/pull/1457) diff --git a/docs/snippets/schemas/v3/connection.schema.mdx b/docs/snippets/schemas/v3/connection.schema.mdx index 4671abf74..2d4607b9d 100644 --- a/docs/snippets/schemas/v3/connection.schema.mdx +++ b/docs/snippets/schemas/v3/connection.schema.mdx @@ -272,6 +272,15 @@ ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false, diff --git a/docs/snippets/schemas/v3/gitlab.schema.mdx b/docs/snippets/schemas/v3/gitlab.schema.mdx index f911c68a7..017e5fc5e 100644 --- a/docs/snippets/schemas/v3/gitlab.schema.mdx +++ b/docs/snippets/schemas/v3/gitlab.schema.mdx @@ -51,6 +51,15 @@ ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false, diff --git a/docs/snippets/schemas/v3/index.schema.mdx b/docs/snippets/schemas/v3/index.schema.mdx index 864359251..172d04988 100644 --- a/docs/snippets/schemas/v3/index.schema.mdx +++ b/docs/snippets/schemas/v3/index.schema.mdx @@ -763,6 +763,15 @@ ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false, diff --git a/packages/backend/src/repoCompileUtils.ts b/packages/backend/src/repoCompileUtils.ts index 04632a796..6888f2510 100644 --- a/packages/backend/src/repoCompileUtils.ts +++ b/packages/backend/src/repoCompileUtils.ts @@ -167,12 +167,13 @@ export const compileGitlabConfig = async ( const warnings = gitlabReposResult.warnings; const hostUrl = (config.url ?? 'https://gitlab.com').replace(/\/+$/, ''); + const webUrl = (config.webUrl ?? hostUrl).replace(/\/+$/, ''); const repoNameRoot = new URL(hostUrl) .toString() .replace(/^https?:\/\//, ''); const repos = gitlabRepos.map((project) => { - const projectUrl = `${hostUrl}/${project.path_with_namespace}`; + const projectUrl = `${webUrl}/${project.path_with_namespace}`; const cloneUrl = new URL(project.http_url_to_repo); cloneUrl.protocol = new URL(hostUrl).protocol; const isFork = project.forked_from_project !== undefined; diff --git a/packages/schemas/src/v3/connection.schema.ts b/packages/schemas/src/v3/connection.schema.ts index c539e918d..15d80600d 100644 --- a/packages/schemas/src/v3/connection.schema.ts +++ b/packages/schemas/src/v3/connection.schema.ts @@ -271,6 +271,15 @@ const schema = { ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false, diff --git a/packages/schemas/src/v3/connection.type.ts b/packages/schemas/src/v3/connection.type.ts index fbfb16570..7d85e86e7 100644 --- a/packages/schemas/src/v3/connection.type.ts +++ b/packages/schemas/src/v3/connection.type.ts @@ -131,6 +131,10 @@ export interface GitlabConnectionConfig { * The URL of the GitLab host. Defaults to https://gitlab.com */ url?: string; + /** + * The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`. + */ + webUrl?: string; /** * Sync all projects visible to the provided `token` (if any) in the GitLab instance. This option is ignored if `url` is either unset or set to https://gitlab.com . */ diff --git a/packages/schemas/src/v3/gitlab.schema.ts b/packages/schemas/src/v3/gitlab.schema.ts index 78412a054..1c5819c90 100644 --- a/packages/schemas/src/v3/gitlab.schema.ts +++ b/packages/schemas/src/v3/gitlab.schema.ts @@ -50,6 +50,15 @@ const schema = { ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false, diff --git a/packages/schemas/src/v3/gitlab.type.ts b/packages/schemas/src/v3/gitlab.type.ts index b73372105..63eea72b5 100644 --- a/packages/schemas/src/v3/gitlab.type.ts +++ b/packages/schemas/src/v3/gitlab.type.ts @@ -25,6 +25,10 @@ export interface GitlabConnectionConfig { * The URL of the GitLab host. Defaults to https://gitlab.com */ url?: string; + /** + * The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`. + */ + webUrl?: string; /** * Sync all projects visible to the provided `token` (if any) in the GitLab instance. This option is ignored if `url` is either unset or set to https://gitlab.com . */ diff --git a/packages/schemas/src/v3/index.schema.ts b/packages/schemas/src/v3/index.schema.ts index 8c1d64b52..2112b3d5b 100644 --- a/packages/schemas/src/v3/index.schema.ts +++ b/packages/schemas/src/v3/index.schema.ts @@ -762,6 +762,15 @@ const schema = { ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false, diff --git a/packages/schemas/src/v3/index.type.ts b/packages/schemas/src/v3/index.type.ts index 7fa7f5a17..088b6829f 100644 --- a/packages/schemas/src/v3/index.type.ts +++ b/packages/schemas/src/v3/index.type.ts @@ -358,6 +358,10 @@ export interface GitlabConnectionConfig { * The URL of the GitLab host. Defaults to https://gitlab.com */ url?: string; + /** + * The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`. + */ + webUrl?: string; /** * Sync all projects visible to the provided `token` (if any) in the GitLab instance. This option is ignored if `url` is either unset or set to https://gitlab.com . */ diff --git a/schemas/v3/gitlab.json b/schemas/v3/gitlab.json index c76a545ea..080f42cd3 100644 --- a/schemas/v3/gitlab.json +++ b/schemas/v3/gitlab.json @@ -22,6 +22,15 @@ ], "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" }, + "webUrl": { + "type": "string", + "format": "url", + "description": "The base URL used to construct links to repositories in the GitLab web UI. Useful when the API is served from a different host than the one users browse (e.g. `https://api.gitlab.example.com` for `url` and `https://gitlab.example.com` for `webUrl`). Defaults to the value of `url`.", + "examples": [ + "https://gitlab.example.com" + ], + "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$" + }, "all": { "type": "boolean", "default": false,