# mkdocs-git-committers-plugin-2
MkDocs plugin for displaying a list of committers associated with a file in
mkdocs. The plugin uses GitHub or GitLab API to fetch the list of contributors
for each page.
🥳 NEW! Works with GitLab too!
For ease of use, this plugin is integrated in the [material for
mkdocs](https://squidfunk.github.io/mkdocs-material/) theme by [Martin
Donath](https://github.com/squidfunk). See [Mkdocs material
documentation](https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-contributors).
Other MkDocs plugins that use information to fetch authors:
- [`mkdocs-git-authors-plugin`](https://github.com/timvink/mkdocs-git-authors-plugin) for displaying user names a number of lines contributed (uses local Git information)
- [`mkdocs-git-committers-plugin`](https://github.com/byrnereese/mkdocs-git-committers-plugin) display contributors for a page (uses local Git information, completed with REST GitHub API v3)
## Setup
Install the plugin using pip:
`pip install mkdocs-git-committers-plugin-2`
Activate the plugin in `mkdocs.yml`:
For a repository hosted on GitHub:
```yaml
plugins:
- git-committers:
repository: organization/repository
```
For a repository hosted on GitLab:
```yaml
plugins:
- git-committers:
gitlab_repository: 12345678
token: !ENV ["GH_TOKEN"]
```
For a repository hosted on GitLab, you need to provide a token so that the
plugin can access the GitLab API. If the token is not set in `mkdocs.yml` it
will be read from the `MKDOCS_GIT_COMMITTERS_APIKEY` environment variable.
For a repository hosted on GitHub, you can provide a token to increase the rate
limit and go beyond the default 60 requests per hour per IP address. The plugin
will make one request per mkdocs document. The token does not need any scope:
uncheck everything when creating the GitHub Token at
[github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new),
unless you access private repositories.
For private GitHub repositories, you only need to allow read-only access to `Contents` and `Metadata` on the target repository. This could be done by setting `Read-only` access of `Permissions > Repository permissions > Contents`.
## Counting Contributors
* In GitHub repositories, the commit authors, [committers](https://stackoverflow.com/a/18754896), and [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) are counted as contributors. However, the plugin requires a GitHub token to fetch the list of co-authors. If co-authors exist but no token is provided, the plugin will show a warning and will only display the commit authors and committers.
* In GitLab repositories, only the commit authors are counted as contributors.
## Config
- `enabled` - Disables plugin if set to `False` for e.g. local builds (default: `True`)
- `repository` - For GitHub, the name of the repository, e.g.
'ojacques/mkdocs-git-committers-plugin-2'
- `gitlab_repository` - For GitLab, the project ID, e.g. '12345678'
- `branch` - The name of the branch to get contributors from. Example: 'master'
(default)
- `token` - A GitHub or GitLab personal access token for REST API calls.
- For GitHub, token does not need any scope: uncheck everything when creating
the GitHub Token at
[github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new),
unless you access private repositories.
- For GitLab, a
[project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html)
scoped to `read_api` is expected to work. That way, the token is limited to
the project and has access to read the repository. You could use a personal
access token at
[gitlab.com/-/profile/personal_access_tokens](https://gitlab.com/-/profile/personal_access_tokens),
but it will grant access to more repositories than you want.
- `enterprise_hostname` - For GitHub enterprise: the GitHub enterprise hostname.
- `gitlab_hostname` - For GitLab: the GitLab hostname if different from
gitlab.com (self-hosted).
- `api_version` - For GitHub and GitLab self-hosted, the API version part that needs to be appended to the URL.
Defaults to v4 for GitLab, and nothing for GitHub Enterprise (you may need `v3`).
- `docs_path` - the path to the documentation folder. Defaults to `docs/`.
- `cache_dir` - The path which holds the authors cache file to speed up
documentation builds. Defaults to `.cache/plugin/git-committers/`. The cache
file is named `page-authors.json`.
- `exclude` - Specify a list of page source paths (one per line) that should not
have author(s) or last commit date included (excluded from processing by this
plugin). Default is empty. Examples:
```
# mkdocs.yml
plugins:
- git-committers:
repository: organization/repository
exclude:
- README.md
- subfolder/page.md
- another_page.md
- all_files_inside_folder/*
- folder_and_subfolders/**
```
## History
This is a fork from the original [`mkdocs-git-committers-plugin`](https://github.com/byrnereese/mkdocs-git-committers-plugin) by @byrnereese.
I had to create this fork so that it could be uploaded and distributed through PyPi. The package has been renamed to `mkdocs-git-committers-plugin-2`.
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
- Use a cache file to speed up following builds: authors are fetched from GitHub for a page only if that page has changed since the last build
All of the above 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 or GitLab.
- For now, non-recursive Git submodule is supported for GitHub, while GitLab submodules and recursive submodules will report no contributors.
- GitLab users may not be properly identified. See [issue #50](https://github.com/ojacques/mkdocs-git-committers-plugin-2/issues/50)
## Usage
You have 2 options to use this plugin:
1. Use Mkdocs material theme (see [Mkdocs material
documentation](https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-contributors)).
1. Use the plugin directly in your template. See below.
### Display Last Commit
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 for last commit
```django hljs
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
<li class="last-updated-holder displayDate loading">
<span class="last-updated-text">Last updated:</span>
<time role="presentation" datetime="2018-10-25T00:00:00.000Z" data-article-date-source="ms.date">{% if last_commit_date %}{{ last_commit_date }}{% endif %}</time>
</li>
</ul>
```
### Display List of Committers
#### Avatar
The avatar of the contributors is provided by GitHub. It uses maximal resolution.
#### Template Code for avatars
```django hljs
{% block footer %}
<ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr">
<li class="contributors-holder">
<span class="contributors-text">Contributors</span>
<ul class="contributors" data-bi-name="contributors">
{%- for user in committers -%}
<li><a href="{{ user.url }}" title="{{ user.name }}" data-bi-name="contributorprofile" target="_blank"><img src="{{ user.avatar }}" alt="{{ user.name }}"></a></li>
{%- endfor -%}
</ul>
</li>
</ul>
{% endblock %}
```
#### CSS
```css
.metadata{
list-style:none;
padding:0;
margin:0;
margin-bottom: 15px;
color: #999;
font-size:0.85em;
}
.metadata.page-metadata .contributors-text{
margin-right:5px
}
body[dir=rtl] .metadata.page-metadata .contributors-text{
margin-right:0;
margin-left:5px
}
.page-metadata .contributors{
display:inline-block;
list-style:none;
margin:0!important;
padding:0!important
}
.page-metadata .contributors li{
display:inline-block;
vertical-align:top;
margin:0;
padding:0
}
```
#### Javascript
```javascript
$( '.contributors img[data-src]' ).each( function() {
src = $(this).attr("data-src");
$(this).attr('src',src);
});
```
More information about templates [here][mkdocs-template].
More information about blocks [here][mkdocs-block].
[mkdocs-plugins]: http://www.mkdocs.org/user-guide/plugins/
[mkdocs-template]: https://www.mkdocs.org/user-guide/custom-themes/#template-variables
[mkdocs-block]: https://www.mkdocs.org/user-guide/styling-your-docs/#overriding-template-blocks
## Acknowledgements
Thank you to the following contributors:
- Byrne Reese - original author, maintainer
- Nathan Hernandez
- Chris Northwood
- Martin Donath
- PTKay
- Guts
- Fir121
- dstockhammer
- thor
- n2N8Z
- barreeeiroo
- j3soon
- vrenjith
- rkorzeniec
- karelbemelmans
- andrew-rowson-lseg
Raw data
{
"_id": null,
"home_page": "https://github.com/ojacques/mkdocs-git-committers-plugin-2/",
"name": "mkdocs-git-committers-plugin-2",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.8",
"maintainer_email": null,
"keywords": "mkdocs, plugin, github, committers",
"author": "Byrne Reese, Olivier Jacques",
"author_email": "byrne@majordojo.com, ojacques2@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/36/4a/783d1c2683bc577bfe875646ce68bc9e0d845d0817a96f2a057033fdc64e/mkdocs_git_committers_plugin_2-2.4.1.tar.gz",
"platform": null,
"description": "# mkdocs-git-committers-plugin-2\n\nMkDocs plugin for displaying a list of committers associated with a file in\nmkdocs. The plugin uses GitHub or GitLab API to fetch the list of contributors\nfor each page.\n\n\ud83e\udd73 NEW! Works with GitLab too!\n\nFor ease of use, this plugin is integrated in the [material for\nmkdocs](https://squidfunk.github.io/mkdocs-material/) theme by [Martin\nDonath](https://github.com/squidfunk). See [Mkdocs material\ndocumentation](https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-contributors).\n\nOther MkDocs plugins that use information to fetch authors:\n\n- [`mkdocs-git-authors-plugin`](https://github.com/timvink/mkdocs-git-authors-plugin) for displaying user names a number of lines contributed (uses local Git information)\n- [`mkdocs-git-committers-plugin`](https://github.com/byrnereese/mkdocs-git-committers-plugin) display contributors for a page (uses local Git information, completed with REST GitHub API v3)\n\n## Setup\n\nInstall the plugin using pip:\n\n`pip install mkdocs-git-committers-plugin-2`\n\nActivate the plugin in `mkdocs.yml`:\n\nFor a repository hosted on GitHub:\n\n```yaml\nplugins:\n - git-committers:\n repository: organization/repository\n```\n\nFor a repository hosted on GitLab:\n\n```yaml\nplugins:\n - git-committers:\n gitlab_repository: 12345678\n token: !ENV [\"GH_TOKEN\"]\n```\n\nFor a repository hosted on GitLab, you need to provide a token so that the\nplugin can access the GitLab API. If the token is not set in `mkdocs.yml` it\nwill be read from the `MKDOCS_GIT_COMMITTERS_APIKEY` environment variable.\n\nFor a repository hosted on GitHub, you can provide a token to increase the rate\nlimit and go beyond the default 60 requests per hour per IP address. The plugin\nwill make one request per mkdocs document. The token does not need any scope:\nuncheck everything when creating the GitHub Token at\n[github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new),\nunless you access private repositories.\n\nFor private GitHub repositories, you only need to allow read-only access to `Contents` and `Metadata` on the target repository. This could be done by setting `Read-only` access of `Permissions > Repository permissions > Contents`.\n\n## Counting Contributors\n\n* In GitHub repositories, the commit authors, [committers](https://stackoverflow.com/a/18754896), and [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) are counted as contributors. However, the plugin requires a GitHub token to fetch the list of co-authors. If co-authors exist but no token is provided, the plugin will show a warning and will only display the commit authors and committers.\n* In GitLab repositories, only the commit authors are counted as contributors.\n\n## Config\n\n- `enabled` - Disables plugin if set to `False` for e.g. local builds (default: `True`)\n- `repository` - For GitHub, the name of the repository, e.g.\n 'ojacques/mkdocs-git-committers-plugin-2'\n- `gitlab_repository` - For GitLab, the project ID, e.g. '12345678'\n- `branch` - The name of the branch to get contributors from. Example: 'master'\n (default)\n- `token` - A GitHub or GitLab personal access token for REST API calls. \n - For GitHub, token does not need any scope: uncheck everything when creating\n the GitHub Token at\n [github.com/settings/personal-access-tokens/new](https://github.com/settings/personal-access-tokens/new),\n unless you access private repositories.\n - For GitLab, a\n [project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html)\n scoped to `read_api` is expected to work. That way, the token is limited to\n the project and has access to read the repository. You could use a personal\n access token at\n [gitlab.com/-/profile/personal_access_tokens](https://gitlab.com/-/profile/personal_access_tokens),\n but it will grant access to more repositories than you want.\n- `enterprise_hostname` - For GitHub enterprise: the GitHub enterprise hostname.\n- `gitlab_hostname` - For GitLab: the GitLab hostname if different from \n gitlab.com (self-hosted).\n- `api_version` - For GitHub and GitLab self-hosted, the API version part that needs to be appended to the URL. \n Defaults to v4 for GitLab, and nothing for GitHub Enterprise (you may need `v3`).\n- `docs_path` - the path to the documentation folder. Defaults to `docs/`.\n- `cache_dir` - The path which holds the authors cache file to speed up\n documentation builds. Defaults to `.cache/plugin/git-committers/`. The cache\n file is named `page-authors.json`.\n- `exclude` - Specify a list of page source paths (one per line) that should not\n have author(s) or last commit date included (excluded from processing by this\n plugin). Default is empty. Examples:\n\n ```\n # mkdocs.yml\n plugins:\n - git-committers:\n repository: organization/repository\n exclude:\n - README.md\n - subfolder/page.md\n - another_page.md\n - all_files_inside_folder/*\n - folder_and_subfolders/**\n ```\n\n## History\n\nThis is a fork from the original [`mkdocs-git-committers-plugin`](https://github.com/byrnereese/mkdocs-git-committers-plugin) by @byrnereese.\n\nI had to create this fork so that it could be uploaded and distributed through PyPi. The package has been renamed to `mkdocs-git-committers-plugin-2`.\n\nThis \"v2\" differs from the original by:\n\n- Fetch contributors directly from GitHub\n- Eliminate the need to match git commit logs with entries in GitHub, and thus GitHub API calls\n- No more risk of matching the incorrect contributor as the information comes directly from GitHub\n- last_commit_date is now populated with local git info\n- Use a cache file to speed up following builds: authors are fetched from GitHub for a page only if that page has changed since the last build\n\nAll of the above improves accuracy and performances.\n\nNote: the plugin configuration in `mkdocs.yml` still uses the original `git-committers` sections.\n\n## Limitations\n\n- Getting the contributors relies on what is available on GitHub or GitLab.\n- For now, non-recursive Git submodule is supported for GitHub, while GitLab submodules and recursive submodules will report no contributors.\n- GitLab users may not be properly identified. See [issue #50](https://github.com/ojacques/mkdocs-git-committers-plugin-2/issues/50)\n\n## Usage\n\nYou have 2 options to use this plugin:\n\n1. Use Mkdocs material theme (see [Mkdocs material\ndocumentation](https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#document-contributors)).\n1. Use the plugin directly in your template. See below.\n\n### Display Last Commit\n\nIn addition to displaying a list of committers for a file, you can also access\nthe last commit date for a page if you want to display the date the file was\nlast updated.\n\n#### Template Code for last commit\n\n```django hljs\n<ul class=\"metadata page-metadata\" data-bi-name=\"page info\" lang=\"en-us\" dir=\"ltr\">\n <li class=\"last-updated-holder displayDate loading\">\n <span class=\"last-updated-text\">Last updated:</span>\n <time role=\"presentation\" datetime=\"2018-10-25T00:00:00.000Z\" data-article-date-source=\"ms.date\">{% if last_commit_date %}{{ last_commit_date }}{% endif %}</time>\n </li>\n</ul>\n```\n\n### Display List of Committers\n\n#### Avatar\n\nThe avatar of the contributors is provided by GitHub. It uses maximal resolution.\n\n#### Template Code for avatars\n\n```django hljs\n{% block footer %}\n<ul class=\"metadata page-metadata\" data-bi-name=\"page info\" lang=\"en-us\" dir=\"ltr\">\n <li class=\"contributors-holder\">\n <span class=\"contributors-text\">Contributors</span>\n <ul class=\"contributors\" data-bi-name=\"contributors\">\n {%- for user in committers -%}\n <li><a href=\"{{ user.url }}\" title=\"{{ user.name }}\" data-bi-name=\"contributorprofile\" target=\"_blank\"><img src=\"{{ user.avatar }}\" alt=\"{{ user.name }}\"></a></li>\n {%- endfor -%}\n </ul>\n </li>\n</ul>\n{% endblock %}\n```\n\n#### CSS\n\n```css\n.metadata{\n list-style:none;\n padding:0;\n margin:0;\n margin-bottom: 15px;\n color: #999;\n font-size:0.85em;\n}\n.metadata.page-metadata .contributors-text{\n margin-right:5px\n}\nbody[dir=rtl] .metadata.page-metadata .contributors-text{\n margin-right:0;\n margin-left:5px\n}\n.page-metadata .contributors{\n display:inline-block;\n list-style:none;\n margin:0!important;\n padding:0!important\n}\n.page-metadata .contributors li{\n display:inline-block;\n vertical-align:top;\n margin:0;\n padding:0\n}\n```\n\n#### Javascript\n\n```javascript\n $( '.contributors img[data-src]' ).each( function() {\n src = $(this).attr(\"data-src\");\n $(this).attr('src',src);\n });\n```\n\nMore information about templates [here][mkdocs-template].\n\nMore information about blocks [here][mkdocs-block].\n\n[mkdocs-plugins]: http://www.mkdocs.org/user-guide/plugins/\n[mkdocs-template]: https://www.mkdocs.org/user-guide/custom-themes/#template-variables\n[mkdocs-block]: https://www.mkdocs.org/user-guide/styling-your-docs/#overriding-template-blocks\n\n## Acknowledgements\n\nThank you to the following contributors:\n\n- Byrne Reese - original author, maintainer\n- Nathan Hernandez\n- Chris Northwood\n- Martin Donath\n- PTKay\n- Guts\n- Fir121\n- dstockhammer\n- thor\n- n2N8Z\n- barreeeiroo\n- j3soon\n- vrenjith\n- rkorzeniec\n- karelbemelmans\n- andrew-rowson-lseg\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "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",
"version": "2.4.1",
"project_urls": {
"Homepage": "https://github.com/ojacques/mkdocs-git-committers-plugin-2/"
},
"split_keywords": [
"mkdocs",
" plugin",
" github",
" committers"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7da71f5ea492f6b441fa84157608608a8d211bea322ecc0957e738b83e22cb0c",
"md5": "68a1ac7cf6cfcf919d2fd869c30de56b",
"sha256": "ec9c1d81445606c471337d1c4a1782c643b7377077b545279dc18b86b7362c6d"
},
"downloads": -1,
"filename": "mkdocs_git_committers_plugin_2-2.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "68a1ac7cf6cfcf919d2fd869c30de56b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.8",
"size": 11614,
"upload_time": "2024-10-04T17:18:42",
"upload_time_iso_8601": "2024-10-04T17:18:42.389379Z",
"url": "https://files.pythonhosted.org/packages/7d/a7/1f5ea492f6b441fa84157608608a8d211bea322ecc0957e738b83e22cb0c/mkdocs_git_committers_plugin_2-2.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "364a783d1c2683bc577bfe875646ce68bc9e0d845d0817a96f2a057033fdc64e",
"md5": "b22118d81096b652e192fa6fd9354d6c",
"sha256": "ea1f80a79cedc42289e0b8e973276df04fb94f56e0ae3efc5385fb28547cf5cb"
},
"downloads": -1,
"filename": "mkdocs_git_committers_plugin_2-2.4.1.tar.gz",
"has_sig": false,
"md5_digest": "b22118d81096b652e192fa6fd9354d6c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.8",
"size": 14924,
"upload_time": "2024-10-04T17:18:44",
"upload_time_iso_8601": "2024-10-04T17:18:44.007342Z",
"url": "https://files.pythonhosted.org/packages/36/4a/783d1c2683bc577bfe875646ce68bc9e0d845d0817a96f2a057033fdc64e/mkdocs_git_committers_plugin_2-2.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-04 17:18:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ojacques",
"github_project": "mkdocs-git-committers-plugin-2",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mkdocs-git-committers-plugin-2"
}