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.
This commit is contained in:
Jose M Vidal 2017-12-15 18:09:06 -05:00
parent 6d77989e34
commit c66f96cf39
No known key found for this signature in database
GPG key ID: 6CCCEDE7C44757DB
2 changed files with 14 additions and 1 deletions

View file

@ -125,7 +125,10 @@ def __get_validated_git_repos__(repos_relative):
return repos return repos
github_usernames = None
def main(): def main():
global github_usernames
terminal.check_terminal_encoding() terminal.check_terminal_encoding()
terminal.set_stdin_encoding() terminal.set_stdin_encoding()
argv = terminal.convert_command_line_to_utf8() 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=", opts, args = optval.gnu_getopt(argv[1:], "f:F:hHlLmrTwx:", ["exclude=", "file-types=", "format=",
"hard:true", "help", "list-file-types:true", "localize-output:true", "hard:true", "help", "list-file-types:true", "localize-output:true",
"metrics:true", "responsibilities:true", "since=", "grading: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)) repos = __get_validated_git_repos__(set(args))
#We need the repos above to be set before we read the git config. #We need the repos above to be set before we read the git config.
@ -149,6 +152,13 @@ def main():
sys.exit(0) sys.exit(0)
elif o in("-f", "--file-types"): elif o in("-f", "--file-types"):
extensions.define(a) 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"): elif o in("-F", "--format"):
if not format.select(a): if not format.select(a):
raise format.InvalidFormatError(_("specified output format not supported.")) raise format.InvalidFormatError(_("specified output format not supported."))

View file

@ -26,8 +26,11 @@ except:
from urllib import urlencode from urllib import urlencode
from . import format from . import format
from . import gitinspector
def get_url(email, size=20): 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() md5hash = hashlib.md5(email.encode("utf-8").lower().strip()).hexdigest()
base_url = "https://www.gravatar.com/avatar/" + md5hash base_url = "https://www.gravatar.com/avatar/" + md5hash
params = None params = None