feat(git): add support for GitLab merge requests#704
Conversation
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.
✅ Deploy Preview for devsydev canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughAdds 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. ChangesProvider-aware pull and merge request references
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
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
✅ Deploy Preview for images-devsy-sh canceled.
|
There was a problem hiding this comment.
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
📒 Files selected for processing (9)
desktop/src/renderer/src/lib/components/workspace/WorkspaceWizard.sveltedesktop/src/renderer/src/lib/utils/workspace-source.test.tsdesktop/src/renderer/src/lib/utils/workspace-source.tspkg/git/git.gopkg/git/git_test.gopkg/git/host.gopkg/git/host_test.gopkg/git/repo.gopkg/git/repo_test.go
…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.
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'spull/N/headrefspec everywhere, while GitLab exposes merge requests atmerge-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) — aHostregistry (HostGitHub,HostGitLab) holding each provider's refspec prefix (pullvsmerge-requests) and local-branch prefix (PRvsMR), withDetectHost(url)andprCandidates(url).pkg/git/repo.go—CheckoutPRnow 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.workspace-source.tsemits the correct refspec by host; the wizard is relabeled "Pull / Merge Request" instead of GitHub-only "Pull Request".Notes
WARNcomment ingit.gopointing at a deletedCreateWorkspaceInput.tsxwas updated to reference the real file.node_modules).Summary by CodeRabbit
New Features
Bug Fixes
Tests