Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport upstream changes #22

Merged
merged 26 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
50bddbe
Add Ruby 2.2.10 to build matrix
etagwerker Apr 27, 2019
524cdd1
Stop using <<~ for heredoc and the safe operator (&.)
etagwerker Apr 27, 2019
6282a66
Remove activesupport dependency
etagwerker Apr 27, 2019
2db8f38
Fix spec to work with Ruby 2.2.10
etagwerker Apr 27, 2019
743605a
Make sure that Kernel.warn tracking works even in Ruby < 2.3
etagwerker May 14, 2019
c7a749a
Make sure that indenting is not all weird
etagwerker May 14, 2019
9d8defd
Try with `time_ago_in_words` instead of `actionview`
etagwerker May 25, 2019
3716898
Support older versions of Ruby
etagwerker May 25, 2019
4a0a70a
Remove named parameters to support older versions of Ruby
etagwerker May 25, 2019
88db284
Remove `time_ago_in_words` dependency
etagwerker Jul 6, 2019
1106a9e
Refactor `exe/bundle_report` -- Move classes to `lib` directory
etagwerker Jul 6, 2019
7c8cd1c
Add coverage for `age` method
etagwerker Jul 6, 2019
94d5ed9
Add .ruby-version and .byebug_history to list of ignored files
etagwerker Jul 6, 2019
cfde4ac
Bundled
etagwerker Jul 24, 2019
c271545
Merge branch 'remove_rest_client'
etagwerker Jul 24, 2019
ba7063f
Merge branch 'update-deprecation-tracker'
etagwerker Jul 24, 2019
38d89f0
Bundled and removed unnecessary require
etagwerker Jul 24, 2019
53a87ba
Merge branch 'fixes/ruby-2-2-syntax-error'
etagwerker Jul 24, 2019
00774bd
Merge branch 'set-ruby-requirement'
etagwerker Jul 24, 2019
ad5762b
Rename gem as `next_rails` to be shipped ASAP
etagwerker Jul 24, 2019
636083f
Rename gem and classes
etagwerker Jul 27, 2019
ff9fa51
Update homepage in gemspec
jamie Sep 26, 2019
b3f3ef6
Merge pull request #1 from jamie/patch-1
etagwerker Sep 26, 2019
707b810
Merge remote-tracking branch 'next_rails/master' into backport-upstre…
mctaylorpants Dec 5, 2019
79658d9
next_rails -> ten_years_rails
mctaylorpants Dec 5, 2019
d824ccc
Update actionview
mctaylorpants Dec 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
/spec/reports/
/tmp/

.byebug_history

# rspec failure tracking
.rspec_status

.ruby-version
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sudo: false
language: ruby
rvm:
- 2.2.10
- 2.3.3
before_install: gem install bundler -v 1.16.1
35 changes: 18 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
PATH
remote: .
specs:
ten_years_rails (0.2.0)
actionview
activesupport
ten_years_rails (1.0.1)
actionview (~> 5.2.3)
colorize (>= 0.8.1)

