runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.52k stars 1.02k forks source link

Automerge support for "require linear history" #1176

Open llamahunter opened 3 years ago

llamahunter commented 3 years ago

When the automerge feature is enabled, but the target branch only supports linear history (i.e. not merge commits), atlantis fails to squash/merge the commit to the target branch after successful apply.

It looks like this issue was briefly raised in the original implementation of automerge, but seems to have gotten lost. https://github.com/runatlantis/atlantis/issues/186#issuecomment-446626233

Currently, we get this error on our repos:

Automerging failed:

merging pull request: PUT https://api.github.com/repos/tivocorp/inception-k8s-deployment-dev/pulls/78/merge: 405 This branch must not contain merge commits. []

Is this an oversight, or is this purposefully unsupported?

lkysow commented 3 years ago

Hmm, we have code to detect which merge method to use:

    const (
        defaultMergeMethod = "merge"
        rebaseMergeMethod  = "rebase"
        squashMergeMethod  = "squash"
    )
    method := defaultMergeMethod
    if !repo.GetAllowMergeCommit() {
        if repo.GetAllowRebaseMerge() {
            method = rebaseMergeMethod
        } else if repo.GetAllowSquashMerge() {
            method = squashMergeMethod
        }
    }

    // Now we're ready to make our API call to merge the pull request.
    options := &github.PullRequestOptions{
        MergeMethod: method,
    }
lkysow commented 3 years ago

Can you make the GET repository API call and see what the value of the:

    AllowRebaseMerge    *bool            `json:"allow_rebase_merge,omitempty"`
    AllowSquashMerge    *bool            `json:"allow_squash_merge,omitempty"`
    AllowMergeCommit    *bool            `json:"allow_merge_commit,omitempty"`

fields are?

llamahunter commented 3 years ago

Hmm... I think there might be some conflation between the global repo Options setting: image and the specific Branch Protection Rule: image

Just because the whole repo allows merge commits does not mean all branches do.

llamahunter commented 3 years ago

Might need a call to https://docs.github.com/en/rest/reference/repos#get-branch-protection somewhere in that logic

lkysow commented 3 years ago

Looks like that's the issue. For now you'll have to relax that rule or change your global repo settings.

lazzurs commented 1 year ago

I've encountered this in a current client and I would propose rather than using the API to get the configuration of the repo to use a configuration variable in Atlantis to allow GitHub users to select their merge method.

While this could be automated the revert showed that Atlantis does not currently have the permissions for this in most cases and providing more permissions to Atlantis to solve this might not be an option in all cases.

piglowskilukasz commented 2 months ago

Are there any plan to implement/solve this feature as suggested in the previous comment?