Last active
February 21, 2021 18:26
-
-
Save jbranchaud/ac421e71842bc733cf17b0c6c5c392d8 to your computer and use it in GitHub Desktop.
TIL Repo: Generate List of Links For Past Week's TILs
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 = `git log HEAD@{'7 days ago'}..HEAD --oneline | sed 's/^\([[:alnum:]]*\) .*$/\1/'` | |
commit_list = results.split(/\n/).map do |item| | |
item.split(' ', 2) | |
end.filter do |sha, commit_message| | |
commit_message.start_with?('Add ') | |
end | |
commit_data = commit_list.map do |sha, commit_message| | |
diff_tree_result = `git diff-tree --no-commit-id --name-only -r #{sha}` | |
files = diff_tree_result.split(/\n/) | |
source_file = (files - ['README.md'])[0] | |
# description = commit_message.sub('Add ', '').split(' as a ')[0] | |
description = File.open(source_file, &:gets).sub('# ', '').strip | |
topic = source_file.split('/')[0].capitalize | |
{ | |
sha: sha, | |
commit_message: commit_message, | |
files: files, | |
source_file: source_file, | |
description: description, | |
topic: topic | |
} | |
end | |
links = commit_data.map do |data| | |
"- [#{data[:description]}](https://github.com/jbranchaud/til/blob/master/#{data[:source_file]}), #[[#{data[:topic]}]]" | |
end | |
links.reverse.each do |link| | |
puts link | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment