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): Add backwards compatible mergability check #3277

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
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
29 changes: 22 additions & 7 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest

isPipelineSkipped := mr.HeadPipeline.Status == "skipped"
allowSkippedPipeline := project.AllowMergeOnSkippedPipeline && isPipelineSkipped
if (mr.DetailedMergeStatus == "mergeable" || mr.DetailedMergeStatus == "ci_still_running") &&

ok, err := g.SupportsDetailedMergeStatus()
if err != nil {
return false, err
}

if ((ok && (mr.DetailedMergeStatus == "mergeable" || mr.DetailedMergeStatus == "ci_still_running")) ||
(!ok && mr.MergeStatus == "can_be_merged")) &&
mr.ApprovalsBeforeMerge <= 0 &&
mr.BlockingDiscussionsResolved &&
!mr.WorkInProgress &&
Expand All @@ -249,6 +256,19 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest
return false, nil
}

func (g *GitlabClient) SupportsDetailedMergeStatus() (bool, error) {
v, err := g.GetVersion()
if err != nil {
return false, err
}

cons, err := version.NewConstraint(">= 15.6")
if err != nil {
return false, err
}
return cons.Check(v), nil
}

// UpdateStatus updates the build status of a commit.
func (g *GitlabClient) UpdateStatus(repo models.Repo, pull models.PullRequest, state models.CommitStatus, src string, description string, url string) error {
gitlabState := gitlab.Pending
Expand Down Expand Up @@ -352,12 +372,7 @@ func (g *GitlabClient) DiscardReviews(repo models.Repo, pull models.PullRequest)

// GetVersion returns the version of the Gitlab server this client is using.
func (g *GitlabClient) GetVersion() (*version.Version, error) {
req, err := g.Client.NewRequest("GET", "/version", nil, nil)
if err != nil {
return nil, err
}
versionResp := new(gitlab.Version)
_, err = g.Client.Do(req, versionResp)
nitrocode marked this conversation as resolved.
Show resolved Hide resolved
versionResp, _, err := g.Client.Version.GetVersion()
if err != nil {
return nil, err
}
Expand Down
Loading