ManageIQ/multi_repo

View on GitHub
lib/multi_repo/helpers/git_mirror.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Class GitMirror has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

  class GitMirror
    def initialize
      require "colorize"
      require "config"
      require "fileutils"
Severity: Minor
Found in lib/multi_repo/helpers/git_mirror.rb - About 2 hrs to fix

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

        def sync_branch(source_remote, source_name, dest_remote, dest_name)
          return unless dest_remote && dest_name
    
          source_fq_name = "#{source_remote}/#{source_name}"
          dest_fq_name   = "#{dest_remote}/#{dest_name}"
    Severity: Minor
    Found in lib/multi_repo/helpers/git_mirror.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 clone_repo has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def clone_repo(upstream_repo, downstream_repo, path, remote_source)
          upstream_remote = settings.git_mirror.remotes[remote_source]
          raise "remote '#{remote_source}'' not found in settings" if upstream_remote.nil?
    
          system("git clone #{upstream_remote}/#{upstream_repo}.git #{path} -o upstream")
    Severity: Minor
    Found in lib/multi_repo/helpers/git_mirror.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 with_repo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def with_repo(repo, options)
          repo_name = downstream_repo_name(repo, options)
          puts "\n==== Mirroring #{repo_name} ====".bold.cyan
    
          working_dir = settings.git_mirror.working_directory
    Severity: Minor
    Found in lib/multi_repo/helpers/git_mirror.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 system has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def system(*args)
          puts "+ #{"dry_run: " if dry_run?}#{args.join(" ")}"
          return true if dry_run?
    
          args << {} unless args.last.is_a?(Hash)
    Severity: Minor
    Found in lib/multi_repo/helpers/git_mirror.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 remote_refs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def remote_refs(repo, remote)
          return unless remote_exists?(remote)
    
          `git ls-remote #{remote} | grep "heads"`.split("\n").collect do |line|
            branch = line.split("/").last
    Severity: Minor
    Found in lib/multi_repo/helpers/git_mirror.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

    Use filter_map instead.
    Open

          `git ls-remote #{remote} | grep "heads"`.split("\n").collect do |line|
            branch = line.split("/").last
            next if remote == "upstream" && !upstream_branch?(repo, branch)
            "#{remote}/#{branch}:refs/heads/#{branch}"
          end.compact.join(" ")

    There are no issues that match your filters.

    Category
    Status