Skip to content

Commit

Permalink
fix: replace "approvals_before_merge" with "approvals_left" when chec…
Browse files Browse the repository at this point in the history
…king if pull is mergeable
  • Loading branch information
CaioAugustoo committed Dec 7, 2024
1 parent e8c3690 commit ff08435
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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 ApprovalsLeft
// 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,19 @@ 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, _, err := g.Client.MergeRequestApprovals.GetConfiguration(repo.FullName, pull.Num)
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

0 comments on commit ff08435

Please sign in to comment.