horizoncd/horizon

View on GitHub
pkg/cluster/gitrepo/gitrepo_cluster.go

Summary

Maintainability
F
1 wk
Test Coverage

Showing 31 of 31 total issues

File gitrepo_cluster.go has 1601 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: Major
Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 3 days to fix

    Method clusterGitopsRepo.UpgradeCluster has 314 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (g *clusterGitopsRepo) UpgradeCluster(ctx context.Context,
    param *UpgradeValuesParam) (string, error) {
    const op = "cluster git repo: upgrade cluster"
    defer wlog.Start(ctx, op).StopPrint()
    currentUser, err := common.UserFromContext(ctx)
    Severity: Major
    Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 day to fix

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

      func (g *clusterGitopsRepo) UpgradeCluster(ctx context.Context,
      param *UpgradeValuesParam) (string, error) {
      const op = "cluster git repo: upgrade cluster"
      defer wlog.Start(ctx, op).StopPrint()
      currentUser, err := common.UserFromContext(ctx)
      Severity: Minor
      Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 day to fix

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

      func (g *clusterGitopsRepo) GetCluster(ctx context.Context,
      application, cluster, templateName string) (_ *ClusterFiles, err error) {
      const op = "cluster git repo: get cluster"
      defer wlog.Start(ctx, op).StopPrint()
       
       
      Severity: Minor
      Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 4 hrs to fix

      clusterGitopsRepo has 33 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type clusterGitopsRepo struct {
      gitlabLib gitlablib.Interface
      clustersGroup *gitlab.Group
      recyclingClustersGroup *gitlab.Group
      templateRepo templaterepo.TemplateRepo
      Severity: Minor
      Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 4 hrs to fix

        Method clusterGitopsRepo.GetCluster has 120 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (g *clusterGitopsRepo) GetCluster(ctx context.Context,
        application, cluster, templateName string) (_ *ClusterFiles, err error) {
        const op = "cluster git repo: get cluster"
        defer wlog.Start(ctx, op).StopPrint()
         
         
        Severity: Major
        Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 3 hrs to fix

          Method clusterGitopsRepo.CreateCluster has 117 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

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

            Method clusterGitopsRepo.UpdateCluster has 102 lines of code (exceeds 50 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: Major
            Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 3 hrs to fix

              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

              Method clusterGitopsRepo.UpgradeCluster has 25 return statements (exceeds 4 allowed).
              Open

              func (g *clusterGitopsRepo) UpgradeCluster(ctx context.Context,
              param *UpgradeValuesParam) (string, error) {
              const op = "cluster git repo: upgrade cluster"
              defer wlog.Start(ctx, op).StopPrint()
              currentUser, err := common.UserFromContext(ctx)
              Severity: Major
              Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 2 hrs to fix

                Method clusterGitopsRepo.GetCluster has 21 return statements (exceeds 4 allowed).
                Open

                func (g *clusterGitopsRepo) GetCluster(ctx context.Context,
                application, cluster, templateName string) (_ *ClusterFiles, err error) {
                const op = "cluster git repo: get cluster"
                defer wlog.Start(ctx, op).StopPrint()
                 
                 
                Severity: Major
                Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 hr to fix

                  Method clusterGitopsRepo.GetClusterValueFiles has 60 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (g *clusterGitopsRepo) GetClusterValueFiles(ctx context.Context,
                  application, cluster string) (_ []ClusterValueFile, err error) {
                  const op = "cluster git repo: get cluster value files"
                  defer wlog.Start(ctx, op).StopPrint()
                   
                   
                  Severity: Minor
                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 hr to fix

                    Method clusterGitopsRepo.UpdatePipelineOutput has 60 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (g *clusterGitopsRepo) UpdatePipelineOutput(ctx context.Context, application, cluster, template string,
                    pipelineOutput interface{}) (commitID string, err error) {
                    const op = "cluster git repo: update pipeline output"
                    defer wlog.Start(ctx, op).StopPrint()
                     
                     
                    Severity: Minor
                    Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 hr to fix

                      Method clusterGitopsRepo.Rollback has 55 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func (g *clusterGitopsRepo) Rollback(ctx context.Context, application, cluster, commit string) (_ string, err error) {
                      const op = "cluster git repo: rollback"
                      defer wlog.Start(ctx, op).StopPrint()
                       
                      currentUser, err := common.UserFromContext(ctx)
                      Severity: Minor
                      Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 hr to fix

                        Method clusterGitopsRepo.UpdatePipelineOutput has 11 return statements (exceeds 4 allowed).
                        Open

                        func (g *clusterGitopsRepo) UpdatePipelineOutput(ctx context.Context, application, cluster, template string,
                        pipelineOutput interface{}) (commitID string, err error) {
                        const op = "cluster git repo: update pipeline output"
                        defer wlog.Start(ctx, op).StopPrint()
                         
                         
                        Severity: Major
                        Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 hr to fix

                          Method clusterGitopsRepo.UpdateCluster has 10 return statements (exceeds 4 allowed).
                          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: Major
                          Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 1 hr to fix

                            Method clusterGitopsRepo.CreateCluster has 9 return statements (exceeds 4 allowed).
                            Open

                            func (g *clusterGitopsRepo) CreateCluster(ctx context.Context, params *CreateClusterParams) (err error) {
                            const op = "cluster git repo: create cluster"
                            defer wlog.Start(ctx, op).StopPrint()
                             
                            currentUser, err := common.UserFromContext(ctx)
                            Severity: Major
                            Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 55 mins to fix

                              Function NewClusterGitlabRepo has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                              func NewClusterGitlabRepo(ctx context.Context, rootGroup *gitlab.Group,
                              templateRepo templaterepo.TemplateRepo,
                              gitlabLib gitlablib.Interface, defaultBranch string, defaultVisibility string) (ClusterGitRepo, error) {
                              Severity: Minor
                              Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 45 mins to fix

                                Method clusterGitopsRepo.getPipelineOutput has 6 return statements (exceeds 4 allowed).
                                Open

                                func (g *clusterGitopsRepo) getPipelineOutput(ctx context.Context,
                                application, cluster string) (map[string]map[string]interface{}, error) {
                                pid := fmt.Sprintf("%v/%v/%v", g.clustersGroup.FullPath, application, cluster)
                                content, err := g.gitlabLib.GetFile(ctx, pid, GitOpsBranch, common.GitopsFilePipelineOutput)
                                if err != nil {
                                Severity: Major
                                Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 40 mins to fix

                                  Method clusterGitopsRepo.Rollback has 6 return statements (exceeds 4 allowed).
                                  Open

                                  func (g *clusterGitopsRepo) Rollback(ctx context.Context, application, cluster, commit string) (_ string, err error) {
                                  const op = "cluster git repo: rollback"
                                  defer wlog.Start(ctx, op).StopPrint()
                                   
                                  currentUser, err := common.UserFromContext(ctx)
                                  Severity: Major
                                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 40 mins to fix

                                    Method clusterGitopsRepo.GetManifest has 6 return statements (exceeds 4 allowed).
                                    Open

                                    func (g *clusterGitopsRepo) GetManifest(ctx context.Context, application,
                                    cluster string, commit *string) (*pkgcommon.Manifest, error) {
                                    const op = "cluster git repo: get manifest"
                                    defer wlog.Start(ctx, op).StopPrint()
                                     
                                     
                                    Severity: Major
                                    Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 40 mins to fix

                                      Method clusterGitopsRepo.revertAction has 6 return statements (exceeds 4 allowed).
                                      Open

                                      func (g *clusterGitopsRepo) revertAction(ctx context.Context, application, cluster,
                                      commit string, diff gitlab.Diff) (*gitlablib.CommitAction, error) {
                                      if diff.DeletedFile {
                                      // file is deleted from gitops branch to the commit
                                      return &gitlablib.CommitAction{
                                      Severity: Major
                                      Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 40 mins to fix

                                        Method clusterGitopsRepo.GetRestartTime has 5 return statements (exceeds 4 allowed).
                                        Open

                                        func (g *clusterGitopsRepo) GetRestartTime(ctx context.Context, application, cluster string,
                                        template string) (string, error) {
                                        ret := make(map[string]map[string]string)
                                        pid := fmt.Sprintf("%v/%v/%v", g.clustersGroup.FullPath, application, cluster)
                                        content, err := g.gitlabLib.GetFile(ctx, pid, g.defaultBranch, common.GitopsFileRestart)
                                        Severity: Major
                                        Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 35 mins to fix

                                          Method clusterGitopsRepo.GetPipelineOutput has 5 return statements (exceeds 4 allowed).
                                          Open

                                          func (g *clusterGitopsRepo) GetPipelineOutput(ctx context.Context, application, cluster string,
                                          template string) (interface{}, error) {
                                          ret := make(map[string]interface{})
                                          pid := fmt.Sprintf("%v/%v/%v", g.clustersGroup.FullPath, application, cluster)
                                          content, err := g.gitlabLib.GetFile(ctx, pid, GitOpsBranch, common.GitopsFilePipelineOutput)
                                          Severity: Major
                                          Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 35 mins to fix

                                            Method clusterGitopsRepo.manifestVersionChanged has 5 return statements (exceeds 4 allowed).
                                            Open

                                            func (g *clusterGitopsRepo) manifestVersionChanged(ctx context.Context, application,
                                            cluster string, commit string) (bool, error) {
                                            currentManifest, err1 := g.GetManifest(ctx, application, cluster, nil)
                                            if err1 != nil {
                                            if _, ok := perror.Cause(err1).(*herrors.HorizonErrNotFound); !ok {
                                            Severity: Major
                                            Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 35 mins to fix

                                              Method clusterGitopsRepo.MergeBranch has 5 return statements (exceeds 4 allowed).
                                              Open

                                              func (g *clusterGitopsRepo) MergeBranch(ctx context.Context, application, cluster,
                                              sourceBranch, targetBranch string, pipelineRunID *uint) (_ string, err error) {
                                              removeSourceBranch := false
                                              pid := fmt.Sprintf("%v/%v/%v", g.clustersGroup.FullPath, application, cluster)
                                               
                                               
                                              Severity: Major
                                              Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 35 mins to fix

                                                Method clusterGitopsRepo.UpdateTags has 5 return statements (exceeds 4 allowed).
                                                Open

                                                func (g *clusterGitopsRepo) UpdateTags(ctx context.Context, application, cluster, templateName string,
                                                tags []*tagmodels.Tag) (err error) {
                                                const op = "cluster git repo: update tags"
                                                defer wlog.Start(ctx, op).StopPrint()
                                                 
                                                 
                                                Severity: Major
                                                Found in pkg/cluster/gitrepo/gitrepo_cluster.go - About 35 mins to fix

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

                                                  go func() {
                                                  defer wg.Done()
                                                  pipelineBytes, err1 = g.gitlabLib.GetFile(ctx, pid, GitOpsBranch, common.GitopsFilePipeline)
                                                  if err1 != nil {
                                                  return
                                                  Severity: Minor
                                                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go and 1 other location - About 35 mins to fix
                                                  pkg/cluster/gitrepo/gitrepo_cluster.go on lines 218..228

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

                                                  go func() {
                                                  defer wg.Done()
                                                  applicationBytes, err2 = g.gitlabLib.GetFile(ctx, pid, GitOpsBranch, common.GitopsFileApplication)
                                                  if err2 != nil {
                                                  return
                                                  Severity: Minor
                                                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go and 1 other location - About 35 mins to fix
                                                  pkg/cluster/gitrepo/gitrepo_cluster.go on lines 207..217

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

                                                  commitMsg := angular.CommitMessage("cluster", angular.Subject{
                                                  Operator: currentUser.GetName(),
                                                  Action: "update cluster",
                                                  Cluster: angular.StringPtr(params.Cluster),
                                                  }, struct {
                                                  Severity: Minor
                                                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go and 1 other location - About 35 mins to fix
                                                  pkg/cluster/gitrepo/gitrepo_cluster.go on lines 548..558

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

                                                  commitMsg := angular.CommitMessage("cluster", angular.Subject{
                                                  Operator: currentUser.GetName(),
                                                  Action: "create cluster",
                                                  Cluster: angular.StringPtr(params.Cluster),
                                                  }, struct {
                                                  Severity: Minor
                                                  Found in pkg/cluster/gitrepo/gitrepo_cluster.go and 1 other location - About 35 mins to fix
                                                  pkg/cluster/gitrepo/gitrepo_cluster.go on lines 664..674

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status