diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-27 20:02:52 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-27 21:30:08 +1000 |
commit | 58ddbae4d12d397a1409eaf961cfdc80f42f9168 (patch) | |
tree | bdf90e87a0fb46cb212a39966c7c20add8e431c7 /pkg/gui/pull_request_menu_panel.go | |
parent | 3802b563b03171607965b8d4771ea8f9d206553b (diff) |
Minor refactor
Diffstat (limited to 'pkg/gui/pull_request_menu_panel.go')
-rw-r--r-- | pkg/gui/pull_request_menu_panel.go | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/pkg/gui/pull_request_menu_panel.go b/pkg/gui/pull_request_menu_panel.go index b0f1ec796..7cdd7dcbd 100644 --- a/pkg/gui/pull_request_menu_panel.go +++ b/pkg/gui/pull_request_menu_panel.go @@ -2,6 +2,7 @@ package gui import ( "fmt" + "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" @@ -10,54 +11,51 @@ import ( func (gui *Gui) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error { menuItems := make([]*menuItem, 0, 4) - if selectedBranch != checkedOutBranch { - menuItems = append(menuItems, &menuItem{ - displayStrings: []string{ - fmt.Sprintf("%s → default branch", selectedBranch.Name), - }, - onPress: func() error { - return createPullRequest(selectedBranch, nil, gui) + fromToDisplayStrings := func(from string, to string) []string { + return []string{fmt.Sprintf("%s → %s", from, to)} + } + + menuItemsForBranch := func(branch *models.Branch) []*menuItem { + return []*menuItem{ + { + displayStrings: fromToDisplayStrings(branch.Name, gui.Tr.DefaultBranch), + onPress: func() error { + return gui.createPullRequest(branch.Name, "") + }, }, - }, &menuItem{ - displayStrings: []string{ - fmt.Sprintf("%s → %s", checkedOutBranch.Name, selectedBranch.Name), + { + displayStrings: fromToDisplayStrings(branch.Name, gui.Tr.SelectBranch), + onPress: func() error { + return gui.prompt(promptOpts{ + title: branch.Name + " →", + findSuggestionsFunc: gui.findBranchNameSuggestions, + handleConfirm: func(targetBranchName string) error { + return gui.createPullRequest(branch.Name, targetBranchName) + }}, + ) + }, }, - onPress: func() error { - return createPullRequest(checkedOutBranch, selectedBranch, gui) + } + } + + if selectedBranch != checkedOutBranch { + menuItems = append(menuItems, + &menuItem{ + displayStrings: fromToDisplayStrings(checkedOutBranch.Name, selectedBranch.Name), + onPress: func() error { + return gui.createPullRequest(checkedOutBranch.Name, selectedBranch.Name) + }, }, - }) + ) + menuItems = append(menuItems, menuItemsForBranch(checkedOutBranch)...) } - menuItems = append(menuItems, &menuItem{ - displayStrings: []string{ - fmt.Sprintf("%s → default branch", checkedOutBranch.Name), - }, - onPress: func() error { - return createPullRequest(checkedOutBranch, nil, gui) - }, - }, &menuItem{ - displayStrings: []string{ - fmt.Sprintf("%s → select branch", checkedOutBranch.Name), - }, - onPress: func() error { - return gui.prompt(promptOpts{ - title: checkedOutBranch.Name + " →", - findSuggestionsFunc: gui.findBranchNameSuggestions, - handleConfirm: func(response string) error { - targetBranch := gui.getBranchByName(response) - if targetBranch == nil { - return gui.createErrorPanel(gui.Tr.BranchNotFoundTitle) - } - return createPullRequest(checkedOutBranch, targetBranch, gui) - }}, - ) - }, - }) + menuItems = append(menuItems, menuItemsForBranch(selectedBranch)...) return gui.createMenu(fmt.Sprintf(gui.Tr.CreatePullRequestOptions), menuItems, createMenuOptions{showCancel: true}) } -func createPullRequest(from *models.Branch, to *models.Branch, gui *Gui) error { +func (gui *Gui) createPullRequest(from string, to string) error { pullRequest := commands.NewPullRequest(gui.GitCommand) url, err := pullRequest.Create(from, to) if err != nil { |