git.stats/src/gitstats/commits.py

25 lines
620 B
Python

"""
Generate a CSV file with daily stats commit count from a set of repositories
"""
from git import Repo
import datetime
REPO = "."
repo = Repo(REPO)
def repo_daily_commits(repo: Repo, year: int):
"""Count how many commit was performed for each days in the year"""
data = {}
for commit in repo.iter_commits(all=True):
timestamp = commit.authored_date
date = datetime.date.fromtimestamp(timestamp)
if int(date.year) != year:
continue
if date not in data:
data[date] = 0
data[date] += 1
return data
print(repo_daily_commits(repo, 2023))