Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created December 19, 2017 17:33
Show Gist options
  • Save emad-elsaid/fe98baeef09278893ee446468feb40e3 to your computer and use it in GitHub Desktop.
Save emad-elsaid/fe98baeef09278893ee446468feb40e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# coding: utf-8
def header(s)
s = "⦿ #{s}"
puts
puts s
puts '=' * s.size
end
def separator_row(maxs)
print '| '
lines = Array.new(maxs.size, '-')
lines.each_with_index do |ele, index|
print "#{ele * (maxs[index] + 4)} | "
end
puts
end
def table(a, header: nil, footer: nil)
return if a.empty?
a = [header] + a if header
a = a + [footer] if footer
maxs = a.inject(Array.new(a.first.size, 0)) do |mem, e|
sizes = e.map(&:to_s).map(&:size)
[mem, sizes].transpose.map(&:max)
end
a.each_with_index do |row, row_index|
print '| '
row.each_with_index do |ele, index|
print "#{ele}#{' ' * (maxs[index] - ele.to_s.size)} | "
end
puts
separator_row(maxs) if header && row_index.zero?
separator_row(maxs) if footer && row_index == a.size - 2
end
end
##############################################################################
git_files = `git ls-files`.lines.map(&:strip)
git_commits = `git rev-list HEAD --count`.strip
##############################################################################
header 'First commit'
puts `git rev-list --pretty=email --max-parents=0 HEAD`
##############################################################################
git_log = `git shortlog -sne`
git_log = git_log
.lines
.map(&:strip)
.map { |l| l.split("\t").reverse }
header "Contributors"
table git_log,
header: ['Contributor', '# of commits'],
footer: ["#{git_log.size} contributors", git_commits]
##############################################################################
extensions = Hash.new(0)
git_files.each do |f|
ext = File.extname(f)
extensions[ext] += 1
end
header 'Files'
table extensions.to_a.sort_by(&:last).reverse,
header: ['Extension', 'Count'],
footer: ["#{extensions.size} types", git_files.size]
##############################################################################
gemfiles = git_files.select { |f| f.end_with?('Gemfile') }
header "Found #{gemfiles.size} Gemfiles" unless gemfiles.empty?
gemfiles_stats = []
gemfiles.each do |gemfile|
Dir.chdir(File.dirname(gemfile)) do
bundle_show_output = `bundle show`
bundle_show = bundle_show_output.lines
if bundle_show_output.include?('Could not find')
gemfiles_stats << [gemfile, 'Bundle install to get # of gems']
else
gemfiles_stats << [gemfile, "#{bundle_show.size - 1} Gems"]
end
end
end
table gemfiles_stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment