Skip to content

feat(git): add support for GitLab merge requests#704

Merged
skevetter merged 6 commits into
mainfrom
fierce-pug
Jul 22, 2026
Merged

feat(git): add support for GitLab merge requests#704
skevetter merged 6 commits into
mainfrom
fierce-pug

Conversation

@skevetter

@skevetter skevetter commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Cloning a GitLab repository at a merge-request ref failed with fatal: couldn't find remote ref pull/N/head. The clone itself succeeded; the follow-up fetch failed because devsy hardcoded GitHub's pull/N/head refspec everywhere, while GitLab exposes merge requests at merge-requests/N/head.

This introduces a small git-host abstraction that owns each provider's convention in one place, replacing the scattered hardcoded assumptions.

Changes

  • pkg/git/host.go (new) — a Host registry (HostGitHub, HostGitLab) holding each provider's refspec prefix (pull vs merge-requests) and local-branch prefix (PR vs MR), with DetectHost(url) and prCandidates(url).
  • pkg/git/repo.goCheckoutPR now takes the repo URL, resolves the host, and falls back to the other convention when the detected refspec is missing. This makes self-hosted GitLab on custom domains work even though URL detection can't recognize them.
  • pkg/git/git.go — broadened the ref regex to accept both conventions; host-aware branch/ID naming.
  • Desktopworkspace-source.ts emits the correct refspec by host; the wizard is relabeled "Pull / Merge Request" instead of GitHub-only "Pull Request".

Notes

  • The stale WARN comment in git.go pointing at a deleted CreateWorkspaceInput.tsx was updated to reference the real file.
  • Go tests (host detection, GitLab refs, GitHub-style-ref-on-GitLab, fallback path) pass. New desktop vitest cases are written but unrun in this worktree (no node_modules).

Summary by CodeRabbit

  • New Features

    • Added checkout support for GitLab merge requests, including self-hosted GitLab repositories.
    • Automatically detects whether a PR/MR reference uses GitHub or GitLab conventions and applies the correct refspec, with fallback behavior when the first attempt fails.
    • Updated the Git advanced options and review step UI to use “Pull / Merge Request” terminology.
  • Bug Fixes

    • Corrected PR/MR ref formatting and normalization across supported Git hosting providers.
  • Tests

    • Expanded unit test coverage for host detection and PR/MR ref conversion for GitHub and GitLab.

Cloning a GitLab repo at a merge-request ref failed with
"couldn't find remote ref pull/N/head": devsy hardcoded GitHub's
pull/N/head refspec everywhere, but GitLab exposes merge requests at
merge-requests/N/head.

Introduce a git-host abstraction (pkg/git/host.go) owning each
provider's refspec and local-branch convention. CheckoutPR now resolves
the refspec from the repository URL's host and falls back to the other
known convention when the detected one has no such ref, so self-hosted
GitLab on custom domains still works. The desktop wizard is relabeled
"Pull / Merge Request" and emits the host-appropriate ref.
@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for devsydev canceled.

Name Link
🔨 Latest commit 95f5c7a
🔍 Latest deploy log https://app.netlify.com/projects/devsydev/deploys/6a5fed32917ca30008442d57

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c3ea773-d170-4185-b908-72ff68e150e7

📥 Commits

Reviewing files that changed from the base of the PR and between 89ef50d and 95f5c7a.

📒 Files selected for processing (7)
  • desktop/src/renderer/src/lib/utils/workspace-source.test.ts
  • desktop/src/renderer/src/lib/utils/workspace-source.ts
  • pkg/git/git.go
  • pkg/git/host.go
  • pkg/git/host_test.go
  • pkg/git/repo.go
  • pkg/git/repo_test.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • desktop/src/renderer/src/lib/utils/workspace-source.test.ts
  • pkg/git/repo.go
  • pkg/git/git.go
  • pkg/git/host_test.go
  • desktop/src/renderer/src/lib/utils/workspace-source.ts
  • pkg/git/host.go
  • pkg/git/repo_test.go

📝 Walkthrough

Walkthrough

Adds GitLab merge-request support across workspace source formatting and Go checkout, with host detection, provider-specific refs and branches, fallback fetching, normalization, and tests. Wizard labels now refer to pull/merge requests.

