Skip to content

Commit

Permalink
Merge pull request #109 from railsbump/fixes/issue-108
Browse files Browse the repository at this point in the history
Rescue exception when there is a gem (gemmy) that is vendored with a PATH
  • Loading branch information
etagwerker authored Dec 6, 2024
2 parents f9f8cee + 21e9708 commit cb82c62
Show file tree
Hide file tree
Showing 26 changed files with 77,727 additions and 2,728 deletions.
10 changes: 9 additions & 1 deletion app/controllers/gemmies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def create

def index
@gemmies = Gemmy.order(created_at: :desc).limit(20)
@inaccessible_gemmies = []
end

def show
Expand All @@ -28,7 +29,8 @@ def show

def compat_table
render locals: {
gemmies: Gemmy.find(params[:gemmy_ids].split(",")),
gemmies: Gemmy.find(params[:gemmy_ids].split(",")),
inaccessible_gemmies: InaccessibleGemmy.find(inaccessible_gemmy_ids),
hide_gem_name: params.key?(:hide_gem_name)
}
end
Expand All @@ -38,4 +40,10 @@ def compat_table
def gemmy_params
params.require(:gemmy).permit(:name)
end

def inaccessible_gemmy_ids
ps = params[:inaccessible_gemmy_ids] || ""

ps.split(",")
end
end
13 changes: 12 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module ApplicationHelper
include Baseline::Helper

def compats_status(compats)
def compats_status(gemmy, compats)
case
when gemmy.inaccessible_gem? then :inconclusive
when compats.compatible.any? then :compatible
when compats.none? || compats.pending.any? then :checking
else :incompatible
Expand All @@ -14,6 +15,8 @@ def compats_label_and_text(compats, gemmy, rails_release)
pending_compats = compats.pending

case
when gemmy.inaccessible_gem? && compats.inconclusive.any?
return ["inconclusive", "We can't determine compatibility of #{gemmy} and #{rails_release} because we don't have access to this gem."]
when compats.none?
return ["checking", "Some versions of #{gemmy} are still being checked for compatibility with #{rails_release}."]
when compatible_compats.none? && pending_compats.none?
Expand Down Expand Up @@ -77,4 +80,12 @@ def compats_label_and_text(compats, gemmy, rails_release)
def head_title
"RailsBump.org: Rails Compatibility Checker Tool"
end

def display_gemmy_name(gemmy)
if gemmy.accessible_gem?
link_to gemmy.name, gemmy
else
gemmy.name
end
end
end
12 changes: 12 additions & 0 deletions app/models/gemmy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ class Gemmy < ApplicationRecord

delegate :to_param, :to_s, to: :name

def accessible_gem?
true
end

def inaccessible_gem?
!accessible_gem?
end

def compats_for_rails_release(rails_release)
compats.merge(rails_release.compats)
end

# Find existing by case-insensitive name
def self.find_by_name(name, raise_error: false)
find_by!("LOWER(name) = ?", name.downcase)
Expand Down
32 changes: 32 additions & 0 deletions app/models/inaccessible_gemmy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class InaccessibleGemmy < ApplicationRecord
belongs_to :lockfile

FORBIDDEN_NAMES = %w(
new
edit
rails
)

validates :name, presence: true, uniqueness: { allow_blank: true }
validates :name, uniqueness: { scope: :lockfile_id }

delegate :to_param, :to_s, to: :name

def accessible_gem?
false
end

def inaccessible_gem?
!accessible_gem?
end

def compats
RailsRelease.all.map do |rails_release|
InconclusiveCompat.build(rails_release: rails_release, status: 'inconclusive')
end.to_a
end

def compats_for_rails_release(rails_release)
InconclusiveCompat.build(rails_release: rails_release, status: 'inconclusive')
end
end
17 changes: 17 additions & 0 deletions app/models/inconclusive_compat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class InconclusiveCompat < Compat
def compatible
[]
end

def inconclusive
[self]
end

def pending
[]
end

def none?
true
end
end
13 changes: 11 additions & 2 deletions app/models/lockfile.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Lockfile < ApplicationRecord
has_many :dependencies, class_name: "LockfileDependency", dependent: :destroy
has_many :gemmies, through: :dependencies
has_many :inaccessible_gemmies, dependent: :destroy

validates :content, presence: true
validates :slug, presence: { if: -> { content.present? } }, uniqueness: { allow_blank: true }
Expand Down Expand Up @@ -34,15 +35,23 @@ def calculated_slug
ActiveSupport::Digest.hexdigest(gem_names.join("#"))
end

def accessible_and_inaccessible_gemmies
(gemmies + inaccessible_gemmies).sort_by(&:name)
end

private

def add_gemmies
return if content.blank?
return if gemmies.any?

gem_names.each do |gem_name|
gemmy = Gemmy.find_by_name(gem_name) || Gemmies::Create.call(gem_name)
self.gemmies << gemmy
begin
gemmy = Gemmy.find_by_name(gem_name) || Gemmies::Create.call(gem_name)
self.gemmies << gemmy
rescue Gemmies::Create::NotFound
self.inaccessible_gemmies.build(name: gem_name)
end
end
end

