lib/spoom/cli/coverage.rb in spoom-1.1.16 vs lib/spoom/cli/coverage.rb in spoom-1.2.0
- old
+ new
@@ -16,15 +16,14 @@
desc "snapshot", "Run srb tc and display metrics"
option :save, type: :string, lazy_default: DATA_DIR, desc: "Save snapshot data as json"
option :rbi, type: :boolean, default: true, desc: "Include RBI files in metrics"
option :sorbet, type: :string, desc: "Path to custom Sorbet bin"
def snapshot
- in_sorbet_project!
- path = exec_path
+ context = context_requiring_sorbet!
sorbet = options[:sorbet]
- snapshot = Spoom::Coverage.snapshot(path: path, rbi: options[:rbi], sorbet_bin: sorbet)
+ snapshot = Spoom::Coverage.snapshot(context, rbi: options[:rbi], sorbet_bin: sorbet)
snapshot.print
save_dir = options[:save]
return unless save_dir
@@ -39,23 +38,23 @@
option :to, type: :string, default: Time.now.strftime("%F"), desc: "To commit date"
option :save, type: :string, lazy_default: DATA_DIR, desc: "Save snapshot data as json"
option :bundle_install, type: :boolean, desc: "Execute `bundle install` before collecting metrics"
option :sorbet, type: :string, desc: "Path to custom Sorbet bin"
def timeline
- in_sorbet_project!
+ context = context_requiring_sorbet!
path = exec_path
sorbet = options[:sorbet]
- ref_before = Spoom::Git.current_branch
- ref_before = Spoom::Git.last_commit(path: path)&.sha unless ref_before
+ ref_before = context.git_current_branch
+ ref_before = context.git_last_commit&.sha unless ref_before
unless ref_before
say_error("Not in a git repository")
say_error("\nSpoom needs to checkout into your previous commits to build the timeline.", status: nil)
exit(1)
end
- unless Spoom::Git.workdir_clean?(path: path)
+ unless context.git_workdir_clean?
say_error("Uncommited changes")
say_error(<<~ERR, status: nil)
Spoom needs to checkout into your previous commits to build the timeline."
@@ -69,37 +68,37 @@
from = parse_time(options[:from], "--from")
to = parse_time(options[:to], "--to")
unless from
- intro_commit = Spoom::Git.sorbet_intro_commit(path: path)
+ intro_commit = context.sorbet_intro_commit
intro_commit = T.must(intro_commit) # we know it's in there since in_sorbet_project!
from = intro_commit.time
end
- timeline = Spoom::Timeline.new(from, to, path: path)
+ timeline = Spoom::Timeline.new(context, from, to)
ticks = timeline.ticks
if ticks.empty?
say_error("No commits to replay, try different `--from` and `--to` options")
exit(1)
end
ticks.each_with_index do |commit, i|
say("Analyzing commit `#{commit.sha}` - #{commit.time.strftime("%F")} (#{i + 1} / #{ticks.size})")
- Spoom::Git.checkout(commit.sha, path: path)
+ context.git_checkout!(ref: commit.sha)
snapshot = T.let(nil, T.nilable(Spoom::Coverage::Snapshot))
if options[:bundle_install]
Bundler.with_unbundled_env do
next unless bundle_install(path, commit.sha)
- snapshot = Spoom::Coverage.snapshot(path: path, sorbet_bin: sorbet)
+ snapshot = Spoom::Coverage.snapshot(context, sorbet_bin: sorbet)
end
else
- snapshot = Spoom::Coverage.snapshot(path: path, sorbet_bin: sorbet)
+ snapshot = Spoom::Coverage.snapshot(context, sorbet_bin: sorbet)
end
next unless snapshot
snapshot.print(indent_level: 2)
say("\n")
@@ -108,11 +107,11 @@
file = "#{save_dir}/#{commit.sha}.json"
File.write(file, snapshot.to_json)
say(" Snapshot data saved under `#{file}`\n\n")
end
- Spoom::Git.checkout(ref_before, path: path)
+ context.git_checkout!(ref: ref_before)
end
desc "report", "Produce a typing coverage report"
option :data, type: :string, default: DATA_DIR, desc: "Snapshots JSON data"
option :file,
@@ -139,11 +138,11 @@
option :color_strong,
type: :string,
default: Spoom::Coverage::D3::COLOR_STRONG,
desc: "Color used for typed: strong"
def report
- in_sorbet_project!
+ context = context_requiring_sorbet!
data_dir = options[:data]
files = Dir.glob("#{data_dir}/*.json")
if files.empty?
message_no_data(data_dir)
@@ -161,10 +160,10 @@
true: options[:color_true],
strict: options[:color_strict],
strong: options[:color_strong],
)
- report = Spoom::Coverage.report(snapshots, palette: palette, path: exec_path)
+ report = Spoom::Coverage.report(context, snapshots, palette: palette)
file = options[:file]
File.write(file, report.html)
say("Report generated under `#{file}`")
say("\nUse `spoom coverage open` to open it.")
end