diff --git a/pkg/commands/remotes.go b/pkg/commands/remotes.go index 7a5428d78..327586e2d 100644 --- a/pkg/commands/remotes.go +++ b/pkg/commands/remotes.go @@ -85,3 +85,18 @@ func (c *GitCommand) GetRemotesToOwnersMap() (map[string]string, error) { } return res, nil } + +func (c *GitCommand) GetRemotesToRepositoryMap() (map[string]string, error) { + remotes, err := c.GetRemotes() + if err != nil { + return nil, err + } + + res := map[string]string{} + for _, remote := range remotes { + info := GetRepoInfoFromURL(remote.Urls[0]) + res[info.Owner] = info.Repository + } + + return res, nil +} diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index b04ff8856..3a9ac67c9 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -76,13 +76,47 @@ func (gui *Gui) refreshBranches() { } func (gui *Gui) refreshGithubPullRequests() { - prs, err := gui.GitCommand.GithubMostRecentPRs() - if err != nil { - _ = gui.surfaceError(err) + _, err := gui.GitCommand.RunCommandWithOutput("git config --local --get-regexp .gh-resolved$") + + if err == nil { + _ = gui.setGithubPullRequests() return } + // when config not exits + _ = gui.refreshRemotes() + _ = gui.prompt(promptOpts{ + title: "Select remote Repository", + initialContent: "", + findSuggestionsFunc: gui.getRemoteUrlSuggestionsFunc(), + handleConfirm: func(repository string) error { + return gui.WithWaitingStatus(gui.Tr.SelectRemoteRepository, func() error { + // ex git config --local --add "remote.origin.gh-resolved" "jesseduffield/lazygit" + _, err := gui.GitCommand.RunCommandWithOutput(fmt.Sprintf("git config --local --add \"remote.origin.gh-resolved\" \"%s\"", repository)) + + if err != nil { + return err + } + + err = gui.setGithubPullRequests() + + if err != nil { + return err + } + _ = gui.postRefreshUpdate(gui.State.Contexts.Branches) + return nil + }) + }, + }) +} + +func (gui *Gui) setGithubPullRequests() error { + prs, err := gui.GitCommand.GithubMostRecentPRs() + if err != nil { + return gui.surfaceError(err) + } gui.State.GithubState.RecentPRs = prs + return nil } // specific functions diff --git a/pkg/gui/find_suggestions.go b/pkg/gui/find_suggestions.go index 343e087e8..35a373635 100644 --- a/pkg/gui/find_suggestions.go +++ b/pkg/gui/find_suggestions.go @@ -29,6 +29,15 @@ func (gui *Gui) getRemoteNames() []string { return result } +// func (gui *Gui) getRemoteUrls() []string { +// result := make([]string, len(gui.State.Remotes)) +// for i, remote := range gui.State.Remotes { +// result[i] = remote.Urls[0] +// gui.GitCommand.GetRemotesToOwnersMap() +// } +// return result +// } + func matchesToSuggestions(matches []string) []*types.Suggestion { suggestions := make([]*types.Suggestion, len(matches)) for i, match := range matches { @@ -46,6 +55,17 @@ func (gui *Gui) getRemoteSuggestionsFunc() func(string) []*types.Suggestion { return fuzzySearchFunc(remoteNames) } +func (gui *Gui) getRemoteUrlSuggestionsFunc() func(string) []*types.Suggestion { + remotesToOwnersMap, _ := gui.GitCommand.GetRemotesToRepositoryMap() + result := make([]string, len(remotesToOwnersMap)) + i := 0 + for owner, repository := range remotesToOwnersMap { + result[i] = owner + "/" + repository + i++ + } + return fuzzySearchFunc(result) +} + func (gui *Gui) getBranchNames() []string { result := make([]string, len(gui.State.Branches)) for i, branch := range gui.State.Branches { diff --git a/pkg/i18n/chinese.go b/pkg/i18n/chinese.go index 06a507a5d..cad10c4ce 100644 --- a/pkg/i18n/chinese.go +++ b/pkg/i18n/chinese.go @@ -433,6 +433,7 @@ func chineseTranslationSet() TranslationSet { FocusCommandLog: "焦点命令日志", CommandLogHeader: "您可以通过按 '%s' 隐藏或集中显示该面板,或使用 `gui.showCommandLog: false`\n将其永久隐藏在您的配置中", RandomTip: "随机提示", + SelectRemoteRepository: "选择存储库", SelectParentCommitForMerge: "选择父提交进行合并", ToggleWhitespaceInDiffView: "切换是否在差异视图中显示空白更改", IgnoringWhitespaceInDiffView: "差异视图中的空格将被忽略", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 76f45443a..857d3a5a6 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -440,6 +440,7 @@ type TranslationSet struct { OpenPr string AbortTitle string AbortPrompt string + SelectRemoteRepository string Spans Spans } @@ -943,6 +944,7 @@ func englishTranslationSet() TranslationSet { SuggestionsTitle: "Suggestions (press %s to focus)", ExtrasTitle: "Extras", PushingTagStatus: "pushing tag", + SelectRemoteRepository: "Select Remote Repository", PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", CommitMessageCopiedToClipboard: "Commit message copied to clipboard", LcCopiedToClipboard: "copied to clipboard",