feat(gitprovider): GitLab merge request review support#513
Open
piekstra wants to merge 1 commit into
Open
Conversation
Adds a gitlab provider adapter over the GitLab REST v4 API and wires it through config, URL parsing, provider dispatch, posting semantics, and the git transport so cr review/respond/agents/me/config work against gitlab.com and self-managed GitLab with PAT auth. - config: git.provider discriminator (github default, gitlab), gitlab restricted to pat auth - prref: ParsePullURL recognizes GitHub pull URLs and GitLab merge request URLs (nested namespaces, legacy form), commands cross-check the URL provider family against the profile - gitlab adapter: discussions as inline threads, position-based diff notes with old/new line mapping, approvals API for approve/revoke, discussion resolution, raw_diffs with per-file reconstruction fallback, members API for review authority - caps: ReviewSummaryAsComment reconciles submit-review markers against notes; HeadRefNamespace fetches refs/merge-requests/N/head for fork MRs; workbench accepts nested namespaces in remote URLs - gitexec: provider-specific HTTPS basic auth username (oauth2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds GitLab merge request review support (#510):
cr review,cr respond,cr agents,cr me, andcr config resolve-profilenow work against gitlab.com and self-managed GitLab instances with PAT auth, alongside the existing GitHub support.Config.
git.provideris a new optional discriminator (github|gitlab). Empty means GitHub, so existing configs are untouched and never rewritten. GitLab profiles are restricted toauth_mode: patand reuse the existinggit_tokencredstore key —cr set-credentialworks unchanged.URL parsing.
prref.ParsePullURLrecognizes both GitHub/pull/NURLs and GitLab/-/merge_requests/NURLs (nested namespaces and the legacy form without/-/included), and every command cross-checks the URL's provider family against the resolved profile with a usage error on mismatch. Nested namespaces flow through as slashedPRRef.Owner; ledger keys already percent-encode segments so no key-format change was needed.GitLab adapter (
internal/gitprovider/gitlab, hand-rollednet/httpover REST v4, mirroring the github package's structure, error taxonomy, secret redaction, and pagination host-pinning):diff_refs, with old/new line counterparts computed from the per-file diff so comments on unchanged context lines post correctly, and rename-awareold_path/new_path. File-level positions are native (position_type: file).SubmitReviewmapsapproveto the approvals API (SHA-guarded; 409 → stale-SHA),request_changesrevokes any active self-approval, and posts the review summary as an MR note. The approval state change happens before the summary note so interrupted posts retry safely (the note carries the idempotency marker).ListReviewsmaps current approvals;ResolveThreadusesPUT .../discussions/:id?resolved=true;ReviewAuthorityuses the members API (Developer+ = eligible).GetDiffusesraw_diffs(GitLab ≥ 15.7) with a per-file reconstruction fallback for older instances; stale head SHAs are rejected before any write.Provider-neutral seams that had GitHub baked in:
ProviderCaps.ReviewSummaryAsComment— outbox reconciles submit-review markers against issue comments for hosts without first-class review objects.ProviderCaps.HeadRefNamespace— workbench fetches fork MR heads fromrefs/merge-requests/N/headinstead ofrefs/pull/N/head; workbench remote URLs accept nested namespaces.gitexecpairs the token with a provider-specific HTTPS basic-auth username (oauth2for GitLab,x-access-tokenunchanged for GitHub).internal/gitprovidersdispatch package is the single construction seam used byinternal/app,agentscmd, andmecmd.Deliberately out of scope (follow-ups):
cr initwizard support for GitLab (profiles are added viaconfig.yml, documented in the README), GitLab CI job-token / group-token auth modes, and benchmark suites against GitLab MRs.Note:
TestDryRunResumesPinnedReviewRunByPinnedSHAsandTestDryRunWithPinnedReviewSHAsUsesCompareDiffAndPinnedFileRefsfail locally on this machine onmaintoo —trustCurrentTempFixturespointsTMPDIRat a directory that is never created and this git build won't write temp files there. Unrelated to this change; happy to file separately.Type of Change
Checklist
make tidypassesmake lintpassesmake testpasses (two pre-existing environment-dependent pipeline test failures reproduce onmain, see note above)make buildpassesRelated Issues
Closes #510