-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_parser.py
More file actions
29 lines (27 loc) · 930 Bytes
/
log_parser.py
File metadata and controls
29 lines (27 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
import subprocess
import json
import sys
def get_git_logs(limit=10):
"""Get the latest git logs as a list of dicts."""
try:
log_format = "%H|%an|%ad|%s"
cmd = ["git", "log", f"--pretty=format:{log_format}", f"-{limit}", "--date=iso"]
raw_output = subprocess.check_output(cmd, text=True)
commits = []
for line in raw_output.split("\n"):
commit_hash, author, date, message = line.split("|", 3)
commits.append({
"hash": commit_hash,
"author": author,
"date": date,
"message": message
})
return commits
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == "__main__":
limit = int(sys.argv[1]) if len(sys.argv) > 1 else 10
logs = get_git_logs(limit)
print(json.dumps(logs, indent=2))