-
-
Notifications
You must be signed in to change notification settings - Fork 23
Optimise logs #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Optimise logs #111
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c29bc54
Optimise logs
fpozzobon 005c019
Code review:
fpozzobon c858fd1
list backward compatible
fpozzobon 96af8a3
moving co-author filter to page responsibility
fpozzobon 82138bf
Add co authors as option
fpozzobon 92f6688
Adding documentation of co_authors and set to false by default
fpozzobon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -198,76 +198,15 @@ def _process_git_blame(self) -> None: | |
| self.add_total_lines() | ||
| self.repo().add_total_lines() | ||
| # Process co-authors if present | ||
| self._process_git_log(commit_data.get("sha"), commit) | ||
|
|
||
| def _process_git_log(self, sha, commit) -> None: | ||
| """ | ||
| Execute git log and parse the results. | ||
|
|
||
| This retrieves [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) from comment. | ||
| Each line will be associated with a Commit object and counted | ||
| to its co-author's "account". | ||
| Whether empty lines are counted is determined by the | ||
| count_empty_lines configuration option. | ||
|
|
||
| git log -1 <sha> will produce output like the following | ||
| for each line in a file: | ||
|
|
||
| When a commit does not contain co-authors: | ||
| commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c | ||
| Author: John Doe <[email protected]> | ||
| Date: Sun Dec 22 11:10:32 2019 +0100 | ||
|
|
||
| add plugin skeleton | ||
|
|
||
| When a commit contains co-authors: | ||
| commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c | ||
| Author: John Doe <[email protected]> | ||
| Date: Sun Dec 22 11:10:32 2019 +0100 | ||
|
|
||
| add plugin skeleton | ||
|
|
||
| Co-authored-by: John Doe <[email protected]> | ||
| Co-authored-by: Rock Smith <[email protected]> | ||
|
|
||
| In this case we skip the original author as redundant using email address to detect it. | ||
|
|
||
| Args: | ||
| sha: the SHA of the commit to process | ||
| Returns: | ||
| --- (this method works through side effects) | ||
| """ | ||
|
|
||
| args = [] | ||
| args.append("-1") # Only existing sha | ||
| args.append(sha) | ||
| cmd = GitCommand("log", args) | ||
| cmd.run() | ||
|
|
||
| lines = cmd.stdout() | ||
|
|
||
| # in case of empty, non-committed files, raise error | ||
| if len(lines) == 0: | ||
| raise GitCommandError | ||
|
|
||
| ignore_authors = self.repo().config("ignore_authors") | ||
| for line in lines: | ||
| if line.startswith("Author: "): | ||
| # skip author as already available in Commit object | ||
| continue | ||
|
|
||
| result = re.search(r"Co-authored-by: (.*) <(.*)>", line) | ||
| if result is not None and result.group(1) != "" and result.group(2) != "": | ||
| # Extract co-authors from the commit | ||
| co_author = self.repo().author(result.group(1), result.group(2)) | ||
| if ( | ||
| co_author.email() not in ignore_authors | ||
| and co_author.email() != commit.author().email() | ||
| ): | ||
| # Create the co-author | ||
| if co_author not in self._authors: | ||
| self._authors.append(co_author) | ||
| co_author.add_lines(self, commit) | ||
| for co_author in commit.co_authors(): | ||
| # Create the co-author | ||
| if ( | ||
| co_author.email() not in ignore_authors | ||
| and co_author.email() != commit.author().email() | ||
| ): | ||
| if co_author not in self._authors: | ||
| self._authors.append(co_author) | ||
| co_author.add_lines(self, commit) | ||
|
|
||
| def path(self) -> Path: | ||
| """ | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| import re | ||
| from pathlib import Path | ||
| from typing import Any, Union | ||
| from typing import Any, Union, List | ||
|
|
||
| from mkdocs_git_authors_plugin.git.command import GitCommand | ||
|
|
||
| from mkdocs_git_authors_plugin.git.command import GitCommandError | ||
|
|
||
|
|
||
| class Repo(object): | ||
| """ | ||
|
|
@@ -49,7 +52,7 @@ def author(self, name, email: str): | |
| self._authors[email] = Author(self, name, email) | ||
| return self._authors[email] | ||
|
|
||
| def get_authors(self) -> list: | ||
| def get_authors(self) -> List[Any]: | ||
| """ | ||
| Sorted list of authors in the repository. | ||
|
|
||
|
|
@@ -113,9 +116,74 @@ def get_commit(self, sha: str, **kwargs) -> Union[Any, None]: | |
| if not self._commits.get(sha): | ||
| from .commit import Commit | ||
|
|
||
| if self.config("add_co_authors"): | ||
| kwargs["co_authors"] = self._get_co_authors(sha) | ||
| else: | ||
| kwargs["co_authors"] = [] | ||
| self._commits[sha] = Commit(self, sha, **kwargs) | ||
| return self._commits.get(sha) | ||
|
|
||
| def _get_co_authors(self, sha) -> List[Any]: | ||
| """ | ||
| Execute git log and parse the results. | ||
|
|
||
| This retrieves [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) from comment. | ||
| Each line will be associated with a Commit object and counted | ||
| to its co-author's "account". | ||
| Whether empty lines are counted is determined by the | ||
| count_empty_lines configuration option. | ||
|
|
||
| git log -1 <sha> will produce output like the following | ||
| for each line in a file: | ||
|
|
||
| When a commit does not contain co-authors: | ||
| commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c | ||
| Author: John Doe <[email protected]> | ||
| Date: Sun Dec 22 11:10:32 2019 +0100 | ||
|
|
||
| add plugin skeleton | ||
|
|
||
| When a commit contains co-authors: | ||
| commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c | ||
| Author: John Doe <[email protected]> | ||
| Date: Sun Dec 22 11:10:32 2019 +0100 | ||
|
|
||
| add plugin skeleton | ||
|
|
||
| Co-authored-by: John Doe <[email protected]> | ||
| Co-authored-by: Rock Smith <[email protected]> | ||
|
|
||
| In this case we skip the original author as redundant using email address to detect it. | ||
|
|
||
| Args: | ||
| sha: the SHA of the commit to process | ||
| author_email: email of the author | ||
| Returns: | ||
| List of co-authors excluding commit author | ||
| """ | ||
| args = ["-1", sha] | ||
| cmd = GitCommand("log", args) | ||
| cmd.run() | ||
|
|
||
| lines = cmd.stdout() | ||
|
|
||
| # in case of empty, non-committed files, raise error | ||
| if len(lines) == 0: | ||
| raise GitCommandError | ||
| co_authors = [] | ||
|
|
||
| for line in lines: | ||
| if line.startswith("Author: "): | ||
| # skip author as already available in Commit object | ||
| continue | ||
|
|
||
| result = re.search(r"Co-authored-by: (.*) <(.*)>", line) | ||
| if result is not None and result.group(1) != "" and result.group(2) != "": | ||
| # Extract co-authors from the commit | ||
| co_author = self.author(result.group(1), result.group(2)) | ||
| co_authors.append(co_author) | ||
| return co_authors | ||
|
|
||
| def page(self, path): | ||
| """ | ||
| Return the (cached) Page object for given path. | ||
|
|
||
This file contains hidden or 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,9 @@ | ||
| site_name: test gitauthors_plugin | ||
| use_directory_urls: true | ||
|
|
||
| plugins: | ||
| - search | ||
| - git-authors: | ||
| add_co_authors: true | ||
| ignore_authors: | ||
| - '[email protected]' |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false (this is the default)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add the documentation of the option lower down in this file?