Skip to content

Commit

Permalink
[WIP] pkg/gui: Automatically select remote to create PR against if th…
Browse files Browse the repository at this point in the history
…ere is only one
  • Loading branch information
moha-gh committed Jun 18, 2022
1 parent baa7a1d commit 5310d37
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions pkg/gui/controllers/branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,19 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra
{
LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.LcSelectBranch),
OnPress: func() error {
if len(self.model.Remotes) == 1 {
toRemote := self.model.Remotes[0].Name
self.c.Log.Debugf("PR will target the only existing remote '%s'", toRemote)
return self.promptForTargetBranchNameAndCreatePullRequest(branch.Name, toRemote)
}

return self.c.Prompt(types.PromptOpts{
Title: "Select Target Remote",
FindSuggestionsFunc: self.helpers.Suggestions.GetRemoteSuggestionsFunc(),
HandleConfirm: func(targetRemote string) error {
self.c.Log.Debugf("PR will target remote '%s'", targetRemote)

return self.c.Prompt(types.PromptOpts{
Title: fmt.Sprintf("%s/%s →", targetRemote, branch.Name),
FindSuggestionsFunc: self.helpers.Suggestions.GetRemoteBranchesForRemoteSuggestionsFunc(targetRemote),
HandleConfirm: func(targetBranchName string) error {
self.c.Log.Debugf("PR will target branch '%s' on remote '%s'", targetBranchName, targetRemote)
return self.createPullRequest(branch.Name, targetBranchName)
},
})
HandleConfirm: func(toRemote string) error {
self.c.Log.Debugf("PR will target remote '%s'", toRemote)

return self.promptForTargetBranchNameAndCreatePullRequest(branch.Name, toRemote)
},
})
},
Expand All @@ -470,6 +469,17 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra
return self.c.Menu(types.CreateMenuOptions{Title: fmt.Sprintf(self.c.Tr.CreatePullRequestOptions), Items: menuItems})
}

func (self *BranchesController) promptForTargetBranchNameAndCreatePullRequest(fromBranch string, toRemote string) error {
return self.c.Prompt(types.PromptOpts{
Title: fmt.Sprintf("%s →", fromBranch),
FindSuggestionsFunc: self.helpers.Suggestions.GetRemoteBranchesForRemoteSuggestionsFunc(toRemote),
HandleConfirm: func(toBranch string) error {
self.c.Log.Debugf("PR will target branch '%s' on remote '%s'", toBranch, toRemote)
return self.createPullRequest(fromBranch, toBranch)
},
})
}

func (self *BranchesController) createPullRequest(from string, to string) error {
url, err := self.helpers.Host.GetPullRequestURL(from, to)
if err != nil {
Expand Down

0 comments on commit 5310d37

Please sign in to comment.