Simplify auto-merge detection

This commit is contained in:
Cristian Dominguez 2021-06-19 01:40:28 -03:00
parent d68a2038b6
commit 498f15653e
2 changed files with 11 additions and 12 deletions

View file

@ -24,7 +24,6 @@ type mergePayload struct {
pullRequestID string
method PullRequestMergeMethod
auto bool
mergeStateStatus string
commitSubject string
setCommitSubject bool
commitBody string
@ -68,7 +67,7 @@ func mergePullRequest(client *http.Client, payload mergePayload) error {
gql := graphql.NewClient(ghinstance.GraphQLEndpoint(payload.repo.RepoHost()), client)
if payload.auto && payload.mergeStateStatus == "BLOCKED" {
if payload.auto {
var mutation struct {
EnablePullRequestAutoMerge struct {
ClientMutationId string

View file

@ -198,17 +198,17 @@ func mergeRun(opts *MergeOptions) error {
deleteBranch := opts.DeleteBranch
crossRepoPR := pr.HeadRepositoryOwner.Login != baseRepo.RepoOwner()
autoMerge := opts.AutoMergeEnable && pr.MergeStateStatus == "BLOCKED"
isPRAlreadyMerged := pr.State == "MERGED"
if !isPRAlreadyMerged {
payload := mergePayload{
repo: baseRepo,
pullRequestID: pr.ID,
mergeStateStatus: pr.MergeStateStatus,
method: opts.MergeMethod,
auto: opts.AutoMergeEnable,
commitBody: opts.Body,
setCommitBody: opts.BodySet,
repo: baseRepo,
pullRequestID: pr.ID,
method: opts.MergeMethod,
auto: autoMerge,
commitBody: opts.Body,
setCommitBody: opts.BodySet,
}
if opts.InteractiveMode {
@ -263,7 +263,7 @@ func mergeRun(opts *MergeOptions) error {
}
if isTerminal {
if payload.auto && payload.mergeStateStatus == "BLOCKED" {
if payload.auto {
method := ""
switch payload.method {
case PullRequestMergeMethodRebase:
@ -283,7 +283,7 @@ func mergeRun(opts *MergeOptions) error {
fmt.Fprintf(opts.IO.ErrOut, "%s %s pull request #%d (%s)\n", cs.SuccessIconWithColor(cs.Magenta), action, pr.Number, pr.Title)
}
}
} else if !opts.IsDeleteBranchIndicated && opts.InteractiveMode && !crossRepoPR && !opts.AutoMergeEnable {
} else if !opts.IsDeleteBranchIndicated && opts.InteractiveMode && !crossRepoPR && !autoMerge {
err := prompt.SurveyAskOne(&survey.Confirm{
Message: fmt.Sprintf("Pull request #%d was already merged. Delete the branch locally?", pr.Number),
Default: false,
@ -295,7 +295,7 @@ func mergeRun(opts *MergeOptions) error {
fmt.Fprintf(opts.IO.ErrOut, "%s Pull request #%d was already merged\n", cs.WarningIcon(), pr.Number)
}
if !deleteBranch || crossRepoPR || opts.AutoMergeEnable {
if !deleteBranch || crossRepoPR || autoMerge {
return nil
}