diff --git a/hack/tools/go.mod b/hack/tools/go.mod index abf655150d08..e994aadd172b 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -13,6 +13,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/pflag v1.0.5 github.com/valyala/fastjson v1.6.4 + golang.org/x/exp v0.0.0-20230724220655-d98519c11495 golang.org/x/tools v0.9.3 google.golang.org/api v0.132.0 k8s.io/api v0.27.2 @@ -112,7 +113,7 @@ require ( github.com/subosito/gotenv v1.4.2 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/mod v0.10.0 // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect golang.org/x/sys v0.10.0 // indirect diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 771ff6460037..674ad0a4d125 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -519,6 +519,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230724220655-d98519c11495 h1:zKGKw2WlGb8oPoRGqQ2PT8g2YoCN1w/YbbQjHXCdUWE= +golang.org/x/exp v0.0.0-20230724220655-d98519c11495/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -543,8 +545,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= -golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/hack/tools/release/notes.go b/hack/tools/release/notes.go index 83fa935a3938..076bf5c54553 100644 --- a/hack/tools/release/notes.go +++ b/hack/tools/release/notes.go @@ -29,10 +29,13 @@ import ( "os" "os/exec" "regexp" - "sort" "strings" "sync" "time" + "unicode" + "unicode/utf8" + + "golang.org/x/exp/slices" ) /* @@ -175,6 +178,10 @@ func getAreaLabel(merge string) (string, error) { var areaLabels []string for _, label := range pr.Labels { if area, ok := trimAreaLabel(label.Name); ok { + if userFriendlyArea, ok := userFriendlyAreas[area]; ok { + area = userFriendlyArea + } + areaLabels = append(areaLabels, area) } } @@ -183,13 +190,9 @@ func getAreaLabel(merge string) (string, error) { case 0: return missingAreaLabelPrefix, nil case 1: - area := areaLabels[0] - if userFriendlyArea, ok := userFriendlyAreas[area]; ok { - area = userFriendlyArea - } - return area, nil + return areaLabels[0], nil default: - return multipleAreaLabelsPrefix + strings.Join(areaLabels, "|") + "]", nil + return multipleAreaLabelsPrefix + strings.Join(areaLabels, "/") + "]", nil } } @@ -366,11 +369,8 @@ func run() int { } default: fmt.Println("## " + key) - sort.Slice(mergeslice, func(i int, j int) bool { - str1 := strings.ToLower(mergeslice[i]) - str2 := strings.ToLower(mergeslice[j]) - return str1 < str2 - }) + slices.SortFunc(mergeslice, lessStringCaseInsensitive) + for _, merge := range mergeslice { fmt.Println(merge) } @@ -509,3 +509,42 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) { func trimReleaseBackportMarker(title string) string { return releaseBackportMarker.ReplaceAllString(title, "${1}") } + +// lessStringCaseInsensitive implements the Less signature for strings with case insensitivity. +// It can be used with the standard library sort utils. +func lessStringCaseInsensitive(a, b string) bool { + for { + rb, sizeB := utf8.DecodeRuneInString(b) + if sizeB == 0 { + // Since b is of size 0, the number of runes + // in a is greater than or + // equal to the number of runes in b, hence + // a is not less than b. + + return false + } + + ra, sizeA := utf8.DecodeRuneInString(a) + if sizeA == 0 { + // Since b is not of size 0 and a's size is 0, + // the number of runes in b is greater than + // the number of runes in a, hence + // a is less than b. + return true + } + + rb = unicode.ToLower(rb) + ra = unicode.ToLower(ra) + + if ra != rb { + return ra < rb + } + + // Trim the runes we just compared and continue. + // This loop will continue until we either find + // a pair of runes that are different or we consume + // all the runes on one of the strings. + a = a[sizeA:] + b = b[sizeB:] + } +}