Skip to content

Instantly share code, notes, and snippets.

@caleb15
Created November 22, 2019 19:24

Revisions

  1. caleb15 created this gist Nov 22, 2019.
    32 changes: 32 additions & 0 deletions most_changed_roles.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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)