mkdocs-git-authors-plugin 0.9.4__tar.gz → 0.9.6__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.4/src/mkdocs_git_authors_plugin.egg-info → mkdocs_git_authors_plugin-0.9.6}/PKG-INFO +3 -2
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/pyproject.toml +1 -1
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/page.py +101 -11
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6/src/mkdocs_git_authors_plugin.egg-info}/PKG-INFO +3 -2
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/tests/test_basic.py +25 -8
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/tests/test_util.py +219 -3
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/LICENSE +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/README.md +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/setup.cfg +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/__init__.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/ci.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/config.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/exclude.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/__init__.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/author.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/command.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/commit.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/repo.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/plugin.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/util.py +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/dependency_links.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/entry_points.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/requires.txt +0 -0
- {mkdocs_git_authors_plugin-0.9.4 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-git-authors-plugin
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.6
|
|
4
4
|
Summary: Mkdocs plugin to display git authors of a page
|
|
5
5
|
Author-email: Tim Vink <vinktim@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -23,6 +23,7 @@ Requires-Python: >=3.8
|
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
24
|
License-File: LICENSE
|
|
25
25
|
Requires-Dist: mkdocs>=1.0
|
|
26
|
+
Dynamic: license-file
|
|
26
27
|
|
|
27
28
|
[](https://github.com/timvink/mkdocs-git-authors-plugin/actions)
|
|
28
29
|

|
|
@@ -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.9.
|
|
15
|
+
version = "0.9.6"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
dependencies = ["mkdocs>=1.0"]
|
|
18
18
|
classifiers = [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import re
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import List
|
|
4
|
+
from typing import Any, List
|
|
5
5
|
|
|
6
6
|
from mkdocs_git_authors_plugin.git.command import GitCommand, GitCommandError
|
|
7
7
|
from mkdocs_git_authors_plugin.git.repo import AbstractRepoObject, Repo
|
|
@@ -73,7 +73,7 @@ class Page(AbstractRepoObject):
|
|
|
73
73
|
or repo.config("show_contribution")
|
|
74
74
|
or repo.config("sort_authors_by") == "contribution"
|
|
75
75
|
)
|
|
76
|
-
self._authors = sorted(self._authors, key=
|
|
76
|
+
self._authors = sorted(self._authors, key=self._sort_key, reverse=reverse)
|
|
77
77
|
self._sorted = True
|
|
78
78
|
author_threshold = repo.config("authorship_threshold_percent")
|
|
79
79
|
if author_threshold > 0 and len(self._authors) > 1:
|
|
@@ -149,7 +149,7 @@ class Page(AbstractRepoObject):
|
|
|
149
149
|
args.append("--ignore-revs-file")
|
|
150
150
|
args.append(self.repo().config("ignore_commits"))
|
|
151
151
|
args.append("--porcelain")
|
|
152
|
-
args.append("-w")
|
|
152
|
+
args.append("-w") # Ignore whitespace changes
|
|
153
153
|
args.append(str(self._path))
|
|
154
154
|
cmd = GitCommand("blame", args)
|
|
155
155
|
cmd.run()
|
|
@@ -189,15 +189,85 @@ class Page(AbstractRepoObject):
|
|
|
189
189
|
author_tz=commit_data.get("author-tz"),
|
|
190
190
|
summary=commit_data.get("summary"),
|
|
191
191
|
)
|
|
192
|
-
if
|
|
193
|
-
|
|
192
|
+
if len(line) > 1 or self.repo().config("count_empty_lines"):
|
|
193
|
+
if commit.author().email() not in ignore_authors:
|
|
194
|
+
author = commit.author()
|
|
195
|
+
if author not in self._authors:
|
|
196
|
+
self._authors.append(author)
|
|
197
|
+
author.add_lines(self, commit)
|
|
198
|
+
self.add_total_lines()
|
|
199
|
+
self.repo().add_total_lines()
|
|
200
|
+
# Process co-authors if present
|
|
201
|
+
self._process_git_log(commit_data.get("sha"), commit)
|
|
202
|
+
|
|
203
|
+
def _process_git_log(self, sha, commit) -> None:
|
|
204
|
+
"""
|
|
205
|
+
Execute git log and parse the results.
|
|
206
|
+
|
|
207
|
+
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.
|
|
208
|
+
Each line will be associated with a Commit object and counted
|
|
209
|
+
to its co-author's "account".
|
|
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()
|
|
194
266
|
):
|
|
195
|
-
|
|
196
|
-
if
|
|
197
|
-
self._authors.append(
|
|
198
|
-
|
|
199
|
-
self.add_total_lines()
|
|
200
|
-
self.repo().add_total_lines()
|
|
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
271
|
|
|
202
272
|
def path(self) -> Path:
|
|
203
273
|
"""
|
|
@@ -210,6 +280,26 @@ class Page(AbstractRepoObject):
|
|
|
210
280
|
"""
|
|
211
281
|
return self._path
|
|
212
282
|
|
|
283
|
+
def _sort_key(self, author) -> Any:
|
|
284
|
+
"""
|
|
285
|
+
Return a sort key for an author.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
author: an Author object
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
comparison key for the sorted() function,
|
|
292
|
+
"""
|
|
293
|
+
repo = self.repo()
|
|
294
|
+
if (
|
|
295
|
+
repo.config("show_line_count")
|
|
296
|
+
or repo.config("show_contribution")
|
|
297
|
+
or repo.config("sort_authors_by") == "contribution"
|
|
298
|
+
):
|
|
299
|
+
return getattr(author, "contribution")(self.path())
|
|
300
|
+
else:
|
|
301
|
+
return getattr(author, "name")()
|
|
302
|
+
|
|
213
303
|
def total_lines(self) -> int:
|
|
214
304
|
"""
|
|
215
305
|
Total number of lines in the markdown source file.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-git-authors-plugin
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.6
|
|
4
4
|
Summary: Mkdocs plugin to display git authors of a page
|
|
5
5
|
Author-email: Tim Vink <vinktim@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -23,6 +23,7 @@ Requires-Python: >=3.8
|
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
24
|
License-File: LICENSE
|
|
25
25
|
Requires-Dist: mkdocs>=1.0
|
|
26
|
+
Dynamic: license-file
|
|
26
27
|
|
|
27
28
|
[](https://github.com/timvink/mkdocs-git-authors-plugin/actions)
|
|
28
29
|

|
|
@@ -45,8 +45,6 @@ SITES_THAT_SHOULD_SUCCEED = [
|
|
|
45
45
|
]
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
48
|
def build_docs_setup(mkdocs_path, output_path) -> Result:
|
|
51
49
|
runner = CliRunner()
|
|
52
50
|
return runner.invoke(
|
|
@@ -144,6 +142,25 @@ def test_ignore_authors_working(tmp_path) -> None:
|
|
|
144
142
|
assert not re.search("Julien", contents)
|
|
145
143
|
|
|
146
144
|
|
|
145
|
+
def test_co_authors_working(tmp_path) -> None:
|
|
146
|
+
result = build_docs_setup("tests/basic_setup/mkdocs_ignore_authors.yml", tmp_path)
|
|
147
|
+
assert (
|
|
148
|
+
result.exit_code == 0
|
|
149
|
+
), f"'mkdocs build' command failed. Error: {result.stdout}"
|
|
150
|
+
|
|
151
|
+
page_file = tmp_path / "page_with_co_authors/index.html"
|
|
152
|
+
assert page_file.exists(), f"{page_file} does not exist"
|
|
153
|
+
|
|
154
|
+
contents = page_file.read_text()
|
|
155
|
+
assert re.search("<span class='git-page-authors", contents)
|
|
156
|
+
assert re.search(
|
|
157
|
+
"fpozzobon@users.noreply.github.com'>Fabien Pozzobon</a>",
|
|
158
|
+
contents,
|
|
159
|
+
)
|
|
160
|
+
assert re.search("<a href='mailto:jdoe@john.com'>John Doe</a>", contents)
|
|
161
|
+
assert not re.search("Julien", contents)
|
|
162
|
+
|
|
163
|
+
|
|
147
164
|
def test_exclude_working_with_genfiles(tmp_path) -> None:
|
|
148
165
|
"""
|
|
149
166
|
A warning for uncommited files should not show up
|
|
@@ -331,11 +348,12 @@ def test_mkapi_v20x(tmp_path) -> None:
|
|
|
331
348
|
assert True
|
|
332
349
|
|
|
333
350
|
|
|
334
|
-
@pytest.mark.skipif(sys.version_info < (3, 7) or sys.version_info > (3, 9), reason="Requires Python 3.7 or higher")
|
|
335
351
|
@pytest.mark.skipif(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
352
|
+
sys.version_info < (3, 7) or sys.version_info > (3, 9),
|
|
353
|
+
reason="Requires Python 3.7 or higher",
|
|
354
|
+
)
|
|
355
|
+
@pytest.mark.skipif(
|
|
356
|
+
not (Version(mkdocs.__version__) < Version("1.6")),
|
|
339
357
|
reason="Requires mkdocs >= 1.6",
|
|
340
358
|
)
|
|
341
359
|
def test_mkapi_v1(tmp_path) -> None:
|
|
@@ -354,12 +372,12 @@ def test_mkapi_v1(tmp_path) -> None:
|
|
|
354
372
|
contents,
|
|
355
373
|
)
|
|
356
374
|
|
|
375
|
+
|
|
357
376
|
def test_custom_docs_dir(tmp_path):
|
|
358
377
|
|
|
359
378
|
testproject_path = tmp_path / "testproject"
|
|
360
379
|
shutil.copytree("tests/custom_docs_dir", testproject_path)
|
|
361
380
|
|
|
362
|
-
|
|
363
381
|
# init git inside the docs directory
|
|
364
382
|
with working_directory(str(testproject_path / "documentation")):
|
|
365
383
|
# setup git history
|
|
@@ -380,4 +398,3 @@ def test_custom_docs_dir(tmp_path):
|
|
|
380
398
|
|
|
381
399
|
contents = index_file.read_text()
|
|
382
400
|
assert re.search("<span class='git-page-authors", contents)
|
|
383
|
-
|
|
@@ -31,12 +31,19 @@ DEFAULT_CONFIG = {
|
|
|
31
31
|
"show_contribution": False,
|
|
32
32
|
"show_line_count": False,
|
|
33
33
|
"show_email_address": True,
|
|
34
|
+
"href": "mailto:{email}",
|
|
34
35
|
"count_empty_lines": True,
|
|
35
|
-
"
|
|
36
|
-
"
|
|
36
|
+
"fallback_to_empty": False,
|
|
37
|
+
"exclude": [],
|
|
38
|
+
"ignore_commits": "",
|
|
39
|
+
"ignore_authors": [],
|
|
40
|
+
"enabled": True,
|
|
41
|
+
"enabled_on_serve": True,
|
|
37
42
|
"sort_authors_by": "name",
|
|
38
43
|
"authorship_threshold_percent": 0,
|
|
39
|
-
"
|
|
44
|
+
"strict": True,
|
|
45
|
+
# "sort_authors_by_name": True,
|
|
46
|
+
# "sort_reverse": False,
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
#### Helpers ####
|
|
@@ -120,6 +127,11 @@ def setup_commit_history(testproject_path):
|
|
|
120
127
|
repo.git.commit(message="homepage", author=author)
|
|
121
128
|
repo.git.add("docs/page_with_tag.md")
|
|
122
129
|
repo.git.commit(message="homepage", author=author)
|
|
130
|
+
repo.git.add("docs/page_with_co_authors.md")
|
|
131
|
+
repo.git.commit(
|
|
132
|
+
message="co-authors commit\nCo-authored-by: Test Person <testtest@gmail.com>\nCo-authored-by: Roger Doe <rdoe@john.com>",
|
|
133
|
+
author=author,
|
|
134
|
+
)
|
|
123
135
|
os.chdir(str(cwd))
|
|
124
136
|
except:
|
|
125
137
|
os.chdir(str(cwd))
|
|
@@ -129,6 +141,16 @@ def setup_commit_history(testproject_path):
|
|
|
129
141
|
return repo
|
|
130
142
|
|
|
131
143
|
|
|
144
|
+
def commit_lines(r, file_name, author_name, author_email, num_of_lines=1):
|
|
145
|
+
with open(file_name, "a") as the_file:
|
|
146
|
+
for i in range(num_of_lines):
|
|
147
|
+
the_file.write("Hello\n")
|
|
148
|
+
|
|
149
|
+
r.index.add([file_name])
|
|
150
|
+
author = gitpython.Actor(author_name, author_email)
|
|
151
|
+
r.index.commit("some commit", author=author)
|
|
152
|
+
|
|
153
|
+
|
|
132
154
|
#### Tests ####
|
|
133
155
|
|
|
134
156
|
|
|
@@ -477,6 +499,200 @@ def test_mkdocs_in_git_subdir(tmp_path):
|
|
|
477
499
|
os.chdir(cwd)
|
|
478
500
|
|
|
479
501
|
|
|
502
|
+
def test_page_authors_summary(tmp_path):
|
|
503
|
+
"""
|
|
504
|
+
Builds a fake git project with some commits.
|
|
505
|
+
|
|
506
|
+
Args:
|
|
507
|
+
tmp_path (PosixPath): Directory of a tempdir
|
|
508
|
+
"""
|
|
509
|
+
cwd = os.getcwd()
|
|
510
|
+
os.chdir(str(tmp_path))
|
|
511
|
+
|
|
512
|
+
config = DEFAULT_CONFIG.copy()
|
|
513
|
+
|
|
514
|
+
# Create a git repo and file
|
|
515
|
+
r = gitpython.Repo.init(tmp_path)
|
|
516
|
+
file_name = str(tmp_path / "new-file")
|
|
517
|
+
|
|
518
|
+
# Initial commit
|
|
519
|
+
commit_lines(r, file_name, "Tim", "abc@abc.com")
|
|
520
|
+
|
|
521
|
+
repo_instance = repo.Repo()
|
|
522
|
+
repo_instance.set_config(config)
|
|
523
|
+
page_instance = repo_instance.page(file_name)
|
|
524
|
+
|
|
525
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
526
|
+
|
|
527
|
+
assert (
|
|
528
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
529
|
+
"<a href='mailto:abc@abc.com'>Tim</a>"
|
|
530
|
+
"</span>"
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
# Now add a line to the file
|
|
534
|
+
# From a second author with same email
|
|
535
|
+
commit_lines(r, file_name, "Tim2", "abc@abc.com")
|
|
536
|
+
|
|
537
|
+
repo_instance = repo.Repo()
|
|
538
|
+
repo_instance.set_config(config)
|
|
539
|
+
page_instance = repo_instance.page(file_name)
|
|
540
|
+
|
|
541
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
542
|
+
|
|
543
|
+
assert (
|
|
544
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
545
|
+
"<a href='mailto:abc@abc.com'>Tim</a>"
|
|
546
|
+
"</span>"
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
# Then a third commit from a new author
|
|
550
|
+
commit_lines(r, file_name, "John", "john@abc.com")
|
|
551
|
+
|
|
552
|
+
repo_instance = repo.Repo()
|
|
553
|
+
repo_instance.set_config(config)
|
|
554
|
+
page_instance = repo_instance.page(file_name)
|
|
555
|
+
|
|
556
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
557
|
+
|
|
558
|
+
assert (
|
|
559
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
560
|
+
"<a href='mailto:john@abc.com'>John</a>, "
|
|
561
|
+
"<a href='mailto:abc@abc.com'>Tim</a>"
|
|
562
|
+
"</span>"
|
|
563
|
+
)
|
|
564
|
+
|
|
565
|
+
os.chdir(cwd)
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def test_page_authors_summary_showing_contribution(tmp_path):
|
|
569
|
+
"""
|
|
570
|
+
Builds a fake git project with some commits.
|
|
571
|
+
|
|
572
|
+
Args:
|
|
573
|
+
tmp_path (PosixPath): Directory of a tempdir
|
|
574
|
+
"""
|
|
575
|
+
cwd = os.getcwd()
|
|
576
|
+
os.chdir(str(tmp_path))
|
|
577
|
+
|
|
578
|
+
config = DEFAULT_CONFIG.copy()
|
|
579
|
+
config["show_contribution"] = True
|
|
580
|
+
|
|
581
|
+
# Create a git repo and file
|
|
582
|
+
r = gitpython.Repo.init(tmp_path)
|
|
583
|
+
file_name = str(tmp_path / "new-file")
|
|
584
|
+
|
|
585
|
+
# Initial commit
|
|
586
|
+
commit_lines(r, file_name, "Tim", "abc@abc.com")
|
|
587
|
+
|
|
588
|
+
repo_instance = repo.Repo()
|
|
589
|
+
repo_instance.set_config(config)
|
|
590
|
+
page_instance = repo_instance.page(file_name)
|
|
591
|
+
|
|
592
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
593
|
+
|
|
594
|
+
# Contribution is not shown if there is only single Author
|
|
595
|
+
assert (
|
|
596
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
597
|
+
"<a href='mailto:abc@abc.com'>Tim</a>"
|
|
598
|
+
"</span>"
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
# Now add a line to the file
|
|
602
|
+
# From a second author with same email
|
|
603
|
+
commit_lines(r, file_name, "Tim2", "abc@abc.com")
|
|
604
|
+
|
|
605
|
+
repo_instance = repo.Repo()
|
|
606
|
+
repo_instance.set_config(config)
|
|
607
|
+
page_instance = repo_instance.page(file_name)
|
|
608
|
+
|
|
609
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
610
|
+
|
|
611
|
+
# Contribution is not shown if there is only single Author
|
|
612
|
+
assert (
|
|
613
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
614
|
+
"<a href='mailto:abc@abc.com'>Tim</a>"
|
|
615
|
+
"</span>"
|
|
616
|
+
)
|
|
617
|
+
|
|
618
|
+
# Then a third commit from a new author
|
|
619
|
+
commit_lines(r, file_name, "John", "john@abc.com")
|
|
620
|
+
|
|
621
|
+
repo_instance = repo.Repo()
|
|
622
|
+
repo_instance.set_config(config)
|
|
623
|
+
page_instance = repo_instance.page(file_name)
|
|
624
|
+
|
|
625
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
626
|
+
|
|
627
|
+
# Contribution is shown if there are multiple authors, ordered by contribution
|
|
628
|
+
assert (
|
|
629
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
630
|
+
"<a href='mailto:abc@abc.com'>Tim</a> (66.67%), "
|
|
631
|
+
"<a href='mailto:john@abc.com'>John</a> (33.33%)"
|
|
632
|
+
"</span>"
|
|
633
|
+
)
|
|
634
|
+
|
|
635
|
+
os.chdir(cwd)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def test_page_authors_summary_showing_contribution_ordering_by_page_contribution(
|
|
639
|
+
tmp_path,
|
|
640
|
+
):
|
|
641
|
+
"""
|
|
642
|
+
Builds a fake git project with some commits.
|
|
643
|
+
|
|
644
|
+
Args:
|
|
645
|
+
tmp_path (PosixPath): Directory of a tempdir
|
|
646
|
+
"""
|
|
647
|
+
cwd = os.getcwd()
|
|
648
|
+
os.chdir(str(tmp_path))
|
|
649
|
+
|
|
650
|
+
config = DEFAULT_CONFIG.copy()
|
|
651
|
+
config["show_contribution"] = True
|
|
652
|
+
|
|
653
|
+
# Create a git repo and files
|
|
654
|
+
r = gitpython.Repo.init(tmp_path)
|
|
655
|
+
file_name = str(tmp_path / "new-file")
|
|
656
|
+
file_name2 = str(tmp_path / "new-file2")
|
|
657
|
+
|
|
658
|
+
# Commits by multiple authors on multiple files
|
|
659
|
+
commit_lines(r, file_name, "Tim", "tim@abc.com", 8)
|
|
660
|
+
commit_lines(r, file_name, "John", "john@abc.com", 4)
|
|
661
|
+
commit_lines(r, file_name, "Thomas", "thomas@abc.com", 2)
|
|
662
|
+
|
|
663
|
+
commit_lines(r, file_name2, "Tim", "tim@abc.com", 4)
|
|
664
|
+
commit_lines(r, file_name2, "John", "john@abc.com", 16)
|
|
665
|
+
commit_lines(r, file_name2, "Thomas", "thomas@abc.com", 8)
|
|
666
|
+
|
|
667
|
+
repo_instance = repo.Repo()
|
|
668
|
+
repo_instance.set_config(config)
|
|
669
|
+
page_instance = repo_instance.page(file_name)
|
|
670
|
+
page_instance2 = repo_instance.page(file_name2)
|
|
671
|
+
|
|
672
|
+
authors_summary = util.page_authors_summary(page_instance, config)
|
|
673
|
+
|
|
674
|
+
# Contribution is shown if there are multiple authors, ordered by contribution on page
|
|
675
|
+
assert (
|
|
676
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
677
|
+
"<a href='mailto:tim@abc.com'>Tim</a> (57.14%), "
|
|
678
|
+
"<a href='mailto:john@abc.com'>John</a> (28.57%), "
|
|
679
|
+
"<a href='mailto:thomas@abc.com'>Thomas</a> (14.29%)"
|
|
680
|
+
"</span>"
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
authors_summary = util.page_authors_summary(page_instance2, config)
|
|
684
|
+
|
|
685
|
+
assert (
|
|
686
|
+
authors_summary == "<span class='git-page-authors git-authors'>"
|
|
687
|
+
"<a href='mailto:john@abc.com'>John</a> (57.14%), "
|
|
688
|
+
"<a href='mailto:thomas@abc.com'>Thomas</a> (28.57%), "
|
|
689
|
+
"<a href='mailto:tim@abc.com'>Tim</a> (14.29%)"
|
|
690
|
+
"</span>"
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
os.chdir(cwd)
|
|
694
|
+
|
|
695
|
+
|
|
480
696
|
def test_summarize_authors():
|
|
481
697
|
"""
|
|
482
698
|
Test summary functions.
|
|
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
|
|
File without changes
|