Last active
June 19, 2019 00:56
-
-
Save JackDanger/1005a66b0ce12535e845e786d62ede6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pp' | |
DIR = File.expand_path(__dir__) | |
module Deprecations | |
extend self | |
PATTERN = /DEPRECATION WARNING: (?<message>.*) \(called from (?<source_method>.+) at (?<source_file>[\w\.\/]+):(?<source_line>\d+)/ | |
def print_team_info(printer = :simple) | |
all.group_by do |deprecation| | |
deprecation[:team] | |
end.sort_by do |_, deprecations| | |
deprecations.size | |
end.reverse.each do |team, deprecations| | |
puts '' | |
puts "#{deprecations.size.to_s.rjust(3, ' ')} for #{team || '-- no team assigned --'} :" | |
deprecations.group_by do |deprecation| | |
deprecation[:message] | |
end.sort_by do |_, deprecations_for_this_message| | |
deprecations_for_this_message.size | |
end.reverse.each do |message, deprecations_for_this_message| | |
puts '' if deprecations.size > 1 | |
puts " #{message.inspect}" | |
deprecations_for_this_message.group_by {|d| d[:source_file] }.each do |file, deprecations_for_this_file| | |
send("print_#{printer}", deprecations_for_this_file) | |
end | |
end | |
end | |
end | |
def print_simple(deprecations) | |
lines = deprecations.map {|d| d[:source_line]}.uniq.map(&:to_i) | |
file_display_name = deprecations.first[:source_file_relative] | |
singular = lines.size == 1 | |
if singular | |
line_message = "line: #{lines.first}" | |
else | |
line_message = "lines: #{lines.join(', ')}" | |
end | |
puts " -- #{file_display_name} (#{line_message})" | |
end | |
def print_jira(deprecations) | |
message = deprecations.first[:message] | |
lines = deprecations.map {|d| d[:source_line]}.uniq.map(&:to_i) | |
file = deprecations.first[:source_file] | |
file_display_name = deprecations.first[:source_file_relative] | |
singular = lines.size == 1 | |
puts '_' * 50 | |
puts "Rails5 deprecation in #{file_display_name.inspect}" | |
puts '' | |
puts "Deprecation message:" | |
puts "{code}#{message}{code}" | |
puts '' | |
puts "In #{file_display_name.inspect}" unless singular | |
lines.each do |line| | |
if singular | |
puts "On line #{line} of #{file_display_name.inspect}:" | |
else | |
puts "On line #{line}:" | |
end | |
puts '{code}' | |
puts File.readlines(file)[(line - 2)..(line + 1)] | |
puts '{code}' | |
end | |
end | |
def all | |
parsed_lines | |
end | |
private | |
def parsed_lines | |
@parsed_lines ||= lines.map { |line| parse line } | |
end | |
def lines | |
@lines ||= DATA.read.split("\n") | |
end | |
def parse(line) | |
match = PATTERN.match(line) | |
if match | |
data = { | |
source_line: match['source_line'], | |
source_file: match['source_file'], | |
source_file_relative: match['source_file'].sub("#{DIR}/", ''), | |
source_method: match['source_method'], | |
message: match['message'], | |
} | |
data[:team] = Codeowners.teams_by_file[data[:source_file]] | |
data | |
else | |
raise "Did not match pattern: #{line.inspect}" | |
end | |
end | |
end | |
module Codeowners | |
extend self | |
def teams_by_file | |
@teams_by_file ||= begin | |
lines.each_with_object({}) do |line, acc| | |
glob, team = line.split(" ") | |
team = team.sub('@', '') | |
if glob.end_with?('/') | |
Dir["#{DIR}/#{glob}**"] | |
else | |
Dir["#{DIR}/#{glob}"] | |
end.each do |file| | |
acc[file] = team | |
end | |
end | |
end | |
end | |
def lines | |
@lines ||= File.read('./CODEOWNERS').split("\n").reject { |line| line =~ /^ *#/ || line =~ /^ *$/ } | |
end | |
end | |
if ARGV.size > 0 | |
printer = ARGV[0] | |
else | |
printer = :simple | |
end | |
puts "#{Deprecations.all.size} deprecations" | |
puts '----------------- ' | |
Deprecations.print_team_info(printer) | |
puts '' | |
__END__ | |
( paste in the deprecation output here ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment