Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/ci-reporter/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/krel/cmd/release_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/krel/cmd/sign_blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down
2 changes: 1 addition & 1 deletion cmd/krel/cmd/testgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/publish-release/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 3 additions & 6 deletions cmd/release-notes/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"os"
"slices"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -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 == "" {
Expand Down
13 changes: 5 additions & 8 deletions cmd/schedule-builder/cmd/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/changelog/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 6 additions & 10 deletions pkg/consts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions pkg/cve/cve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/gcp/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package build
import (
"errors"
"fmt"
maps0 "maps"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/notes/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/notes/document/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
18 changes: 4 additions & 14 deletions pkg/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
"encoding/hex"
"errors"
"fmt"
"maps"
"math/big"
"net/http"
"net/url"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/notes/notes_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/notes/notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/notes/notes_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions pkg/release/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
Loading