From b36f6db521667d691db7f653dc8e984f11f27fee Mon Sep 17 00:00:00 2001 From: Yuki Osaki Date: Sun, 31 Oct 2021 23:16:04 +0900 Subject: [PATCH] refactor logic --- pkg/gui/branches_panel.go | 4 +--- pkg/gui/gui.go | 7 +++++++ pkg/gui/pull_request_menu_panel.go | 5 ++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 7490ff23f..4b9a8b573 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -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) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index eb84b4810..ba8af1108 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -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 +} diff --git a/pkg/gui/pull_request_menu_panel.go b/pkg/gui/pull_request_menu_panel.go index e3115d7e2..023acf1f8 100644 --- a/pkg/gui/pull_request_menu_panel.go +++ b/pkg/gui/pull_request_menu_panel.go @@ -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) },