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/pull_request_menu_panel.go | |
parent | f2645da16a4bd4335c4c77e43517b5fd8d8ca259 (diff) |
Implement pull request options menu
Diffstat (limited to 'pkg/gui/pull_request_menu_panel.go')
-rw-r--r-- | pkg/gui/pull_request_menu_panel.go | 52 |
1 files changed, 52 insertions, 0 deletions
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 +} |