diff --git a/pkg/commands/git_commands/github.go b/pkg/commands/git_commands/github.go index d1515a7b2..636a76a7d 100644 --- a/pkg/commands/git_commands/github.go +++ b/pkg/commands/git_commands/github.go @@ -69,6 +69,7 @@ type PullRequestNode struct { Url string `json:"url"` HeadRepositoryOwner GithubRepositoryOwner `json:"headRepositoryOwner"` State string `json:"state"` + IsDraft bool `json:"isDraft"` } type GithubRepositoryOwner struct { @@ -90,6 +91,7 @@ func fetchPullRequestsQuery(branches []string, owner string, repo string) string state number url + isDraft headRepositoryOwner { login } @@ -212,7 +214,7 @@ func (self *GitHubCommands) FetchRecentPRsAux(repoOwner string, repoName string, HeadRefName: node.HeadRefName, Number: node.Number, Title: node.Title, - State: node.State, + State: lo.Ternary(node.IsDraft && node.State != "CLOSED", "DRAFT", node.State), Url: node.Url, HeadRepositoryOwner: models.GithubRepositoryOwner{ Login: node.HeadRepositoryOwner.Login, diff --git a/pkg/commands/models/github.go b/pkg/commands/models/github.go index 57dcfd679..d34edb77f 100644 --- a/pkg/commands/models/github.go +++ b/pkg/commands/models/github.go @@ -5,7 +5,7 @@ type GithubPullRequest struct { HeadRefName string `json:"headRefName"` Number int `json:"number"` Title string `json:"title"` - State string `json:"state"` // "MERGED", "OPEN", "CLOSED" + State string `json:"state"` // "MERGED", "OPEN", "CLOSED", "DRAFT" 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 543297c43..af5271b9f 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -3,13 +3,15 @@ package controllers import ( "errors" "fmt" - "strconv" + "strings" + "github.com/gookit/color" "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/presentation/icons" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -206,10 +208,13 @@ func (self *BranchesController) GetOnRenderToMain() func() { ) 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) + ptyTask.Prefix = style.PrintHyperlink(fmt.Sprintf("%s %s %s %s\n", + icons.IconForRemoteUrl(pr.Url), + coloredStateText(pr.State), + pr.Title, + style.FgCyan.Sprintf("#%d", pr.Number)), + pr.Url) + ptyTask.Prefix += strings.Repeat("─", self.c.Contexts().Normal.GetView().InnerWidth()) + "\n" } } @@ -224,20 +229,56 @@ 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 { +func stateText(state string) string { + // TODO: add icons only if nerd fonts are used switch state { case "OPEN": - return style.FgGreen + return " Open" case "CLOSED": - return style.FgRed + return " Closed" case "MERGED": - return style.FgMagenta + return " Merged" + case "DRAFT": + return " Draft" default: - return style.FgDefault + return "" + } +} + +func coloredStateText(state string) string { + return fmt.Sprintf("%s%s%s", + withPrFgColor(state, ""), + withPrBgColor(state, style.FgWhite.Sprint(stateText(state))), + withPrFgColor(state, "")) +} + +func withPrFgColor(state string, text string) string { + switch state { + case "OPEN": + return style.FgGreen.Sprint(text) + case "CLOSED": + return style.FgRed.Sprint(text) + case "MERGED": + return style.FgMagenta.Sprint(text) + case "DRAFT": + return color.RGB(0x66, 0x66, 0x66, false).Sprint(text) + default: + return style.FgDefault.Sprint(text) + } +} + +func withPrBgColor(state string, text string) string { + switch state { + case "OPEN": + return style.BgGreen.Sprint(text) + case "CLOSED": + return style.BgRed.Sprint(text) + case "MERGED": + return style.BgMagenta.Sprint(text) + case "DRAFT": + return color.RGB(0x66, 0x66, 0x66, true).Sprint(text) + default: + return style.BgDefault.Sprint(text) } } diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index 3e1e5046b..ed475f85a 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -268,6 +268,8 @@ func prColor(state string) style.TextStyle { return style.FgRed case "MERGED": return style.FgMagenta + case "DRAFT": + return style.FgBlackLighter default: return style.FgDefault }