Skip to content

Commit

Permalink
Enable godot and gci linters and fix their issues
Browse files Browse the repository at this point in the history
Enabling the linters and also updating golangci-lint.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Jul 5, 2024
1 parent 63a302d commit 07fdfe8
Show file tree
Hide file tree
Showing 117 changed files with 540 additions and 455 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
version: v1.58
version: v1.59
args: --timeout=15m
11 changes: 9 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ linters:
- errname
- exportloopref
- fatcontext
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecksumtype
- goconst
- gocritic
- gocyclo
- godot
- godox
- gofmt
- gofumpt
Expand Down Expand Up @@ -100,11 +102,9 @@ linters:
# - forbidigo
# - forcetypeassert
# - funlen
# - gci
# - gochecknoglobals
# - gochecknoinits
# - gocognit
# - godot
# - inamedparam
# - interfacebloat
# - ireturn
Expand All @@ -127,6 +127,13 @@ linters:
# - wrapcheck
# - wsl
linters-settings:
gci:
sections:
- standard
- default
- prefix(k8s.io)
- prefix(sigs.k8s.io)
- localmodule
revive:
rules:
- name: unused-parameter
Expand Down
21 changes: 11 additions & 10 deletions cmd/ci-reporter/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/oauth2"

"sigs.k8s.io/release-utils/env"
)

Expand All @@ -39,7 +40,7 @@ var githubCmd = &cobra.Command{
},
}

