Skip to content

Instantly share code, notes, and snippets.

@marciomazza
Last active June 7, 2019 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciomazza/d14e47fa70f8c457595971ad6892ebec to your computer and use it in GitHub Desktop.
Save marciomazza/d14e47fa70f8c457595971ad6892ebec to your computer and use it in GitHub Desktop.
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