Sha256: d7b5c7e82171a0c7e9a130154e62834ff8cacd6e711e7c3870e59941940752df

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require "rubycritic/commands/compare"
require "skunk/rubycritic/analysed_modules_collection"
require "skunk/cli/commands/output"

# nodoc #
module Skunk
  module Command
    # Knows how to compare two branches and their stink score average
    class Compare < RubyCritic::Command::Compare
      # switch branch and analyse files but don't generate a report
      def analyse_branch(branch)
        ::RubyCritic::SourceControlSystem::Git.switch_branch(::RubyCritic::Config.send(branch))
        critic = critique(branch)
        ::RubyCritic::Config.send(:"#{branch}_score=", critic.stink_score_average)
        ::RubyCritic::Config.root = branch_directory(branch)
      end

      # generate report only for modified files but don't report it
      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

      # create a txt file with the branch score details
      def build_details
        details = "Base branch (#{::RubyCritic::Config.base_branch}) "\
          "average stink score: #{::RubyCritic::Config.base_branch_score} \n"\
          "Feature branch (#{::RubyCritic::Config.feature_branch}) "\
          "average stink score: #{::RubyCritic::Config.feature_branch_score} \n"
        Skunk::Command::Output.create_directory(::RubyCritic::Config.compare_root_directory)
        File.open(build_details_path, "w") { |file| file.write(details) }
        puts details
      end

      def build_details_path
        "#{::RubyCritic::Config.compare_root_directory}/build_details.txt"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
skunk-0.4.2 lib/skunk/cli/commands/compare.rb
skunk-0.4.1 lib/skunk/cli/commands/compare.rb
skunk-0.4.0 lib/skunk/cli/commands/compare.rb