horizoncd/horizon

View on GitHub

Showing 676 of 677 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

    Similar blocks of code found in 2 locations. 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/registry/harbor/v1/mockserver/server.go and 1 other location - About 2 days to fix
    pkg/cluster/registry/harbor/v2/mockserver/server.go on lines 1..160

    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 1196.

    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

    // 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/registry/harbor/v2/mockserver/server.go and 1 other location - About 2 days to fix
    pkg/cluster/registry/harbor/v1/mockserver/server.go on lines 1..161

    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 1196.

    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

    Function Init has 392 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func Init(ctx context.Context, flags *Flags, coreConfig *config.Config) {
        // init roles
        file, err := os.OpenFile(flags.RoleConfigFile, os.O_RDONLY, 0644)
        if err != nil {
            panic(err)
    Severity: Major
    Found in core/cmd/cmd.go - About 1 day to fix

      File controller_basic.go has 917 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 core/controller/cluster/controller_basic.go - About 1 day 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

          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 cd.GetClusterStateV1 has a Cognitive Complexity of 70 (exceeds 20 allowed). Consider refactoring.
          Open

          func (c *cd) GetClusterStateV1(ctx context.Context,
              params *GetClusterStateParams) (clusterState *ClusterState, err error) {
              const op = "cd: get cluster status"
              defer wlog.Start(ctx, op).StopPrint()
          
          
          Severity: Minor
          Found in pkg/cd/cd.go - About 1 day 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

          File controller.go has 774 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 core/controller/template/controller.go - About 1 day to fix

            File controller.go has 768 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 core/controller/pipelinerun/controller.go - About 1 day to fix

              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

              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.ListV2 has a Cognitive Complexity of 63 (exceeds 20 allowed). Consider refactoring.
              Open

              func (c *controller) ListV2(ctx context.Context, query *q.Query, withFullPath bool) (Templates, error) {
                  var (
                      groupIDs []uint
                      err      error
                  )
              Severity: Minor
              Found in core/controller/template/controller.go - About 7 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 eventHandlerService.Start has a Cognitive Complexity of 62 (exceeds 20 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: Minor
              Found in pkg/eventhandler/eventhandler.go - About 7 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.GetByFullPath has a Cognitive Complexity of 60 (exceeds 20 allowed). Consider refactoring.
              Open

              func (c *controller) GetByFullPath(ctx context.Context,
                  resourcePath string, resourceType string) (*service.Child, error) {
                  const op = "get record by fullPath"
                  defer wlog.Start(ctx, op).StopPrint()
              
              
              Severity: Minor
              Found in core/controller/group/controller.go - About 6 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

              File controller.go has 695 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/application/controller.go - About 6 hrs to fix

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

                func (h *Registry) sendHTTPRequest(ctx context.Context, method string,
                    url string, body io.Reader, retry bool, operation string) (*http.Response, error) {
                    begin := time.Now()
                    var rsp *http.Response
                    var err error
                Severity: Major
                Found in pkg/cluster/registry/harbor/v2/registry_harbor.go and 1 other location - About 6 hrs to fix
                pkg/cluster/registry/harbor/v1/registry_harbor.go on lines 115..150

                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 463.

                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 (h *Registry) sendHTTPRequest(ctx context.Context, method string,
                    url string, body io.Reader, retry bool, operation string) (*http.Response, error) {
                    begin := time.Now()
                    var rsp *http.Response
                    var err error
                Severity: Major
                Found in pkg/cluster/registry/harbor/v1/registry_harbor.go and 1 other location - About 6 hrs to fix
                pkg/cluster/registry/harbor/v2/registry_harbor.go on lines 117..152

                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 463.

                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_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

                  File cmd.go has 664 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/cmd/cmd.go - About 5 hrs to fix

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

                    func (a *API) UpdateTemplate(c *gin.Context) {
                        op := "template: update template"
                    
                        t := c.Param(_templateParam)
                        var (
                    Severity: Major
                    Found in core/http/api/v2/template/apis.go and 1 other location - About 5 hrs to fix
                    core/http/api/v2/template/apis.go on lines 577..611

                    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 410.

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language