GEM
remote: https://rubygems.org/
specs:
actionview (5.2.3)
activesupport (= 5.2.3)
actionview (5.2.4)
activesupport (= 5.2.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activesupport (5.2.3)
activesupport (5.2.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -25,36 +24,37 @@ GEM
concurrent-ruby (1.1.5)
crass (1.0.5)
diff-lcs (1.3)
erubi (1.8.0)
i18n (1.6.0)
erubi (1.9.0)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
loofah (2.3.1)
loofah (2.4.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mini_portile2 (2.4.0)
minitest (5.11.3)
nokogiri (1.10.5)
minitest (5.13.0)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
rake (10.5.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec-expectations (3.8.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
rspec-mocks (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rspec-support (3.8.2)
thread_safe (0.3.6)
timecop (0.9.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)

Expand All @@ -66,6 +66,7 @@ DEPENDENCIES
rake (~> 10.0)
rspec (~> 3.0)
ten_years_rails!
timecop (~> 0.9.1)

BUNDLED WITH
1.17.2
211 changes: 4 additions & 207 deletions exe/bundle_report
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#
at_exit do
require "optparse"
require "ten_years_rails"

options = {}
option_parser = OptionParser.new do |opts|
opts.banner = <<~EOS
opts.banner = <<-EOS
Usage: #{$0} [report-type] [options]

report-type There are two report types available: `outdated` and `compatibility`
Expand Down Expand Up @@ -46,9 +47,9 @@ at_exit do
report_type = ARGV.first

case report_type
when "outdated" then BundleReport.outdated
when "outdated" then TenYearsRails::BundleReport.outdated
else
BundleReport.compatibility(rails_version: options.fetch(:rails_version, "5.0"), include_rails_gems: options.fetch(:include_rails_gems, false))
TenYearsRails::BundleReport.compatibility(rails_version: options.fetch(:rails_version, "5.0"), include_rails_gems: options.fetch(:include_rails_gems, false))
end
end

Expand All @@ -57,207 +58,3 @@ require "bundler/setup"

require "action_view"
require "active_support/core_ext/object/acts_like"
require "colorize"
require "cgi"
require "erb"
require "json"

class BundleReport
def self.compatibility(rails_version:, include_rails_gems:)
incompatible_gems = BundleReport::GemInfo.all.reject do |gem|
gem.compatible_with_rails?(rails_version: rails_version) || (!include_rails_gems && gem.from_rails?)
end.sort_by do |gem|
[
gem.latest_version.compatible_with_rails?(rails_version: rails_version) ? 0 : 1,
gem.name
].join("-")
end

incompatible_gems_by_state = incompatible_gems.group_by { |gem| gem.state(rails_version) }

template = <<~ERB
<% if incompatible_gems_by_state[:latest_compatible] -%>
<%= "=> Incompatible with Rails #{rails_version} (with new versions that are compatible):".white.bold %>
<%= "These gems will need to be upgraded before upgrading to Rails #{rails_version}.".italic %>

<% incompatible_gems_by_state[:latest_compatible].each do |gem| -%>
<%= gem_header(gem) %> - upgrade to <%= gem.latest_version.version %>
<% end -%>

<% end -%>
<% if incompatible_gems_by_state[:incompatible] -%>
<%= "=> Incompatible with Rails #{rails_version} (with no new compatible versions):".white.bold %>
<%= "These gems will need to be removed or replaced before upgrading to Rails #{rails_version}.".italic %>

<% incompatible_gems_by_state[:incompatible].each do |gem| -%>
<%= gem_header(gem) %> - new version, <%= gem.latest_version.version %>, is not compatible with Rails #{rails_version}
<% end -%>

<% end -%>
<% if incompatible_gems_by_state[:no_new_version] -%>
<%= "=> Incompatible with Rails #{rails_version} (with no new versions):".white.bold %>
<%= "These gems will need to be upgraded by us or removed before upgrading to Rails #{rails_version}.".italic %>
<%= "This list is likely to contain internal gems, like Cuddlefish.".italic %>

<% incompatible_gems_by_state[:no_new_version].each do |gem| -%>
<%= gem_header(gem) %> - new version not found
<% end -%>

<% end -%>
<%= incompatible_gems.length.to_s.red %> gems incompatible with Rails <%= rails_version %>
ERB

puts ERB.new(template, nil, "-").result(binding)
end

def self.gem_header(_gem)
header = "#{_gem.name} #{_gem.version}".bold
header << " (loaded from git)".magenta if _gem.sourced_from_git?
header
end

def self.outdated
gems = BundleReport::GemInfo.all
out_of_date_gems = gems.reject(&:up_to_date?).sort_by(&:created_at)
percentage_out_of_date = ((out_of_date_gems.count / gems.count.to_f) * 100).round
sourced_from_git = gems.select(&:sourced_from_git?)

out_of_date_gems.each do |_gem|
header = "#{_gem.name} #{_gem.version}"

puts <<~MESSAGE
#{header.bold.white}: released #{_gem.age} (latest version, #{_gem.latest_version.version}, released #{_gem.latest_version.age})
MESSAGE
end

puts ""
puts <<~MESSAGE
#{"#{sourced_from_git.count}".yellow} gems are sourced from git
#{"#{out_of_date_gems.length}".red} of the #{gems.count} gems are out-of-date (#{percentage_out_of_date}%)
MESSAGE
end

class GemInfo
include ActionView::Helpers::DateHelper

class NullGemInfo < GemInfo
def initialize; end

def age
"-"
end

def time_to_latest_version
"-"
end

def created_at
Time.now
end

def up_to_date?
false
end

def version
"NOT FOUND"
end

def unsatisfied_rails_dependencies(*)
["unknown"]
end

def state(_)
:null
end
end

def self.all
Gem::Specification.each.map do |gem_specification|
new(gem_specification)
end
end

attr_reader :gem_specification, :version, :name
def initialize(gem_specification)
@gem_specification = gem_specification
@version = gem_specification.version
@name = gem_specification.name
end

def age
"#{time_ago_in_words(created_at)} ago"
end

def sourced_from_git?
!!gem_specification.git_version
end

def time_to_latest_version
distance_of_time_in_words(created_at, latest_version.created_at)
end

def created_at
@created_at ||= gem_specification.date
end

def up_to_date?
version == latest_version.version
end

def state(rails_version)
if compatible_with_rails?(rails_version: rails_version)
:compatible
elsif latest_version.compatible_with_rails?(rails_version: rails_version)
:latest_compatible
elsif latest_version.version == "NOT FOUND"
:no_new_version
else
:incompatible
end
end

def latest_version
@latest_version ||= begin
latest_gem_specification = Gem.latest_spec_for(name)
if latest_gem_specification
GemInfo.new(latest_gem_specification)
else
NullGemInfo.new
end
end
end

def compatible_with_rails?(rails_version: Gem::Version.new("5.0"))
unsatisfied_rails_dependencies(rails_version: rails_version).empty?
end

def unsatisfied_rails_dependencies(rails_version:)
rails_dependencies = gem_specification.runtime_dependencies.select {|dependency| rails_gems.include?(dependency.name) }

rails_dependencies.reject do |rails_dependency|
rails_dependency.requirement.satisfied_by?(Gem::Version.new(rails_version))
end
end

def from_rails?
rails_gems.include?(name)
end

private def rails_gems
[
"rails",
"activemodel",
"activerecord",
"actionmailer",
"actioncable",
"actionpack",
"actionview",
"activejob",
"activestorage",
"activesupport",
"railties",
]
end
end
end
9 changes: 6 additions & 3 deletions exe/deprecations
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ require "colorize"
require "optparse"
require "set"

def run_tests(deprecation_warnings, tracker_mode:, next_mode:)
def run_tests(deprecation_warnings, opts = {})
tracker_mode = opts[:tracker_mode]
next_mode = opts[:next_mode]
rspec_command = if next_mode
"bin/next rspec"
else
Expand All @@ -16,7 +18,8 @@ def run_tests(deprecation_warnings, tracker_mode:, next_mode:)
exec command
end

def print_info(deprecation_warnings, verbose: false)
def print_info(deprecation_warnings, opts = {})
verbose = !!opts[:verbose]
frequency_by_message = deprecation_warnings.each_with_object({}) do |(test_file, messages), hash|
messages.each do |message|
hash[message] ||= { test_files: Set.new, occurrences: 0 }
Expand All @@ -36,7 +39,7 @@ end

options = {}
option_parser = OptionParser.new do |opts|
opts.banner = <<~MESSAGE
opts.banner = <<-MESSAGE
Usage: #{__FILE__.to_s} [options] [mode]

Parses the deprecation warning shitlist and show info or run tests.
Expand Down
Loading