gitlabhq/gitlab-ci

View on GitHub

Showing 58 of 58 total issues

Method unpack has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def unpack
      Dir.chdir(GitlabCi.config.backup.path)

      # check for existing backups in the backup dir
      file_list = Dir.glob("*_gitlab_ci_backup.tar").each.map { |f| f.split(/_/).first.to_i }
Severity: Minor
Found in lib/backup/manager.rb - About 1 hr to fix

    Method convert_to_postgresql has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def convert_to_postgresql
          mysql_dump_gz = db_file_name + '.mysql'
          psql_dump_gz = db_file_name + '.psql'
          drop_indexes_sql = File.join(db_dir, 'drop_indexes.sql')
    
    
    Severity: Minor
    Found in lib/backup/database.rb - About 1 hr to fix

      Method attachments has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

        def attachments
          fields = []
      
          if commit.matrix?
            commit.builds_without_retry.each do |build|
      Severity: Minor
      Found in app/models/project_services/slack_message.rb - About 1 hr 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 can_execute? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def can_execute?(build)
          return if build.allow_failure?
      
          commit = build.commit
          return unless commit
      Severity: Minor
      Found in app/models/project_services/slack_service.rb - About 55 mins 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 authenticate_public_page! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def authenticate_public_page!
          unless project.public
            unless current_user
              redirect_to(new_user_sessions_path(state: generate_oauth_state(request.fullpath))) and return
            end
      Severity: Minor
      Found in app/controllers/application_controller.rb - About 55 mins 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 can_execute? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def can_execute?(build)
          return if build.allow_failure?
      
          commit = build.commit
          return unless commit
      Severity: Minor
      Found in app/models/project_services/hip_chat_service.rb - About 55 mins 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 execute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def execute(project, params)
          before_sha = params[:before]
          sha = params[:checkout_sha] || params[:after]
          origin_ref = params[:ref]
          
      Severity: Minor
      Found in app/services/create_commit_service.rb - About 55 mins 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 can_execute? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def can_execute?(build)
          return if build.allow_failure?
      
          # it doesn't make sense to send emails for retried builds
          commit = build.commit
      Severity: Minor
      Found in app/models/project_services/mail_service.rb - About 55 mins 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 gitlab has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def gitlab
          @limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i
          @page = @offset == 0 ? 1 : (@offset / @limit + 1)
      
          current_user.reset_cache if params[:reset_cache]
      Severity: Minor
      Found in app/controllers/projects_controller.rb - About 45 mins 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 status has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def status
          if skip_ci?
            return 'skipped'
          elsif yaml_errors.present?
            return 'failed'
      Severity: Minor
      Found in app/models/commit.rb - About 45 mins 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 execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def execute
          puts "GitLab CI #{current_version.major} upgrade tool"
          puts "Your version is #{current_version}"
          puts "Latest available version for GitLab CI #{current_version.major} is #{latest_version}"
      
      
      Severity: Minor
      Found in lib/upgrader.rb - About 45 mins 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

      Avoid deeply nested control flow statements.
      Open

                          if "DEFAULT '0'" in extra:
                              final_default = "FALSE"
                          elif "DEFAULT '1'" in extra:
                              final_default = "TRUE"
      
      
      Severity: Major
      Found in lib/support/mysql-postgresql-converter/db_converter.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if enum_name not in enum_types:
                                output.write("CREATE TYPE {0} AS ENUM ({1}); \n".format(enum_name, types_str));
                                enum_types.append(enum_name)
        
        
        Severity: Major
        Found in lib/support/mysql-postgresql-converter/db_converter.py - About 45 mins to fix

          Method get_xterm_color_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_xterm_color_class(command_stack, prefix)
                # the 38 and 48 commands have to be followed by "5" and the color index
                return unless command_stack.length >= 2
                return unless command_stack[0] == "5"
          
          
          Severity: Minor
          Found in lib/ansi2html.rb - About 45 mins 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 initial_parsing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def initial_parsing
              @before_script = @config[:before_script] || []
              @image = @config[:image]
              @services = @config[:services]
              @stages = @config[:stages] || @config[:types]
          Severity: Minor
          Found in lib/gitlab_ci_yaml_processor.rb - About 45 mins 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

          Avoid deeply nested control flow statements.
          Open

                              if final_default:
                                  cast_lines.append("ALTER TABLE \"%s\" ALTER COLUMN \"%s\" SET DEFAULT %s" % (current_table, name, final_default))
                          # ID fields need sequences [if they are integers?]
                          if name == "id" and set_sequence is True:
          Severity: Major
          Found in lib/support/mysql-postgresql-converter/db_converter.py - About 45 mins to fix

            Consider simplifying this complex logical expression.
            Open

                    if line.startswith("--") or line.startswith("/*") or line.startswith("LOCK TABLES") or line.startswith("DROP TABLE") or line.startswith("UNLOCK TABLES") or not line:
                        continue
            
                    # Outside of anything handling
                    if current_table is None:
            Severity: Major
            Found in lib/support/mysql-postgresql-converter/db_converter.py - About 40 mins to fix

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

                      gitlab_projects = Project.from_gitlab(
                        current_user, :owned, { page: params[:page], per_page: params[:per_page], ci_enabled_first: true }
                      )
                      ids = gitlab_projects.map { |project| project.id }
              
              
              Severity: Minor
              Found in lib/api/projects.rb and 1 other location - About 35 mins to fix
              lib/api/projects.rb on lines 36..43

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

              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

                      gitlab_projects = Project.from_gitlab(
                        current_user, :authorized, { page: params[:page], per_page: params[:per_page], ci_enabled_first: true }
                      )
                      ids = gitlab_projects.map { |project| project.id }
              
              
              Severity: Minor
              Found in lib/api/projects.rb and 1 other location - About 35 mins to fix
              lib/api/projects.rb on lines 50..57

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

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

                  def dump(mysql_to_postgresql=false)
                    FileUtils.rm_f(db_file_name)
                    compress_rd, compress_wr = IO.pipe
                    compress_pid = spawn(*%W(gzip -1 -c), in: compress_rd, out: [db_file_name, 'w', 0600])
                    compress_rd.close
              Severity: Minor
              Found in lib/backup/database.rb - About 35 mins 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

              Severity
              Category
              Status
              Source
              Language