Skip to content

Commit 5eb3c36

Browse files
authored
Merge pull request #20 from ojacques/fix-19
Fix #19: do not fail if file is not on GitHub
2 parents 1c35a3f + e1777fd commit 5eb3c36

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ I had to create this fork so that it could be uploaded and distributed through P
88

99
This "v2" differs from the original by:
1010

11-
* Fetch contributors directly from GitHub
12-
* Eliminate the need to match git commit logs with entries in GitHub, and thus GitHub API calls
13-
* No more risk of matching the incorrect contributor as the information comes directly from GitHub
14-
* last_commit_date is now populated with local git info
15-
* No need for GitHub personal access token, as there are no more GitHub GraphQL API calls
11+
- Fetch contributors directly from GitHub
12+
- Eliminate the need to match git commit logs with entries in GitHub, and thus GitHub API calls
13+
- No more risk of matching the incorrect contributor as the information comes directly from GitHub
14+
- last_commit_date is now populated with local git info
15+
- No need for GitHub personal access token, as there are no more GitHub GraphQL API calls
1616

1717
All of the above massively improves accuracy and performances.
1818

1919
Note: the plugin configuration in `mkdocs.yml` still uses the original `git-committers` sections.
2020

21+
## Limitations
22+
23+
- Getting the contributors relies on what is available on GitHub. This means that for new files, the build will report no contributors (and informed you with a 404 error which can be ignored)
24+
When the file is merged, the contributors will be added normally.
25+
- For now, Git submodule is not supported and will report no contributors.
26+
2127
## Setup
2228

2329
Install the plugin using pip:
@@ -33,18 +39,17 @@ plugins:
3339
branch: main
3440
```
3541
36-
3742
> **Note:** If you have no `plugins` entry in your config file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set, but now you have to enable it explicitly.
3843

3944
More information about plugins in the [MkDocs documentation][mkdocs-plugins].
4045

4146
## Config
4247

43-
* `enabled` - Disables plugin if set to `False` for e.g. local builds (default: `True`)
44-
* `repository` - The name of the repository, e.g. 'ojacques/mkdocs-git-committers-plugin-2'
45-
* `branch` - The name of the branch to get contributors from. Example: 'master' (default)
46-
* `enterprise_hostname` - For GitHub enterprise: the enterprise hostname.
47-
* `docs_path` - the path to the documentation folder. Defaults to `docs`.
48+
- `enabled` - Disables plugin if set to `False` for e.g. local builds (default: `True`)
49+
- `repository` - The name of the repository, e.g. 'ojacques/mkdocs-git-committers-plugin-2'
50+
- `branch` - The name of the branch to get contributors from. Example: 'master' (default)
51+
- `enterprise_hostname` - For GitHub enterprise: the enterprise hostname.
52+
- `docs_path` - the path to the documentation folder. Defaults to `docs`.
4853

4954
If the token is not set in `mkdocs.yml` it will be read from the `MKDOCS_GIT_COMMITTERS_APIKEY` environment variable.
5055

@@ -56,7 +61,7 @@ In addition to displaying a list of committers for a file, you can also access
5661
the last commit date for a page if you want to display the date the file was
5762
last updated.
5863

59-
#### Template Code
64+
#### Template Code for last commit
6065

6166
```django hljs
6267
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
@@ -73,7 +78,7 @@ last updated.
7378

7479
The avatar of the contributors is provided by GitHub. It uses maximal resolution.
7580

76-
#### Template Code
81+
#### Template Code for avatars
7782

7883
```django hljs
7984
{% block footer %}
@@ -143,7 +148,7 @@ More information about blocks [here][mkdocs-block].
143148

144149
Thank you to the following contributors:
145150

146-
* Byrne Reese - original author, maintainer
147-
* Nathan Hernandez
148-
* Chris Northwood
149-
* Martin Donath
151+
- Byrne Reese - original author, maintainer
152+
- Nathan Hernandez
153+
- Chris Northwood
154+
- Martin Donath

mkdocs_git_committers_plugin_2/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ def list_contributors(self, path):
6464
url_contribs = self.githuburl + self.config['repository'] + "/contributors-list/" + self.config['branch'] + "/" + path
6565
LOG.info("Fetching contributors for " + path)
6666
LOG.debug(" from " + url_contribs)
67+
authors=[]
6768
try:
6869
response = requests.get(url_contribs)
6970
response.raise_for_status()
7071
except HTTPError as http_err:
71-
LOG.error(f'HTTP error occurred: {http_err}')
72+
LOG.error(f'HTTP error occurred: {http_err}\n(404 is normal if file is not on GitHub yet or Git submodule)')
7273
except Exception as err:
7374
LOG.error(f'Other error occurred: {err}')
7475
else:
7576
html = response.text
7677
# Parse the HTML
7778
soup = bs(html, "lxml")
7879
lis = soup.find_all('li')
79-
authors=[]
8080
for li in lis:
8181
a_tags = li.find_all('a')
8282
login = a_tags[0]['href'].replace("/", "")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='mkdocs-git-committers-plugin-2',
6-
version='1.0.1',
6+
version='1.0.2',
77
description='An MkDocs plugin to create a list of contributors on the page',
88
long_description='The git-committers plugin will seed the template context with a list of github committers and other useful GIT info such as last modified date',
99
keywords='mkdocs pdf github',

0 commit comments

Comments
 (0)