From bcca36e8568de1f8ecb58ddaea18e61b058b352f Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Fri, 11 Jul 2025 11:23:21 +0200 Subject: [PATCH] fix(gitlab): support fast-forward merges (#210) This change allows detecting that the releaser-pleaser PR is well merged. As of today, it fails with "ERR failed to create pending releases: pull request is missing the merge commit". --- internal/forge/gitlab/gitlab.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/forge/gitlab/gitlab.go b/internal/forge/gitlab/gitlab.go index 06de7fd..d710f41 100644 --- a/internal/forge/gitlab/gitlab.go +++ b/internal/forge/gitlab/gitlab.go @@ -193,7 +193,7 @@ func (g *GitLab) prForCommit(ctx context.Context, commit git.Commit) (*git.PullR var mergeRequest *gitlab.BasicMergeRequest for _, mr := range associatedMRs { // We only look for the MR that has this commit set as the "merge/squash commit" => The result of squashing this branch onto main - if mr.MergeCommitSHA == commit.Hash || mr.SquashCommitSHA == commit.Hash { + if mr.MergeCommitSHA == commit.Hash || mr.SquashCommitSHA == commit.Hash || mr.SHA == commit.Hash { mergeRequest = mr break } @@ -403,12 +403,15 @@ func gitlabMRToReleasePullRequest(pr *gitlab.BasicMergeRequest) *releasepr.Relea } } - // Commit SHA is saved in either [MergeCommitSHA] or [SquashCommitSHA] depending on which merge method was used. + // Commit SHA is saved in either [MergeCommitSHA], [SquashCommitSHA] or [SHA] depending on which merge method was used. var releaseCommit *git.Commit - if pr.MergeCommitSHA != "" { + switch { + case pr.MergeCommitSHA != "": releaseCommit = &git.Commit{Hash: pr.MergeCommitSHA} - } else if pr.SquashCommitSHA != "" { + case pr.SquashCommitSHA != "": releaseCommit = &git.Commit{Hash: pr.SquashCommitSHA} + case pr.MergedAt != nil && pr.SHA != "": + releaseCommit = &git.Commit{Hash: pr.SHA} } return &releasepr.ReleasePullRequest{