class RubyCritic::Command::Compare
Attributes
paths[R]
status_reporter[R]
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/rubycritic/commands/compare.rb, line 14 def initialize(options) super @build_number = 0 end
Public Instance Methods
execute()
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 19 def execute compare_branches status_reporter.score = Config.feature_branch_score status_reporter end
Private Instance Methods
analyse_branch(branch)
click to toggle source
switch branch and analyse files
# File lib/rubycritic/commands/compare.rb, line 48 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
analyse_modified_files()
click to toggle source
generate report only for modified files
# File lib/rubycritic/commands/compare.rb, line 57 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
branch_directory(branch)
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 87 def branch_directory(branch) "#{Config.root}/compare/#{Config.send(branch)}" end
build_details()
click to toggle source
create a txt file with the branch score details
# File lib/rubycritic/commands/compare.rb, line 92 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
compare_branches()
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 29 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
compare_code_quality()
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 64 def compare_code_quality build_details compare_threshold end
compare_threshold()
click to toggle source
mark build as failed if the diff b/w the score of two branches is greater than threshold value
# File lib/rubycritic/commands/compare.rb, line 71 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
critique(branch)
click to toggle source
store the analysed moduled collection based on the branch
# File lib/rubycritic/commands/compare.rb, line 99 def critique(branch) module_collection = AnalysersRunner.new(paths).run Config.send(:"#{branch}_collection=", module_collection) RevisionComparator.new(paths).statuses = module_collection end
mark_build_fail?()
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 79 def mark_build_fail? Config.threshold_score >= 0 && threshold_reached? end
set_root_paths()
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 41 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
threshold_reached?()
click to toggle source
# File lib/rubycritic/commands/compare.rb, line 83 def threshold_reached? (Config.base_branch_score - Config.feature_branch_score) > Config.threshold_score end