Expand Down
18 changes: 9 additions & 9 deletions app/views/gemmies/compat_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- stimulus_controller = "compat-table"
- rails_releases = local_assigns.key?(:rails_release) ? RailsRelease.where(id: local_assigns.fetch(:rails_release).id) : RailsRelease.order(:version)

= async_turbo_frame :compat_table, src: [:compat_table, :gemmies, { gemmy_ids: gemmies.pluck(:id).join(","), hide_gem_name: hide_gem_name }.compact_blank], target: "_top" do
= async_turbo_frame :compat_table, src: [:compat_table, :gemmies, { inaccessible_gemmy_ids: inaccessible_gemmies.pluck(:id).join(","), gemmy_ids: gemmies.pluck(:id).join(","), hide_gem_name: hide_gem_name }.compact_blank], target: "_top" do
%table.compat-table.table.table-striped{ data: { controller: stimulus_controller } }

%thead
Expand All @@ -22,20 +22,20 @@
= rails_release.version

%tbody
- gemmies.each do |gemmy|
- compats = gemmy.compats

- all_gemmies = (gemmies + inaccessible_gemmies).sort_by(&:name)
- all_gemmies.each do |gemmy|
%tr
- unless hide_gem_name
%td
= link_to gemmy.name, gemmy
- cache [gemmy, compats] do
= display_gemmy_name gemmy
- cache [gemmy, gemmy.compats] do
- rails_releases.each do |rails_release|
- rails_release_compats = compats.merge(rails_release.compats)
- status = compats_status(rails_release_compats)
- rails_release_compats = gemmy.compats_for_rails_release(rails_release)
- status = compats_status(gemmy, rails_release_compats)
- cell_params = rails_release.earlier? ? { data: { "#{stimulus_controller}-target": "earlierRailsVersion" }, class: "d-none #{status}" } : { class: status }
- label, text = compats_label_and_text(rails_release_compats, gemmy, rails_release)

%td{ **cell_params }
= render "shared/compat_cell", status: status, label: label, text: text
= "(#{link_to "more", gemmy_rails_release_path(gemmy, rails_release), title: "#{gemmy} gem: Compatibility with Rails #{rails_release.version}"})"
- if gemmy.accessible_gem?
= "(#{link_to "more", gemmy_rails_release_path(gemmy, rails_release), title: "#{gemmy} gem: Compatibility with Rails #{rails_release.version}"})"
2 changes: 1 addition & 1 deletion app/views/gemmies/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
%section
%h2
Latest checked gems
= render template: "gemmies/compat_table", locals: { gemmies: @gemmies }
= render template: "gemmies/compat_table", locals: { gemmies: @gemmies, inaccessible_gemmies: @inaccessible_gemmies }

%section
%h2
Expand Down
2 changes: 1 addition & 1 deletion app/views/gemmies/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
= link_to "Show on RubyGems.org", "https://rubygems.org/gems/#{@gemmy.name}", target: "_blank"

%section
= render template: "gemmies/compat_table", locals: { gemmies: [@gemmy], hide_gem_name: true }
= render template: "gemmies/compat_table", locals: { gemmies: [@gemmy], inaccessible_gemmies: [], hide_gem_name: true }

= render "email_notifications/form", notifiable: @gemmy
4 changes: 2 additions & 2 deletions app/views/lockfiles/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
Checked
= l @lockfile.created_at, format: :long
= pluralize @lockfile.gemmies.size, "gem"
= pluralize @lockfile.accessible_and_inaccessible_gemmies.size, "gem"
= link_to "Show content", "#", data: { bs_toggle: "modal", bs_target: "#lockfile-content-modal" }

%section
= render template: "gemmies/compat_table", locals: { gemmies: @lockfile.gemmies }
= render template: "gemmies/compat_table", locals: { gemmies: @lockfile.gemmies, inaccessible_gemmies: @lockfile.inaccessible_gemmies }

= render "email_notifications/form", notifiable: @lockfile

Expand Down
2 changes: 1 addition & 1 deletion app/views/rails_releases/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

- compats = @gemmy.compats
- rails_release_compats = compats.merge(@rails_release.compats)
- status = compats_status(rails_release_compats)
- status = compats_status(gemmy, rails_release_compats)
- label, text = compats_label_and_text(rails_release_compats, @gemmy, @rails_release)

%section{ class: status }
Expand Down
2 changes: 2 additions & 0 deletions app/views/shared/_compat_cell.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
%i.fas.fa-spinner.fa-pulse
- when :compatible
%i.far.fa-thumbs-up
- when :inconclusive
%i.far.fa-question-circle
- else
%i.far.fa-thumbs-down
= label
11 changes: 11 additions & 0 deletions db/migrate/20241125191510_create_inaccessible_gemmies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateInaccessibleGemmies < ActiveRecord::Migration[7.1]
def change
create_table :inaccessible_gemmies do |t|
t.text :name
t.belongs_to :lockfile, null: false, foreign_key: true
t.timestamps
end

add_index :inaccessible_gemmies, [:lockfile_id, :name], unique: true
end
end
12 changes: 11 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cb82c62

Please sign in to comment.