// look for token in environment variables & create a github client
// look for token in environment variables & create a github client.
func setGithubConfig(_ *cobra.Command, _ []string) {
cfg.GithubToken = env.Default("GITHUB_TOKEN", "")
if cfg.GithubToken == "" {
Expand All @@ -54,7 +55,7 @@ func setGithubConfig(_ *cobra.Command, _ []string) {
cfg.GithubClient = githubv4.NewClient(httpClient)
}

// GithubReporterName used to identify github reporter
// GithubReporterName used to identify github reporter.
var GithubReporterName CIReporterName = "github"

func init() {
Expand All @@ -65,15 +66,15 @@ func init() {
// GithubReporter implementation
//

// GithubReporter github CIReporter implementation
// GithubReporter github CIReporter implementation.
type GithubReporter struct{}

// GetCIReporterHead implementation from CIReporter
// GetCIReporterHead implementation from CIReporter.
func (r GithubReporter) GetCIReporterHead() CIReporterInfo {
return CIReporterInfo{Name: GithubReporterName}
}

// CollectReportData implementation from CIReporter
// CollectReportData implementation from CIReporter.
func (r GithubReporter) CollectReportData(cfg *Config) ([]*CIReportRecord, error) {
// set filter configuration
denyListFilter := map[FilteredFieldName][]FilteredListVal{}
Expand Down Expand Up @@ -126,10 +127,10 @@ const ciSignalProjectBoardID = "PN_kwDOAM_34M4AAThW"
type ciSignalProjectBoardKey string

const (
// custom project board keys that get extracted via graphql
// custom project board keys that get extracted via graphql.
IssueURLKey = ciSignalProjectBoardKey("Issue URL")
PullRequestURLKey = ciSignalProjectBoardKey("PullRequest URL")
// project board column headers
// project board column headers.
TestgridBoardKey = ciSignalProjectBoardKey("Testgrid Board")
SlackDiscussionLinkKey = ciSignalProjectBoardKey("Slack discussion link")
StatusKey = ciSignalProjectBoardKey("Status")
Expand All @@ -140,7 +141,7 @@ const (

// GitHubProjectBoardFieldSettings settings for a column of a github beta project board
// --> | Testgrid Board | -> { ID: XXX, Name: Testgrid Board, ... }
// This information is required to match the settings ID to the name since table entries ref. id
// This information is required to match the settings ID to the name since table entries ref. id.
type GitHubProjectBoardFieldSettings struct {
Width int `json:"width"`
Options []struct {
Expand Down Expand Up @@ -204,12 +205,12 @@ type (
Fields map[fieldName]fieldValue
}

// Types for project board filtering
// Types for project board filtering.
FilteredFieldName string
FilteredListVal string
)

// GetGithubReportData used to request the raw report data from github
// GetGithubReportData used to request the raw report data from github.
func GetGithubReportData(cfg Config, denyListFieldFilter, allowListFieldFilter map[FilteredFieldName][]FilteredListVal) ([]*TransformedProjectBoardItem, error) {
// lookup project board information
var queryCiSignalProjectBoard ciSignalProjectBoardGraphQLQuery
Expand Down
26 changes: 13 additions & 13 deletions cmd/ci-reporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Execute() error {
return rootCmd.Execute()
}

// Config configuration that is getting injected into ci-signal report functions
// Config configuration that is getting injected into ci-signal report functions.
type Config struct {
GithubClient *githubv4.Client
GithubToken string
Expand All @@ -67,7 +67,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&cfg.Filepath, "file", "f", "", "Specify a filepath to write the report to a file")
}

// RunReport used to execute
// RunReport used to execute.
func RunReport(cfg *Config, reporters *CIReporters) error {
go func() {
s := spin.New()
Expand Down Expand Up @@ -95,29 +95,29 @@ func RunReport(cfg *Config, reporters *CIReporters) error {
// Generic reporter types
//

// CIReportDataFields used so specify multiple reports
// CIReportDataFields used so specify multiple reports.
type CIReportDataFields []CIReportData

// Marshal used to marshal CIReports into bytes
// Marshal used to marshal CIReports into bytes.
func (d *CIReportDataFields) Marshal() ([]byte, error) {
return json.Marshal(d)
}

// CIReportData format of the ci report data that is being generated
// CIReportData format of the ci report data that is being generated.
type CIReportData struct {
Info CIReporterInfo `json:"info"`
Records []*CIReportRecord `json:"records"`
}

// CIReporterInfo meta information about a reporter implementation
// CIReporterInfo meta information about a reporter implementation.
type CIReporterInfo struct {
Name CIReporterName `json:"name"`
}

// CIReporterName identifying name of a reporter
// CIReporterName identifying name of a reporter.
type CIReporterName string

// CIReportRecord generic report data format
// CIReportRecord generic report data format.
type CIReportRecord struct {
Title string `json:"title"`
TestgridBoard string `json:"testgrid_board"`
Expand All @@ -132,21 +132,21 @@ type CIReportRecord struct {
// Generic CIReporter interface and related functions
//

// CIReporter interface that is used to implement a new reporter
// CIReporter interface that is used to implement a new reporter.
type CIReporter interface {
// GetCIReporterHead sets meta information which is used to differentiate reporters
GetCIReporterHead() CIReporterInfo
// CollectReportData is used to request / collect all report data
CollectReportData(*Config) ([]*CIReportRecord, error)
}

// CIReporters used to specify multiple CIReports, type gets extended by helper functions to collect and visualize report data
// CIReporters used to specify multiple CIReports, type gets extended by helper functions to collect and visualize report data.
type CIReporters []CIReporter

// AllImplementedReporters list of implemented reports that are used to generate ci-reports
// AllImplementedReporters list of implemented reports that are used to generate ci-reports.
var AllImplementedReporters = CIReporters{GithubReporter{}, TestgridReporter{}}

// SearchReporter used to filter a implemented reporter by name
// SearchReporter used to filter a implemented reporter by name.
func SearchReporter(reporterName string) (CIReporter, error) {
var reporter CIReporter
reporterFound := false
Expand All @@ -163,7 +163,7 @@ func SearchReporter(reporterName string) (CIReporter, error) {
return reporter, nil
}

// CollectReportDataFromReporters used to collect data for multiple reporters
// CollectReportDataFromReporters used to collect data for multiple reporters.
func (r *CIReporters) CollectReportDataFromReporters(cfg *Config) (*CIReportDataFields, error) {
collectedReports := CIReportDataFields{}
for i := range *r {
Expand Down
11 changes: 6 additions & 5 deletions cmd/ci-reporter/cmd/testgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"k8s.io/release/pkg/testgrid"
)

Expand All @@ -36,23 +37,23 @@ var testgridCmd = &cobra.Command{
},
}

// TestgridReporterName used to identify github reporter
// TestgridReporterName used to identify github reporter.
var TestgridReporterName CIReporterName = "testgrid"

func init() {
testgridCmd.Flags().StringVarP(&cfg.ReleaseVersion, "release-version", "v", "", "Specify a Kubernetes release versions like '1.22' which will populate the report additionally")
rootCmd.AddCommand(testgridCmd)
}

// TestgridReporter github CIReporter implementation
// TestgridReporter github CIReporter implementation.
type TestgridReporter struct{}

// GetCIReporterHead implementation from CIReporter
// GetCIReporterHead implementation from CIReporter.
func (r TestgridReporter) GetCIReporterHead() CIReporterInfo {
return CIReporterInfo{Name: TestgridReporterName}
}

// CollectReportData implementation from CIReporter
// CollectReportData implementation from CIReporter.
func (r TestgridReporter) CollectReportData(cfg *Config) ([]*CIReportRecord, error) {
testgridReportData, err := GetTestgridReportData(*cfg)
if err != nil {
Expand All @@ -78,7 +79,7 @@ func (r TestgridReporter) CollectReportData(cfg *Config) ([]*CIReportRecord, err
return records, nil
}

// GetTestgridReportData used to request the raw report data from testgrid
// GetTestgridReportData used to request the raw report data from testgrid.
func GetTestgridReportData(cfg Config) (testgrid.DashboardData, error) {
testgridDashboardNames := []testgrid.DashboardName{"sig-release-master-blocking", "sig-release-master-informing"}
if cfg.ReleaseVersion != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/ci-reporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"

"github.com/sirupsen/logrus"

"k8s.io/release/cmd/ci-reporter/cmd"
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/gcbuilder/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"k8s.io/release/pkg/gcp/build"
"sigs.k8s.io/release-utils/log"

"k8s.io/release/pkg/gcp/build"
)

// rootCmd represents the base command when called without any subcommands
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "gcbuilder",
Short: "gcbuilder",
Expand Down
2 changes: 1 addition & 1 deletion cmd/krel/cmd/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type announceOptions struct {

var announceOpts = &announceOptions{}

// announceCmd represents the subcommand for `krel announce`
// announceCmd represents the subcommand for `krel announce`.
var announceCmd = &cobra.Command{
Use: "announce",
Short: "Build and announce Kubernetes releases",
Expand Down
6 changes: 3 additions & 3 deletions cmd/krel/cmd/announce_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const releaseAnnouncementMsg = `Kubernetes Community,
<p><br><br>Published by your <a href=hhttps://git.k8s.io/website/content/en/releases/release-managers.md href target="_blank">Kubernetes Release Managers</a>.</p>
`

// buildAnnounceCmd represents the subcommand for `krel announce build`
// buildAnnounceCmd represents the subcommand for `krel announce build`.
var buildAnnounceCmd = &cobra.Command{
Use: "build",
Short: "Build the announcement Kubernetes releases",
Expand Down Expand Up @@ -164,7 +164,7 @@ func init() {
announceCmd.AddCommand(buildAnnounceCmd)
}

// runBuildBranchAnnounce build the announcement file when creating the Kubernetes release branch
// runBuildBranchAnnounce build the announcement file when creating the Kubernetes release branch.
func runBuildBranchAnnounce(opts *buildBranchAnnounceOptions, buildOpts *buildAnnounceOptions) error {
logrus.Info("Building release announcement for branch creation")

Expand All @@ -183,7 +183,7 @@ func runBuildBranchAnnounce(opts *buildBranchAnnounceOptions, buildOpts *buildAn
return buildOpts.saveAnnouncement(announcementSubject, announcement)
}

// runBuildReleaseAnnounce build the announcement file when creating a new Kubernetes release
// runBuildReleaseAnnounce build the announcement file when creating a new Kubernetes release.
func runBuildReleaseAnnounce(opts *buildReleaseAnnounceOptions, buildOpts *buildAnnounceOptions, announceOpts *announceOptions) error {
if err := announceOpts.Validate(); err != nil {
return fmt.Errorf("validating announcement send options: %w", err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/krel/cmd/announce_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"k8s.io/release/pkg/mail"
"k8s.io/release/pkg/release"
"sigs.k8s.io/release-utils/env"
"sigs.k8s.io/release-utils/http"
"sigs.k8s.io/release-utils/util"

"k8s.io/release/pkg/mail"
"k8s.io/release/pkg/release"
)

const (
Expand All @@ -36,7 +37,7 @@ const (
emailFlag = "email"
)

// announceCmd represents the subcommand for `krel announce`
// announceCmd represents the subcommand for `krel announce`.
var sendAnnounceCmd = &cobra.Command{
Use: "send",
Short: "Announce Kubernetes releases",
Expand Down
3 changes: 2 additions & 1 deletion cmd/krel/cmd/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (

"github.com/stretchr/testify/require"

"k8s.io/release/pkg/changelog"
"sigs.k8s.io/release-sdk/git"

"k8s.io/release/pkg/changelog"
)

func (s *sut) getChangelogOptions(tag string) *changelog.Options {
Expand Down
Loading

0 comments on commit 07fdfe8

Please sign in to comment.