Skip to content

GitLab merge requests behind the forge descriptor (forge: "gitlab" config) - #1

Merged
solalbaudoincs merged 2 commits into
forge-agnosticfrom
gitlab-source
Oct 30, 2026
Merged

solalbaudoincs merged 2 commits into
forge-agnosticfrom
gitlab-source

Conversation

@solalbaudoincs

@solalbaudoincs solalbaudoincs commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Builds on mrolafsson#5 (stacked — base is forge-agnostic, retarget to main once mrolafsson#5 lands). Implements mrolafsson#6.

Summary

A GitLab mode behind the seams mrolafsson#5 created: a gitlabForge descriptor and a gitlabSource implementing source over GitLab REST v4, stdlib only. GitHub stays the default and its behavior is unchanged. 179/179 tests pass (165 baseline + 14 new against a fake GitLab server).

Switch

Runtime, from config: "forge": "gitlab" in config.json (default github; unknown value = config error). The descriptor gains what the TUI and label hooks need per forge: newSource, prsForBranches, prsByNumber, viewer, startPrompt, nestedPaths (GitLab namespaces nest: group/sub/project). Call sites that hard-coded GitHub (tui.go, repopicker.go, labels.go, agents.go, status) now go through the descriptor — same text when GitHub is active. The demo stays on the GitHub forge.

GitLab client (gitlab.go, new)

  • Auth: glab auth token does not exist (gitlab-org/cli#8231, declined), so: GITLAB_TOKEN / GITLAB_ACCESS_TOKEN / OAUTH_TOKEN env, else glab config get token --host <host>. Header Authorization: Bearer <token> (accepted for PATs and OAuth tokens alike).
  • Tabs: Mine = GET /merge_requests?scope=created_by_me&state=opened; repo = GET /projects/:id/merge_requests. Pagination page/per_page via X-Next-Page. No review-requested tab — caps.reviewRequested=false, the TUI hides it (and a remembered last-tab falls back to the first tab).
  • Draft: GitLab's Draft:/WIP:/[Draft] title prefixes, rewritten via PUT on the MR title.
  • Merge: PUT …/merge with sha (pinned head — same "changed since load" protection as GitHub), squash per the project's squash_option; auto-merge sends auto_merge + merge_when_pipeline_succeeds (covers older GitLab), off via cancel_auto_merge with fallback to the pre-19.5 endpoint.
  • Checks: head_pipeline jobs; allow_failure jobs are not required checks. Review decisions from approvals + /reviewers.
  • Every string from the API goes through the existing sanitize machinery, like the GitHub client.

Also in the diff

  • fanOut / pageHosts: the multi-host paging pulled out of githubSource unchanged so both forges share it.
  • pr.repo() cuts at the last / (identical for owner/name); remote/repo-key parsing accepts nested owners when the forge allows it.
  • README gains a short GitLab section.

Tests

14 new tests in gitlab_test.go against a fake GitLab server (in the style of the fake GitHub): list paging, MR→shared-struct mapping (incl. locked state, nested groups), merge pinning + 409, draft prefix handling, auto-merge on/off fallbacks, URL parsing (/-/merge_requests/N), fork refs, capability gating, repos picker, signed-out handling. Full suite 179/179; gofmt/vet clean.

The commits: 0aa1273 the feature, f17501c comments/wording.

Known limitations (documented on purpose, follow-up candidates)

  • Diff line counting: GitLab's diff field has no ---/+++ headers, so the current skip drops a real deleted -- comment / added ++x line; only @@ needs skipping.
  • Self-managed GitLab under a sub-path (https://host/gitlab/...): the project path is derived from web_url, so it comes out wrong and per-MR calls 404. Plain self-managed instances at the host root work.
  • Only the first page of discussions is read; notes on deleted lines show as line 0; child/bridge pipeline jobs are not shown.

None of these regress anything — GitHub is untouched, and the GitHub-only paths are unchanged.

Solal Baudoin added 2 commits October 30, 2026 16:39
A gitlabSource over GitLab's REST API (v4) maps merge requests onto the
plugin's pull requests, and gitlabForge spells GitLab's URLs, fork refs,
merge methods and sign-in. "forge": "gitlab" in config.json switches
the plugin to it; GitHub stays the default, and the demo stays on GitHub.

The descriptor now also builds the picker's source and answers the label
hooks and status (newSource, api), so no call site names GitHub's client.
The multi-host cursor and repo paging are shared (fanOut, pageHosts), and
repo paths may nest (group/sub/project) when the forge says so.
The forge's comments still spoke of GitLab as a forge to come, and the
list-cap notice was built at start-up, before the config chose the
forge, so it said GitHub on GitLab.
@solalbaudoincs
solalbaudoincs marked this pull request as ready for review October 30, 2026 16:23
@solalbaudoincs
solalbaudoincs merged commit 2d0b8dd into forge-agnostic Oct 30, 2026
@solalbaudoincs
solalbaudoincs deleted the gitlab-source branch October 30, 2026 16:23
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.

1 participant