Skip to content

Commit 1c1ff87

Browse files
committed
Add source attribute github/gitlab to authors
1 parent 153043d commit 1c1ff87

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

mkdocs_git_committers_plugin_2/plugin.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self):
4343
self.last_request_return_code = 0
4444
self.githuburl = "https://api.github.com"
4545
self.gitlaburl = "https://gitlab.com/api/v4"
46-
self.gitlabauthors = dict()
46+
self.gitlabauthors_cache = dict()
4747

4848
def on_config(self, config):
4949
self.enabled = self.config['enabled']
@@ -106,18 +106,20 @@ def get_contributors_to_file(self, path):
106106
authors.append({'login': commit['author']['login'],
107107
'name': commit['author']['login'],
108108
'url': commit['author']['html_url'],
109-
'avatar': commit['author']['avatar_url']})
109+
'avatar': commit['author']['avatar_url'],
110+
'source': 'github'})
110111
else:
111112
# GitLab
112113
if commit['author_name']:
113114
# If author is not already in the list of authors
114115
if commit['author_name'] not in [author['name'] for author in authors]:
115116
# Look for GitLab author in our cache self.gitlabauthors. If not found fetch it from GitLab API and save it in cache.
116-
if commit['author_name'] in self.gitlabauthors:
117-
authors.append({'login': self.gitlabauthors[commit['author_name']]['username'],
117+
if commit['author_name'] in self.gitlabauthors_cache:
118+
authors.append({'login': self.gitlabauthors_cache[commit['author_name']]['username'],
118119
'name': commit['author_name'],
119-
'url': self.gitlabauthors[commit['author_name']]['web_url'],
120-
'avatar': self.gitlabauthors[commit['author_name']]['avatar_url']})
120+
'url': self.gitlabauthors_cache[commit['author_name']]['web_url'],
121+
'avatar': self.gitlabauthors_cache[commit['author_name']]['avatar_url'],
122+
'source': 'gitlab'})
121123
else:
122124
# Fetch author from GitLab API
123125
url = self.gitlaburl + "/users?search=" + requests.utils.quote(commit['author_name'])
@@ -129,11 +131,12 @@ def get_contributors_to_file(self, path):
129131
for user in res:
130132
if user['name'] == commit['author_name']:
131133
# Save it in cache
132-
self.gitlabauthors[commit['author_name']] = user
134+
self.gitlabauthors_cache[commit['author_name']] = user
133135
authors.append({'login': user['username'],
134136
'name': user['name'],
135137
'url': user['web_url'],
136-
'avatar': user['avatar_url']})
138+
'avatar': user['avatar_url'],
139+
'source': 'gitlab'})
137140
break
138141
else:
139142
LOG.error("git-committers: " + str(r.status_code) + " " + r.reason)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="mkdocs-git-committers-plugin-2",
12-
version="2.1.0",
12+
version="2.2.0",
1313
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",
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)