Skip to content

Commit 39bdeee

Browse files
author
Nate Smith
authored
Merge pull request cli#550 from rista404/draft-pr-212
Use gray color for PR number if PR is a draft
2 parents d4012b1 + 2a42f61 commit 39bdeee

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

api/queries_pr.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type PullRequest struct {
4040
}
4141
}
4242
IsCrossRepository bool
43+
IsDraft bool
4344
MaintainerCanModify bool
4445

4546
ReviewDecision string
@@ -156,6 +157,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
156157
login
157158
}
158159
isCrossRepository
160+
isDraft
159161
commits(last: 1) {
160162
nodes {
161163
commit {
@@ -366,6 +368,7 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, branch string)
366368
login
367369
}
368370
isCrossRepository
371+
isDraft
369372
}
370373
}
371374
}
@@ -460,6 +463,7 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
460463
login
461464
}
462465
isCrossRepository
466+
isDraft
463467
}
464468
`
465469

command/pr.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func prList(cmd *cobra.Command, args []string) error {
214214
if table.IsTTY() {
215215
prNum = "#" + prNum
216216
}
217-
table.AddField(prNum, nil, colorFuncForState(pr.State))
217+
table.AddField(prNum, nil, colorFuncForPR(pr))
218218
table.AddField(replaceExcessiveWhitespace(pr.Title), nil, nil)
219219
table.AddField(pr.HeadLabel(), nil, utils.Cyan)
220220
table.EndRow()
@@ -227,6 +227,14 @@ func prList(cmd *cobra.Command, args []string) error {
227227
return nil
228228
}
229229

230+
func colorFuncForPR(pr api.PullRequest) func(string) string {
231+
if pr.State == "OPEN" && pr.IsDraft {
232+
return utils.Gray
233+
} else {
234+
return colorFuncForState(pr.State)
235+
}
236+
}
237+
230238
func colorFuncForState(state string) func(string) string {
231239
switch state {
232240
case "OPEN":
@@ -385,7 +393,13 @@ func prSelectorForCurrentBranch(ctx context.Context) (prNumber int, prHeadRef st
385393
func printPrs(w io.Writer, totalCount int, prs ...api.PullRequest) {
386394
for _, pr := range prs {
387395
prNumber := fmt.Sprintf("#%d", pr.Number)
388-
fmt.Fprintf(w, " %s %s %s", utils.Green(prNumber), text.Truncate(50, replaceExcessiveWhitespace(pr.Title)), utils.Cyan("["+pr.HeadLabel()+"]"))
396+
397+
prNumberColorFunc := utils.Green
398+
if pr.IsDraft {
399+
prNumberColorFunc = utils.Gray
400+
}
401+
402+
fmt.Fprintf(w, " %s %s %s", prNumberColorFunc(prNumber), text.Truncate(50, replaceExcessiveWhitespace(pr.Title)), utils.Cyan("["+pr.HeadLabel()+"]"))
389403

390404
checks := pr.ChecksStatus()
391405
reviews := pr.ReviewStatus()

0 commit comments

Comments
 (0)