refactor logic

This commit is contained in:
Yuki Osaki 2021-10-31 23:16:04 +09:00
parent 769a6cd069
commit b36f6db521
3 changed files with 10 additions and 6 deletions

View file

@ -101,9 +101,7 @@ func (gui *Gui) handleBranchPress() error {
func (gui *Gui) handleCreateOrShowPullRequestPress() error {
branch := gui.getSelectedBranch()
prs, _ := gui.GitCommand.GenerateGithubPullRequestMap(gui.State.GithubRecentPRs, []*models.Branch{branch})
pr, hasPr := prs[branch]
pr, hasPr := gui.GetPr(branch)
if hasPr {
return gui.OSCommand.OpenLink(pr.Url)

View file

@ -731,3 +731,10 @@ func (gui *Gui) setColorScheme() error {
return nil
}
func (gui *Gui) GetPr(branch *models.Branch) (*models.GithubPullRequest, bool) {
prs, _ := gui.GitCommand.GenerateGithubPullRequestMap(gui.State.GithubRecentPRs, []*models.Branch{branch})
pr, hasPr := prs[branch]
return pr, hasPr
}

View file

@ -39,12 +39,11 @@ func (gui *Gui) createOrOpenPullRequestMenu(selectedBranch *models.Branch, check
}
}
prs, _ := gui.GitCommand.GenerateGithubPullRequestMap(gui.State.GithubRecentPRs, []*models.Branch{selectedBranch})
pr, hasPr := prs[selectedBranch]
pr, hasPr := gui.GetPr(selectedBranch)
if hasPr {
menuItems = append(menuItems, &menuItem{
displayString: gui.GitCommand.Tr.OpenPr + strconv.Itoa(pr.Number),
displayString: gui.GitCommand.Tr.MustSpecifyOriginError + strconv.Itoa(pr.Number),
onPress: func() error {
return gui.OSCommand.OpenLink(pr.Url)
},