Skip to content

Commit

Permalink
Add result for list of sentry gems
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Sep 26, 2024
1 parent 2b4da76 commit 0f28c02
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ task :examine do
watt_version
node_version
datadog_gem
sentry_gems
]

output = projects.map do |project|
Expand Down
11 changes: 11 additions & 0 deletions lib/rails_exam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/ruby_exam.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
61 changes: 61 additions & 0 deletions spec/lib/rails_exam_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 0f28c02

Please sign in to comment.