Created
April 25, 2018 20:59
-
-
Save scragg0x/7269b80d8e17c76ef5a9e8a7e22b9bf0 to your computer and use it in GitHub Desktop.
Get commit history grouped by tag / user
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
import argparse | |
from subprocess import check_output | |
from datetime import datetime | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--dir', default='.', help='Git Directory') | |
parser.add_argument('--start', help='From Date YYYY-MM-DD') | |
args = parser.parse_args() | |
if args.start: | |
start_date = datetime.strptime(args.start, "%Y-%m-%d") | |
git_tags_cmd = "git for-each-ref --sort=taggerdate --format '%(refname) %(taggerdate)' refs/tags" | |
tags = [] | |
for line in check_output(git_tags_cmd, shell=True, cwd=args.dir).strip().split("\n"): | |
parts = line.split(" ") | |
name = "".join(parts[0].split("/")[2:]) | |
date = datetime.strptime(" ".join(parts[1:-1]), "%c") | |
tags.append(dict(name=name, date=date)) | |
for i in range(len(tags)): | |
if i == 0: | |
continue | |
if start_date and start_date > tags[i]['date']: | |
continue | |
tags[i]['changes'] = check_output("git shortlog {0} --not {1}".format(tags[i]['name'], tags[i-1]['name']), shell=True, cwd=args.dir) | |
print("{0} - {1}".format(tags[i]['name'], tags[i]['date'].isoformat())) | |
print(tags[i]['changes']) | |
print('---------------------------------------------') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python changelog.py --dir /my/git/repo --start 2018-01-01 > changes.txt