Skip to content

Instantly share code, notes, and snippets.

@alexwright
Created October 25, 2012 16:08
Show Gist options
  • Save alexwright/3953706 to your computer and use it in GitHub Desktop.
Save alexwright/3953706 to your computer and use it in GitHub Desktop.
def get_commit_activity(self, project):
from datetime import date, timedelta
from pygit2 import Repository
from pygit2 import GIT_SORT_TIME
repo = Repository(project.gitrepo)
weeks = self.get_weeks()
for commit in repo.walk(repo.head.oid, GIT_SORT_TIME):
commit_time = date.fromtimestamp(commit.commit_time)
commit_week = commit_time - timedelta(days=commit_time.weekday())
if commit_week not in weeks:
continue
weeks[commit_week]['mine'] += 1
counts = []
max = 0
for k in sorted(weeks.iterkeys()):
counts.append({
"week": k.isoformat(),
"mine": weeks[k]['mine'],
"others": weeks[k]['others'],
})
return counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment