diff --git a/pkg/commands/git_commands/github.go b/pkg/commands/git_commands/github.go index 3d32b59d8..d1515a7b2 100644 --- a/pkg/commands/git_commands/github.go +++ b/pkg/commands/git_commands/github.go @@ -211,6 +211,7 @@ func (self *GitHubCommands) FetchRecentPRsAux(repoOwner string, repoName string, pr := &models.GithubPullRequest{ HeadRefName: node.HeadRefName, Number: node.Number, + Title: node.Title, State: node.State, Url: node.Url, HeadRepositoryOwner: models.GithubRepositoryOwner{ diff --git a/pkg/commands/models/github.go b/pkg/commands/models/github.go index d938fe1ee..57dcfd679 100644 --- a/pkg/commands/models/github.go +++ b/pkg/commands/models/github.go @@ -4,6 +4,7 @@ package models type GithubPullRequest struct { HeadRefName string `json:"headRefName"` Number int `json:"number"` + Title string `json:"title"` State string `json:"state"` // "MERGED", "OPEN", "CLOSED" Url string `json:"url"` HeadRepositoryOwner GithubRepositoryOwner `json:"headRepositoryOwner"` diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index c796e19ab..543297c43 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -3,12 +3,14 @@ package controllers import ( "errors" "fmt" + "strconv" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" + "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" @@ -192,7 +194,23 @@ func (self *BranchesController) GetOnRenderToMain() func() { } else { cmdObj := self.c.Git().Branch.GetGraphCmdObj(branch.FullRefName()) - task = types.NewRunPtyTask(cmdObj.GetCmd()) + ptyTask := types.NewRunPtyTask(cmdObj.GetCmd()) + task = ptyTask + + // Shouldn't we hold on to the map for longer instead of generating it every time? + // It is also generated every time we render the branches list. + prs := git_commands.GenerateGithubPullRequestMap( + self.c.Model().PullRequests, + self.c.Model().Branches, + self.c.Model().Remotes, + ) + + if pr, ok := prs[branch.Name]; ok { + ptyTask.Prefix = fmt.Sprintf("%s %s (%s)\n\n", + coloredPrNumber(pr), + style.FgYellow.Sprint(style.PrintHyperlink(pr.Title, pr.Url)), + pr.State) + } } self.c.RenderToMainViews(types.RefreshMainOpts{ @@ -206,6 +224,23 @@ func (self *BranchesController) GetOnRenderToMain() func() { } } +func coloredPrNumber(pr *models.GithubPullRequest) string { + return prColor(pr.State).Sprint("#" + strconv.Itoa(pr.Number)) +} + +func prColor(state string) style.TextStyle { + switch state { + case "OPEN": + return style.FgGreen + case "CLOSED": + return style.FgRed + case "MERGED": + return style.FgMagenta + default: + return style.FgDefault + } +} + func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branch) error { upstream := lo.Ternary(selectedBranch.RemoteBranchStoredLocally(), selectedBranch.ShortUpstreamRefName(),