trabajo-afectivo/lib/tasks/zammad/ci/bundle/orphaned.rb
Martin Gruner 572d91f65e Maintenance: Add CI check for possibly orphaned bundled gems.
This runs only on develop and is allowed to fail.
2022-01-27 08:52:24 +01:00

48 lines
1.2 KiB
Ruby

# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
require_dependency 'tasks/zammad/command.rb'
module Tasks
module Zammad
module Ci
module Bundle
class Orphaned < Tasks::Zammad::Command
def self.usage
"#{super} age_in_years"
end
ARGUMENT_COUNT = 1
def self.task_handler
age = validate_age
orphaned_gems = find_orphaned_gems(age)
if orphaned_gems.count.zero?
puts "No bundled gems released more than #{age} year(s) ago found."
return
end
puts "The following bundled gems were released more than #{age} year(s) ago:"
orphaned_gems.each do |s|
puts " #{s.name}:#{s.version} #{s.date.strftime('%F')}"
end
abort
end
def self.validate_age
age = ARGV[1]
if age.to_i.to_s != age
abort "Please provide a valid number for 'age_in_years'.\n#{usage}"
end
age.to_i
end
def self.find_orphaned_gems(age)
Bundler.definition.specs.select { |s| s.date < age.years.ago }
end
end
end
end
end
end