Skip to content

Comments

fix: remove trailing slashes from host url to fix links to code host platforms#915

Merged
msukkari merged 6 commits intomainfrom
cursor/SOU-533-gitlab-link-double-slash-e95d
Feb 21, 2026
Merged

fix: remove trailing slashes from host url to fix links to code host platforms#915
msukkari merged 6 commits intomainfrom
cursor/SOU-533-gitlab-link-double-slash-e95d

Conversation

@msukkari
Copy link
Contributor

@msukkari msukkari commented Feb 21, 2026

Stripped trailing slashes from hostUrl for GitLab and Azure DevOps to fix invalid "Open in GitLab" links.

The issue occurred when hostUrl was configured with a trailing slash, leading to a double slash in the generated URL and subsequent 404 errors. This change ensures URLs are correctly formed.


Linear Issue: SOU-533

Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes
    • Fixed malformed "Open in GitLab" links that could include double slashes when a configured GitLab host URL ended with a trailing slash.
    • Normalized trailing slashes for host URLs across integrations (GitHub, GitLab, Gitea, Gerrit, Bitbucket, Azure DevOps, generic hosts) to ensure consistent, correct link formation.

When users configure a GitLab or Azure DevOps connection with a trailing
slash in the URL (e.g., https://gitlab.example.com/), the constructed
project URLs would have a double slash (https://gitlab.example.com//path)
causing 404 errors when opening links.

This fix strips trailing slashes from the hostUrl before constructing URLs.

Fixes SOU-533

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
@cursor
Copy link

cursor bot commented Feb 21, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

Walkthrough

Normalize configured Git host base URLs by stripping trailing slash(es) during resolution across multiple backends (GitLab, GitHub, Gitea, Gerrit, Bitbucket, Azure DevOps, Generic Git Host); add changelog entry documenting the fix for Open in GitLab link double-slash handling.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Add Unreleased fixed item documenting removal of double slash in "Open in GitLab" links when host URL ends with a trailing slash.
Host URL normalization
packages/backend/src/repoCompileUtils.ts
Apply .replace(/\/+$/, '') to resolved host URLs when deriving hostUrl for multiple compile*Config functions (GitHub, GitLab, Gitea, Gerrit, Bitbucket, Azure DevOps, Generic Git Host), affecting downstream URL construction and repoNameRoot calculations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing trailing slashes from host URLs to fix broken links to code host platforms.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/SOU-533-gitlab-link-double-slash-e95d

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@msukkari msukkari marked this pull request as ready for review February 21, 2026 00:53
@github-actions

This comment has been minimized.

@msukkari
Copy link
Contributor Author

@cursor add changelog

@cursor
Copy link

cursor bot commented Feb 21, 2026

Added the changelog entry under [Unreleased] > ### Fixed:

- Fixed "Open in GitLab" links having a double slash when the GitLab host URL is configured with a trailing slash. [#915](https://github.com/sourcebot-dev/sourcebot/pull/915)

The commit has been pushed to the branch.

Open in Web Open in Cursor 

cursoragent and others added 2 commits February 21, 2026 00:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/backend/src/repoCompileUtils.ts (1)

64-64: Consider applying trailing-slash normalization consistently to all providers.

GitHub (line 64), Gitea (line 245), Gerrit (line 312), and Bitbucket (line 399) lack the same normalization. For those providers, trailing slashes in hostUrl don't currently produce double-slash URLs (webUrls come from API responses, not string concatenation), but the stored external_codeHostUrl would be inconsistently formatted across providers. Normalizing all providers defensively prevents the same class of bug if URL construction patterns change.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/backend/src/repoCompileUtils.ts` at line 64, The hostUrl for GitHub
(const hostUrl = config.url ?? 'https://github.com'), Gitea, Gerrit, and
Bitbucket blocks should be normalized the same way as other providers to avoid
inconsistent trailing slashes; add or reuse a small helper (e.g.,
normalizeHostUrl or stripTrailingSlash) and apply it to the hostUrl value in
each provider before storing external_codeHostUrl and any URL construction,
ensuring the stored external_codeHostUrl has a consistent format across
providers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 12: Update the changelog entry that currently references only GitLab (the
line mentioning "Fixed 'Open in GitLab' links... [`#915`]") to also mention Azure
DevOps: state that trailing slashes are stripped from hostUrl for both GitLab
and Azure DevOps (or word it as "Open in GitLab and Azure DevOps links no longer
break when the host URL has a trailing slash"), and keep the PR reference `#915`;
this ensures ADO users can find the fix.

In `@packages/backend/src/repoCompileUtils.ts`:
- Line 163: hostUrl normalization only strips a single trailing slash, so values
like config.url = "https://gitlab.example.com//" can leave a trailing slash and
cause double slashes later; update the hostUrl assignment (the const hostUrl
expression that uses config.url) to strip all trailing slashes by replacing the
current regex with one that matches one-or-more slashes (use /\/+$/) so
concatenation later (e.g., where hostUrl is used at line 169) won’t produce
double slashes.

---

Nitpick comments:
In `@packages/backend/src/repoCompileUtils.ts`:
- Line 64: The hostUrl for GitHub (const hostUrl = config.url ??
'https://github.com'), Gitea, Gerrit, and Bitbucket blocks should be normalized
the same way as other providers to avoid inconsistent trailing slashes; add or
reuse a small helper (e.g., normalizeHostUrl or stripTrailingSlash) and apply it
to the hostUrl value in each provider before storing external_codeHostUrl and
any URL construction, ensuring the stored external_codeHostUrl has a consistent
format across providers.

cursoragent and others added 2 commits February 21, 2026 01:03
Changed regex from /\\/$/ to /\\/+$/ to handle cases where
there might be multiple trailing slashes in the configured URL.

Co-authored-by: Michael Sukkarieh <msukkari@users.noreply.github.com>
@msukkari msukkari changed the title Gitlab link double slash fix: remove trailing slashes from host url to fix links to code host platforms Feb 21, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/backend/src/repoCompileUtils.ts (1)

90-103: Defensively normalize hostUrl inside createGitHubRepoRecord to prevent external callers from storing un-normalized host URLs.

The function is exported and accepts hostUrl as input. While compileGithubConfig normalizes the URL before calling (line 64), and the hardcoded call in api.ts uses a normalized URL, the exported function stores the raw hostUrl in external_codeHostUrl (line 117) without validation. An external caller could pass a trailing-slash URL that would be stored unchanged.

🛡️ Proposed defensive normalization
 export const createGitHubRepoRecord = ({
     repo,
     hostUrl,
     branches,
     tags,
     isAutoCleanupDisabled,
 }: {
     repo: OctokitRepository,
     hostUrl: string,
     ...
 }) => {
-    const repoNameRoot = new URL(hostUrl)
+    const normalizedHostUrl = hostUrl.replace(/\/+$/, '');
+    const repoNameRoot = new URL(normalizedHostUrl)
         .toString()
         .replace(/^https?:\/\//, '');

And replace all subsequent uses of hostUrl within the function body with normalizedHostUrl.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/backend/src/repoCompileUtils.ts` around lines 90 - 103,
createGitHubRepoRecord currently accepts hostUrl and stores it raw into
external_codeHostUrl; defensively normalize hostUrl at the start of
createGitHubRepoRecord (e.g., construct a URL object from hostUrl and derive a
normalized string like url.origin or strip trailing slash) and assign that to a
new normalizedHostUrl variable; then replace subsequent uses of hostUrl
(including where external_codeHostUrl is set and where repoNameRoot is created)
with normalizedHostUrl so callers cannot store an un-normalized URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/backend/src/repoCompileUtils.ts`:
- Line 64: The trailing-slash normalization for hostUrl is already corrected to
use .replace(/\/+$/, ''); no code changes required—just verify all occurrences
of the hostUrl assignment in repoCompileUtils.ts (the const hostUrl
declarations) consistently use .replace(/\/+$/, '') across the referenced spots
(lines noted in the review) and keep them unchanged.

---

Nitpick comments:
In `@packages/backend/src/repoCompileUtils.ts`:
- Around line 90-103: createGitHubRepoRecord currently accepts hostUrl and
stores it raw into external_codeHostUrl; defensively normalize hostUrl at the
start of createGitHubRepoRecord (e.g., construct a URL object from hostUrl and
derive a normalized string like url.origin or strip trailing slash) and assign
that to a new normalizedHostUrl variable; then replace subsequent uses of
hostUrl (including where external_codeHostUrl is set and where repoNameRoot is
created) with normalizedHostUrl so callers cannot store an un-normalized URL.

@msukkari msukkari merged commit fdae9e7 into main Feb 21, 2026
11 checks passed
@msukkari msukkari deleted the cursor/SOU-533-gitlab-link-double-slash-e95d branch February 21, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants