diff --git a/cmd/ci-reporter/cmd/github.go b/cmd/ci-reporter/cmd/github.go index 94b0a01ef68..fb840e2bd96 100644 --- a/cmd/ci-reporter/cmd/github.go +++ b/cmd/ci-reporter/cmd/github.go @@ -220,7 +220,7 @@ func GetGithubReportData(ctx context.Context, cfg Config, denyListFieldFilter, a // lookup project board information var queryCiSignalProjectBoard ciSignalProjectBoardGraphQLQuery - variablesProjectBoardFields := map[string]interface{}{ + variablesProjectBoardFields := map[string]any{ "projectBoardID": githubv4.ID(ciSignalProjectBoardID), } if err := cfg.GithubClient.Query(ctx, &queryCiSignalProjectBoard, variablesProjectBoardFields); err != nil { diff --git a/cmd/krel/cmd/release_notes.go b/cmd/krel/cmd/release_notes.go index 9f3c3dc622b..3fcacf08c57 100644 --- a/cmd/krel/cmd/release_notes.go +++ b/cmd/krel/cmd/release_notes.go @@ -1312,7 +1312,7 @@ func fixReleaseNotes(workDir string, releaseNotes *notes.ReleaseNotes) error { } // Check two values and print a prefix if they are different. -func pointIfChanged(label string, var1, var2 interface{}) string { +func pointIfChanged(label string, var1, var2 any) string { changed := false // Check if alues are string var1String, ok1 := var1.(string) diff --git a/cmd/krel/cmd/sign_blobs.go b/cmd/krel/cmd/sign_blobs.go index ec38acd0744..0501043829f 100644 --- a/cmd/krel/cmd/sign_blobs.go +++ b/cmd/krel/cmd/sign_blobs.go @@ -169,7 +169,7 @@ func runSignBlobs(signOpts *signOptions, signBlobOpts *signBlobOptions, args []s gcsClient := object.NewGCS() - for _, file := range strings.Fields(output) { + for file := range strings.FieldsSeq(output) { if strings.HasSuffix(file, ".sha256") || strings.HasSuffix(file, ".sha512") || strings.HasSuffix(file, ":") || strings.HasSuffix(file, ".docker_tag") || strings.Contains(file, "SHA256SUMS") || strings.Contains(file, "SHA512SUMS") || diff --git a/cmd/krel/cmd/testgrid.go b/cmd/krel/cmd/testgrid.go index e76179eefe9..f8708040fba 100644 --- a/cmd/krel/cmd/testgrid.go +++ b/cmd/krel/cmd/testgrid.go @@ -121,7 +121,7 @@ func runTestGridShot(opts *TestGridOptions) error { return fmt.Errorf("unable to retrieve release announcement form url: %s: %w", testGridDashboard, err) } - var result map[string]interface{} + var result map[string]any err = json.Unmarshal(content, &result) if err != nil { diff --git a/cmd/publish-release/cmd/github.go b/cmd/publish-release/cmd/github.go index c9ff98f8411..b29a1ae14ae 100644 --- a/cmd/publish-release/cmd/github.go +++ b/cmd/publish-release/cmd/github.go @@ -192,8 +192,8 @@ func getAssetsFromStrings(assetStrings []string) ([]sbom.Asset, error) { for _, s := range assetStrings { isBucket = false - if strings.HasPrefix(s, "gs:") { - s = strings.TrimPrefix(s, "gs:") + if after, ok := strings.CutPrefix(s, "gs:"); ok { + s = after isBucket = true } diff --git a/cmd/release-notes/check.go b/cmd/release-notes/check.go index 927eb122ca4..6087048028b 100644 --- a/cmd/release-notes/check.go +++ b/cmd/release-notes/check.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "os" + "slices" "github.com/spf13/cobra" @@ -53,12 +54,8 @@ func (o *checkPROptions) ValidateAndFinish() error { lenErr = errors.New("no pull requests numbers specified") } - for _, n := range o.PullRequests { - if n == 0 { - prNrErr = errors.New("invalid pull request number (must be an integer larger than 0)") - - break - } + if slices.Contains(o.PullRequests, 0) { + prNrErr = errors.New("invalid pull request number (must be an integer larger than 0)") } if o.GithubOrg == "" { diff --git a/cmd/schedule-builder/cmd/markdown.go b/cmd/schedule-builder/cmd/markdown.go index ba5090c14e3..a2de78a937d 100644 --- a/cmd/schedule-builder/cmd/markdown.go +++ b/cmd/schedule-builder/cmd/markdown.go @@ -21,6 +21,7 @@ import ( "embed" "fmt" "os" + "slices" "strings" "text/template" // NOLINT // Mark text/template as not to be checked for producing yaml. "time" @@ -156,7 +157,7 @@ func removeDotfromVersion(a string) string { // process applies the data structure 'vars' onto an already // parsed template 't', and returns the resulting string. -func process(t *template.Template, vars interface{}) string { +func process(t *template.Template, vars any) string { var tmplBytes bytes.Buffer err := t.Execute(&tmplBytes, vars) @@ -167,7 +168,7 @@ func process(t *template.Template, vars interface{}) string { return tmplBytes.String() } -func processFile(fileName string, vars interface{}) string { +func processFile(fileName string, vars any) string { tmpl, err := template.ParseFS(tpls, fileName) if err != nil { panic(err) @@ -306,12 +307,8 @@ func updatePatchSchedule(refTime time.Time, schedule PatchSchedule, eolBranches for i, sched := range schedule.Schedules { appendItem := true - for _, k := range removeSchedules { - if i == k { - appendItem = false - - break - } + if slices.Contains(removeSchedules, i) { + appendItem = false } if appendItem { diff --git a/pkg/changelog/impl.go b/pkg/changelog/impl.go index 079635a0098..99c82c2d798 100644 --- a/pkg/changelog/impl.go +++ b/pkg/changelog/impl.go @@ -83,7 +83,7 @@ type impl interface { ) error ParseHTMLTemplate(text string) (*template.Template, error) TemplateExecute( - tpl *template.Template, wr io.Writer, data interface{}, + tpl *template.Template, wr io.Writer, data any, ) error Abs(path string) (string, error) @@ -198,7 +198,7 @@ func (*defaultImpl) ParseHTMLTemplate(text string) (*template.Template, error) { } func (*defaultImpl) TemplateExecute( - tpl *template.Template, wr io.Writer, data interface{}, + tpl *template.Template, wr io.Writer, data any, ) error { return tpl.Execute(wr, data) } diff --git a/pkg/consts/main.go b/pkg/consts/main.go index ad497bb72e6..4d3a734c48d 100644 --- a/pkg/consts/main.go +++ b/pkg/consts/main.go @@ -16,7 +16,11 @@ limitations under the License. package consts -import "github.com/sirupsen/logrus" +import ( + "slices" + + "github.com/sirupsen/logrus" +) const ( PackageCRITools string = "cri-tools" @@ -72,15 +76,7 @@ func IsSupported(field string, input, expected []string) bool { notSupported := []string{} for _, i := range input { - supported := false - - for _, j := range expected { - if i == j { - supported = true - - break - } - } + supported := slices.Contains(expected, i) if !supported { notSupported = append(notSupported, i) diff --git a/pkg/cve/cve.go b/pkg/cve/cve.go index 54cb7af08f8..04683fe12b5 100644 --- a/pkg/cve/cve.go +++ b/pkg/cve/cve.go @@ -39,36 +39,36 @@ type CVE struct { // ReadRawInterface populates the CVE data struct from the raw array // as returned by the YAML parser. -func (cve *CVE) ReadRawInterface(cvedata interface{}) error { - if val, ok := cvedata.(map[interface{}]interface{})["id"].(string); ok { +func (cve *CVE) ReadRawInterface(cvedata any) error { + if val, ok := cvedata.(map[any]any)["id"].(string); ok { cve.ID = val } - if val, ok := cvedata.(map[interface{}]interface{})["title"].(string); ok { + if val, ok := cvedata.(map[any]any)["title"].(string); ok { cve.Title = val } - if val, ok := cvedata.(map[interface{}]interface{})["issue"].(string); ok { + if val, ok := cvedata.(map[any]any)["issue"].(string); ok { cve.TrackingIssue = val } - if val, ok := cvedata.(map[interface{}]interface{})["vector"].(string); ok { + if val, ok := cvedata.(map[any]any)["vector"].(string); ok { cve.CVSSVector = val } - if val, ok := cvedata.(map[interface{}]interface{})["score"].(float64); ok { + if val, ok := cvedata.(map[any]any)["score"].(float64); ok { cve.CVSSScore = float32(val) } - if val, ok := cvedata.(map[interface{}]interface{})["rating"].(string); ok { + if val, ok := cvedata.(map[any]any)["rating"].(string); ok { cve.CVSSRating = val } - if val, ok := cvedata.(map[interface{}]interface{})["description"].(string); ok { + if val, ok := cvedata.(map[any]any)["description"].(string); ok { cve.Description = val } // Linked PRs is a list of the PR IDs - if val, ok := cvedata.(map[interface{}]interface{})["linkedPRs"].([]interface{}); ok { + if val, ok := cvedata.(map[any]any)["linkedPRs"].([]any); ok { cve.LinkedPRs = []int{} for _, prid := range val { diff --git a/pkg/gcp/build/build.go b/pkg/gcp/build/build.go index 06156481fe1..4bb0dcbe15c 100644 --- a/pkg/gcp/build/build.go +++ b/pkg/gcp/build/build.go @@ -19,6 +19,7 @@ package build import ( "errors" "fmt" + maps0 "maps" "os" "path" "path/filepath" @@ -384,9 +385,7 @@ func mergeMaps(maps ...map[string]string) map[string]string { out := map[string]string{} for _, m := range maps { - for k, v := range m { - out[k] = v - } + maps0.Copy(out, m) } return out diff --git a/pkg/notes/document/document.go b/pkg/notes/document/document.go index 53252096138..25dfc773a3e 100644 --- a/pkg/notes/document/document.go +++ b/pkg/notes/document/document.go @@ -430,8 +430,8 @@ func (d *Document) template(templateSpec string) (string, error) { templatePathOrOnline := strings.TrimPrefix(templateSpec, options.GoTemplatePrefix) // Check for inline template - if strings.HasPrefix(templatePathOrOnline, options.GoTemplatePrefixInline) { - return strings.TrimPrefix(templatePathOrOnline, options.GoTemplatePrefixInline), nil + if after, ok := strings.CutPrefix(templatePathOrOnline, options.GoTemplatePrefixInline); ok { + return after, nil } // Assume file-based template diff --git a/pkg/notes/document/document_test.go b/pkg/notes/document/document_test.go index 7df52803852..da5297e0929 100644 --- a/pkg/notes/document/document_test.go +++ b/pkg/notes/document/document_test.go @@ -283,7 +283,7 @@ func repoTagTarball(t *testing.T, path, repoTag string) { manifestJSONPath := filepath.Join(filepath.Dir(path), manifestJSON) require.NoError(t, os.WriteFile( manifestJSONPath, - []byte(fmt.Sprintf(`[{"RepoTags": [%q]}]`, repoTag)), + fmt.Appendf(nil, `[{"RepoTags": [%q]}]`, repoTag), os.FileMode(0o644), )) require.NoError(t, command.NewWithWorkDir(filepath.Dir(path), diff --git a/pkg/notes/notes.go b/pkg/notes/notes.go index f598d586e3e..c48032a17e5 100644 --- a/pkg/notes/notes.go +++ b/pkg/notes/notes.go @@ -24,10 +24,12 @@ import ( "encoding/hex" "errors" "fmt" + "maps" "math/big" "net/http" "net/url" "regexp" + "slices" "sort" "strconv" "strings" @@ -517,7 +519,7 @@ func (g *Gatherer) ReleaseNoteFromCommit(result *Result) (*ReleaseNote, error) { author := pr.GetUser().GetLogin() authorURL := pr.GetUser().GetHTMLURL() prURL := pr.GetHTMLURL() - isFeature := hasString(labelsWithPrefix(pr, "kind"), "feature") + isFeature := slices.Contains(labelsWithPrefix(pr, "kind"), "feature") sigLabels := labelsWithPrefix(pr, "sig") noteSuffix := prettifySIGList(sigLabels) @@ -1058,16 +1060,6 @@ func unlist(note string) string { return res.String() } -func hasString(a []string, x string) bool { - for _, n := range a { - if x == n { - return true - } - } - - return false -} - // canWaitAndRetry retruen true if the gatherer hit the GitHub API secondary rate limit. func canWaitAndRetry(r *gogithub.Response, err error) bool { // If we hit the secondary rate limit... @@ -1349,9 +1341,7 @@ func (rn *ReleaseNote) ApplyMap(noteMap *ReleaseNotesMap, markdownLinks bool) er rn.DataFields = make(map[string]ReleaseNotesDataField) } - for key, df := range noteMap.DataFields { - rn.DataFields[key] = df - } + maps.Copy(rn.DataFields, noteMap.DataFields) // If parts of the markup where modified, change them // TODO: Spin this to sep function diff --git a/pkg/notes/notes_map.go b/pkg/notes/notes_map.go index 109f3d511a1..a7b69731eb7 100644 --- a/pkg/notes/notes_map.go +++ b/pkg/notes/notes_map.go @@ -127,7 +127,7 @@ type ReleaseNotesMap struct { } // ReleaseNotesDataField extra data added to a release note. -type ReleaseNotesDataField interface{} +type ReleaseNotesDataField any // DirectoryMapProvider is a provider that gets maps from a directory. type DirectoryMapProvider struct { diff --git a/pkg/notes/notes_test.go b/pkg/notes/notes_test.go index a802931c379..e1941e57ee0 100644 --- a/pkg/notes/notes_test.go +++ b/pkg/notes/notes_test.go @@ -440,7 +440,7 @@ func testApplyMapHelper(t *testing.T, testDir string, makeNewNote func() *Releas require.True(t, ok, "found map test without testcase") // Read the property this test case checks - property, ok := testcase.(map[interface{}]interface{})["property"].(string) + property, ok := testcase.(map[any]any)["property"].(string) require.True(t, ok) require.NotEmpty(t, property) require.NotEmpty(t, property, "testcase found without property") @@ -451,10 +451,10 @@ func testApplyMapHelper(t *testing.T, testDir string, makeNewNote func() *Releas originalVal := reflect.Indirect(reflectedOriginalNote).FieldByName(property) // Factor the test name - testName, ok := testcase.(map[interface{}]interface{})["name"].(string) + testName, ok := testcase.(map[any]any)["name"].(string) require.True(t, ok) - switch expectedValue := testcase.(map[interface{}]interface{})["expected"].(type) { + switch expectedValue := testcase.(map[any]any)["expected"].(type) { case bool: actualVal := reflect.Indirect(reflectedNote).FieldByName(property).Bool() require.Equalf(t, expectedValue, actualVal, "Failed %s", testName) @@ -464,7 +464,7 @@ func testApplyMapHelper(t *testing.T, testDir string, makeNewNote func() *Releas actualVal := reflect.Indirect(reflectedNote).FieldByName(property).String() require.Equalf(t, expectedValue, actualVal, "Failed %s", testName) require.NotEqualf(t, expectedValue, originalVal.String(), "Failed %s", testName) - case []interface{}: + case []any: // Handle string slice cases actualVal := reflect.Indirect(reflectedNote).FieldByName(property) actualSlice := make([]string, 0) diff --git a/pkg/notes/notes_v2.go b/pkg/notes/notes_v2.go index 516e6f93b92..5d4e394c439 100644 --- a/pkg/notes/notes_v2.go +++ b/pkg/notes/notes_v2.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "os" + "slices" "strings" "sync" "time" @@ -176,7 +177,7 @@ func (g *Gatherer) buildReleaseNote(pair *commitPrPair) (*ReleaseNote, error) { author := pr.GetUser().GetLogin() authorURL := pr.GetUser().GetHTMLURL() prURL := pr.GetHTMLURL() - isFeature := hasString(labelsWithPrefix(pr, "kind"), "feature") + isFeature := slices.Contains(labelsWithPrefix(pr, "kind"), "feature") sigLabels := labelsWithPrefix(pr, "sig") noteSuffix := prettifySIGList(sigLabels) diff --git a/pkg/release/publish.go b/pkg/release/publish.go index 3ca8dc539fb..17fd5c875db 100644 --- a/pkg/release/publish.go +++ b/pkg/release/publish.go @@ -69,8 +69,8 @@ type publisherClient interface { TempDir(dir, pattern string) (name string, err error) CopyToLocal(remote, local string) error ReadFile(filename string) ([]byte, error) - Unmarshal(data []byte, v interface{}) error - Marshal(v interface{}) ([]byte, error) + Unmarshal(data []byte, v any) error + Marshal(v any) ([]byte, error) TempFile(dir, pattern string) (f *os.File, err error) CopyToRemote(local, remote string) error } @@ -133,11 +133,11 @@ func (*defaultPublisher) ReadFile(filename string) ([]byte, error) { return os.ReadFile(filename) } -func (*defaultPublisher) Unmarshal(data []byte, v interface{}) error { +func (*defaultPublisher) Unmarshal(data []byte, v any) error { return json.Unmarshal(data, v) } -func (*defaultPublisher) Marshal(v interface{}) ([]byte, error) { +func (*defaultPublisher) Marshal(v any) ([]byte, error) { return json.Marshal(v) } @@ -421,8 +421,8 @@ func (p *Publisher) PublishToGcs( func FixPublicReleaseNotesURL(gcsPath string) string { const prefix = "gs://" + ProductionBucket - if strings.HasPrefix(gcsPath, prefix) { - gcsPath = ProductionBucketURL + strings.TrimPrefix(gcsPath, prefix) + if after, ok := strings.CutPrefix(gcsPath, prefix); ok { + gcsPath = ProductionBucketURL + after } return gcsPath diff --git a/pkg/release/push_git_objects.go b/pkg/release/push_git_objects.go index 686cf718cb3..a4e2519dac7 100644 --- a/pkg/release/push_git_objects.go +++ b/pkg/release/push_git_objects.go @@ -19,6 +19,7 @@ package release import ( "errors" "fmt" + "slices" "strings" "github.com/blang/semver/v4" @@ -157,15 +158,7 @@ func (gp *GitObjectPusher) PushTag(newTag string) (err error) { } // verify that the tag exists locally before trying to push - tagExists := false - - for _, tag := range currentTags { - if tag == newTag { - tagExists = true - - break - } - } + tagExists := slices.Contains(currentTags, newTag) if !tagExists { return fmt.Errorf("unable to push tag %s, it does not exist in the repo yet", newTag) diff --git a/pkg/testgrid/testgrid-scraper.go b/pkg/testgrid/testgrid-scraper.go index 055c30c7939..3ebfc97f87b 100644 --- a/pkg/testgrid/testgrid-scraper.go +++ b/pkg/testgrid/testgrid-scraper.go @@ -38,7 +38,7 @@ type SummaryLookup struct { // This function implements a concurrency pattern to send http requests concurrently. func ReqTestgridDashboardSummaries(ctx context.Context, dashboardNames []DashboardName) (DashboardData, error) { // Worker - requestData := func(done <-chan interface{}, dashboardNames ...DashboardName) <-chan SummaryLookup { + requestData := func(done <-chan any, dashboardNames ...DashboardName) <-chan SummaryLookup { summaryLookups := make(chan SummaryLookup) go func() { @@ -61,7 +61,7 @@ func ReqTestgridDashboardSummaries(ctx context.Context, dashboardNames []Dashboa return summaryLookups } - done := make(chan interface{}) + done := make(chan any) defer close(done) dashboardData := DashboardData{} @@ -196,17 +196,17 @@ func (j *JobSummary) GetJobURL(jobName JobName) string { // Test contains information about tests if the status if the Job is failing. type Test struct { - DisplayName string `json:"display_name"` - TestName string `json:"test_name"` - FailCount int64 `json:"fail_count"` - FailTimestamp int64 `json:"fail_timestamp"` - PassTimestamp int64 `json:"pass_timestamp"` - BuildLink string `json:"build_link"` - BuildURLText string `json:"build_url_text"` - BuildLinkText string `json:"build_link_text"` - FailureMessage string `json:"failure_message"` - LinkedBugs []interface{} `json:"linked_bugs"` - FailTestLink string `json:"fail_test_link"` + DisplayName string `json:"display_name"` + TestName string `json:"test_name"` + FailCount int64 `json:"fail_count"` + FailTimestamp int64 `json:"fail_timestamp"` + PassTimestamp int64 `json:"pass_timestamp"` + BuildLink string `json:"build_link"` + BuildURLText string `json:"build_url_text"` + BuildLinkText string `json:"build_link_text"` + FailureMessage string `json:"failure_message"` + LinkedBugs []any `json:"linked_bugs"` + FailTestLink string `json:"fail_test_link"` } // DashboardName type for the testgrid dashboard (like sig-release-master-blocking).