horizoncd/horizon

View on GitHub
core/controller/cluster/controller_basic_v2.go

Summary

Maintainability
F
5 days
Test Coverage
D
62%

Showing 18 of 18 total issues

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

func (c *controller) UpdateClusterV2(ctx context.Context, clusterID uint,
r *UpdateClusterRequestV2, mergePatch bool) error {
const op = "cluster controller: update cluster v2"
defer wlog.Start(ctx, op).StopPrint()
 
 
Severity: Minor
Found in core/controller/cluster/controller_basic_v2.go - About 7 hrs to fix

File controller_basic_v2.go has 685 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/cluster/controller_basic_v2.go - About 6 hrs to fix

    Method controller.UpdateClusterV2 has 149 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (c *controller) UpdateClusterV2(ctx context.Context, clusterID uint,
    r *UpdateClusterRequestV2, mergePatch bool) error {
    const op = "cluster controller: update cluster v2"
    defer wlog.Start(ctx, op).StopPrint()
     
     
    Severity: Major
    Found in core/controller/cluster/controller_basic_v2.go - About 4 hrs to fix

      Method controller.createPipelineRun has 124 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
      r *CreatePipelineRunRequest) (*prmodels.Pipelinerun, error) {
      defer wlog.Start(ctx, "cluster controller: create pipeline run").StopPrint()
       
      cluster, err := c.clusterMgr.GetByID(ctx, clusterID)
      Severity: Major
      Found in core/controller/cluster/controller_basic_v2.go - About 3 hrs to fix

        Method controller.CreateClusterV2 has 122 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *controller) CreateClusterV2(ctx context.Context,
        params *CreateClusterParamsV2) (*CreateClusterResponseV2, error) {
        const op = "cluster controller: create cluster v2"
        defer wlog.Start(ctx, op).StopPrint()
         
         
        Severity: Major
        Found in core/controller/cluster/controller_basic_v2.go - About 3 hrs to fix

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

          func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
          r *CreatePipelineRunRequest) (*prmodels.Pipelinerun, error) {
          defer wlog.Start(ctx, "cluster controller: create pipeline run").StopPrint()
           
          cluster, err := c.clusterMgr.GetByID(ctx, clusterID)
          Severity: Minor
          Found in core/controller/cluster/controller_basic_v2.go - About 3 hrs to fix

          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

            Method controller.UpdateClusterV2 has 26 return statements (exceeds 4 allowed).
            Open

            func (c *controller) UpdateClusterV2(ctx context.Context, clusterID uint,
            r *UpdateClusterRequestV2, mergePatch bool) error {
            const op = "cluster controller: update cluster v2"
            defer wlog.Start(ctx, op).StopPrint()
             
             
            Severity: Major
            Found in core/controller/cluster/controller_basic_v2.go - About 2 hrs to fix

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

              func (c *controller) CreateClusterV2(ctx context.Context,
              params *CreateClusterParamsV2) (*CreateClusterResponseV2, error) {
              const op = "cluster controller: create cluster v2"
              defer wlog.Start(ctx, op).StopPrint()
               
               
              Severity: Minor
              Found in core/controller/cluster/controller_basic_v2.go - About 1 hr to fix

              Method controller.CreateClusterV2 has 19 return statements (exceeds 4 allowed).
              Open

              func (c *controller) CreateClusterV2(ctx context.Context,
              params *CreateClusterParamsV2) (*CreateClusterResponseV2, error) {
              const op = "cluster controller: create cluster v2"
              defer wlog.Start(ctx, op).StopPrint()
               
               
              Severity: Major
              Found in core/controller/cluster/controller_basic_v2.go - About 1 hr to fix

                Method controller.GetClusterV2 has 16 return statements (exceeds 4 allowed).
                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 1 hr to fix

                  Method controller.createPipelineRun has 13 return statements (exceeds 4 allowed).
                  Open

                  func (c *controller) createPipelineRun(ctx context.Context, clusterID uint,
                  r *CreatePipelineRunRequest) (*prmodels.Pipelinerun, error) {
                  defer wlog.Start(ctx, "cluster controller: create pipeline run").StopPrint()
                   
                  cluster, err := c.clusterMgr.GetByID(ctx, clusterID)
                  Severity: Major
                  Found in core/controller/cluster/controller_basic_v2.go - About 1 hr to fix

                    Avoid deeply nested control flow statements.
                    Open

                    } else if r.Git.Branch != "" {
                    gitRefType = codemodels.GitRefTypeBranch
                    gitRef = r.Git.Branch
                    }
                    Severity: Major
                    Found in core/controller/cluster/controller_basic_v2.go - About 45 mins to fix

                      Method controller.CreatePipelineRun has 5 return statements (exceeds 4 allowed).
                      Open

                      func (c *controller) CreatePipelineRun(ctx context.Context, clusterID uint,
                      r *CreatePipelineRunRequest) (*prmodels.PipelineBasic, error) {
                      const op = "pipelinerun controller: create pipelinerun"
                      defer wlog.Start(ctx, op).StopPrint()
                       
                       
                      Severity: Major
                      Found in core/controller/cluster/controller_basic_v2.go - About 35 mins to fix

                        Method controller.GetClusterStatusV2 has 5 return statements (exceeds 4 allowed).
                        Open

                        func (c *controller) GetClusterStatusV2(ctx context.Context, clusterID uint) (*StatusResponseV2, error) {
                        const op = "cluster controller: get cluster status v2"
                        defer wlog.Start(ctx, op).StopPrint()
                         
                        cluster, err := c.clusterMgr.GetByID(ctx, clusterID)
                        Severity: Major
                        Found in core/controller/cluster/controller_basic_v2.go - About 35 mins to fix

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

                          func (c *controller) customizeCreateReqBuildTemplateInfo(ctx context.Context, params *CreateClusterParamsV2,
                          application *appmodels.Application) (*BuildTemplateInfo, error) {
                          buildTemplateInfo := &BuildTemplateInfo{}
                          appGitRepoFile, err := c.applicationGitRepo.GetApplication(ctx, application.Name, params.Environment)
                          if err != nil {
                          Severity: Minor
                          Found in core/controller/cluster/controller_basic_v2.go - About 35 mins to fix

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

                          if err != nil {
                          // Prevent errors like "project has already been taken" caused by automatic retries due to api timeouts
                          if deleteErr := c.clusterGitRepo.DeleteCluster(ctx, application.Name, cluster.Name, cluster.ID); deleteErr != nil {
                          if _, ok := perror.Cause(deleteErr).(*herrors.HorizonErrNotFound); !ok {
                          err = perror.WithMessage(err, deleteErr.Error())
                          Severity: Major
                          Found in core/controller/cluster/controller_basic_v2.go and 1 other location - About 1 hr to fix
                          core/controller/cluster/controller_basic.go on lines 521..532

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

                          if r.Git != nil {
                          if r.Git.Commit != "" {
                          gitRefType = codemodels.GitRefTypeCommit
                          gitRef = r.Git.Commit
                          } else if r.Git.Tag != "" {
                          Severity: Major
                          Found in core/controller/cluster/controller_basic_v2.go and 1 other location - About 1 hr to fix
                          core/controller/cluster/controller_build_deploy.go on lines 65..76

                          There are no issues that match your filters.

                          Category
                          Status