mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-12-07 23:22:40 +02:00
Minor refactor
This commit is contained in:
@@ -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)
|
||||
},
|
||||
}, &menuItem{
|
||||
displayStrings: []string{
|
||||
fmt.Sprintf("%s → %s", checkedOutBranch.Name, selectedBranch.Name),
|
||||
},
|
||||
onPress: func() error {
|
||||
return createPullRequest(checkedOutBranch, selectedBranch, gui)
|
||||
},
|
||||
})
|
||||
fromToDisplayStrings := func(from string, to string) []string {
|
||||
return []string{fmt.Sprintf("%s → %s", from, to)}
|
||||
}
|
||||
|
||||
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)
|
||||
}},
|
||||
)
|
||||
},
|
||||
})
|
||||
menuItemsForBranch := func(branch *models.Branch) []*menuItem {
|
||||
return []*menuItem{
|
||||
{
|
||||
displayStrings: fromToDisplayStrings(branch.Name, gui.Tr.DefaultBranch),
|
||||
onPress: func() error {
|
||||
return gui.createPullRequest(branch.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)
|
||||
}},
|
||||
)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
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, 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 {
|
||||
|
||||
Reference in New Issue
Block a user