Created
May 1, 2024 20:45
-
-
Save donkirkby/3e57b6cf20a4b8ad0f3a75d75d7d90ab to your computer and use it in GitHub Desktop.
Look for git changes not tagged with issue numbers
This file contains hidden or 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
from collections import defaultdict | |
import re | |
from subprocess import CalledProcessError, run, PIPE, STDOUT | |
# Dump list of changed files | |
# git diff --name-only v6.6.3 master | |
# Log of changes to a file between two commits | |
# git log v6.6.3..master views/qcs_task/index.rhtml | |
# Look for issue numbers in commit messages | |
# TODO: Look for final commits of merge requests to find issue number? | |
# Summarize authors for any that don't belong to an issue. | |
def main(): | |
start = 'v6.6.3' | |
end = 'master' | |
limit = None | |
try: | |
result = run(['git', 'diff', '--name-only', start, end], | |
stdout=PIPE, | |
stderr=STDOUT, | |
encoding='UTF8', | |
check=True) | |
file_names = result.stdout.splitlines() | |
issue_numbers = set() | |
author_commits = defaultdict(list) | |
for file_name in file_names[:limit]: | |
msg_result = run(['git', | |
'log', | |
'--format=%B', | |
f'{start}..{end}', | |
'--', | |
file_name], | |
stdout=PIPE, | |
stderr=STDOUT, | |
encoding='UTF8', | |
check=True) | |
log_text = msg_result.stdout | |
found_issues = re.findall(r'#(\d+)\W', log_text) | |
if found_issues: | |
issue_numbers.update(found_issues) | |
continue | |
title = log_text.splitlines()[0] | |
author_result = run(['git', | |
'log', | |
'--format=%an', | |
f'{start}..{end}', | |
'--', | |
file_name], | |
stdout=PIPE, | |
stderr=STDOUT, | |
encoding='UTF8', | |
check=True) | |
author_lines = author_result.stdout.splitlines() | |
authors = sorted(set(author_lines)) | |
print(f'{file_name} - {", ".join(authors)}') | |
issue_display = ', '.join(sorted(issue_numbers, key=int)) | |
print(f'Mentioned issues {issue_display}') | |
except CalledProcessError as ex: | |
print(ex.stdout) | |
raise | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment