Skip to content

Commit

Permalink
fix(gitlab): release not created when release pr was squashed (#86)
Browse files Browse the repository at this point in the history
When the release pull request was squashed on GitLab, the release
creation fails with error

    Error: failed to create pending releases: pull request is missing the merge commit

This fixes the problem by checking both `MergeCommitSHA` and
`SquashCommitSHA` and using whichever is set.
  • Loading branch information
apricote authored Oct 17, 2024
1 parent 763018f commit 3caa736
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/forge/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ func (g *GitLab) prForCommit(ctx context.Context, commit git.Commit) (*git.PullR

var mergeRequest *gitlab.MergeRequest
for _, mr := range associatedMRs {
// We only look for the MR that has this commit set as the "merge commit" => The result of squashing this branch onto main
if mr.MergeCommitSHA == commit.Hash {
// 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 {
mergeRequest = mr
break
}
Expand Down Expand Up @@ -387,9 +387,12 @@ func gitlabMRToReleasePullRequest(pr *gitlab.MergeRequest) *releasepr.ReleasePul
}
}

// Commit SHA is saved in either [MergeCommitSHA] or [SquashCommitSHA] depending on which merge method was used.
var releaseCommit *git.Commit
if pr.MergeCommitSHA != "" {
releaseCommit = &git.Commit{Hash: pr.MergeCommitSHA}
} else if pr.SquashCommitSHA != "" {
releaseCommit = &git.Commit{Hash: pr.SquashCommitSHA}
}

return &releasepr.ReleasePullRequest{
Expand Down

0 comments on commit 3caa736

Please sign in to comment.