refactor(discussion view): use slices package for label sorting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Babak K. Shandiz 2026-04-24 22:19:59 +01:00
parent 6bd96abd6a
commit 75b71505c8
No known key found for this signature in database
GPG key ID: 9472CAEFF56C742E

View file

@ -3,7 +3,7 @@ package view
import (
"fmt"
"io"
"sort"
"slices"
"strings"
"time"
@ -331,12 +331,13 @@ func labelList(labels []client.DiscussionLabel, cs *iostreams.ColorScheme) strin
return ""
}
sort.SliceStable(labels, func(i, j int) bool {
return strings.ToLower(labels[i].Name) < strings.ToLower(labels[j].Name)
sortedLabels := slices.Clone(labels)
slices.SortStableFunc(sortedLabels, func(i, j client.DiscussionLabel) int {
return strings.Compare(i.Name, j.Name)
})
names := make([]string, len(labels))
for i, l := range labels {
names := make([]string, len(sortedLabels))
for i, l := range sortedLabels {
if cs == nil {
names[i] = l.Name
} else {