Module: RailVerdict::Doctor
- Defined in:
- lib/rail_verdict/doctor.rb
Defined Under Namespace
Classes: Outcome
Class Method Summary collapse
Class Method Details
.execute(repository_root:, config_path:, runner: ProcessRunner, rubocop_command_resolver: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rail_verdict/doctor.rb', line 11 def execute(repository_root:, config_path:, runner: ProcessRunner, rubocop_command_resolver: nil) root = File.realpath(repository_root) resolved_config = resolve_config_path(root, config_path) configuration = Configuration.load(resolved_config) probes = {} configuration.analyzers.each do |name, selection| next unless selection.fetch("enabled") adapter = build_adapter(name, rubocop_command_resolver) next unless adapter probes[name] = adapter.probe(root, runner: runner) end analyzer_versions = probes.transform_values(&:version) context = RunContext.build( repository_root: root, configuration: configuration, analyzer_versions: analyzer_versions, revision_resolver: ->(_root) { nil } ) analyzers_report = {} configuration.analyzers.each do |name, selection| probe = probes[name] analyzers_report[name] = { "enabled" => selection.fetch("enabled"), "required" => selection.fetch("required"), "status" => probe&.status || "disabled", "version" => probe&.version } end hints = {} configuration.analyzers.each do |name, sel| probe = probes[name] status = probe&.status || "disabled" next if %w[succeeded disabled].include?(status) hints[name] = doctor_hint(name, probe) end baseline_hint = nil if configuration.mode == "no_new_debt" baseline_path = Baseline.resolve_path(repository_root: root, configuration: configuration) baseline_hint = File.file?(baseline_path) ? nil : "baseline missing for no_new_debt; run `railverdict baseline create`" end report = { "doctor" => "1.0", "ruby_version" => context.ruby_version, "target_ruby_version" => context.target_ruby_version, "rails_version" => context.rails_version, "configuration" => { "path" => relative_path(resolved_config, root), "valid" => true, "mode" => configuration.mode, "digest" => configuration.digest }, "analyzers" => analyzers_report, "hints" => hints, "baseline_hint" => baseline_hint }.compact Outcome.new(report: report, exit_code: 0) rescue ConfigurationError => error Outcome.new( report: { "doctor" => "1.0", "configuration" => { "valid" => false, "error" => error. }, "analyzers" => {} }, exit_code: 2 ) rescue RailVerdict::Error, SystemCallError => error Outcome.new( report: { "doctor" => "1.0", "configuration" => { "valid" => false, "error" => error. }, "analyzers" => {} }, exit_code: 2 ) end |