Skip to content

Commit

Permalink
Add source attribute github/gitlab to authors
Browse files Browse the repository at this point in the history
  • Loading branch information
ojacques committed Nov 3, 2023
1 parent 153043d commit 1c1ff87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions mkdocs_git_committers_plugin_2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):
self.last_request_return_code = 0
self.githuburl = "https://api.github.com"
self.gitlaburl = "https://gitlab.com/api/v4"
self.gitlabauthors = dict()
self.gitlabauthors_cache = dict()

def on_config(self, config):
self.enabled = self.config['enabled']
Expand Down Expand Up @@ -106,18 +106,20 @@ def get_contributors_to_file(self, path):
authors.append({'login': commit['author']['login'],
'name': commit['author']['login'],
'url': commit['author']['html_url'],
'avatar': commit['author']['avatar_url']})
'avatar': commit['author']['avatar_url'],
'source': 'github'})
else:
# GitLab
if commit['author_name']:
# If author is not already in the list of authors
if commit['author_name'] not in [author['name'] for author in authors]:
# Look for GitLab author in our cache self.gitlabauthors. If not found fetch it from GitLab API and save it in cache.
if commit['author_name'] in self.gitlabauthors:
authors.append({'login': self.gitlabauthors[commit['author_name']]['username'],
if commit['author_name'] in self.gitlabauthors_cache:
authors.append({'login': self.gitlabauthors_cache[commit['author_name']]['username'],
'name': commit['author_name'],
'url': self.gitlabauthors[commit['author_name']]['web_url'],
'avatar': self.gitlabauthors[commit['author_name']]['avatar_url']})
'url': self.gitlabauthors_cache[commit['author_name']]['web_url'],
'avatar': self.gitlabauthors_cache[commit['author_name']]['avatar_url'],
'source': 'gitlab'})
else:
# Fetch author from GitLab API
url = self.gitlaburl + "/users?search=" + requests.utils.quote(commit['author_name'])
Expand All @@ -129,11 +131,12 @@ def get_contributors_to_file(self, path):
for user in res:
if user['name'] == commit['author_name']:
# Save it in cache
self.gitlabauthors[commit['author_name']] = user
self.gitlabauthors_cache[commit['author_name']] = user
authors.append({'login': user['username'],
'name': user['name'],
'url': user['web_url'],
'avatar': user['avatar_url']})
'avatar': user['avatar_url'],
'source': 'gitlab'})
break
else:
LOG.error("git-committers: " + str(r.status_code) + " " + r.reason)
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.1.0",
version="2.2.0",
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

0 comments on commit 1c1ff87

Please sign in to comment.