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: edge-case in gitlab_client #2495

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest
}

// Get Commit Statuses
statuses, _, err := g.Client.Commits.GetCommitStatuses(mr.ProjectID, mr.HeadPipeline.SHA, nil)
statuses, _, err := g.Client.Commits.GetCommitStatuses(mr.ProjectID, mr.SHA, nil)
if err != nil {
return false, err
}
Expand All @@ -221,7 +221,23 @@ func (g *GitlabClient) PullIsMergeable(repo models.Repo, pull models.PullRequest
}
}

isPipelineSkipped := mr.HeadPipeline.Status == "skipped"
isPipelineSkipped := false
if mr.HeadPipeline != nil {
isPipelineSkipped = mr.HeadPipeline.Status == "skipped"
} else {
pipelines, _, err := g.Client.Pipelines.ListProjectPipelines(repo.FullName, &gitlab.ListProjectPipelinesOptions{
SHA: &mr.SHA,
})
if err != nil {
return false, err
}
for _, p := range pipelines {
if p.Status == "skipped" {
isPipelineSkipped = true
break
}
}
Comment on lines +234 to +239
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if there's a better way to navigate to a common HeadPipeline

}
allowSkippedPipeline := project.AllowMergeOnSkippedPipeline && isPipelineSkipped
if mr.MergeStatus == "can_be_merged" &&
mr.ApprovalsBeforeMerge <= 0 &&
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/gitlab_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ func TestGitlabClient_PullIsMergeable(t *testing.T) {
case "/api/v4/projects/4580910":
w.WriteHeader(http.StatusOK)
w.Write([]byte(projectSuccess)) // nolint: errcheck
case "/api/v4/projects/4580910/repository/commits/67cb91d3f6198189f433c045154a885784ba6977/statuses":
case "/api/v4/projects/4580910/repository/commits/cb86d70f464632bdfbe1bb9bc0f2f9d847a774a0/statuses":
w.WriteHeader(http.StatusOK)
response := fmt.Sprintf(`[{"id":133702594,"sha":"67cb91d3f6198189f433c045154a885784ba6977","ref":"patch-1","status":"%s","name":"%s","target_url":null,"description":"ApplySuccess","created_at":"2018-12-12T18:31:57.957Z","started_at":null,"finished_at":"2018-12-12T18:31:58.480Z","allow_failure":false,"coverage":null,"author":{"id":1755902,"username":"lkysow","name":"LukeKysow","state":"active","avatar_url":"https://secure.gravatar.com/avatar/25fd57e71590fe28736624ff24d41c5f?s=80&d=identicon","web_url":"https://gitlab.com/lkysow"}}]`, c.status, c.statusName)
response := fmt.Sprintf(`[{"id":133702594,"sha":"cb86d70f464632bdfbe1bb9bc0f2f9d847a774a0","ref":"patch-1","status":"%s","name":"%s","target_url":null,"description":"ApplySuccess","created_at":"2018-12-12T18:31:57.957Z","started_at":null,"finished_at":"2018-12-12T18:31:58.480Z","allow_failure":false,"coverage":null,"author":{"id":1755902,"username":"lkysow","name":"LukeKysow","state":"active","avatar_url":"https://secure.gravatar.com/avatar/25fd57e71590fe28736624ff24d41c5f?s=80&d=identicon","web_url":"https://gitlab.com/lkysow"}}]`, c.status, c.statusName)
w.Write([]byte(response)) // nolint: errcheck
default:
t.Errorf("got unexpected request at %q", r.RequestURI)
Expand Down