Skip to content

Commit

Permalink
Merge pull request #20 from ojacques/fix-19
Browse files Browse the repository at this point in the history
Fix #19: do not fail if file is not on GitHub
  • Loading branch information
ojacques authored Sep 2, 2022
2 parents 1c35a3f + e1777fd commit 5eb3c36
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ I had to create this fork so that it could be uploaded and distributed through P

This "v2" differs from the original by:

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

All of the above massively improves accuracy and performances.

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

## Limitations

- 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)
When the file is merged, the contributors will be added normally.
- For now, Git submodule is not supported and will report no contributors.

## Setup

Install the plugin using pip:
Expand All @@ -33,18 +39,17 @@ plugins:
branch: main
```
> **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.

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

## Config

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

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

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

#### Template Code
#### Template Code for last commit

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

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

#### Template Code
#### Template Code for avatars

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

Thank you to the following contributors:

* Byrne Reese - original author, maintainer
* Nathan Hernandez
* Chris Northwood
* Martin Donath
- Byrne Reese - original author, maintainer
- Nathan Hernandez
- Chris Northwood
- Martin Donath
4 changes: 2 additions & 2 deletions mkdocs_git_committers_plugin_2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ def list_contributors(self, path):
url_contribs = self.githuburl + self.config['repository'] + "/contributors-list/" + self.config['branch'] + "/" + path
LOG.info("Fetching contributors for " + path)
LOG.debug(" from " + url_contribs)
authors=[]
try:
response = requests.get(url_contribs)
response.raise_for_status()
except HTTPError as http_err:
LOG.error(f'HTTP error occurred: {http_err}')
LOG.error(f'HTTP error occurred: {http_err}\n(404 is normal if file is not on GitHub yet or Git submodule)')
except Exception as err:
LOG.error(f'Other error occurred: {err}')
else:
html = response.text
# Parse the HTML
soup = bs(html, "lxml")
lis = soup.find_all('li')
authors=[]
for li in lis:
a_tags = li.find_all('a')
login = a_tags[0]['href'].replace("/", "")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='mkdocs-git-committers-plugin-2',
version='1.0.1',
version='1.0.2',
description='An MkDocs plugin to create a list of contributors on the page',
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',
keywords='mkdocs pdf github',
Expand Down

0 comments on commit 5eb3c36

Please sign in to comment.