From c66f96cf39c53d2aaa64c7478ec09955d1049f27 Mon Sep 17 00:00:00 2001 From: Jose M Vidal Date: Fri, 15 Dec 2017 18:09:06 -0500 Subject: [PATCH] Add github avatars to html output. Add '--github file.csv' argument. The file should have a first column of emails and a second one of github usernames. The html output will then use the github avatar for each committer. --- gitinspector/gitinspector.py | 12 +++++++++++- gitinspector/gravatar.py | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gitinspector/gitinspector.py b/gitinspector/gitinspector.py index 7149294..1bde438 100644 --- a/gitinspector/gitinspector.py +++ b/gitinspector/gitinspector.py @@ -125,7 +125,10 @@ def __get_validated_git_repos__(repos_relative): return repos +github_usernames = None + def main(): + global github_usernames terminal.check_terminal_encoding() terminal.set_stdin_encoding() argv = terminal.convert_command_line_to_utf8() @@ -136,7 +139,7 @@ def main(): opts, args = optval.gnu_getopt(argv[1:], "f:F:hHlLmrTwx:", ["exclude=", "file-types=", "format=", "hard:true", "help", "list-file-types:true", "localize-output:true", "metrics:true", "responsibilities:true", "since=", "grading:true", - "timeline:true", "until=", "version", "weeks:true"]) + "timeline:true", "until=", "version", "weeks:true", "github="]) repos = __get_validated_git_repos__(set(args)) #We need the repos above to be set before we read the git config. @@ -149,6 +152,13 @@ def main(): sys.exit(0) elif o in("-f", "--file-types"): extensions.define(a) + elif o == "--github": + import csv + github_usernames = {} + with open(a, 'rt') as f: + reader = csv.reader(f) + for row in reader: + github_usernames[row[0]] = row[1] elif o in("-F", "--format"): if not format.select(a): raise format.InvalidFormatError(_("specified output format not supported.")) diff --git a/gitinspector/gravatar.py b/gitinspector/gravatar.py index 1ca5070..e8b11d7 100644 --- a/gitinspector/gravatar.py +++ b/gitinspector/gravatar.py @@ -26,8 +26,11 @@ except: from urllib import urlencode from . import format +from . import gitinspector def get_url(email, size=20): + if gitinspector.github_usernames and email in gitinspector.github_usernames: + return "https://github.com/" + gitinspector.github_usernames[email] + ".png?size=20" md5hash = hashlib.md5(email.encode("utf-8").lower().strip()).hexdigest() base_url = "https://www.gravatar.com/avatar/" + md5hash params = None