Fix Linting errors (#142)

This commit is contained in:
Johannes Batzill 2023-06-15 21:27:06 +00:00 committed by Harness
parent b6edadfd8e
commit 06067d4f6c
11 changed files with 40 additions and 40 deletions

View File

@ -8,6 +8,7 @@ package main
import (
"context"
"github.com/harness/gitness/cli/server"
"github.com/harness/gitness/events"
"github.com/harness/gitness/gitrpc"
@ -44,10 +45,6 @@ import (
"github.com/harness/gitness/types/check"
)
import (
_ "github.com/mattn/go-sqlite3"
)
// Injectors from wire.go:
func initSystem(ctx context.Context, config *types.Config) (*server.System, error) {
@ -137,8 +134,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
githookController := githook.ProvideController(db, authorizer, principalStore, repoStore, eventsReporter)
serviceaccountController := serviceaccount.NewController(principalUID, authorizer, principalStore, spaceStore, repoStore, tokenStore)
principalController := principal.ProvideController(principalStore)
checkStore := database.ProvideCheckStore(db, principalInfoCache)
checkController := check2.ProvideController(db, authorizer, checkStore, repoStore, gitrpcInterface)
checkController := check2.ProvideController(db, authorizer, repoStore, gitrpcInterface)
apiHandler := router.ProvideAPIHandler(config, authenticator, repoController, spaceController, pullreqController, webhookController, githookController, serviceaccountController, controller, principalController, checkController)
gitHandler := router.ProvideGitHandler(config, provider, repoStore, authenticator, authorizer, gitrpcInterface)
webHandler := router.ProvideWebHandler(config)

View File

@ -203,12 +203,16 @@ func (g Adapter) ListCommits(ctx context.Context,
// In case of rename of a file, same commit will be listed twice - Once in old file and second time in new file.
// Hence, we are making it a pattern to only list it as part of new file and not as part of old file.
func cleanupCommitsForRename(commits []types.Commit, renameDetails []types.PathRenameDetails, path string) []types.Commit {
func cleanupCommitsForRename(
commits []types.Commit,
renameDetails []types.PathRenameDetails,
path string,
) []types.Commit {
if len(commits) == 0 {
return commits
}
for _, renameDetail := range renameDetails {
// Since rename details is present here it implies that we would have some commits and hence we need not do null check.
// Since rename details is present it implies that we have commits and hence don't need null check.
if commits[0].SHA == renameDetail.CommitSHABefore && path == renameDetail.OldPath {
return commits[1:]
}

View File

@ -50,6 +50,7 @@ func (in *ReportInput) Validate() error {
}
in.Payload.Kind = payloadKind
//nolint:gocritic // more values to follow on the enum (we want linter warning in case it is missed)
switch in.Payload.Kind {
case enum.CheckPayloadKindExternal:
// the default external type does not support payload: clear it here
@ -96,7 +97,7 @@ func (c *Controller) Report(
now := time.Now().UnixMilli()
metadataJson, _ := json.Marshal(metadata)
metadataJSON, _ := json.Marshal(metadata)
statusCheckReport := &types.Check{
CreatedBy: session.Principal.ID,
@ -109,7 +110,7 @@ func (c *Controller) Report(
Summary: in.Summary,
Link: in.Link,
Payload: in.Payload,
Metadata: metadataJson,
Metadata: metadataJSON,
ReportedBy: *session.Principal.ToPrincipalInfo(),
}

View File

@ -21,25 +21,22 @@ import (
)
type Controller struct {
db *sqlx.DB
authorizer authz.Authorizer
checkStore store.CheckStore
reqCheckStore store.ReqCheckStore
repoStore store.RepoStore
gitRPCClient gitrpc.Interface
db *sqlx.DB
authorizer authz.Authorizer
checkStore store.CheckStore
repoStore store.RepoStore
gitRPCClient gitrpc.Interface
}
func NewController(
db *sqlx.DB,
authorizer authz.Authorizer,
checkStore store.CheckStore,
repoStore store.RepoStore,
gitRPCClient gitrpc.Interface,
) *Controller {
return &Controller{
db: db,
authorizer: authorizer,
checkStore: checkStore,
repoStore: repoStore,
gitRPCClient: gitRPCClient,
}

View File

@ -19,12 +19,10 @@ var WireSet = wire.NewSet(
)
func ProvideController(db *sqlx.DB, authorizer authz.Authorizer,
checkStore store.CheckStore,
repoStore store.RepoStore,
rpcClient gitrpc.Interface,
) *Controller {
return NewController(db, authorizer,
checkStore,
repoStore,
rpcClient)
}

View File

@ -100,6 +100,7 @@ func (c *Controller) State(ctx context.Context,
var mergeBaseSHA string
var stateChange change
//nolint:nestif // refactor if needed
if pr.State != enum.PullReqStateOpen && in.State == enum.PullReqStateOpen {
if sourceSHA, err = c.verifyBranchExistence(ctx, sourceRepo, pr.SourceBranch); err != nil {
return nil, err

View File

@ -29,7 +29,7 @@ func (c *Controller) Delete(ctx context.Context, session *auth.Session, repoRef
}
log.Ctx(ctx).Info().Msgf("Delete request received for repo %s , id: %d", repo.Path, repo.ID)
// TODO: uncomment when soft delete is implemented
//return c.DeleteNoAuth(ctx, session, repo)
// return c.DeleteNoAuth(ctx, session, repo)
return nil
}

View File

@ -28,7 +28,7 @@ func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef
}
// TODO: uncomment when soft delete is implemented
log.Ctx(ctx).Info().Msgf("Delete request received for space %s", space.Path)
//return c.DeleteNoAuth(ctx, session, space.ID)
// return c.DeleteNoAuth(ctx, session, space.ID)
return nil
}

View File

@ -39,7 +39,7 @@ var queryParameterAccountID = openapi3.ParameterOrRef{
Parameter: &openapi3.Parameter{
Name: "accountIdentifier",
In: openapi3.ParameterInQuery,
Description: ptr.String("The account ID the principals are retrieved for (Not requried in standalone)."),
Description: ptr.String("The account ID the principals are retrieved for (Not required in standalone)."),
Required: ptr.Bool(false),
Schema: &openapi3.SchemaOrRef{
Schema: &openapi3.Schema{

View File

@ -25,6 +25,8 @@ func Translate(err error) *Error {
gitrpcError *gitrpc.Error
)
// TODO: Improve performance of checking multiple errors with errors.Is
// check if err is RBAC error
if rbacErr := processRBACErrors(err); rbacErr != nil {
return rbacErr
@ -102,25 +104,25 @@ func httpStatusCode(code gitrpc.Status) int {
func processRBACErrors(err error) *Error {
msg := err.Error()
switch errors.Unwrap(err) {
switch {
case
rbac.ErrBaseURLRequired,
rbac.ErrInvalidPrincipalType,
rbac.ErrAccountRequired,
rbac.ErrPrincipalIdentifierRequired,
rbac.ErrPermissionsRequired,
rbac.ErrResourceTypeRequired,
rbac.ErrResourceTypeKeyRequired,
rbac.ErrResourceTypeValueRequired,
rbac.ErrPermissionRequired,
rbac.ErrPermissionsSizeExceeded,
rbac.ErrInvalidCacheEntryType,
rbac.ErrNoHeader,
rbac.ErrAuthorizationTokenRequired,
rbac.ErrOddNumberOfArguments:
errors.Is(err, rbac.ErrBaseURLRequired),
errors.Is(err, rbac.ErrInvalidPrincipalType),
errors.Is(err, rbac.ErrAccountRequired),
errors.Is(err, rbac.ErrPrincipalIdentifierRequired),
errors.Is(err, rbac.ErrPermissionsRequired),
errors.Is(err, rbac.ErrResourceTypeRequired),
errors.Is(err, rbac.ErrResourceTypeKeyRequired),
errors.Is(err, rbac.ErrResourceTypeValueRequired),
errors.Is(err, rbac.ErrPermissionRequired),
errors.Is(err, rbac.ErrPermissionsSizeExceeded),
errors.Is(err, rbac.ErrInvalidCacheEntryType),
errors.Is(err, rbac.ErrNoHeader),
errors.Is(err, rbac.ErrAuthorizationTokenRequired),
errors.Is(err, rbac.ErrOddNumberOfArguments):
return New(http.StatusBadRequest, msg)
case rbac.ErrMapperFuncCannotBeNil,
rbac.ErrLoggerCannotBeNil:
case errors.Is(err, rbac.ErrMapperFuncCannotBeNil),
errors.Is(err, rbac.ErrLoggerCannotBeNil):
return New(http.StatusInternalServerError, msg)
}

View File

@ -9,6 +9,7 @@ import (
"fmt"
"github.com/harness/gitness/internal/store"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)