Skip to content

Instantly share code, notes, and snippets.

@caleb15
Created November 22, 2019 19:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caleb15/da591031936f35d80e14a42ca7ba4350 to your computer and use it in GitHub Desktop.
Save caleb15/da591031936f35d80e14a42ca7ba4350 to your computer and use it in GitHub Desktop.
python script for aggregating changes by folder.
import re
# run ./git-most.sh > most.txt before this script
# adjust whitelist var if you only want to see changes to a certain filetype/file/path
most_changed_paths = {}
whitelist = '' # '.yml'
with open('most.txt') as f:
for line in f.readlines():
split_line = line.split('\t')
if len(split_line) == 1:
continue # ignore malformed lines
num = int(split_line[0])
path = split_line[1].strip()
if whitelist:
if whitelist not in path:
continue
match = re.fullmatch(r'(roles/[^/]+)/.*', path)
if match:
roleDir = match.group(1)
if roleDir in most_changed_paths:
most_changed_paths[roleDir] += num
else:
most_changed_paths[roleDir] = num
sorted_most_changed_paths = sorted(most_changed_paths.items(), key=lambda kv: kv[1])
sorted_most_changed_paths.reverse()
for path in sorted_most_changed_paths:
print(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment