Last active
September 20, 2018 20:23
-
-
Save darktef/5e3da351c9b80cb802822cfcb0c84a10 to your computer and use it in GitHub Desktop.
Ruby - Grab the commit history of all related files
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
results = [] | |
file_names = `find . -print | grep '.*referral.*'`.split("\n");nil | |
file_names.each do |name| | |
output = `git log --follow --pretty=format:'{"commit": "%H","author": "%aN <%aE>","date": "%ad","message": "%f"},' -- #{name}` | |
results.concat(JSON.parse('[' + output.gsub("\n", '')[0..-2] + ']')) | |
end | |
mapping = {} | |
results.each do |res| | |
next if mapping[res['commit']] | |
mapping[res['commit']] = res | |
end | |
sorted_mapping = mapping.sort_by { |key,val| Date.strptime(val["date"], "%a %b %d %H:%M:%S %Y %z") } | |
File.open("related_commits.json","w") do |f| | |
f.write(sorted_mapping.to_json) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment