Skip to content

fix: support self-managed GitLab and scope GitLab API calls - #116

Open
katsenkatorz wants to merge 2 commits into
chmouel:mainfrom
katsenkatorz:fix/glab-host
Open

katsenkatorz wants to merge 2 commits into
chmouel:mainfrom
katsenkatorz:fix/glab-host

Conversation

@katsenkatorz

Copy link
Copy Markdown

Fixes #115.

Two GitLab fixes, one per commit:

  • Self-managed hosts. A remote whose hostname does not contain gitlab was classified as an unknown forge, so pressing p silently ended with no MR for every worktree. When the host is unknown, DetectHost now asks glab config get api_host --host <host> and treats the host as GitLab if glab has a configuration for it. The lookup is local, fast and cached by the existing sync.Once.
  • Project scoping. MR and issue lookups called the global /merge_requests and /issues endpoints, which return the user's items across every project. A branch name shared with another project resolved to the wrong MR, and merge_requests/<iid> returned 404. They now use projects/:id/..., which glab resolves to the current repository.

Testing

  • New unit tests for host detection (glab-configured host, unconfigured host, glab not called for github.com, hostname parsing). Existing stubs now assert the project-scoped paths.
  • Manual check on a self-managed instance: before, 0 MRs found; with only the first fix, MRs loaded but one branch matched an MR from another project; with both, the correct MR is shown.
  • make lint, make docs-check pass. On macOS, five herdr tests in internal/multiplexer and internal/app fail on main too (/var vs /private/var paths), unrelated to this change.

This contribution was authored by an AI agent (Claude Code, claude-opus-5-5) on behalf of the contributor.

Remotes on self-managed GitLab instances whose hostname did not contain
"gitlab" were classified as an unknown forge, so MR and CI data never
loaded. Hosts that glab has a configuration for are now treated as
GitLab, since glab is already required for every GitLab call.
The MR and issue lookups called the global /merge_requests and /issues
endpoints, which return the user's items across every project. A branch
name shared with another project could therefore resolve to the wrong
MR, and lookups by number returned 404. They now target the project of
the current repository.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

New Review Started

This review has been superseded by a new analysis

Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Detect self-managed GitLab hosts and scope MR and issue lookups

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Recognise self-managed GitLab remotes configured in glab, even when their hostnames omit “gitlab”.
• Scope MR and issue lookups to the current project to prevent cross-project matches and failed IID
 lookups.
• Add host-detection tests, assert scoped API paths, and document the host requirement.
Diagram

graph TD
  R["Origin remote"] --> D{"Known forge?"}
  D -- "GitLab" --> S["GitLab service"] --> M["Project MR API"]
  D -- "Unknown" --> G["glab host config"] -- "Unconfigured" --> U["Other or unknown"]
  S --> I["Project issue API"]
  G -- "Configured" --> S
  D -- "Other" --> U
Loading
High-Level Assessment

The approach fits the existing glab dependency: a local configuration check handles ambiguous hosts, while project-scoped endpoints let glab resolve the current repository. Explicit project-ID resolution would add work without a clear benefit here.

Files changed (8) +113 / -23

Bug fix (3) +34 / -12
service_gitlab.goScope GitLab MR and issue requests to the current project +5/-5

Scope GitLab MR and issue requests to the current project

• Changes list and IID lookups for merge requests and issues from global endpoints to projects/:id endpoints. This prevents results from other projects and makes IID lookups address the intended project.

internal/git/service_gitlab.go

service_host.goDetect glab-configured self-managed GitLab hosts +28/-6

Detect glab-configured self-managed GitLab hosts

• Extracts the hostname from the origin remote and checks local glab configuration when hostname-based forge detection is inconclusive. The existing sync.Once caches the resulting classification.

internal/git/service_host.go

service_pr.goScope worktree MR reference lookup to its project +1/-1

Scope worktree MR reference lookup to its project

• Uses the project-scoped MR IID endpoint when retrieving the head commit for a GitLab worktree created from an MR.

internal/git/service_pr.go

Tests (3) +76 / -10
service_gitlab_test.goAssert project-scoped GitLab API paths +8/-8

Assert project-scoped GitLab API paths

• Updates command stubs for MR and issue list and single-item tests to accept the new project-scoped paths.

internal/git/service_gitlab_test.go

service_host_test.goCover configured hosts and hostname extraction +66/-0

Cover configured hosts and hostname extraction

• Adds SSH and HTTPS self-managed host cases, an unconfigured-host case, and hostname parsing checks. Verifies that detecting a known GitHub host does not invoke glab.

internal/git/service_host_test.go

service_pr_test.goExpect scoped MR lookups in worktree tests +2/-2

Expect scoped MR lookups in worktree tests

• Updates both GitLab worktree-creation stubs to match the project-scoped MR reference request.

internal/git/service_pr_test.go

Documentation (2) +3 / -1
ci-and-pr-status.mdDocument self-managed GitLab host recognition +2/-0

Document self-managed GitLab host recognition

• Explains that hosts without “gitlab” in their name are recognised when configured in glab, and gives an authentication example.

docs/core/ci-and-pr-status.md

lazyworktree.1Clarify glab requirements in the manual +1/-1

Clarify glab requirements in the manual

• Notes that self-managed GitLab hosts are recognised when configured in glab.

lazyworktree.1

This branch has not been deployed

No deployments
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.

Support self-hosted GitLab instances whose hostname does not contain "gitlab"

1 participant