Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GitLab - use "approvals_left" instead of "approvals_before_merge" when checking if pull is mergeable #5049

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (g *GitlabClient) PullIsApproved(logger logging.SimpleLogging, repo models.

// PullIsMergeable returns true if the merge request can be merged.
// In GitLab, there isn't a single field that tells us if the pull request is
// mergeable so for now we check the merge_status and approvals_before_merge
// mergeable so for now we check the merge_status and approvals_left
// fields.
// In order to check if the repo required these, we'd need to make another API
// call to get the repo settings.
Expand Down Expand Up @@ -360,14 +360,22 @@ func (g *GitlabClient) PullIsMergeable(logger logging.SimpleLogging, repo models
logger.Debug("Merge status: '%s'", mr.MergeStatus) //nolint:staticcheck // Need to reference deprecated field for backwards compatibility
}

approval, resp, err := g.Client.MergeRequestApprovals.GetConfiguration(repo.FullName, pull.Num)
if resp != nil {
logger.Debug("GET /projects/%d/merge_requests/%d/approvals returned: %d", mr.ProjectID, mr.IID, resp.StatusCode)
}
if err != nil {
return false, err
}

if ((supportsDetailedMergeStatus &&
(mr.DetailedMergeStatus == "mergeable" ||
mr.DetailedMergeStatus == "ci_still_running" ||
mr.DetailedMergeStatus == "ci_must_pass" ||
mr.DetailedMergeStatus == "need_rebase")) ||
(!supportsDetailedMergeStatus &&
mr.MergeStatus == "can_be_merged")) && //nolint:staticcheck // Need to reference deprecated field for backwards compatibility
mr.ApprovalsBeforeMerge <= 0 &&
approval.ApprovalsLeft == 0 &&
mr.BlockingDiscussionsResolved &&
!mr.WorkInProgress &&
(allowSkippedPipeline || !isPipelineSkipped) {
Expand Down
Loading