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

Feature Request: Allow Auto Merge with Squash or Rebase option #2047

Open
vimitd opened this issue Feb 4, 2022 · 6 comments
Open

Feature Request: Allow Auto Merge with Squash or Rebase option #2047

vimitd opened this issue Feb 4, 2022 · 6 comments
Labels
feature New functionality/enhancement question Further information is requested Stale

Comments

@vimitd
Copy link

vimitd commented Feb 4, 2022

Hi All,

is it possible to auto merge with squash or rebases? I think if we don't have this feature we need to implement this because its difficult to look into history.

@vimitd vimitd changed the title is it possible to Auto Merge with Squash or Rebase option ? Feature Request: Allow Auto Merge with Squash or Rebase option Feb 4, 2022
@jamengual jamengual added question Further information is requested feature New functionality/enhancement labels Aug 26, 2022
@musabmirza-amperon

This comment was marked as duplicate.

2 similar comments
@ralphotowo

This comment was marked as duplicate.

@codrinh

This comment was marked as duplicate.

@aairey
Copy link

aairey commented Feb 2, 2024

With only rebase allowed on the repo you get this error:

Unable to merge pull, error: merging pull request: PUT https://api.github.com/repos/org/repo/pulls/112/merge: 405 This branch must not contain merge commits. []

@nitrocode
Copy link
Member

Seems like this ability exists but perhaps there is a bug or perhaps your pr did have merge conflicts?

func (g *GithubClient) MergePull(pull models.PullRequest, _ models.PullRequestOptions) error {
// Users can set their repo to disallow certain types of merging.
// We detect which types aren't allowed and use the type that is.
repo, resp, err := g.client.Repositories.Get(g.ctx, pull.BaseRepo.Owner, pull.BaseRepo.Name)
if resp != nil {
g.logger.Debug("GET /repos/%v/%v returned: %v", pull.BaseRepo.Owner, pull.BaseRepo.Name, resp.StatusCode)
}
if err != nil {
return errors.Wrap(err, "fetching repo info")
}
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,
}
g.logger.Debug("PUT /repos/%v/%v/pulls/%d/merge", repo.Owner, repo.Name, pull.Num)
mergeResult, resp, err := g.client.PullRequests.Merge(
g.ctx,
pull.BaseRepo.Owner,
pull.BaseRepo.Name,
pull.Num,
// NOTE: Using the empty string here causes GitHub to autogenerate
// the commit message as it normally would.
"",
options)
if resp != nil {
g.logger.Debug("POST /repos/%v/%v/pulls/%d/merge returned: %v", repo.Owner, repo.Name, pull.Num, resp.StatusCode)
}
if err != nil {
return errors.Wrap(err, "merging pull request")
}
if !mergeResult.GetMerged() {
return fmt.Errorf("could not merge pull request: %s", mergeResult.GetMessage())
}
return nil
}

@aairey
Copy link

aairey commented Jun 27, 2024

I believe this is a duplicate of #1176

It seems it was fixed in March, but the changes were rolled back.

A final fix is still needed imho - but more discussion is available on the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

7 participants