ManageIQ/miq_bot

View on GitHub

Showing 52 of 52 total issues

Class CommitMonitor has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

class CommitMonitor
  include Sidekiq::Worker
  sidekiq_options :queue => :miq_bot_glacial, :retry => false

  include SidekiqWorkerMixin
Severity: Minor
Found in app/workers/commit_monitor.rb - About 3 hrs to fix

    Class CrossRepoTest has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class CrossRepoTest < Base
          # Reference to the branch we are creating off of origin/master
          attr_reader :branch_ref
    
          # The user calling the command
    Severity: Minor
    Found in lib/github_service/commands/cross_repo_test.rb - About 3 hrs to fix

      Class Repo has 24 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Repo < ActiveRecord::Base
        BASE_PATH = Rails.root.join("repos")
      
        has_many :branches, :dependent => :destroy
      
      
      Severity: Minor
      Found in app/models/repo.rb - About 2 hrs to fix

        Class Branch has 23 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class Branch
            attr_reader :branch
            def initialize(branch)
              @branch = branch
            end
        Severity: Minor
        Found in lib/git_service/branch.rb - About 2 hrs to fix

          Method synchronize_pr_branches has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

            def synchronize_pr_branches(expected)
              raise "repo cannot not have PR branches" unless can_have_prs?
          
              git_fetch # TODO: Let's get rid of this!
          
          
          Severity: Minor
          Found in app/models/repo.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 synchronize_pr_branches has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def synchronize_pr_branches(expected)
              raise "repo cannot not have PR branches" unless can_have_prs?
          
              git_fetch # TODO: Let's get rid of this!
          
          
          Severity: Minor
          Found in app/models/repo.rb - About 1 hr to fix

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

                def dispatch!(issuer:, text:)
                  lines = text.split("\n")
                  lines.each do |line|
                    match = command_regex.match(line.strip)
                    next unless match
            Severity: Minor
            Found in lib/github_service/command_dispatcher.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 _execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def _execute(issuer:, value:)
                    unremovable    = []
                    valid, invalid = extract_label_names(value)
                    process_extracted_labels(issuer, valid, invalid, unremovable)
            
            
            Severity: Minor
            Found in lib/github_service/commands/remove_label.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 check_line has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def check_line(line, patch)
                  file_path = patch.delta.new_file[:path]
                  Settings.diff_content_checker.offenses.each do |offender, options|
                    next if options.except.try(:any?) { |except| file_path.start_with?(except) }
            
            

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

              def check_complete
                # NOTE: The mutex may need to be upgraded to a database row lock
                #       if we go multi-process
                SEMAPHORE.synchronize do
                  begin
            Severity: Minor
            Found in app/models/batch_job.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(issuer:, value:)
                    user = value.strip.delete('@')
            
                    if valid_assignee?(user)
                      if requested_reviewers.include?(user)
            Severity: Minor
            Found in lib/github_service/commands/remove_reviewer.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 create_all_from_master has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.create_all_from_master(name)
                Repo.all.each do |repo|
                  next if repo.branches.exists?(:name => name)
            
                  b = repo.branches.new(:name => name)
            Severity: Minor
            Found in app/models/branch.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

            Method check_diff_lines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def check_diff_lines
                  branch.git_service.diff.with_each_line do |line, _parent_hunk, parent_patch|
                    next unless line.addition?
                    check_line(line, parent_patch)
                  end

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

                def status_summary
                  changed, added, deleted = raw_diff.stat
                  [
                    changed.positive? ? "#{changed} #{"file".pluralize(changed)} changed" : nil,
                    added.positive? ? "#{added} #{"insertion".pluralize(added)}(+)" : nil,
            Severity: Minor
            Found in lib/git_service/diff.rb - About 25 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 find_branch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def find_branch(branch_id, required_mode = nil)
                @branch ||= Branch.where(:id => branch_id).first
            
                if branch.nil?
                  logger.warn("Branch #{branch_id} no longer exists.  Skipping.")
            Severity: Minor
            Found in app/workers/concerns/branch_worker_mixin.rb - About 25 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 dedup_repo_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def dedup_repo_list(repo_list)
                    repo_list
                      .sort # Unadorned repo name will always sort before adorned repo names
                      .uniq
                      .slice_when { |a, b| bare_repo_name(a) != bare_repo_name(b) }
            Severity: Minor
            Found in lib/github_service/commands/cross_repo_test.rb - About 25 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 process_branch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def process_branch
                labels = []
                label_rules.each do |rule|
                  if diff_file_names.any? { |file_name| file_name =~ rule.regex }
                    labels << rule.label
            Severity: Minor
            Found in app/workers/commit_monitor_handlers/commit_range/path_based_labeler.rb - About 25 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 file_status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def file_status
                  raw_diff.patches.each_with_object({}) do |patch, h|
                    if new_file = patch.delta.new_file.try(:[], :path)
                      additions = h.fetch_path(new_file, :additions) || 0
                      h.store_path(new_file, :additions, (additions + patch.additions))
            Severity: Minor
            Found in lib/git_service/diff.rb - About 25 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

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

                  def validate_labels(label_names)
                    # First reload the cache if there are any invalid labels
                    GithubService.refresh_labels(issue.fq_repo_name) unless label_names.all? { |l| GithubService.valid_label?(issue.fq_repo_name, l) }
            
                    # Then see if any are *still* invalid and split the list
            Severity: Minor
            Found in lib/github_service/commands/add_label.rb and 1 other location - About 15 mins to fix
            lib/github_service/commands/remove_label.rb on lines 46..51

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

            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

                  def validate_labels(label_names)
                    # First reload the cache if there are any invalid labels
                    GithubService.refresh_labels(issue.fq_repo_name) unless label_names.all? { |l| GithubService.valid_label?(issue.fq_repo_name, l) }
            
                    # Then see if any are *still* invalid and split the list
            Severity: Minor
            Found in lib/github_service/commands/remove_label.rb and 1 other location - About 15 mins to fix
            lib/github_service/commands/add_label.rb on lines 31..36

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

            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