Skip to content

Native GitLab Merge Request ref support#4851

Open
JDanRibeiro wants to merge 12 commits intoGitTools:mainfrom
JDanRibeiro:feature/gitlab-merge-request-support
Open

Native GitLab Merge Request ref support#4851
JDanRibeiro wants to merge 12 commits intoGitTools:mainfrom
JDanRibeiro:feature/gitlab-merge-request-support

Conversation

@JDanRibeiro
Copy link

@JDanRibeiro JDanRibeiro commented Mar 11, 2026

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>/head
  • refs/merge-requests/<iid>/merge

GitVersion now detects these refs and exposes the internal branch name as pull-requests/<iid>, so existing GitVersion.yml configuration works (e.g. pull-request.regex, pull-request.label).

Type of change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change
  • Refactor / cleanup (no functional change)
  • Performance improvement
  • Documentation only
  • Build / CI / tooling

Related Issue

Resolves #XYZ

Motivation and Context

GitVersion currently relies on pull request refs under refs/heads/* or provider-specific refs like refs/pull/*. In GitLab CI, Merge Requests use refs/merge-requests/<iid>/(head|merge), which are not under refs/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 standard pull-requests/<iid> naming.

Scope / Impact

  • Affected projects: GitVersion.Core, GitVersion.BuildAgents, GitVersion.LibGit2Sharp, docs
  • User-visible behavior: GitLab MR pipelines are recognised as pull-request branches; branch name becomes pull-requests/<iid>
  • Backward compatibility: No change for existing providers; existing pull-request config continues to work

How Has This Been Tested?

cd src
dotnet build GitVersion.App.Tests\GitVersion.App.Tests.csproj -f net8.0
dotnet test --project GitVersion.App.Tests\GitVersion.App.Tests.csproj -f net8.0 --filter "FullyQualifiedName~VerifyPullRequestInput"
  • VerifyPullRequestInput includes GitLab refs: refs/merge-requests/15/head and refs/merge-requests/15/mergeFriendly = pull-requests/15, IsPullRequest = true (6 tests passed).

Screenshots (if appropriate)

N/A

Public API / Compatibility notes

  • Public API changed: yes
  • Files updated: src/GitVersion.Core/PublicAPI.Unshipped.txt (added ReferenceName.TryParseGitLabMergeRequestRef)

Checklist

  • My code follows the code style of this project.
  • I have added/updated tests to cover my changes.
  • All new and existing tests passed locally.
  • I updated documentation (gitlab.md, docker.md).
  • I verified the change does not break other providers/agents (GitHub/Azure/Bitbucket/etc.).
  • I updated src/GitVersion.Core/PublicAPI.Unshipped.txtt for the new public API.

Copilot AI review requested due to automatic review settings March 11, 2026 03:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ReferenceName to recognize GitLab MR refs and expose them as pull-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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@arturcic arturcic self-requested a review March 12, 2026 06:38
@arturcic arturcic force-pushed the main branch 4 times, most recently from fae75da to 5cc0855 Compare March 13, 2026 00:07
@JDanRibeiro JDanRibeiro requested a review from Copilot March 13, 2026 03:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JDanRibeiro JDanRibeiro requested a review from Copilot March 13, 2026 05:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@arturcic arturcic force-pushed the main branch 5 times, most recently from ea01ec3 to 329d120 Compare March 16, 2026 19:10
Copy link
Member

@arturcic arturcic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gittools-bot
Copy link
Contributor

@JDanRibeiro please rebase only your changes onto main instead of merging main into your branch

@arturcic arturcic force-pushed the main branch 2 times, most recently from 860c000 to 143e2a8 Compare March 18, 2026 00:18
@JDanRibeiro JDanRibeiro force-pushed the feature/gitlab-merge-request-support branch from cab1a2e to fb48a1a Compare March 18, 2026 00:32
@JDanRibeiro JDanRibeiro requested a review from arturcic March 18, 2026 02:34
@JDanRibeiro JDanRibeiro force-pushed the feature/gitlab-merge-request-support branch from 74686e4 to 754c8c2 Compare March 20, 2026 00:37
@sonarqubecloud
Copy link

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.

6 participants