-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to ignore authors and/or commits
- Loading branch information
1 parent
0f3f1b5
commit 96fb712
Showing
7 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ plugins: | |
fallback_to_empty: false | ||
sort_authors_by: name | ||
authorship_threshold_percent: 10 | ||
ignore_authors: | ||
- [email protected] | ||
ignore_commits: .git-blame-ignore-revs | ||
exclude: | ||
- index.md | ||
enabled: true | ||
|
@@ -59,6 +62,14 @@ If this option is set to `true` (default: `false`) the plugin will work even out | |
|
||
Default is empty. Specify a list of page source paths (one per line) that should not have author(s) included (excluded from processing by this plugin). This can be useful for example to remove the authors from the front page. The source path of a page is relative to your `docs/` folder. You can also use [globs](https://docs.python.org/3/library/glob.html) instead of full source paths. To exclude `docs/subfolder/page.md` specify in your `mkdocs.yml` a line under `exclude:` with `- subfolder/page.md`. Some examples: | ||
|
||
## `ignore_authors` | ||
|
||
Default is empty. Specifies a list of emails for authors whose contributions should be ignored by this plugin. | ||
|
||
## `ignore_commits` | ||
|
||
Default is empty. Specifies a file containing a list of commit hashes (one per line) that should be ignored. Changes made in these commits will be attributed to the previous commit that changed the line. | ||
|
||
```yaml | ||
# mkdocs.yml | ||
plugins: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
site_name: test gitauthors_plugin | ||
use_directory_urls: true | ||
|
||
plugins: | ||
- search | ||
- git-authors: | ||
ignore_authors: | ||
- '[email protected]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,23 @@ def test_exclude_working(tmp_path): | |
|
||
|
||
|
||
def test_ignore_authors_working(tmp_path): | ||
|
||
result = build_docs_setup("tests/basic_setup/mkdocs_ignore_authors.yml", tmp_path) | ||
assert result.exit_code == 0, ( | ||
"'mkdocs build' command failed. Error: %s" % result.stdout | ||
) | ||
|
||
page_file = tmp_path / "page_with_tag/index.html" | ||
assert page_file.exists(), "%s does not exist" % page_file | ||
|
||
contents = page_file.read_text() | ||
assert re.search("<span class='git-page-authors", contents) | ||
assert re.search("<a href='mailto:[email protected]'>Tim Vink</a>", contents) | ||
assert not re.search("Julien", contents) | ||
|
||
|
||
|
||
def test_exclude_working_with_genfiles(tmp_path): | ||
""" | ||
A warning for uncommited files should not show up | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
"sort_reverse": False, | ||
"sort_authors_by": "name", | ||
"authorship_threshold_percent": 0, | ||
"ignore_authors": [], | ||
} | ||
|
||
#### Helpers #### | ||
|
@@ -275,6 +276,148 @@ def test_retrieve_authors(tmp_path): | |
os.chdir(cwd) | ||
|
||
|
||
def test_retrieve_authors_ignoring_commits(tmp_path): | ||
""" | ||
Builds a fake git project with some commits. | ||
Args: | ||
tmp_path (PosixPath): Directory of a tempdir | ||
""" | ||
cwd = os.getcwd() | ||
os.chdir(str(tmp_path)) | ||
|
||
# Create file | ||
file_name = str(tmp_path / "new-file") | ||
with open(file_name, "w") as the_file: | ||
the_file.write("line 1\n") | ||
the_file.write("line 2\n") | ||
|
||
# Create git repo and commit file | ||
r = gitpython.Repo.init(tmp_path) | ||
r.index.add([file_name]) | ||
author = gitpython.Actor("Tim", "[email protected]") | ||
r.index.commit("initial commit", author=author) | ||
|
||
# Update the file | ||
with open(file_name, "w") as the_file: | ||
the_file.write("line 1.1\n") | ||
the_file.write("line 2.1\n") | ||
r.index.add([file_name]) | ||
author = gitpython.Actor("John", "[email protected]") | ||
commit = r.index.commit("second commit", author=author) | ||
|
||
repo_instance = repo.Repo() | ||
repo_instance.set_config(DEFAULT_CONFIG) | ||
repo_instance.page(file_name) | ||
authors = repo_instance.get_authors() | ||
authors = util.page_authors(authors, file_name) | ||
authors[0]["last_datetime"] = None | ||
|
||
assert authors == [ | ||
{ | ||
"name": "John", | ||
"email": "[email protected]", | ||
"last_datetime": None, | ||
"lines": 2, | ||
"lines_all_pages": 2, | ||
"contribution": "100.0%", | ||
"contribution_all_pages": "100.0%", | ||
} | ||
] | ||
|
||
# Get the authors while ignoring the last commit | ||
ignored_commits_files = str(tmp_path / "ignored_commits.txt") | ||
with open(ignored_commits_files, "w") as the_file: | ||
the_file.write(commit.hexsha + "\n") | ||
repo_instance = repo.Repo() | ||
config = DEFAULT_CONFIG.copy() | ||
config['ignore_commits'] = ignored_commits_files | ||
repo_instance.set_config(config) | ||
repo_instance.page(file_name) | ||
authors = repo_instance.get_authors() | ||
authors = util.page_authors(authors, file_name) | ||
authors[0]["last_datetime"] = None | ||
|
||
assert authors == [ | ||
{ | ||
"name": "Tim", | ||
"email": "[email protected]", | ||
"last_datetime": None, | ||
"lines": 2, | ||
"lines_all_pages": 2, | ||
"contribution": "100.0%", | ||
"contribution_all_pages": "100.0%", | ||
}, | ||
] | ||
|
||
os.chdir(cwd) | ||
|
||
|
||
def test_retrieve_authors_ignoring_emails(tmp_path): | ||
""" | ||
Builds a fake git project with some commits. | ||
Args: | ||
tmp_path (PosixPath): Directory of a tempdir | ||
""" | ||
cwd = os.getcwd() | ||
os.chdir(str(tmp_path)) | ||
|
||
# Create file | ||
file_name = str(tmp_path / "new-file") | ||
with open(file_name, "w") as the_file: | ||
the_file.write("line 1\n") | ||
the_file.write("line 2\n") | ||
|
||
# Create git repo and commit file | ||
r = gitpython.Repo.init(tmp_path) | ||
r.index.add([file_name]) | ||
author = gitpython.Actor("Tim", "[email protected]") | ||
r.index.commit("initial commit", author=author) | ||
|
||
# Add more content | ||
with open(file_name, "a+") as the_file: | ||
the_file.write("line 3\n") | ||
the_file.write("line 4\n") | ||
r.index.add([file_name]) | ||
author = gitpython.Actor("John", "[email protected]") | ||
r.index.commit("second commit", author=author) | ||
|
||
# Get the authors while ignoring [email protected] user | ||
repo_instance = repo.Repo() | ||
config = DEFAULT_CONFIG.copy() | ||
config['ignore_authors'] = ['[email protected]'] | ||
repo_instance.set_config(config) | ||
repo_instance.page(file_name) | ||
authors = repo_instance.get_authors() | ||
authors = util.page_authors(authors, file_name) | ||
authors[0]["last_datetime"] = None | ||
authors[1]["last_datetime"] = None | ||
|
||
assert authors == [ | ||
{ | ||
"contribution": "0.0%", | ||
"contribution_all_pages": "0.0%", | ||
"email": "[email protected]", | ||
"last_datetime": None, | ||
"lines": 0, | ||
"lines_all_pages": 0, | ||
"name": "John" | ||
}, | ||
{ | ||
"name": "Tim", | ||
"email": "[email protected]", | ||
"last_datetime": None, | ||
"lines": 2, | ||
"lines_all_pages": 2, | ||
"contribution": "100.0%", | ||
"contribution_all_pages": "100.0%", | ||
}, | ||
] | ||
|
||
os.chdir(cwd) | ||
|
||
|
||
def test_mkdocs_in_git_subdir(tmp_path): | ||
""" | ||
Sometimes `mkdocs.yml` is not in the root of the repo. | ||
|