Native GitLab Merge Request ref support#4851
Native GitLab Merge Request ref support#4851JDanRibeiro wants to merge 12 commits intoGitTools:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds first-class support for GitLab Merge Request refs (refs/merge-requests/<iid>/(head|merge)) so GitVersion recognizes MR pipelines as pull-request branches and normalizes them to pull-request/<iid> across core logic, build-agent detection, and docs.
Changes:
- Extend
ReferenceNameto recognize GitLab MR refs and expose them aspull-request/<iid>(plus new public helper API). - Update repository normalization / branch resolution to map GitLab MR refs to local
refs/heads/pull-request/<iid>. - Adjust GitLab CI agent and docs to use
CI_MERGE_REQUEST_REF_PATH; add unit coverage for MR ref parsing.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/GitVersion.LibGit2Sharp/Git/GitRepository.mutating.cs | Creates a local refs/heads/pull-request/<iid> branch when the remote ref is a GitLab MR ref. |
| src/GitVersion.Core/PublicAPI.Shipped.txt | Ships the new ReferenceName.TryParseGitLabMergeRequestRef public API surface. |
| src/GitVersion.Core/Git/ReferenceName.cs | Detects GitLab MR refs and shortens them to the friendly pull-request/<iid> form. |
| src/GitVersion.Core/Core/RepositoryStore.cs | Resolves GitLab MR ref inputs to the corresponding local pull-request/<iid> branch when present. |
| src/GitVersion.Core/Core/GitPreparer.cs | Normalizes GitLab MR refs into a local refs/heads/pull-request/<iid> branch for consistent downstream behavior. |
| src/GitVersion.BuildAgents/Agents/GitLabCi.cs | Prefers CI_MERGE_REQUEST_REF_PATH over CI_COMMIT_REF_NAME to identify MR pipelines correctly. |
| src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs | Adds unit cases validating ReferenceName behavior for GitLab MR refs. |
| docs/input/docs/usage/docker.md | Documents required GitLab CI env vars (incl. MR ref path) when running GitVersion via Docker. |
| docs/input/docs/reference/build-servers/gitlab.md | Documents native GitLab Merge Request pipeline support and the pull-request/<iid> mapping. |
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
fae75da to
5cc0855
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
ea01ec3 to
329d120
Compare
arturcic
left a comment
There was a problem hiding this comment.
The Git primitives should not have knowledge of the build agent specifics, so please do not include anything GitLab specific logic in Core ot LibGit2Sharp.
|
@JDanRibeiro please rebase only your changes onto |
860c000 to
143e2a8
Compare
cab1a2e to
fb48a1a
Compare
…ing with project convention
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
74686e4 to
754c8c2
Compare
|



Description
This PR adds native GitLab Merge Request ref support so GitVersion can treat GitLab MR pipelines as pull request branches without CI workarounds (no need to create synthetic refs under
refs/heads/...).GitLab exposes merge requests as:
refs/merge-requests/<iid>/headrefs/merge-requests/<iid>/mergeGitVersion now detects these refs and exposes the internal branch name as
pull-requests/<iid>, so existingGitVersion.ymlconfiguration works (e.g.pull-request.regex,pull-request.label).Type of change
Related Issue
Resolves #XYZ
Motivation and Context
GitVersion currently relies on pull request refs under
refs/heads/*or provider-specific refs likerefs/pull/*. In GitLab CI, Merge Requests userefs/merge-requests/<iid>/(head|merge), which are not underrefs/heads/*, so GitVersion did not detect them unless CI created synthetic refs. This PR adds first-class detection for GitLab MR refs and maps them to the standardpull-requests/<iid>naming.Scope / Impact
pull-requests/<iid>How Has This Been Tested?
refs/merge-requests/15/headandrefs/merge-requests/15/merge→Friendly = pull-requests/15,IsPullRequest = true(6 tests passed).Screenshots (if appropriate)
N/A
Public API / Compatibility notes
src/GitVersion.Core/PublicAPI.Unshipped.txt(addedReferenceName.TryParseGitLabMergeRequestRef)Checklist
src/GitVersion.Core/PublicAPI.Unshipped.txttfor the new public API.