Skip to content

Commit

Permalink
addressing linter comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nzin committed Aug 26, 2023
1 parent 6c4c663 commit 77bd344
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 84 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rebuild: gen build
build:
@GO111MODULE=on go build -o goliac ./cmd/goliac

test:
test: verifiers
@GO111MODULE=on go test -race -covermode=atomic -coverprofile=coverage.txt ./internal/...
@go tool cover -html coverage.txt -o cover.html

Expand All @@ -28,7 +28,7 @@ verifiers: verify_lint verify_swagger

verify_lint:
@echo "Running $@"
@golangci-lint run -D errcheck ./pkg/...
@golangci-lint run -D errcheck ./internal/...

verify_swagger:
@echo "Running $@"
Expand All @@ -37,8 +37,8 @@ verify_swagger:
swagger: verify_swagger
@echo "Regenerate swagger files"
@rm -f /tmp/configure_goliac.go
@cp ./internal/swagger_gen/restapi/configure_goliac.go /tmp/configure_goliac.go 2>/dev/null || :
@rm -rf ./internal/swagger_gen
@mkdir ./internal/swagger_gen
@swagger generate server -t ./internal/swagger_gen -f ./docs/api_docs/bundle.yaml
@cp /tmp/configure_goliac.go ./internal/swagger_gen/restapi/configure_goliac.go 2>/dev/null || :
@cp ./swagger_gen/restapi/configure_goliac.go /tmp/configure_goliac.go 2>/dev/null || :
@rm -rf ./swagger_gen
@mkdir ./swagger_gen
@swagger generate server -t ./swagger_gen -f ./docs/api_docs/bundle.yaml
@cp /tmp/configure_goliac.go ./swagger_gen/restapi/configure_goliac.go 2>/dev/null || :
4 changes: 2 additions & 2 deletions internal/entity/entity_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func CompareRulesetParameters(ruletype string, left RuleSetParameters, right Rul
}
return true
case "required_status_checks":
if res, _, _ := StringArrayEquivalent(left.RequiredStatusChecks, right.RequiredStatusChecks); res == false {
if res, _, _ := StringArrayEquivalent(left.RequiredStatusChecks, right.RequiredStatusChecks); !res {
return false
}
if left.StrictRequiredStatusChecksPolicy != right.StrictRequiredStatusChecksPolicy {
Expand Down Expand Up @@ -111,7 +111,7 @@ func ReadRuleSetDirectory(fs afero.Fs, dirname string) (map[string]*RuleSet, []e
errors = append(errors, err)
return rulesets, errors, warning
}
if exist == false {
if !exist {
return rulesets, errors, warning
}

Expand Down
6 changes: 3 additions & 3 deletions internal/entity/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ReadRepositories(fs afero.Fs, archivedDirname string, teamDirname string, t
errors = append(errors, err)
return repos, errors, warning
}
if exist == true {
if exist {
entries, err := afero.ReadDir(fs, archivedDirname)
if err != nil {
errors = append(errors, err)
Expand Down Expand Up @@ -91,7 +91,7 @@ func ReadRepositories(fs afero.Fs, archivedDirname string, teamDirname string, t
errors = append(errors, err)
return repos, errors, warning
}
if exist == false {
if !exist {
return repos, errors, warning
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func (r *Repository) Validate(filename string, teams map[string]*Team, externalU
}

if archived != r.Data.IsArchived {
if archived == true {
if archived {
return fmt.Errorf("invalid archived: %s is in the archived directory without the `archived` boolean", filename)
} else {
return fmt.Errorf("invalid archived: %s has `archived` set to true, but isn't in the archived directory", filename)
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ReadTeamDirectory(fs afero.Fs, dirname string, users map[string]*User) (map
errors = append(errors, err)
return teams, errors, warning
}
if exist == false {
if !exist {
return teams, errors, warning
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func ReadAndAdjustTeamDirectory(fs afero.Fs, dirname string, users map[string]*U
if err != nil {
return teamschanged, err
}
if exist == false {
if !exist {
return teamschanged, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/entity/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ReadUserDirectory(fs afero.Fs, dirname string) (map[string]*User, []error,
errors = append(errors, err)
return users, errors, warning
}
if exist == false {
if !exist {
return users, errors, warning
}

Expand Down
4 changes: 2 additions & 2 deletions internal/entity/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ metadata:
name: user1
data:
githubID: github1
`), 644)
`), 0644)
assert.Nil(t, err)
users, errs, warns := ReadUserDirectory(fs, "users")
assert.Equal(t, len(errs), 0)
Expand Down Expand Up @@ -73,7 +73,7 @@ apiVersion: v1
kind: User
data:
githubID: github1
`), 644)
`), 0644)
assert.Nil(t, err)
_, errs, warns := ReadUserDirectory(fs, "users")
assert.Equal(t, len(errs), 1)
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func StringArrayEquivalent(a, b []string) (bool, []string, []string) {
result = false
}

for r, _ := range rights {
for r := range rights {
if _, ok := lefts[r]; !ok {
leftOnly = append(leftOnly, r)
result = false
}
}
for l, _ := range lefts {
for l := range lefts {
if _, ok := rights[l]; !ok {
rightOnly = append(rightOnly, l)
result = false
Expand Down
8 changes: 4 additions & 4 deletions internal/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -82,7 +82,7 @@ func (t *AuthorizedTransport) RoundTrip(req *http.Request) (*http.Response, erro
* )
*/
func NewGitHubClientImpl(githubServer, organizationName string, appID int, privateKeyFile string) (GitHubClient, error) {
privateKey, err := ioutil.ReadFile(privateKeyFile)
privateKey, err := os.ReadFile(privateKeyFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func (client *GitHubClientImpl) QueryGraphQLAPI(query string, variables map[stri
// Retry the request.
return client.QueryGraphQLAPI(query, variables)
} else {
responseBody, err := ioutil.ReadAll(resp.Body)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func (client *GitHubClientImpl) CallRestAPI(endpoint, method string, body map[st
// Retry the request.
return client.CallRestAPI(endpoint, method, body)
} else {
responseBody, err := ioutil.ReadAll(resp.Body)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
12 changes: 5 additions & 7 deletions internal/goliac.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"strings"
gosync "sync"

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/entity"
Expand Down Expand Up @@ -42,7 +41,6 @@ type GoliacImpl struct {
remote sync.GoliacRemoteExecutor
githubClient github.GitHubClient
repoconfig *config.RepositoryConfig
applyMutex gosync.Mutex
}

func NewGoliacImpl() (Goliac, error) {
Expand Down Expand Up @@ -70,8 +68,8 @@ func NewGoliacImpl() (Goliac, error) {
}

func (g *GoliacImpl) LoadAndValidateGoliacOrganization(repositoryUrl, branch string) error {
errs := []error{}
warns := []entity.Warning{}
var errs []error
var warns []entity.Warning
if strings.HasPrefix(repositoryUrl, "https://") || strings.HasPrefix(repositoryUrl, "git@") {
accessToken, err := g.githubClient.GetAccessToken()
if err != nil {
Expand All @@ -98,7 +96,7 @@ func (g *GoliacImpl) LoadAndValidateGoliacOrganization(repositoryUrl, branch str
for _, warn := range warns {
logrus.Warn(warn)
}
if errs != nil && len(errs) != 0 {
if len(errs) != 0 {
for _, err := range errs {
logrus.Error(err)
}
Expand Down Expand Up @@ -130,7 +128,7 @@ func (g *GoliacImpl) ApplyToGithub(dryrun bool, teamreponame string, branch stri
ga := NewGithubBatchExecutor(g.remote, g.repoconfig.MaxChangesets)
reconciliator := sync.NewGoliacReconciliatorImpl(ga, g.repoconfig)

ctx := context.WithValue(context.TODO(), "author", commit.Author.Email)
ctx := context.WithValue(context.TODO(), sync.KeyAuthor, commit.Author.Email)
err = reconciliator.Reconciliate(ctx, g.local, g.remote, teamreponame, dryrun)
if err != nil {
return fmt.Errorf("Error when reconciliating: %v", err)
Expand Down Expand Up @@ -175,7 +173,7 @@ func (g *GoliacImpl) UsersUpdate(repositoryUrl, branch string) error {
}

userplugin, found := sync.GetUserSyncPlugin(g.repoconfig.UserSync.Plugin)
if found == false {
if !found {
return fmt.Errorf("User Sync Plugin %s not found", g.repoconfig.UserSync.Plugin)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/goliac_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"time"

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/swagger_gen/models"
"github.com/Alayacare/goliac/internal/swagger_gen/restapi"
"github.com/Alayacare/goliac/internal/swagger_gen/restapi/operations"
"github.com/Alayacare/goliac/internal/swagger_gen/restapi/operations/health"
"github.com/Alayacare/goliac/swagger_gen/models"
"github.com/Alayacare/goliac/swagger_gen/restapi"
"github.com/Alayacare/goliac/swagger_gen/restapi/operations"
"github.com/Alayacare/goliac/swagger_gen/restapi/operations/health"
"github.com/go-openapi/loads"
"github.com/go-openapi/runtime/middleware"
"github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion internal/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (s *Scaffold) generateUsers(fs afero.Fs, userspath string) (map[string]stri
}
} else {
// fail back on github id
for githubid, _ := range s.remote.Users() {
for githubid := range s.remote.Users() {
usermap[githubid] = githubid
user := entity.User{}
user.ApiVersion = "v1"
Expand Down
3 changes: 3 additions & 0 deletions internal/sync/githubsaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func LoadUsersFromGithubOrgSaml(client github.GitHubClient) (map[string]*entity.
count := 0
for hasNextPage {
data, err := client.QueryGraphQLAPI(listUsersFromGithubOrgSaml, variables)
if err != nil {
return users, err
}
var gResult GraplQLUsersFromGithubOrgSaml

// parse first page
Expand Down
Loading

0 comments on commit 77bd344

Please sign in to comment.