Changes

Provider-aware pull and merge request references

Layer / File(s) Summary
Host conventions and reference parsing
pkg/git/host.go, pkg/git/git.go, pkg/git/*_test.go
Defines GitHub and GitLab refspecs, branch names, host detection, request parsing, candidate ordering, and normalization coverage.
Provider-aware PR checkout
pkg/git/repo.go, pkg/git/repo_test.go
CheckoutPR uses the repository URL to try provider-specific fetch refspecs, switches after success, and falls back when a ref is unavailable.
Desktop request reference generation
desktop/src/renderer/src/lib/utils/*, desktop/src/renderer/src/lib/components/workspace/WorkspaceWizard.svelte
Workspace sources generate GitHub or GitLab request suffixes, while wizard labels use pull/merge request terminology.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CloneFromInfo
  participant Repo
  participant HostDetection
  participant GitRemote
  CloneFromInfo->>Repo: CheckoutPR(repoURL, prRef)
  Repo->>HostDetection: Resolve candidate providers
  HostDetection-->>Repo: Provider refspecs and branch names
  Repo->>GitRemote: Fetch candidate refspec
  GitRemote-->>Repo: Fetch success or missing ref
  Repo->>GitRemote: Switch to local request branch
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding GitLab merge request support to git-related checkout and ref handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for images-devsy-sh canceled.

Name Link
🔨 Latest commit 95f5c7a
🔍 Latest deploy log https://app.netlify.com/projects/images-devsy-sh/deploys/6a5fed33f3f68000087fa4ca

@skevetter
skevetter marked this pull request as ready for review July 21, 2026 21:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/git/host.go`:
- Around line 53-61: Update DetectHost in pkg/git/host.go to extract the
repository hostname from SSH and URL forms before matching knownHosts, so path
segments cannot influence provider detection. Apply the same hostname-only
detection in desktop/src/renderer/src/lib/utils/workspace-source.ts before
selecting the suffix. Add GitHub cases with “gitlab” in the owner or path to
pkg/git/host_test.go and
desktop/src/renderer/src/lib/utils/workspace-source.test.ts, asserting GitHub
detection and the `@pull/N/head` source suffix respectively.

In `@pkg/git/repo.go`:
- Around line 99-105: Update the fetch loop in the repository method containing
r.Fetch so alternate-provider fallback occurs only when the fetch error confirms
the requested remote ref is missing; return authentication, network,
cancellation, and other non-ref errors immediately without overwriting them.
Preserve the existing retry and Switch flow for missing refs, and add a
regression test covering a non-ref fetch failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b000405a-b157-454a-a1e0-79a5dc9c763a

📥 Commits

Reviewing files that changed from the base of the PR and between 1f33fb7 and 89ef50d.

📒 Files selected for processing (9)
  • desktop/src/renderer/src/lib/components/workspace/WorkspaceWizard.svelte
  • desktop/src/renderer/src/lib/utils/workspace-source.test.ts
  • desktop/src/renderer/src/lib/utils/workspace-source.ts
  • pkg/git/git.go
  • pkg/git/git_test.go
  • pkg/git/host.go
  • pkg/git/host_test.go
  • pkg/git/repo.go
  • pkg/git/repo_test.go

Comment thread pkg/git/host.go
Comment thread pkg/git/repo.go Outdated
…fs only

Address review: DetectHost matched the whole URL, so an owner/path
containing 'gitlab'/'github' could misdetect the provider — now matches
only the hostname. CheckoutPR's fallback fired on any fetch error,
masking auth/network failures behind a second lookup's error — now only
missing-ref errors trigger the alternate-provider retry.
@skevetter
skevetter marked this pull request as draft July 21, 2026 21:55
@skevetter skevetter changed the title fix(git): resolve GitLab merge requests, not just GitHub PRs feat(git): add support for GitLab merge requests Jul 21, 2026
@skevetter
skevetter marked this pull request as ready for review July 21, 2026 22:31
@skevetter
skevetter merged commit 4aaf030 into main Jul 22, 2026
66 checks passed
@skevetter
skevetter deleted the fierce-pug branch July 22, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant