Commit f26671eb authored by Gustavo Padovan's avatar Gustavo Padovan
Browse files

contribution-stats: add option to order results

parent e31910d1
......@@ -55,8 +55,14 @@ def is_maintainer(commit, email, name):
def total_commits(d):
return sum((v[0] for v in d.values()))
def print_commits(f, dict, summary):
for email, data in sorted(dict.items(), key=lambda item: item[1], reverse=True):
def order_results(results, args):
if args.numbered:
return sorted(results.items(), key=lambda item: item[1], reverse=True)
return sorted(results.items(), key=lambda item: contributors[item[0]])
def print_commits(f, results, summary):
for email, data in results:
f.write("%s <%s> (%d):\n" % (contributors[email], email, data[0]))
if not summary:
for c in data[1]:
......@@ -86,11 +92,14 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.set_defaults(func=lambda x: parser.print_help())
parser.add_argument('-s', '--summary', action='store_true',
help="enable details for each section")
help="sort output according to the number of commits instead of alphabetic order")
parser.add_argument('-n', '--numbered', action='store_true',
help="suppress commit description and provide a commit count summary only")
parser.add_argument('-o', '--output', metavar="FILE",
help="output to a file instead of stdout")
parser.add_argument('--html', metavar="FILE",
help="output to a html instead of stdout")
args = parser.parse_args(sys.argv[1:])
repo = Repository(os.getcwd())
......@@ -122,13 +131,12 @@ if __name__ == "__main__":
add_commit(tag[1], m[1], commit)
results = []
# XXX order dicts here
results.append(("Authored ({}):".format(total_commits(authored)), authored))
results.append(("Maintainer Committed ({}):".format(total_commits(committed)), committed))
results.append(("Signed-off-by ({}):".format(total_commits(signed)), signed))
results.append(("On behalf of ({}):".format(total_commits(onbehalf)), onbehalf))
results.append(("Authored ({}):".format(total_commits(authored)), order_results(authored, args)))
results.append(("Maintainer Committed ({}):".format(total_commits(committed)), order_results(committed, args)))
results.append(("Signed-off-by ({}):".format(total_commits(signed)), order_results(signed, args)))
results.append(("On behalf of ({}):".format(total_commits(onbehalf)), order_results(onbehalf, args)))
for tag in OTHER_TAGS:
results.append(("{} ({}):".format(tag[0],total_commits(tag[1])), tag[1]))
results.append(("{} ({}):".format(tag[0],total_commits(tag[1])), order_results(tag[1], args)))
if args.html:
generate_html(results, args)
{% for r in results %}
<h4>{{ r[0] }}</h4>
{% for email, data in r[1].items() %}
{% for email, data in r[1] %}
<strong>{{ contributors[email] }} {{ email }} ({{ data[0]}}):</strong><br />
{% if not summary %}
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