diff options
author | Denis Palashevskii <palash.denis@outlook.com> | 2021-04-21 15:23:36 +0400 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-27 21:30:08 +1000 |
commit | 0e6598adbd7c5321c3e9ec46d303a707d0e5ecbb (patch) | |
tree | aefc546c8367137cc5d23039530171899ab251a8 /pkg/gui | |
parent | f2645da16a4bd4335c4c77e43517b5fd8d8ca259 (diff) |
Implement pull request options menu
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/branches_panel.go | 18 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 7 | ||||
-rw-r--r-- | pkg/gui/pull_request_menu_panel.go | 52 |
3 files changed, 69 insertions, 8 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 863622f94..da55c9df8 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -91,23 +91,25 @@ func (gui *Gui) handleBranchPress() error { } func (gui *Gui) handleCreatePullRequestPress() error { - pullRequest := commands.NewPullRequest(gui.GitCommand) - branch := gui.getSelectedBranch() - url, err := pullRequest.Create(branch) - if err != nil { - return gui.surfaceError(err) + return createPullRequest(branch, nil, gui) +} + +func (gui *Gui) handleCreatePullRequestMenu() error { + selectedBranch := gui.getSelectedBranch() + if selectedBranch == nil { + return nil } - gui.OnRunCommand(oscommands.NewCmdLogEntry(fmt.Sprintf("Creating pull request at URL: %s", url), "Create pull request", false)) + checkedOutBranch := gui.getCheckedOutBranch() - return nil + return gui.createPullRequestMenu(selectedBranch, checkedOutBranch) } func (gui *Gui) handleCopyPullRequestURLPress() error { pullRequest := commands.NewPullRequest(gui.GitCommand) branch := gui.getSelectedBranch() - url, err := pullRequest.CopyURL(branch) + url, err := pullRequest.CopyURL(branch, nil) if err != nil { return gui.surfaceError(err) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 2e690a1e4..5519f1954 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -548,6 +548,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { { ViewName: "branches", Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)}, + Key: gui.getKey(config.Branches.ViewPullRequestOptions), + Handler: gui.handleCreatePullRequestMenu, + Description: gui.Tr.LcCreatePullRequest, + }, + { + ViewName: "branches", + Contexts: []string{string(LOCAL_BRANCHES_CONTEXT_KEY)}, Key: gui.getKey(config.Branches.CopyPullRequestURL), Handler: gui.handleCopyPullRequestURLPress, Description: gui.Tr.LcCopyPullRequestURL, diff --git a/pkg/gui/pull_request_menu_panel.go b/pkg/gui/pull_request_menu_panel.go new file mode 100644 index 000000000..088cae2eb --- /dev/null +++ b/pkg/gui/pull_request_menu_panel.go @@ -0,0 +1,52 @@ +package gui + +import ( + "fmt" + "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" +) + +func (gui *Gui) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error { + menuItems := make([]*menuItem, 0, 2) + + if selectedBranch != checkedOutBranch { + menuItems = append(menuItems, &menuItem{ + displayStrings: []string{ + fmt.Sprintf("%s -> default branch", selectedBranch.Name), + }, + onPress: func() error { + return createPullRequest(selectedBranch, nil, gui) + }, + }, &menuItem{ + displayStrings: []string{ + fmt.Sprintf("%s -> %s", checkedOutBranch.Name, selectedBranch.Name), + }, + onPress: func() error { + return createPullRequest(checkedOutBranch, selectedBranch, gui) + }, + }) + } + + menuItems = append(menuItems, &menuItem{ + displayStrings: []string{ + fmt.Sprintf("%s -> default branch", checkedOutBranch.Name), + }, + onPress: func() error { + return createPullRequest(checkedOutBranch, nil, gui) + }, + }) + + return gui.createMenu(fmt.Sprintf(gui.Tr.CreatePullRequest), menuItems, createMenuOptions{showCancel: true}) +} + +func createPullRequest(checkedOutBranch *models.Branch, selectedBranch *models.Branch, gui *Gui) error { + pullRequest := commands.NewPullRequest(gui.GitCommand) + url, err := pullRequest.Create(checkedOutBranch, selectedBranch) + if err != nil { + return gui.surfaceError(err) + } + gui.OnRunCommand(oscommands.NewCmdLogEntry(fmt.Sprintf("Creating pull request at URL: %s", url), "Create pull request", false)) + + return nil +} |