Skip to content

Instantly share code, notes, and snippets.

@durandom
Last active July 5, 2016 12:07
Show Gist options
  • Save durandom/e62e666db8df6fcf570f52b02a3ccbf1 to your computer and use it in GitHub Desktop.
Save durandom/e62e666db8df6fcf570f52b02a3ccbf1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'active_support/core_ext/numeric/time'
require 'date'
require 'pathname'
require 'optparse'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../../manageiq/', __FILE__)
Dir.chdir APP_ROOT
class Matcher
attr_accessor :pattern, :name, :ignores
def initialize(name, pattern)
self.name = name
self.pattern = pattern
self.ignores = %w(
CHANGELOG.md
Gemfile
AUTHORS
README.md
LICENSE.txt
lib/miq_automation_engine/
db/
app/assets/
*.js
gems/
config/
manageiq-providers-amazon/
product/
spec/vcr_cassettes/
spec/tools/
)
yield self if block_given?
end
def to_s
name
end
def add_ignores(ignores)
self.ignores += Array(ignores)
end
end
matchers = [
Matcher.new('SupportMatrix', 'is_available|:available '),
Matcher.new('Amazon', 'amazon|aws|ec2') do |m|
m.add_ignores(['app/models/authenticator', 'app/models/authenticator/amazon.rb'])
end,
Matcher.new('Ansible', 'ansible') do |m|
m.add_ignores('app/models/manageiq/providers/ansible_tower/')
end,
Matcher.new('Azure', 'azure') do |m|
m.add_ignores('app/models/manageiq/providers/azure/')
end,
Matcher.new('Foreman', 'foreman') do |m|
m.add_ignores('app/models/manageiq/providers/foreman/')
end,
Matcher.new('Google', 'google|gce') do |m|
m.add_ignores('app/models/manageiq/providers/google/')
end,
Matcher.new('Hawkular', 'hawkular') do |m|
m.add_ignores('app/models/manageiq/providers/hawkular/')
end,
Matcher.new('Kubernetes', 'kubernetes') do |m|
m.add_ignores('app/models/manageiq/providers/kubernetes/')
end,
Matcher.new('Microsoft', 'microsoft|scvmm') do |m|
m.add_ignores('app/models/manageiq/providers/microsoft/')
end,
Matcher.new('Openshift', 'openshift') do |m|
m.add_ignores('app/models/manageiq/providers/openshift/')
m.add_ignores('app/models/manageiq/providers/openshift_enterprise/')
end,
Matcher.new('Openstack', 'openstack') do |m|
m.add_ignores('app/models/manageiq/providers/openstack/')
end,
Matcher.new('Redhat', 'redhat|rhevm') do |m|
m.add_ignores('app/models/manageiq/providers/redhat/')
end,
Matcher.new('Vmware', 'vmware') do |m|
m.add_ignores('app/models/manageiq/providers/vmware/')
end,
]
# options = {:show_matches => false, :debug => false, :verbose => false}
options = {}
OptionParser.new do |opts|
opts.on("-s", "--show-matches", "Show matches instead of count") do
options[:show_matches] = true
end
opts.on("-v", "--verbose", "Breakdown by paths") do
options[:verbose] = true
end
opts.on("-oPROVIDER", "--only=PROVIDER", matchers.map(&:to_s).map(&:downcase), "Only this provider (#{matchers.map(&:to_s).map(&:downcase).join(', ')}") do |provider|
options[:provider] = provider
end
opts.on("-d", "--debug", "Only show commands") do
options[:debug] = true
end
opts.on("-h", "--help", "Displays this help") do
puts opts
exit
end
end.parse!
paths = if options[:verbose]
%w(
app/controllers
app/decorators
app/helpers
app/models
app/presenters
app/views
spec
.)
else
%w(.)
end
if options[:debug] || options[:show_matches]
date = 1.day.ago
else
date = Date.parse("20 Jun 2016")
end
if options[:provider]
matchers.select!{|m| m.to_s.downcase.start_with?(options[:provider])}
end
print ","
matchers.each do |m|
print "#{m},"
print (',' * paths.count) if options[:verbose]
end
if options[:verbose]
print "\n,"
matchers.each do
print paths.join(',')
print ','
end
end
while (date < DateTime.now) do
print "\n'#{date},"
ref = `git rev-list -n 1 --before="#{date}" master`
`git checkout #{ref}`
matchers.each do |m|
cmd = %w(ag)
cmd += m.ignores.map{|i| "--ignore '#{i}'"}
cmd << " --ignore spec/" unless options[:verbose]
# ignore comments
cmd << "'^[^\n\r#]*(#{m.pattern})'"
paths.each do |path|
scan = cmd.dup
scan << path
scan << " | wc -l" unless options[:show_matches]
scan = scan.join(' ')
if options[:debug]
puts scan
else
if options[:show_matches]
system(scan)
else
counter = `#{scan}`
print "#{counter.chop},"
end
end
end
end
date = date + 1.week
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment