mkdocs-git-authors-plugin 0.9.6__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mkdocs_git_authors_plugin-0.9.6/src/mkdocs_git_authors_plugin.egg-info → mkdocs_git_authors_plugin-0.10.0}/PKG-INFO +1 -1
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/pyproject.toml +1 -1
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/config.py +1 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/git/commit.py +14 -1
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/git/page.py +9 -70
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/git/repo.py +70 -2
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin.egg-info}/PKG-INFO +1 -1
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/tests/test_basic.py +1 -1
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/LICENSE +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/README.md +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/setup.cfg +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/__init__.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/ci.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/exclude.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/git/__init__.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/git/author.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/git/command.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/plugin.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin/util.py +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin.egg-info/dependency_links.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin.egg-info/entry_points.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin.egg-info/requires.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/src/mkdocs_git_authors_plugin.egg-info/top_level.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.6 → mkdocs_git_authors_plugin-0.10.0}/tests/test_util.py +0 -0
|
@@ -12,7 +12,7 @@ authors = [
|
|
|
12
12
|
]
|
|
13
13
|
keywords = ["mkdocs", "git", "contributors", "committers", "authors", "plugin"]
|
|
14
14
|
urls = {Homepage = "https://github.com/timvink/mkdocs-git-authors-plugin"}
|
|
15
|
-
version = "0.
|
|
15
|
+
version = "0.10.0"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
dependencies = ["mkdocs>=1.0"]
|
|
18
18
|
classifiers = [
|
|
@@ -6,6 +6,7 @@ class GitAuthorsPluginConfig(Config):
|
|
|
6
6
|
show_contribution = config_options.Type(bool, default=False)
|
|
7
7
|
show_line_count = config_options.Type(bool, default=False)
|
|
8
8
|
show_email_address = config_options.Type(bool, default=True)
|
|
9
|
+
add_co_authors = config_options.Type(bool, default=False)
|
|
9
10
|
href = config_options.Type(str, default="mailto:{email}")
|
|
10
11
|
count_empty_lines = config_options.Type(bool, default=True)
|
|
11
12
|
fallback_to_empty = config_options.Type(bool, default=False)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import re
|
|
2
|
-
from typing import Union
|
|
2
|
+
from typing import Any, Union, List
|
|
3
3
|
|
|
4
4
|
from mkdocs_git_authors_plugin import util
|
|
5
5
|
from mkdocs_git_authors_plugin.git.repo import AbstractRepoObject, Repo
|
|
@@ -24,6 +24,7 @@ class Commit(AbstractRepoObject):
|
|
|
24
24
|
author_time: str,
|
|
25
25
|
author_tz: str,
|
|
26
26
|
summary: str,
|
|
27
|
+
co_authors: List[Any],
|
|
27
28
|
):
|
|
28
29
|
"""Initialize a commit from its SHA.
|
|
29
30
|
|
|
@@ -48,6 +49,7 @@ class Commit(AbstractRepoObject):
|
|
|
48
49
|
self._datetime = util.commit_datetime(author_time, author_tz)
|
|
49
50
|
self._datetime_string = util.commit_datetime_string(self._datetime)
|
|
50
51
|
self._summary = summary
|
|
52
|
+
self._co_authors = co_authors
|
|
51
53
|
|
|
52
54
|
def author(self):
|
|
53
55
|
"""
|
|
@@ -60,6 +62,17 @@ class Commit(AbstractRepoObject):
|
|
|
60
62
|
"""
|
|
61
63
|
return self._author
|
|
62
64
|
|
|
65
|
+
def co_authors(self):
|
|
66
|
+
"""
|
|
67
|
+
The commit's co-author.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Co-Authors list
|
|
73
|
+
"""
|
|
74
|
+
return self._co_authors
|
|
75
|
+
|
|
63
76
|
def datetime(self, _type=str) -> Union[str, util.datetime]:
|
|
64
77
|
"""
|
|
65
78
|
The commit's commit time.
|
|
@@ -198,76 +198,15 @@ class Page(AbstractRepoObject):
|
|
|
198
198
|
self.add_total_lines()
|
|
199
199
|
self.repo().add_total_lines()
|
|
200
200
|
# Process co-authors if present
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
Whether empty lines are counted is determined by the
|
|
211
|
-
count_empty_lines configuration option.
|
|
212
|
-
|
|
213
|
-
git log -1 <sha> will produce output like the following
|
|
214
|
-
for each line in a file:
|
|
215
|
-
|
|
216
|
-
When a commit does not contain co-authors:
|
|
217
|
-
commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c
|
|
218
|
-
Author: John Doe <jdoe@john.com>
|
|
219
|
-
Date: Sun Dec 22 11:10:32 2019 +0100
|
|
220
|
-
|
|
221
|
-
add plugin skeleton
|
|
222
|
-
|
|
223
|
-
When a commit contains co-authors:
|
|
224
|
-
commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c
|
|
225
|
-
Author: John Doe <jdoe@john.com>
|
|
226
|
-
Date: Sun Dec 22 11:10:32 2019 +0100
|
|
227
|
-
|
|
228
|
-
add plugin skeleton
|
|
229
|
-
|
|
230
|
-
Co-authored-by: John Doe <jdoe@john.com>
|
|
231
|
-
Co-authored-by: Rock Smith <rsmith@smith.com>
|
|
232
|
-
|
|
233
|
-
In this case we skip the original author as redundant using email address to detect it.
|
|
234
|
-
|
|
235
|
-
Args:
|
|
236
|
-
sha: the SHA of the commit to process
|
|
237
|
-
Returns:
|
|
238
|
-
--- (this method works through side effects)
|
|
239
|
-
"""
|
|
240
|
-
|
|
241
|
-
args = []
|
|
242
|
-
args.append("-1") # Only existing sha
|
|
243
|
-
args.append(sha)
|
|
244
|
-
cmd = GitCommand("log", args)
|
|
245
|
-
cmd.run()
|
|
246
|
-
|
|
247
|
-
lines = cmd.stdout()
|
|
248
|
-
|
|
249
|
-
# in case of empty, non-committed files, raise error
|
|
250
|
-
if len(lines) == 0:
|
|
251
|
-
raise GitCommandError
|
|
252
|
-
|
|
253
|
-
ignore_authors = self.repo().config("ignore_authors")
|
|
254
|
-
for line in lines:
|
|
255
|
-
if line.startswith("Author: "):
|
|
256
|
-
# skip author as already available in Commit object
|
|
257
|
-
continue
|
|
258
|
-
|
|
259
|
-
result = re.search(r"Co-authored-by: (.*) <(.*)>", line)
|
|
260
|
-
if result is not None and result.group(1) != "" and result.group(2) != "":
|
|
261
|
-
# Extract co-authors from the commit
|
|
262
|
-
co_author = self.repo().author(result.group(1), result.group(2))
|
|
263
|
-
if (
|
|
264
|
-
co_author.email() not in ignore_authors
|
|
265
|
-
and co_author.email() != commit.author().email()
|
|
266
|
-
):
|
|
267
|
-
# Create the co-author
|
|
268
|
-
if co_author not in self._authors:
|
|
269
|
-
self._authors.append(co_author)
|
|
270
|
-
co_author.add_lines(self, commit)
|
|
201
|
+
for co_author in commit.co_authors():
|
|
202
|
+
# Create the co-author
|
|
203
|
+
if (
|
|
204
|
+
co_author.email() not in ignore_authors
|
|
205
|
+
and co_author.email() != commit.author().email()
|
|
206
|
+
):
|
|
207
|
+
if co_author not in self._authors:
|
|
208
|
+
self._authors.append(co_author)
|
|
209
|
+
co_author.add_lines(self, commit)
|
|
271
210
|
|
|
272
211
|
def path(self) -> Path:
|
|
273
212
|
"""
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import re
|
|
1
2
|
from pathlib import Path
|
|
2
|
-
from typing import Any, Union
|
|
3
|
+
from typing import Any, Union, List
|
|
3
4
|
|
|
4
5
|
from mkdocs_git_authors_plugin.git.command import GitCommand
|
|
5
6
|
|
|
7
|
+
from mkdocs_git_authors_plugin.git.command import GitCommandError
|
|
8
|
+
|
|
6
9
|
|
|
7
10
|
class Repo(object):
|
|
8
11
|
"""
|
|
@@ -49,7 +52,7 @@ class Repo(object):
|
|
|
49
52
|
self._authors[email] = Author(self, name, email)
|
|
50
53
|
return self._authors[email]
|
|
51
54
|
|
|
52
|
-
def get_authors(self) ->
|
|
55
|
+
def get_authors(self) -> List[Any]:
|
|
53
56
|
"""
|
|
54
57
|
Sorted list of authors in the repository.
|
|
55
58
|
|
|
@@ -113,9 +116,74 @@ class Repo(object):
|
|
|
113
116
|
if not self._commits.get(sha):
|
|
114
117
|
from .commit import Commit
|
|
115
118
|
|
|
119
|
+
if self.config("add_co_authors"):
|
|
120
|
+
kwargs["co_authors"] = self._get_co_authors(sha)
|
|
121
|
+
else:
|
|
122
|
+
kwargs["co_authors"] = []
|
|
116
123
|
self._commits[sha] = Commit(self, sha, **kwargs)
|
|
117
124
|
return self._commits.get(sha)
|
|
118
125
|
|
|
126
|
+
def _get_co_authors(self, sha) -> List[Any]:
|
|
127
|
+
"""
|
|
128
|
+
Execute git log and parse the results.
|
|
129
|
+
|
|
130
|
+
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.
|
|
131
|
+
Each line will be associated with a Commit object and counted
|
|
132
|
+
to its co-author's "account".
|
|
133
|
+
Whether empty lines are counted is determined by the
|
|
134
|
+
count_empty_lines configuration option.
|
|
135
|
+
|
|
136
|
+
git log -1 <sha> will produce output like the following
|
|
137
|
+
for each line in a file:
|
|
138
|
+
|
|
139
|
+
When a commit does not contain co-authors:
|
|
140
|
+
commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c
|
|
141
|
+
Author: John Doe <jdoe@john.com>
|
|
142
|
+
Date: Sun Dec 22 11:10:32 2019 +0100
|
|
143
|
+
|
|
144
|
+
add plugin skeleton
|
|
145
|
+
|
|
146
|
+
When a commit contains co-authors:
|
|
147
|
+
commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c
|
|
148
|
+
Author: John Doe <jdoe@john.com>
|
|
149
|
+
Date: Sun Dec 22 11:10:32 2019 +0100
|
|
150
|
+
|
|
151
|
+
add plugin skeleton
|
|
152
|
+
|
|
153
|
+
Co-authored-by: John Doe <jdoe@john.com>
|
|
154
|
+
Co-authored-by: Rock Smith <rsmith@smith.com>
|
|
155
|
+
|
|
156
|
+
In this case we skip the original author as redundant using email address to detect it.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
sha: the SHA of the commit to process
|
|
160
|
+
author_email: email of the author
|
|
161
|
+
Returns:
|
|
162
|
+
List of co-authors excluding commit author
|
|
163
|
+
"""
|
|
164
|
+
args = ["-1", sha]
|
|
165
|
+
cmd = GitCommand("log", args)
|
|
166
|
+
cmd.run()
|
|
167
|
+
|
|
168
|
+
lines = cmd.stdout()
|
|
169
|
+
|
|
170
|
+
# in case of empty, non-committed files, raise error
|
|
171
|
+
if len(lines) == 0:
|
|
172
|
+
raise GitCommandError
|
|
173
|
+
co_authors = []
|
|
174
|
+
|
|
175
|
+
for line in lines:
|
|
176
|
+
if line.startswith("Author: "):
|
|
177
|
+
# skip author as already available in Commit object
|
|
178
|
+
continue
|
|
179
|
+
|
|
180
|
+
result = re.search(r"Co-authored-by: (.*) <(.*)>", line)
|
|
181
|
+
if result is not None and result.group(1) != "" and result.group(2) != "":
|
|
182
|
+
# Extract co-authors from the commit
|
|
183
|
+
co_author = self.author(result.group(1), result.group(2))
|
|
184
|
+
co_authors.append(co_author)
|
|
185
|
+
return co_authors
|
|
186
|
+
|
|
119
187
|
def page(self, path):
|
|
120
188
|
"""
|
|
121
189
|
Return the (cached) Page object for given path.
|
|
@@ -143,7 +143,7 @@ def test_ignore_authors_working(tmp_path) -> None:
|
|
|
143
143
|
|
|
144
144
|
|
|
145
145
|
def test_co_authors_working(tmp_path) -> None:
|
|
146
|
-
result = build_docs_setup("tests/basic_setup/
|
|
146
|
+
result = build_docs_setup("tests/basic_setup/mkdocs_add_co_authors.yml", tmp_path)
|
|
147
147
|
assert (
|
|
148
148
|
result.exit_code == 0
|
|
149
149
|
), f"'mkdocs build' command failed. Error: {result.stdout}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|