mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-11 16:16:28 -04:00
update it not to inject the PRs into our branches
This commit is contained in:
parent
7fbf4fa7f7
commit
a71db3355a
|
|
@ -11,7 +11,6 @@ type Branch struct {
|
|||
Pullables string
|
||||
UpstreamName string
|
||||
Head bool
|
||||
PR *GithubPullRequest
|
||||
}
|
||||
|
||||
func (b *Branch) RefName() string {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ func (gui *Gui) refreshBranches() {
|
|||
_ = gui.surfaceError(err)
|
||||
}
|
||||
gui.State.Branches = builder.Build()
|
||||
gui.State.BranchesWithGithubPullRequests = builder.GitCommand.InjectGithubPullRequests(gui.State.GithubRecentPRs, gui.State.Branches)
|
||||
gui.State.BranchesWithGithubPullRequests = builder.GitCommand.FoundBranchWithGithubPullRequest(gui.State.GithubRecentPRs, gui.State.Branches)
|
||||
if err := gui.postRefreshUpdate(gui.State.Contexts.Branches); err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
|
@ -76,7 +77,11 @@ func (gui *Gui) refreshBranches() {
|
|||
}
|
||||
|
||||
func (gui *Gui) refreshGithubPullRequests() {
|
||||
prs := gui.GitCommand.GithubMostRecentPRs()
|
||||
prs, err := gui.GitCommand.GithubMostRecentPRs()
|
||||
if err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
|
||||
if len(prs) > 0 {
|
||||
gui.State.GithubRecentPRs = prs
|
||||
}
|
||||
|
|
@ -97,8 +102,13 @@ func (gui *Gui) handleBranchPress() error {
|
|||
|
||||
func (gui *Gui) handleCreateOrShowPullRequestPress() error {
|
||||
branch := gui.getSelectedBranch()
|
||||
if branch.PR != nil {
|
||||
return gui.OSCommand.OpenLink(branch.PR.Url)
|
||||
remotesToOwnersMap, _ := gui.GitCommand.GetRemotesToOwnersMap()
|
||||
prs := gui.State.GithubRecentPRs
|
||||
|
||||
pr, has_pr := presentation.GetPr(branch, remotesToOwnersMap, prs)
|
||||
|
||||
if has_pr {
|
||||
return gui.OSCommand.OpenLink(pr.Url)
|
||||
}
|
||||
return gui.createPullRequest(branch.Name, "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (gui *Gui) refreshReflogCommitsConsideringStartup() {
|
|||
// The github cli can be quite slow so we load the github PRs sparately
|
||||
gui.refreshGithubPullRequests()
|
||||
wg.Wait()
|
||||
gui.State.BranchesWithGithubPullRequests = gui.GitCommand.InjectGithubPullRequests(gui.State.GithubRecentPRs, gui.State.Branches)
|
||||
gui.State.BranchesWithGithubPullRequests = gui.GitCommand.FoundBranchWithGithubPullRequest(gui.State.GithubRecentPRs, gui.State.Branches)
|
||||
_ = gui.postRefreshUpdate(gui.State.Contexts.Branches)
|
||||
gui.refreshStatus()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -286,11 +286,11 @@ type guiMutexes struct {
|
|||
type guiState struct {
|
||||
// the file panels (files and commit files) can render as a tree, so we have
|
||||
// managers for them which handle rendering a flat list of files in tree form
|
||||
FileManager *filetree.FileManager
|
||||
CommitFileManager *filetree.CommitFileManager
|
||||
Submodules []*models.SubmoduleConfig
|
||||
Branches []*models.Branch
|
||||
GithubRecentPRs map[string]models.GithubPullRequest
|
||||
FileManager *filetree.FileManager
|
||||
CommitFileManager *filetree.CommitFileManager
|
||||
Submodules []*models.SubmoduleConfig
|
||||
Branches []*models.Branch
|
||||
GithubRecentPRs map[string]models.GithubPullRequest
|
||||
BranchesWithGithubPullRequests bool
|
||||
Commits []*models.Commit
|
||||
StashEntries []*models.StashEntry
|
||||
|
|
|
|||
|
|
@ -66,8 +66,12 @@ func (gui *Gui) branchesListContext() *ListContext {
|
|||
OnFocus: gui.handleBranchSelect,
|
||||
Gui: gui,
|
||||
GetDisplayStrings: func() [][]string {
|
||||
remotesToOwnersMap, _ := gui.GitCommand.GetRemotesToOwnersMap()
|
||||
|
||||
return presentation.GetBranchListDisplayStrings(
|
||||
gui.State.Branches,
|
||||
gui.State.GithubRecentPRs,
|
||||
remotesToOwnersMap,
|
||||
gui.State.ScreenMode != SCREEN_NORMAL,
|
||||
gui.State.Modes.Diffing.Ref,
|
||||
gui.State.BranchesWithGithubPullRequests,
|
||||
|
|
|
|||
|
|
@ -10,19 +10,31 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||
)
|
||||
|
||||
func GetBranchListDisplayStrings(branches []*models.Branch, fullDescription bool, diffName string, showGithub bool) [][]string {
|
||||
func GetBranchListDisplayStrings(
|
||||
branches []*models.Branch,
|
||||
prs map[string]models.GithubPullRequest,
|
||||
remotesToOwnersMap map[string]string,
|
||||
fullDescription bool,
|
||||
diffName string,
|
||||
showGithub bool) [][]string {
|
||||
lines := make([][]string, len(branches))
|
||||
|
||||
for i := range branches {
|
||||
diffed := branches[i].Name == diffName
|
||||
lines[i] = getBranchDisplayStrings(branches[i], fullDescription, diffed, showGithub)
|
||||
lines[i] = getBranchDisplayStrings(branches[i], prs, remotesToOwnersMap, fullDescription, diffed, showGithub)
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
// getBranchDisplayStrings returns the display string of branch
|
||||
func getBranchDisplayStrings(b *models.Branch, fullDescription bool, diffed, showGithub bool) []string {
|
||||
func getBranchDisplayStrings(
|
||||
b *models.Branch,
|
||||
prs map[string]models.GithubPullRequest,
|
||||
remotesToOwnersMap map[string]string,
|
||||
fullDescription bool,
|
||||
diffed,
|
||||
showGithub bool) []string {
|
||||
displayName := b.Name
|
||||
if b.DisplayName != "" {
|
||||
displayName = b.DisplayName
|
||||
|
|
@ -44,15 +56,16 @@ func getBranchDisplayStrings(b *models.Branch, fullDescription bool, diffed, sho
|
|||
|
||||
res := []string{recencyColor.Sprint(b.Recency), coloredName}
|
||||
if showGithub {
|
||||
if b.PR != nil {
|
||||
pr, has_pr := GetPr(b, remotesToOwnersMap, prs)
|
||||
if has_pr {
|
||||
colour := style.FgMagenta // = state MERGED
|
||||
switch b.PR.State {
|
||||
switch pr.State {
|
||||
case "OPEN":
|
||||
colour = style.FgGreen
|
||||
case "CLOSED":
|
||||
colour = style.FgRed
|
||||
}
|
||||
res = append(res, colour.Sprint("#"+strconv.Itoa(b.PR.Number)))
|
||||
res = append(res, colour.Sprint("#"+strconv.Itoa(pr.Number)))
|
||||
} else {
|
||||
res = append(res, "")
|
||||
}
|
||||
|
|
@ -94,3 +107,22 @@ func ColoredBranchStatus(branch *models.Branch) string {
|
|||
func BranchStatus(branch *models.Branch) string {
|
||||
return fmt.Sprintf("↑%s↓%s", branch.Pushables, branch.Pullables)
|
||||
}
|
||||
|
||||
func GetPr(branch *models.Branch, remotesToOwnersMap map[string]string, prs map[string]models.GithubPullRequest) (*models.GithubPullRequest, bool) {
|
||||
if len(prs) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if len(remotesToOwnersMap) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
remoteAndName := strings.SplitN(branch.UpstreamName, "/", 2)
|
||||
owner, foundRemoteOwner := remotesToOwnersMap[remoteAndName[0]]
|
||||
if len(remoteAndName) != 2 || !foundRemoteOwner {
|
||||
return nil, false
|
||||
}
|
||||
pr, hasPr := prs[owner+":"+remoteAndName[1]]
|
||||
|
||||
return &pr, hasPr
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
)
|
||||
|
||||
func (gui *Gui) createOrOpenPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error {
|
||||
|
|
@ -39,11 +40,15 @@ func (gui *Gui) createOrOpenPullRequestMenu(selectedBranch *models.Branch, check
|
|||
}
|
||||
}
|
||||
|
||||
if selectedBranch.PR != nil {
|
||||
remotesToOwnersMap, _ := gui.GitCommand.GetRemotesToOwnersMap()
|
||||
prs := gui.State.GithubRecentPRs
|
||||
pr, has_pr := presentation.GetPr(selectedBranch, remotesToOwnersMap, prs)
|
||||
|
||||
if has_pr {
|
||||
menuItems = append(menuItems, &menuItem{
|
||||
displayString: "open #" + strconv.Itoa(selectedBranch.PR.Number),
|
||||
displayString: "open #" + strconv.Itoa(pr.Number),
|
||||
onPress: func() error {
|
||||
return gui.OSCommand.OpenLink(selectedBranch.PR.Url)
|
||||
return gui.OSCommand.OpenLink(pr.Url)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue