horizoncd/horizon

View on GitHub

Showing 676 of 677 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (d *dao) GetByNameFuzzily(ctx context.Context, name string,
    includeSoftDelete bool) ([]*models.Application, error) {
    var applications []*models.Application

    statement := d.db.Unscoped().WithContext(ctx).Where("name like ?", fmt.Sprintf("%%%s%%", name))
Severity: Major
Found in pkg/application/dao/dao.go and 1 other location - About 2 hrs to fix
pkg/cluster/dao/dao.go on lines 400..416

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 243.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (d *dao) GetByNameFuzzily(ctx context.Context, name string, includeSoftDelete bool) ([]*models.Cluster, error) {
    var clusters []*models.Cluster

    statement := d.db.Unscoped().WithContext(ctx).Where("name like ?", fmt.Sprintf("%%%s%%", name))
    if !includeSoftDelete {
Severity: Major
Found in pkg/cluster/dao/dao.go and 1 other location - About 2 hrs to fix
pkg/application/dao/dao.go on lines 80..97

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 243.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File controller.go has 535 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright © 2023 Horizoncd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Severity: Minor
Found in core/controller/group/controller.go - About 2 hrs to fix

    RegionInformers has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type RegionInformers struct {
        regionMgr manager.Manager
    
        defaultResync time.Duration
    
    
    Severity: Minor
    Found in pkg/regioninformers/regioninformers.go - About 2 hrs to fix

      controller has 25 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type controller struct {
          gitgetter            git.Helper
          templateRepo         templaterepo.TemplateRepo
          groupMgr             gmanager.Manager
          templateMgr          tmanager.Manager
      Severity: Minor
      Found in core/controller/template/controller.go - About 2 hrs to fix

        controller has 25 methods (exceeds 20 allowed). Consider refactoring.
        Open

        type controller struct {
            prMgr              *prmanager.PRManager
            appMgr             appmanager.Manager
            clusterMgr         clustermanager.Manager
            envMgr             envmanager.Manager
        Severity: Minor
        Found in core/controller/pipelinerun/controller.go - About 2 hrs to fix

          Method controller.DeleteCluster has 95 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (c *controller) DeleteCluster(ctx context.Context, clusterID uint, hard bool) (err error) {
              const op = "cluster controller: delete cluster"
              defer wlog.Start(ctx, op).StopPrint()
          
              // get some relevant models
          Severity: Major
          Found in core/controller/cluster/controller_basic.go - About 2 hrs to fix

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            func NewHarborRegistry(config *registry.Config) (registry.Registry, error) {
                transport := http.Transport{
                    TLSClientConfig: &tls.Config{
                        InsecureSkipVerify: config.InsecureSkipVerify,
                    },
            Severity: Major
            Found in pkg/cluster/registry/harbor/v1/registry_harbor.go and 1 other location - About 2 hrs to fix
            pkg/cluster/registry/harbor/v2/registry_harbor.go on lines 65..93

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 238.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            func NewHarborRegistry(config *registry.Config) (registry.Registry, error) {
                transport := http.Transport{
                    TLSClientConfig: &tls.Config{
                        InsecureSkipVerify: config.InsecureSkipVerify,
                    },
            Severity: Major
            Found in pkg/cluster/registry/harbor/v2/registry_harbor.go and 1 other location - About 2 hrs to fix
            pkg/cluster/registry/harbor/v1/registry_harbor.go on lines 64..92

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 238.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Method controller.LoginOrLink has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
            Open

            func (c *controller) LoginOrLink(ctx context.Context,
                code string, state string, redirectURL string) (*usermodel.User, error) {
                bts, err := base64.StdEncoding.DecodeString(state)
                if err != nil {
                    return nil, perror.Wrapf(
            Severity: Minor
            Found in core/controller/idp/controller.go - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method controller.GetClusterV2 has 92 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (c *controller) GetClusterV2(ctx context.Context, clusterID uint) (*GetClusterResponseV2, error) {
                const op = "cluster controller: get cluster v2"
                defer wlog.Start(ctx, op).StopPrint()
            
                // 1. get cluster from db
            Severity: Major
            Found in core/controller/cluster/controller_basic_v2.go - About 2 hrs to fix

              File cd.go has 527 lines of code (exceeds 500 allowed). Consider refactoring.
              Open

              /*
              Copyright The Kubernetes Authors.
              
              Licensed under the Apache License, Version 2.0 (the "License");
              you may not use this file except in compliance with the License.
              Severity: Minor
              Found in pkg/cd/cd.go - About 2 hrs to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func (a *API) GetChildren(c *gin.Context) {
                    groupID := c.Param(_paramGroupID)
                    intID, err := strconv.ParseUint(groupID, 10, 0)
                    if err != nil {
                        response.AbortWithRequestError(c, common.InvalidRequestParam, fmt.Sprintf("invalid param, groupID: %s", groupID))
                Severity: Major
                Found in core/http/api/v2/group/apis.go and 1 other location - About 2 hrs to fix
                core/http/api/v2/group/apis.go on lines 237..260

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 228.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func (a *API) GetSubGroups(c *gin.Context) {
                    groupID := c.Param(_paramGroupID)
                    intID, err := strconv.ParseUint(groupID, 10, 0)
                    if err != nil {
                        response.AbortWithRequestError(c, common.InvalidRequestParam, fmt.Sprintf("invalid param, groupID: %s", groupID))
                Severity: Major
                Found in core/http/api/v2/group/apis.go and 1 other location - About 2 hrs to fix
                core/http/api/v2/group/apis.go on lines 211..234

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 228.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Method eventHandlerService.Start has 90 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (e *eventHandlerService) Start() {
                    go func() {
                        defer func() {
                            if err := recover(); err != nil {
                                log.Errorf(e.ctx, "event handler service panic: %s", string(debug.Stack()))
                Severity: Major
                Found in pkg/eventhandler/eventhandler.go - About 2 hrs to fix

                  Function parsePodLifeCycle has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func parsePodLifeCycle(pod corev1.Pod) []*LifeCycleItem {
                      var lifeCycle []*LifeCycleItem
                      // if DeletionTimestamp is set, pod is Terminating
                      if pod.DeletionTimestamp != nil {
                          lifeCycle = []*LifeCycleItem{
                  Severity: Minor
                  Found in pkg/cd/util.go - About 2 hrs to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method clusterGitopsRepo.UpdateCluster has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (g *clusterGitopsRepo) UpdateCluster(ctx context.Context, params *UpdateClusterParams) error {
                      const op = "cluster git repo: update cluster"
                      defer wlog.Start(ctx, op).StopPrint()
                  
                      currentUser, err := common.UserFromContext(ctx)
                  Severity: Minor
                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 2 hrs to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method appGitopsRepo.CreateOrUpdateApplication has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (g appGitopsRepo) CreateOrUpdateApplication(ctx context.Context,
                      application string, req CreateOrUpdateRequest) error {
                      const op = "gitlab repo: create or update application"
                      defer wlog.Start(ctx, op).StopPrint()
                  
                  
                  Severity: Minor
                  Found in pkg/application/gitrepo/gitrepo_applicationv2.go - About 2 hrs to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method WebhookLogGenerator.Process has 88 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (w *WebhookLogGenerator) Process(ctx context.Context, events []*models.Event,
                      resume bool) error {
                      var (
                          webhookLogs        []*webhookmodels.WebhookLog
                          conditionsToCreate = map[uint]map[uint]messageDependency{}
                  Severity: Major
                  Found in pkg/eventhandler/wlgenerator/wlgenerator.go - About 2 hrs to fix

                    Method controller.executeRollback has 88 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (c *controller) executeRollback(ctx context.Context, application *appmodels.Application,
                        cluster *clustermodels.Cluster, pr *prmodels.Pipelinerun) error {
                        // 1. get pipelinerun to rollback
                        if pr.RollbackFrom == nil {
                            return perror.Wrapf(herrors.ErrParamInvalid, "pipelinerun to rollback is empty")
                    Severity: Major
                    Found in core/controller/pipelinerun/controller.go - About 2 hrs to fix
                      Severity
                      Category
                      Status
                      Source
                      Language