mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-31 02:25:35 +03:00 
			
		
		
		
	more and more move rebase commit refreshing into existing abstraction and more and more WIP and more handling clicks properly fix merge conflicts update cheatsheet lots more preparation to start moving things into controllers WIP better typing expand on remotes controller moving more code into controllers
		
			
				
	
	
		
			79 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package gui
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 
 | |
| 	"github.com/jesseduffield/lazygit/pkg/commands/hosting_service"
 | |
| 	"github.com/jesseduffield/lazygit/pkg/commands/models"
 | |
| 	"github.com/jesseduffield/lazygit/pkg/gui/popup"
 | |
| )
 | |
| 
 | |
| func (gui *Gui) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error {
 | |
| 	menuItems := make([]*popup.MenuItem, 0, 4)
 | |
| 
 | |
| 	fromToDisplayStrings := func(from string, to string) []string {
 | |
| 		return []string{fmt.Sprintf("%s → %s", from, to)}
 | |
| 	}
 | |
| 
 | |
| 	menuItemsForBranch := func(branch *models.Branch) []*popup.MenuItem {
 | |
| 		return []*popup.MenuItem{
 | |
| 			{
 | |
| 				DisplayStrings: fromToDisplayStrings(branch.Name, gui.c.Tr.LcDefaultBranch),
 | |
| 				OnPress: func() error {
 | |
| 					return gui.createPullRequest(branch.Name, "")
 | |
| 				},
 | |
| 			},
 | |
| 			{
 | |
| 				DisplayStrings: fromToDisplayStrings(branch.Name, gui.c.Tr.LcSelectBranch),
 | |
| 				OnPress: func() error {
 | |
| 					return gui.c.Prompt(popup.PromptOpts{
 | |
| 						Title:               branch.Name + " →",
 | |
| 						FindSuggestionsFunc: gui.suggestionsHelper.GetBranchNameSuggestionsFunc(),
 | |
| 						HandleConfirm: func(targetBranchName string) error {
 | |
| 							return gui.createPullRequest(branch.Name, targetBranchName)
 | |
| 						}},
 | |
| 					)
 | |
| 				},
 | |
| 			},
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	if selectedBranch != checkedOutBranch {
 | |
| 		menuItems = append(menuItems,
 | |
| 			&popup.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.c.Menu(popup.CreateMenuOptions{Title: fmt.Sprintf(gui.c.Tr.CreatePullRequestOptions), Items: menuItems})
 | |
| }
 | |
| 
 | |
| func (gui *Gui) createPullRequest(from string, to string) error {
 | |
| 	hostingServiceMgr := gui.getHostingServiceMgr()
 | |
| 	url, err := hostingServiceMgr.GetPullRequestURL(from, to)
 | |
| 	if err != nil {
 | |
| 		return gui.c.Error(err)
 | |
| 	}
 | |
| 
 | |
| 	gui.c.LogAction(gui.c.Tr.Actions.OpenPullRequest)
 | |
| 
 | |
| 	if err := gui.OSCommand.OpenLink(url); err != nil {
 | |
| 		return gui.c.Error(err)
 | |
| 	}
 | |
| 
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func (gui *Gui) getHostingServiceMgr() *hosting_service.HostingServiceMgr {
 | |
| 	remoteUrl := gui.git.Config.GetRemoteURL()
 | |
| 	configServices := gui.c.UserConfig.Services
 | |
| 	return hosting_service.NewHostingServiceMgr(gui.Log, gui.Tr, remoteUrl, configServices)
 | |
| }
 |