class Skunk::Cli::Command::Compare

Knows how to compare two branches and their skunk score average

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/skunk/cli/commands/compare.rb, line 17
def initialize(options)
  super
  @options = options
  @status_reporter = Skunk::Command::StatusReporter.new(options)
end

Public Instance Methods

analyse_branch(branch) click to toggle source

switch branch and analyse files but don't generate a report

# File lib/skunk/cli/commands/compare.rb, line 29
def analyse_branch(branch)
  ::RubyCritic::SourceControlSystem::Git.switch_branch(::RubyCritic::Config.send(branch))
  critic = critique(branch)
  ::RubyCritic::Config.send(:"#{branch}_score=", critic.skunk_score_average)
  ::RubyCritic::Config.root = branch_directory(branch)
end
analyse_modified_files() click to toggle source

generate report only for modified files but don't report it

# File lib/skunk/cli/commands/compare.rb, line 37
def analyse_modified_files
  modified_files = ::RubyCritic::Config
                   .feature_branch_collection
                   .where(::RubyCritic::SourceControlSystem::Git.modified_files)
  ::RubyCritic::AnalysedModulesCollection.new(modified_files.map(&:path),
                                              modified_files)
  ::RubyCritic::Config.root = "#{::RubyCritic::Config.root}/compare"
end
build_details() click to toggle source

create a txt file with the branch score details

# File lib/skunk/cli/commands/compare.rb, line 47
def build_details
  details = CompareScore.new(
    ::RubyCritic::Config.base_branch,
    ::RubyCritic::Config.feature_branch,
    ::RubyCritic::Config.base_branch_score.to_f.round(2),
    ::RubyCritic::Config.feature_branch_score.to_f.round(2)
  ).message

  Skunk::Command::Output.create_directory(::RubyCritic::Config.compare_root_directory)
  File.open(build_details_path, "w") { |file| file.write(details) }
  puts details
end
build_details_path() click to toggle source
# File lib/skunk/cli/commands/compare.rb, line 60
def build_details_path
  "#{::RubyCritic::Config.compare_root_directory}/build_details.txt"
end
execute() click to toggle source
# File lib/skunk/cli/commands/compare.rb, line 23
def execute
  compare_branches
  status_reporter
end