1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-12-24 00:21:22 +02:00

WIP Add draft state, iterate on UI design

This commit is contained in:
Stefan Haller
2025-10-18 18:06:14 +02:00
parent f6a80280a0
commit 35fc12ee42
4 changed files with 61 additions and 16 deletions

View File

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

View File

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

View File

@@ -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)
}
}

View File

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