1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-10-30 23:57:43 +02:00

Show PR information in main view above the branch log when a branch is selected

This commit is contained in:
Stefan Haller
2025-10-17 14:08:27 +02:00
parent ebc97cf2b7
commit 3d879bf94a
3 changed files with 38 additions and 1 deletions

View File

@@ -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{

View File

@@ -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"`

View File

@@ -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(),