Skip to content

Conversation

@aslafy-z
Copy link
Contributor

@aslafy-z aslafy-z commented Dec 5, 2025

Currently, gitprovider.PullRequest.MergeCommitSHA is set only from glMR.MergeCommitSHA by the GitLab provider.

This works for merge strategies that create a merge commit, but it breaks for repositories configured to use fast-forward merges without a merge commit: in those cases, the commit information stays empty even though the merge request is successfully merged.

GitLab’s API exposes three relevant fields on merge requests:

  • merge_commit_sha: SHA of the merge commit (when one exists).
  • squash_commit_sha: SHA of the squash commit.
  • sha: SHA of the head commit in the source branch.

According to the documentation, a squashed merge is supposed to populate squash_commit_sha, and (depending on merge method) may or may not create a merge commit. However, there are known inconsistencies in GitLab’s current implementation:

  • Squash merges currently populate merge_commit_sha with the squashed commit and leave squash_commit_sha unset in the webhook payloads.
  • There is ongoing work to backfill and correctly populate squash_commit_sha and to fix related webhook behavior.

See:

To handle both the current behavior and the intended future behavior, this PR updates convertGitlabMR to compute an “effective merge commit SHA” only when the merge request is in the merged state, using the following precedence:

  1. glMR.MergeCommitSHA if it is set
    • Covers today’s GitLab behavior for classic merge commits, and for squash merges where GitLab currently puts the squash commit into merge_commit_sha.
  2. glMR.SquashCommitSHA if MergeCommitSHA is empty but SquashCommitSHA is set
    • Covers the future / intended behavior and fast-forward-with-squash cases where there is no merge commit but a squash commit exists.
  3. glMR.SHA if both MergeCommitSHA and SquashCommitSHA are empty
    • Covers fast-forward-without-squash, where no merge or squash commit is created and the target branch is advanced to the source tip.

For unmerged merge requests, MergeCommitSHA remains empty.

This makes the GitLab provider resilient to both current and future GitLab implementations while ensuring MergeCommitSHA accurately reflects the commit that actually landed on the target branch for merged requests.

@aslafy-z aslafy-z requested a review from a team as a code owner December 5, 2025 16:18
@netlify
Copy link

netlify bot commented Dec 5, 2025

Deploy Preview for docs-kargo-io ready!

Name Link
🔨 Latest commit e49223d
🔍 Latest deploy log https://app.netlify.com/projects/docs-kargo-io/deploys/69359c551e0dfe0008cbfdd2
😎 Deploy Preview https://deploy-preview-5454.docs.kargo.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@aslafy-z aslafy-z changed the title feat(gitprovider/gitlab): Support for squash merge and fast forward feat(gitprovider/gitlab): Wait - Support for squash merge and fast forward Dec 5, 2025
@hiddeco hiddeco added this to the v1.9.0 milestone Dec 6, 2025
@krancour
Copy link
Member

krancour commented Dec 6, 2025

@fuskovic because of your familiarity with all the webhook receivers, I'd like you to look at this PR as well, please. Please consult the GitLab docs and/or experiment a bit with their API to verify this is indeed how things work on their end.

@aslafy-z aslafy-z changed the title feat(gitprovider/gitlab): Wait - Support for squash merge and fast forward feat(gitprovider/gitlab): Support for squash merge and fast forward Dec 7, 2025
@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.12%. Comparing base (901c8b1) to head (e49223d).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5454      +/-   ##
==========================================
+ Coverage   55.07%   55.12%   +0.05%     
==========================================
  Files         426      426              
  Lines       31528    31566      +38     
==========================================
+ Hits        17363    17401      +38     
  Misses      13161    13161              
  Partials     1004     1004              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aslafy-z aslafy-z requested a review from hiddeco December 7, 2025 15:37
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.

4 participants