Skip to content

Commit

Permalink
fix: account for Require Linear History when selecting merge method
Browse files Browse the repository at this point in the history
  • Loading branch information
tpolekhin committed Mar 15, 2023
1 parent 5a7f020 commit d2827d4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d2827d4

Please sign in to comment.