From 798c1d937aa54c8720b6e0ead5bf8c9715ffa31f Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Sat, 2 Sep 2023 08:25:13 +0200 Subject: [PATCH] Add basic git commit date counter --- .gitignore | 2 ++ requirements.txt | 3 +++ src/gitstats/commits.py | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100644 src/gitstats/commits.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f7550b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +.venv diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bdd037a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pandas +numpy +GitPython \ No newline at end of file diff --git a/src/gitstats/commits.py b/src/gitstats/commits.py new file mode 100644 index 0000000..e812192 --- /dev/null +++ b/src/gitstats/commits.py @@ -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)) \ No newline at end of file