class RubyCritic::Command::Compare
def analyse_branch(branch)
def analyse_branch(branch) SourceControlSystem::Git.switch_branch(Config.send(branch)) critic = critique(branch) Config.send(:"#{branch}_score=", critic.score) Config.root = branch_directory(branch) report(critic) end
def analyse_modified_files
def analyse_modified_files modified_files = Config.feature_branch_collection.where(SourceControlSystem::Git.modified_files) analysed_modules = AnalysedModulesCollection.new(modified_files.map(&:path), modified_files) Config.root = "#{Config.root}/compare" report(analysed_modules) end
def branch_directory(branch)
def branch_directory(branch) "#{Config.root}/compare/#{Config.send(branch)}" end
def build_details
def build_details details = "Base branch (#{Config.base_branch}) score: #{Config.base_branch_score} \n"\ "Feature branch (#{Config.feature_branch}) score: #{Config.feature_branch_score} \n" File.open("#{Config.compare_root_directory}/build_details.txt", 'w') { |file| file.write(details) } end
def compare_branches
def compare_branches @build_number = Utils::BuildNumberFile.new.update_build_number set_root_paths original_no_browser_config = Config.no_browser Config.no_browser = true analyse_branch(:base_branch) analyse_branch(:feature_branch) Config.no_browser = original_no_browser_config analyse_modified_files compare_code_quality end
def compare_code_quality
def compare_code_quality build_details compare_threshold end
def compare_threshold
mark build as failed if the diff b/w the score of
def compare_threshold return unless mark_build_fail? print("Threshold: #{Config.threshold_score}\n") print("Difference: #{(Config.base_branch_score - Config.feature_branch_score).abs}\n") abort('The score difference between the two branches is over the threshold.') end
def critique(branch)
def critique(branch) module_collection = AnalysersRunner.new(paths).run Config.send(:"#{branch}_collection=", module_collection) RevisionComparator.new(paths).statuses = module_collection end
def execute
def execute compare_branches status_reporter.score = Config.feature_branch_score status_reporter end
def initialize(options)
def initialize(options) super @build_number = 0 end
def mark_build_fail?
def mark_build_fail? Config.threshold_score >= 0 && threshold_reached? end
def set_root_paths
def set_root_paths Config.base_root_directory = Pathname.new(branch_directory(:base_branch)) Config.feature_root_directory = Pathname.new(branch_directory(:feature_branch)) Config.compare_root_directory = Pathname.new("#{Config.root}/compare") end
def threshold_reached?
def threshold_reached? (Config.base_branch_score - Config.feature_branch_score) > Config.threshold_score end