Skip to content

Commit

Permalink
fix(merge): include merge body in approval
Browse files Browse the repository at this point in the history
When you merge with the dependabot option (alt-m), then we now include
the "@dependabot merge" body in the approval message instead of first
approving and then writing a comment.

Hopefully this solves a rare bug where dependabot doesn't actually merge
the PR and you have to manually comment with the same merge message again.
  • Loading branch information
Edholm committed Nov 1, 2022
1 parent 7c9bdd2 commit 2e4b7e8
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions tui_cmds.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"

"github.com/atotto/clipboard"
tea "github.com/charmbracelet/bubbletea"
"github.com/einride/gh-dependabot/internal/gh"
Expand All @@ -25,17 +27,24 @@ const (

func mergePullRequest(pr pullRequest, method mergeMethod) tea.Cmd {
return func() tea.Msg {
if _, err := gh.Run("pr", "review", "--approve", pr.url); err != nil {
return errorMessage{err: err}
}
var args []string
if method == MethodDependabot {
args = []string{"pr", "comment", "--body", string(method), pr.url}
} else {
args = []string{"pr", "merge", "--auto", string(method), pr.url}
}
if _, err := gh.Run(args...); err != nil {
return errorMessage{err: err}
switch method {
case MethodRebase:
fallthrough
case MethodMerge:
fallthrough
case MethodSquash:
if _, err := gh.Run("pr", "review", "--approve", pr.url); err != nil {
return errorMessage{err: err}
}
if _, err := gh.Run("pr", "merge", "--auto", string(method), pr.url); err != nil {
return errorMessage{err: err}
}
case MethodDependabot:
if _, err := gh.Run("pr", "review", "--approve", "--body", string(method), pr.url); err != nil {
return errorMessage{err: err}
}
default:
return errorMessage{err: fmt.Errorf("unknown merge method: %q", method)}
}
return pullRequestMerged{pr: pr}
}
Expand Down

0 comments on commit 2e4b7e8

Please sign in to comment.