Last active
October 27, 2021 19:50
-
-
Save dg/f404a54592142d162ec71918e091752b to your computer and use it in GitHub Desktop.
Git log to JSON
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
# install pygit2: pip install pygit2 | |
import pygit2 | |
import json | |
repo = pygit2.Repository('path/to/repository') | |
last = repo[repo.head.target] | |
data = [] | |
for commit in repo.walk(last.id): | |
data.append({ | |
'hash': str(commit.id), | |
'message': commit.message, | |
'author': { | |
'name': commit.author.name, | |
'email': commit.author.email, | |
'time': commit.author.time, | |
}, | |
'committer': { | |
'name': commit.committer.name, | |
'email': commit.committer.email, | |
'time': commit.committer.time, | |
}, | |
'changes': len(repo.diff(commit.tree, commit.parents[0])) if commit.parents else 0, | |
}) | |
json = json.dumps(data, indent=4) | |
print(json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment