Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get commits from an author in a time period
from datetime import datetime
from git import Repo
def get_commits_from_author(repo_path, author_term, start_date, end_date):
repo = Repo(repo_path)
start_date, end_date = [
datetime.fromisoformat(d).date() for d in (start_date, end_date)
]
return [
commit
for commit in repo.iter_commits()
if author_term in commit.author.email
and start_date <= commit.committed_datetime.date() <= end_date
]
def loc_in_my_commits(*args, **kwargs):
commits = get_commits_from_author(*args, **kwargs)
return sum(commit.stats.total["lines"] for commit in commits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment