diff --git a/Rakefile b/Rakefile index f54f0e4..bb6514b 100644 --- a/Rakefile +++ b/Rakefile @@ -20,6 +20,7 @@ task :examine do watt_version node_version datadog_gem + sentry_gems ] output = projects.map do |project| diff --git a/lib/rails_exam.rb b/lib/rails_exam.rb index 61dfd5a..59c1413 100644 --- a/lib/rails_exam.rb +++ b/lib/rails_exam.rb @@ -9,6 +9,7 @@ def results framework_defaults: framework_defaults, kinetic_version: kinetic_version, rails_version: rails_version, + sentry_gems: sentry_gems, watt_version: watt_version } end @@ -47,6 +48,16 @@ def rails_version captures.first end + def sentry_gems + gemfile_data = @project.files["Gemfile"] + return unless gemfile_data + + gems = gemfile_data.lines.map { |line| line.match(/gem .(sentry-.*)./)&.captures&.first }.compact + return unless gems.any? + + gems.join("|") + end + def watt_version gemfile_lock_data = @project.files["Gemfile.lock"] return unless gemfile_lock_data diff --git a/lib/ruby_exam.rb b/lib/ruby_exam.rb index fc24d83..06aaed6 100644 --- a/lib/ruby_exam.rb +++ b/lib/ruby_exam.rb @@ -1,8 +1,4 @@ class RubyExam - # def self.from_repo(project_name) - # sentry_gem = `cat projects/#{project_name}/Gemfile | ag "gem .sentry."`.split(" ")[1]&.gsub(/["']/, "") - # end - def initialize(project) @project = project end diff --git a/spec/lib/rails_exam_spec.rb b/spec/lib/rails_exam_spec.rb index e5faca3..5ab5de5 100644 --- a/spec/lib/rails_exam_spec.rb +++ b/spec/lib/rails_exam_spec.rb @@ -218,6 +218,67 @@ end end + describe "sentry gems result" do + let(:files) { {"Gemfile" => gemfile_data} } + let(:project) { double(:project, files: files) } + + context "when the gemfile data is nil" do + let(:gemfile_data) { nil } + + it "returns nil" do + exam = RailsExam.new(project) + sentry_gems = exam.results[:sentry_gems] + expect(sentry_gems).to eq nil + end + end + + context "when the gemfile data is an empty string" do + let(:gemfile_data) { nil } + + it "returns nil" do + exam = RailsExam.new(project) + sentry_gems = exam.results[:sentry_gems] + expect(sentry_gems).to eq nil + end + end + + context "when the gemfile data has no sentry gems" do + let(:gemfile_data) { 'gem "gris"' } + + it "returns nil" do + exam = RailsExam.new(project) + sentry_gems = exam.results[:sentry_gems] + expect(sentry_gems).to eq nil + end + end + + context "when the gemfile data has a sentry gem" do + let(:gemfile_data) { 'gem "sentry-ruby"' } + + it "returns that sentry gem name" do + exam = RailsExam.new(project) + sentry_gems = exam.results[:sentry_gems] + expect(sentry_gems).to eq "sentry-ruby" + end + end + + context "when the gemfile data has a few sentry gems" do + let(:gemfile_data) do + <<-EOF + gem "sentry-ruby" + gem "sentry-rails" + gem "sentry-sidekiq" + EOF + end + + it "returns those sentry gems joined with a pipe" do + exam = RailsExam.new(project) + sentry_gems = exam.results[:sentry_gems] + expect(sentry_gems).to eq "sentry-ruby|sentry-rails|sentry-sidekiq" + end + end + end + describe "watt version result" do let(:files) { {"Gemfile.lock" => gemfile_lock_data} } let(:project) { double(:project, files: files) }