Commit 046db88f authored by Gustavo Padovan's avatar Gustavo Padovan

Add scripts to find contributions stats

Still a bit of WIP
parent 73faaef8
#! /usr/bin/env python
from pygit2 import Repository, Tag
from pygit2 import GIT_SORT_TOPOLOGICAL
import re
details=True
GIT_TREE="/home/gfpadovan/p/linux"
EMAIL_PATTERN = "@collabora.co"
CONTENT = " (?P<name>[\w\-\. ]+) <(?P<username>.*" + EMAIL_PATTERN + ".*)>"
contributors = {}
authored = {}
committed = {}
signed = {}
reviewed = {}
acked = {}
tested = {}
reported = {}
OTHER_TAGS = [
("Reviewed-by:", reviewed),
("Acked-by:", acked),
("Tested-by:", tested),
("Reported-by:", reported)
]
def add_commit(dict, email, commit):
if email not in dict.keys():
dict[email] = [0, []]
dict[email][0] += 1
item = [str(commit.id), commit.message.split('\n')[0]]
dict[email][1].append(item)
def add_contributor(contributors, email, name):
if email not in contributors.keys():
contributors[email] = name
def not_author_or_committer(commit, email, name):
if commit.author.email != email and commit.committer.email != email:
return True
return False
def is_maintainer(commit, email, name):
if (commit.author.email != email and commit.committer.email == email) \
or (commit.author.name != name and commit.committer.name == name):
return True
return False
def total_commits(d):
sum = 0
for v in d.values():
sum += v[0]
return sum
def print_commits(dict):
for email, data in sorted(dict.items(), key=lambda item: item[1], reverse=True):
print("%s <%s> %d" % (contributors[email], email, data[0]))
if details:
for c in data[1]:
print("\t%s %s" % (c[0][0:9], c[1]))
print("")
if __name__ == "__main__":
repo = Repository(GIT_TREE)
first_commit = repo.revparse_single('v3.12')
if isinstance(first_commit, Tag):
first_commit = first_commit.get_object()
last_commit = repo.revparse_single('HEAD')
if isinstance(last_commit, Tag):
last_commit = last_commit.get_object()
for commit in repo.walk(last_commit.id, GIT_SORT_TOPOLOGICAL):
if EMAIL_PATTERN in commit.author.email:
add_contributor(contributors, commit.author.email, commit.author.name)
add_commit(authored, commit.author.email, commit)
p = re.compile('Signed-off-by:' + CONTENT)
match = p.findall(commit.message)
for m in match:
add_contributor(contributors, m[1], m[0])
if not_author_or_committer(commit, m[1], m[0]):
add_commit(signed, m[1], commit)
if is_maintainer(commit, m[1], m[0]):
add_commit(committed, m[1], commit)
for tag in OTHER_TAGS:
p = re.compile(tag[0] + CONTENT)
match = p.findall(commit.message)
for m in match:
add_contributor(contributors, m[1], m[0])
add_commit(tag[1], m[1], commit)
if commit.id == first_commit.id:
break
print("# Authored (%d)\n" % total_commits(authored))
print_commits(authored)
print("")
print("# Maintainer Committed (%d)\n" % total_commits(committed))
print_commits(committed)
print("")
print("# Signed-off-by: (%d)\n" % total_commits(signed))
print_commits(signed)
print("")
for tag in OTHER_TAGS:
print("# %s (%d)\n" % (tag[0],total_commits(tag[1])))
print_commits(tag[1])
print("")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment