Skip to content

Commit 335cbf7

Browse files
committed
WIP Add draft state, iterate on UI design
1 parent 3d879bf commit 335cbf7

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

pkg/commands/git_commands/github.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type PullRequestNode struct {
6969
Url string `json:"url"`
7070
HeadRepositoryOwner GithubRepositoryOwner `json:"headRepositoryOwner"`
7171
State string `json:"state"`
72+
IsDraft bool `json:"isDraft"`
7273
}
7374

7475
type GithubRepositoryOwner struct {
@@ -90,6 +91,7 @@ func fetchPullRequestsQuery(branches []string, owner string, repo string) string
9091
state
9192
number
9293
url
94+
isDraft
9395
headRepositoryOwner {
9496
login
9597
}
@@ -212,7 +214,7 @@ func (self *GitHubCommands) FetchRecentPRsAux(repoOwner string, repoName string,
212214
HeadRefName: node.HeadRefName,
213215
Number: node.Number,
214216
Title: node.Title,
215-
State: node.State,
217+
State: lo.Ternary(node.IsDraft && node.State != "CLOSED", "DRAFT", node.State),
216218
Url: node.Url,
217219
HeadRepositoryOwner: models.GithubRepositoryOwner{
218220
Login: node.HeadRepositoryOwner.Login,

pkg/commands/models/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type GithubPullRequest struct {
55
HeadRefName string `json:"headRefName"`
66
Number int `json:"number"`
77
Title string `json:"title"`
8-
State string `json:"state"` // "MERGED", "OPEN", "CLOSED"
8+
State string `json:"state"` // "MERGED", "OPEN", "CLOSED", "DRAFT"
99
Url string `json:"url"`
1010
HeadRepositoryOwner GithubRepositoryOwner `json:"headRepositoryOwner"`
1111
}

pkg/gui/controllers/branches_controller.go

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package controllers
33
import (
44
"errors"
55
"fmt"
6-
"strconv"
6+
"strings"
77

8+
"github.com/gookit/color"
89
"github.com/jesseduffield/gocui"
910
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
1011
"github.com/jesseduffield/lazygit/pkg/commands/models"
1112
"github.com/jesseduffield/lazygit/pkg/gui/context"
1213
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
14+
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
1315
"github.com/jesseduffield/lazygit/pkg/gui/style"
1416
"github.com/jesseduffield/lazygit/pkg/gui/types"
1517
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -206,10 +208,13 @@ func (self *BranchesController) GetOnRenderToMain() func() {
206208
)
207209

208210
if pr, ok := prs[branch.Name]; ok {
209-
ptyTask.Prefix = fmt.Sprintf("%s %s (%s)\n\n",
210-
coloredPrNumber(pr),
211-
style.FgYellow.Sprint(style.PrintHyperlink(pr.Title, pr.Url)),
212-
pr.State)
211+
ptyTask.Prefix = style.PrintHyperlink(fmt.Sprintf("%s %s %s %s\n",
212+
icons.IconForRemoteUrl(pr.Url),
213+
coloredStateText(pr.State),
214+
pr.Title,
215+
style.FgCyan.Sprintf("#%d", pr.Number)),
216+
pr.Url)
217+
ptyTask.Prefix += strings.Repeat("─", self.c.Contexts().Normal.GetView().InnerWidth()) + "\n"
213218
}
214219
}
215220

@@ -224,20 +229,56 @@ func (self *BranchesController) GetOnRenderToMain() func() {
224229
}
225230
}
226231

227-
func coloredPrNumber(pr *models.GithubPullRequest) string {
228-
return prColor(pr.State).Sprint("#" + strconv.Itoa(pr.Number))
232+
func stateText(state string) string {
233+
// TODO: add icons only if nerd fonts are used
234+
switch state {
235+
case "OPEN":
236+
return " Open"
237+
case "CLOSED":
238+
return " Closed"
239+
case "MERGED":
240+
return " Merged"
241+
case "DRAFT":
242+
return " Draft"
243+
default:
244+
return ""
245+
}
246+
}
247+
248+
func coloredStateText(state string) string {
249+
return fmt.Sprintf("%s%s%s",
250+
withPrFgColor(state, ""),
251+
withPrBgColor(state, style.FgWhite.Sprint(stateText(state))),
252+
withPrFgColor(state, ""))
253+
}
254+
255+
func withPrFgColor(state string, text string) string {
256+
switch state {
257+
case "OPEN":
258+
return style.FgGreen.Sprint(text)
259+
case "CLOSED":
260+
return style.FgRed.Sprint(text)
261+
case "MERGED":
262+
return style.FgMagenta.Sprint(text)
263+
case "DRAFT":
264+
return color.RGB(0x66, 0x66, 0x66, false).Sprint(text)
265+
default:
266+
return style.FgDefault.Sprint(text)
267+
}
229268
}
230269

231-
func prColor(state string) style.TextStyle {
270+
func withPrBgColor(state string, text string) string {
232271
switch state {
233272
case "OPEN":
234-
return style.FgGreen
273+
return style.BgGreen.Sprint(text)
235274
case "CLOSED":
236-
return style.FgRed
275+
return style.BgRed.Sprint(text)
237276
case "MERGED":
238-
return style.FgMagenta
277+
return style.BgMagenta.Sprint(text)
278+
case "DRAFT":
279+
return color.RGB(0x66, 0x66, 0x66, true).Sprint(text)
239280
default:
240-
return style.FgDefault
281+
return style.BgDefault.Sprint(text)
241282
}
242283
}
243284

pkg/gui/presentation/branches.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ func prColor(state string) style.TextStyle {
269269
return style.FgRed
270270
case "MERGED":
271271
return style.FgMagenta
272+
case "DRAFT":
273+
return style.FgBlackLighter
272274
default:
273275
return style.FgDefault
274276
}

0 commit comments

Comments
 (0)