Add basic git commit date counter

This commit is contained in:
Samuel Ortion 2023-09-02 08:25:13 +02:00
parent 6bdcb02a93
commit 798c1d937a
3 changed files with 30 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__
.venv

3
requirements.txt Normal file
View File

@ -0,0 +1,3 @@
pandas
numpy
GitPython

25
src/gitstats/commits.py Normal file
View File

@ -0,0 +1,25 @@
"""
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))