Skip to content

Pickup the actual username instead of login name for Github #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mkdocs_git_committers_plugin_2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self):
self.should_save_cache = False

def on_config(self, config):
LOG.info("git-committers plugin - custom build")
self.enabled = self.config['enabled']
if not self.enabled:
LOG.info("git-committers plugin DISABLED")
Expand Down Expand Up @@ -119,13 +120,13 @@ def get_contributors_to_file(self, path, submodule_repo=None):
# GitHub
if commit['author'] and commit['author']['login'] and commit['author']['login'] not in [author['login'] for author in authors]:
authors.append({'login': commit['author']['login'],
'name': commit['author']['login'],
'name': commit['author'].get('name') or commit['author']['login'],
'url': commit['author']['html_url'],
'avatar': commit['author']['avatar_url'] if commit['author']['avatar_url'] is not None else ''
})
if commit['committer'] and commit['committer']['login'] and commit['committer']['login'] not in [author['login'] for author in authors]:
authors.append({'login': commit['committer']['login'],
'name': commit['committer']['login'],
'name': commit['author'].get('name') or commit['author']['login'],
'url': commit['committer']['html_url'],
'avatar': commit['committer']['avatar_url'] if commit['committer']['avatar_url'] is not None else ''
})
Expand Down Expand Up @@ -263,6 +264,7 @@ def list_contributors(self, path):
if self.cache_date and time.strptime(last_commit_date, "%Y-%m-%d") < time.strptime(self.cache_date, "%Y-%m-%d"):
# If page_autors in cache is not empty, return it
if self.cache_page_authors[path]['authors']:
LOG.info(f"git-committers: using cached authors for {path}")
return self.cache_page_authors[path]['authors'], self.cache_page_authors[path]['last_commit_date']

authors=[]
Expand All @@ -281,6 +283,7 @@ def list_contributors(self, path):
if path not in self.cache_page_authors or self.cache_page_authors[path] != {'last_commit_date': last_commit_date, 'authors': authors}:
self.should_save_cache = True
self.cache_page_authors[path] = {'last_commit_date': last_commit_date, 'authors': authors}
self.save_cache()

return authors, last_commit_date

Expand Down Expand Up @@ -308,6 +311,9 @@ def on_page_context(self, context, page, config, nav):
return context

def on_post_build(self, config):
self.save_cache()

def save_cache(self):
if not self.should_save_cache:
return
LOG.info("git-committers: saving page authors cache file")
Expand All @@ -319,7 +325,7 @@ def on_post_build(self, config):

def on_pre_build(self, config):
if os.path.exists(self.config['cache_dir'] + "/page-authors.json"):
LOG.info("git-committers: found page authors cache file - loading it")
LOG.info(f"git-committers: found page authors cache file at {self.config['cache_dir'] + '/page-authors.json'} - loading it")
f = open(self.config['cache_dir'] + "/page-authors.json", "r")
cache = json.loads(f.read())
self.cache_date = cache['cache_date']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="mkdocs-git-committers-plugin-2",
version="2.5.0",
version="2.5.2",
description="An MkDocs plugin to create a list of contributors on the page. The git-committers plugin will seed the template context with a list of GitHub or GitLab committers and other useful GIT info such as last modified date",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down