From d2827d429a89c6b7b8856fc89e3c3c3b0a58879b Mon Sep 17 00:00:00 2001 From: Tymofii Polekhin Date: Wed, 15 Mar 2023 16:07:10 +0100 Subject: [PATCH] fix: account for Require Linear History when selecting merge method --- server/events/vcs/github_client.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 7287913436..3257a4eb61 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -579,13 +579,21 @@ func (g *GithubClient) MergePull(pull models.PullRequest, pullOptions models.Pul if err != nil { return errors.Wrap(err, "fetching repo info") } + protection, resp, err := g.client.Repositories.GetBranchProtection(context.Background(), *repo.Owner.Name, *repo.Name, pull.BaseBranch) + if err != nil { + return errors.Wrap(err, "getting branch protection rules") + } + requireLinearHistory := false + if resp.Response.StatusCode == 200 { + requireLinearHistory = protection.GetRequireLinearHistory().Enabled + } const ( defaultMergeMethod = "merge" rebaseMergeMethod = "rebase" squashMergeMethod = "squash" ) method := defaultMergeMethod - if !repo.GetAllowMergeCommit() { + if !repo.GetAllowMergeCommit() || requireLinearHistory { if repo.GetAllowRebaseMerge() { method = rebaseMergeMethod } else if repo.GetAllowSquashMerge() {