Skip to content

Commit 59d1ad0

Browse files
committed
WIP Add draft state, iterate on UI design
1 parent d5b1305 commit 59d1ad0

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
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: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"strconv"
7+
"strings"
78

89
"github.com/jesseduffield/gocui"
910
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
@@ -206,10 +207,12 @@ func (self *BranchesController) GetOnRenderToMain() func() {
206207
)
207208

208209
if pr, ok := prs[branch.Name]; ok {
209-
ptyTask.Prefix = fmt.Sprintf("%s %s (%s)\n\n",
210+
ptyTask.Prefix = fmt.Sprintf("%s %s %s\n",
210211
coloredPrNumber(pr),
211-
style.FgYellow.Sprint(style.PrintHyperlink(pr.Title, pr.Url)),
212-
pr.State)
212+
style.PrintHyperlink(pr.Title, pr.Url),
213+
coloredStateText(pr.State))
214+
ptyTask.Prefix += strings.Repeat("─", self.c.Contexts().Normal.GetView().InnerWidth()) + "\n"
215+
213216
}
214217
}
215218

@@ -224,6 +227,26 @@ func (self *BranchesController) GetOnRenderToMain() func() {
224227
}
225228
}
226229

230+
func stateText(state string) string {
231+
// TODO: add icons only if nerd fonts are used
232+
switch state {
233+
case "OPEN":
234+
return " Open"
235+
case "CLOSED":
236+
return " Closed"
237+
case "MERGED":
238+
return " Merged"
239+
case "DRAFT":
240+
return " Draft"
241+
default:
242+
return ""
243+
}
244+
}
245+
246+
func coloredStateText(state string) string {
247+
return prColor(state).Sprint(stateText(state))
248+
}
249+
227250
func coloredPrNumber(pr *models.GithubPullRequest) string {
228251
return prColor(pr.State).Sprint("#" + strconv.Itoa(pr.Number))
229252
}
@@ -236,6 +259,8 @@ func prColor(state string) style.TextStyle {
236259
return style.FgRed
237260
case "MERGED":
238261
return style.FgMagenta
262+
case "DRAFT":
263+
return style.FgBlackLighter
239264
default:
240265
return style.FgDefault
241266
}

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)