From 52072b0669f8835ccaeb234ed9d7703c69559a06 Mon Sep 17 00:00:00 2001 From: Emil Edholm Date: Mon, 11 Jul 2022 09:12:33 +0200 Subject: [PATCH] feat: option to merge using Dependabot comment Press alt+m to post a "@dependabot merge" comment which will tell Dependabot to merge the PR itself. This commit also switches the keybindings for the different merge options due to the unreliability of detecting +Enter in various different constellations of terminal emulators / tmux etc. --- tui_cmds.go | 19 +++++++++++++++++-- tui_list.go | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/tui_cmds.go b/tui_cmds.go index 3f5565f..fb25f7b 100644 --- a/tui_cmds.go +++ b/tui_cmds.go @@ -13,12 +13,27 @@ type pullRequestMerged struct { pr pullRequest } -func mergePullRequest(pr pullRequest, mergeMethod string) tea.Cmd { +type mergeMethod string + +const ( + MethodRebase mergeMethod = "--rebase" + MethodMerge mergeMethod = "--merge" + MethodSquash mergeMethod = "--squash" + MethodDependabot mergeMethod = "@dependabot merge" +) + +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} } - if _, err := gh.Run("pr", "merge", "--auto", mergeMethod, pr.url); err != nil { + 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} } return pullRequestMerged{pr: pr} diff --git a/tui_list.go b/tui_list.go index 30206e2..8a856b6 100644 --- a/tui_list.go +++ b/tui_list.go @@ -14,12 +14,13 @@ import ( var listViewStyle = lipgloss.NewStyle().Padding(1, 2) type keyMap struct { - mergeRebase key.Binding - mergeDefault key.Binding - mergeSquash key.Binding - rebase key.Binding - view key.Binding - browse key.Binding // open PR in default browser. + mergeRebase key.Binding + mergeDefault key.Binding + mergeSquash key.Binding + mergeDependabot key.Binding + rebase key.Binding + view key.Binding + browse key.Binding // open PR in default browser. } func newKeyMap() *keyMap { @@ -29,12 +30,16 @@ func newKeyMap() *keyMap { key.WithHelp("enter", "merge (rebase)"), ), mergeDefault: key.NewBinding( - key.WithKeys("ctrl+enter"), - key.WithHelp("ctrl+enter", "merge (merge-commit)"), + key.WithKeys("ctrl+m"), + key.WithHelp("ctrl+m", "merge (merge-commit)"), ), mergeSquash: key.NewBinding( - key.WithKeys("shift+enter"), - key.WithHelp("shift+enter", "merge (squash)"), + key.WithKeys("M"), + key.WithHelp("shift+m", "merge (squash)"), + ), + mergeDependabot: key.NewBinding( + key.WithKeys("alt+m"), + key.WithHelp("alt+m", "merge (Dependabot)"), ), rebase: key.NewBinding( key.WithKeys("r"), @@ -56,6 +61,7 @@ func (d keyMap) Bindings() []key.Binding { d.mergeRebase, d.mergeDefault, d.mergeSquash, + d.mergeDependabot, d.rebase, d.view, d.browse, @@ -110,7 +116,7 @@ func (m ListView) Update(msg tea.Msg) (ListView, tea.Cmd) { cmds = append( cmds, m.listModel.StartSpinner(), - mergePullRequest(selectedItem, "--rebase"), + mergePullRequest(selectedItem, MethodRebase), ) } case key.Matches(msg, m.keyMap.mergeDefault): @@ -119,7 +125,7 @@ func (m ListView) Update(msg tea.Msg) (ListView, tea.Cmd) { cmds = append( cmds, m.listModel.StartSpinner(), - mergePullRequest(selectedItem, "--merge"), + mergePullRequest(selectedItem, MethodMerge), ) } case key.Matches(msg, m.keyMap.mergeSquash): @@ -128,7 +134,16 @@ func (m ListView) Update(msg tea.Msg) (ListView, tea.Cmd) { cmds = append( cmds, m.listModel.StartSpinner(), - mergePullRequest(selectedItem, "--squash"), + mergePullRequest(selectedItem, MethodSquash), + ) + } + case key.Matches(msg, m.keyMap.mergeDependabot): + if selectedItem, ok := m.listModel.SelectedItem().(pullRequest); ok { + m.listModel.RemoveItem(m.listModel.Index()) + cmds = append( + cmds, + m.listModel.StartSpinner(), + mergePullRequest(selectedItem, MethodDependabot), ) } case key.Matches(msg, m.keyMap.rebase):