Skip to content

Commit 930ee60

Browse files
committed
Disable colorizing labels in issue list output
- Labels with dark color are not visible on a dark background - "Raw" `issue view` output should never output color, not even with CLICOLOR_FORCE=1
1 parent 4b499be commit 930ee60

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

pkg/cmd/issue/shared/display.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func PrintIssues(io *iostreams.IOStreams, prefix string, totalCount int, issues
2222
issueNum = "#" + issueNum
2323
}
2424
issueNum = prefix + issueNum
25-
labels := IssueLabelList(issue, cs)
25+
labels := issueLabelList(&issue)
2626
if labels != "" && table.IsTTY() {
2727
labels = fmt.Sprintf("(%s)", labels)
2828
}
@@ -56,14 +56,14 @@ func truncateLabels(w int, t string) string {
5656
return fmt.Sprintf("(%s)", truncated)
5757
}
5858

59-
func IssueLabelList(issue api.Issue, cs *iostreams.ColorScheme) string {
59+
func issueLabelList(issue *api.Issue) string {
6060
if len(issue.Labels.Nodes) == 0 {
6161
return ""
6262
}
6363

64-
labelNames := make([]string, 0, len(issue.Labels.Nodes))
65-
for _, label := range issue.Labels.Nodes {
66-
labelNames = append(labelNames, cs.HexToRGB(label.Color, label.Name))
64+
labelNames := make([]string, len(issue.Labels.Nodes))
65+
for i, label := range issue.Labels.Nodes {
66+
labelNames[i] = label.Name
6767
}
6868

6969
return strings.Join(labelNames, ", ")

pkg/cmd/issue/view/view.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/MakeNowJust/heredoc"
1111
"github.com/cli/cli/api"
1212
"github.com/cli/cli/internal/ghrepo"
13-
"github.com/cli/cli/pkg/cmd/issue/shared"
1413
issueShared "github.com/cli/cli/pkg/cmd/issue/shared"
1514
prShared "github.com/cli/cli/pkg/cmd/pr/shared"
1615
"github.com/cli/cli/pkg/cmdutil"
@@ -125,7 +124,7 @@ func viewRun(opts *ViewOptions) error {
125124
return nil
126125
}
127126

128-
return printRawIssuePreview(opts.IO.Out, issue, opts.IO.ColorScheme())
127+
return printRawIssuePreview(opts.IO.Out, issue)
129128
}
130129

131130
func findIssue(client *http.Client, baseRepoFn func() (ghrepo.Interface, error), selector string, loadComments bool) (*api.Issue, error) {
@@ -141,9 +140,9 @@ func findIssue(client *http.Client, baseRepoFn func() (ghrepo.Interface, error),
141140
return issue, err
142141
}
143142

144-
func printRawIssuePreview(out io.Writer, issue *api.Issue, cs *iostreams.ColorScheme) error {
143+
func printRawIssuePreview(out io.Writer, issue *api.Issue) error {
145144
assignees := issueAssigneeList(*issue)
146-
labels := shared.IssueLabelList(*issue, cs)
145+
labels := issueLabelList(issue, nil)
147146
projects := issueProjectList(*issue)
148147

149148
// Print empty strings for empty values so the number of metadata lines is consistent when
@@ -193,7 +192,7 @@ func printHumanIssuePreview(opts *ViewOptions, issue *api.Issue) error {
193192
fmt.Fprint(out, cs.Bold("Assignees: "))
194193
fmt.Fprintln(out, assignees)
195194
}
196-
if labels := shared.IssueLabelList(*issue, cs); labels != "" {
195+
if labels := issueLabelList(issue, cs); labels != "" {
197196
fmt.Fprint(out, cs.Bold("Labels: "))
198197
fmt.Fprintln(out, labels)
199198
}
@@ -278,3 +277,20 @@ func issueProjectList(issue api.Issue) string {
278277
}
279278
return list
280279
}
280+
281+
func issueLabelList(issue *api.Issue, cs *iostreams.ColorScheme) string {
282+
if len(issue.Labels.Nodes) == 0 {
283+
return ""
284+
}
285+
286+
labelNames := make([]string, len(issue.Labels.Nodes))
287+
for i, label := range issue.Labels.Nodes {
288+
if cs == nil {
289+
labelNames[i] = label.Name
290+
} else {
291+
labelNames[i] = cs.HexToRGB(label.Color, label.Name)
292+
}
293+
}
294+
295+
return strings.Join(labelNames, ", ")
296+
}

0 commit comments

Comments
 (0)