|
35 | 35 | "sort_reverse": False,
|
36 | 36 | "sort_authors_by": "name",
|
37 | 37 | "authorship_threshold_percent": 0,
|
| 38 | + "ignore_authors": [], |
38 | 39 | }
|
39 | 40 |
|
40 | 41 | #### Helpers ####
|
@@ -275,6 +276,148 @@ def test_retrieve_authors(tmp_path):
|
275 | 276 | os.chdir(cwd)
|
276 | 277 |
|
277 | 278 |
|
| 279 | +def test_retrieve_authors_ignoring_commits(tmp_path): |
| 280 | + """ |
| 281 | + Builds a fake git project with some commits. |
| 282 | +
|
| 283 | + Args: |
| 284 | + tmp_path (PosixPath): Directory of a tempdir |
| 285 | + """ |
| 286 | + cwd = os.getcwd() |
| 287 | + os.chdir(str(tmp_path)) |
| 288 | + |
| 289 | + # Create file |
| 290 | + file_name = str(tmp_path / "new-file") |
| 291 | + with open(file_name, "w") as the_file: |
| 292 | + the_file.write("line 1\n") |
| 293 | + the_file.write("line 2\n") |
| 294 | + |
| 295 | + # Create git repo and commit file |
| 296 | + r = gitpython.Repo.init(tmp_path) |
| 297 | + r.index.add([file_name]) |
| 298 | + author = gitpython. Actor( "Tim", "[email protected]") |
| 299 | + r.index.commit("initial commit", author=author) |
| 300 | + |
| 301 | + # Update the file |
| 302 | + with open(file_name, "w") as the_file: |
| 303 | + the_file.write("line 1.1\n") |
| 304 | + the_file.write("line 2.1\n") |
| 305 | + r.index.add([file_name]) |
| 306 | + author = gitpython. Actor( "John", "[email protected]") |
| 307 | + commit = r.index.commit("second commit", author=author) |
| 308 | + |
| 309 | + repo_instance = repo.Repo() |
| 310 | + repo_instance.set_config(DEFAULT_CONFIG) |
| 311 | + repo_instance.page(file_name) |
| 312 | + authors = repo_instance.get_authors() |
| 313 | + authors = util.page_authors(authors, file_name) |
| 314 | + authors[0]["last_datetime"] = None |
| 315 | + |
| 316 | + assert authors == [ |
| 317 | + { |
| 318 | + "name": "John", |
| 319 | + |
| 320 | + "last_datetime": None, |
| 321 | + "lines": 2, |
| 322 | + "lines_all_pages": 2, |
| 323 | + "contribution": "100.0%", |
| 324 | + "contribution_all_pages": "100.0%", |
| 325 | + } |
| 326 | + ] |
| 327 | + |
| 328 | + # Get the authors while ignoring the last commit |
| 329 | + ignored_commits_files = str(tmp_path / "ignored_commits.txt") |
| 330 | + with open(ignored_commits_files, "w") as the_file: |
| 331 | + the_file.write(commit.hexsha + "\n") |
| 332 | + repo_instance = repo.Repo() |
| 333 | + config = DEFAULT_CONFIG.copy() |
| 334 | + config['ignore_commits'] = ignored_commits_files |
| 335 | + repo_instance.set_config(config) |
| 336 | + repo_instance.page(file_name) |
| 337 | + authors = repo_instance.get_authors() |
| 338 | + authors = util.page_authors(authors, file_name) |
| 339 | + authors[0]["last_datetime"] = None |
| 340 | + |
| 341 | + assert authors == [ |
| 342 | + { |
| 343 | + "name": "Tim", |
| 344 | + |
| 345 | + "last_datetime": None, |
| 346 | + "lines": 2, |
| 347 | + "lines_all_pages": 2, |
| 348 | + "contribution": "100.0%", |
| 349 | + "contribution_all_pages": "100.0%", |
| 350 | + }, |
| 351 | + ] |
| 352 | + |
| 353 | + os.chdir(cwd) |
| 354 | + |
| 355 | + |
| 356 | +def test_retrieve_authors_ignoring_emails(tmp_path): |
| 357 | + """ |
| 358 | + Builds a fake git project with some commits. |
| 359 | +
|
| 360 | + Args: |
| 361 | + tmp_path (PosixPath): Directory of a tempdir |
| 362 | + """ |
| 363 | + cwd = os.getcwd() |
| 364 | + os.chdir(str(tmp_path)) |
| 365 | + |
| 366 | + # Create file |
| 367 | + file_name = str(tmp_path / "new-file") |
| 368 | + with open(file_name, "w") as the_file: |
| 369 | + the_file.write("line 1\n") |
| 370 | + the_file.write("line 2\n") |
| 371 | + |
| 372 | + # Create git repo and commit file |
| 373 | + r = gitpython.Repo.init(tmp_path) |
| 374 | + r.index.add([file_name]) |
| 375 | + author = gitpython. Actor( "Tim", "[email protected]") |
| 376 | + r.index.commit("initial commit", author=author) |
| 377 | + |
| 378 | + # Add more content |
| 379 | + with open(file_name, "a+") as the_file: |
| 380 | + the_file.write("line 3\n") |
| 381 | + the_file.write("line 4\n") |
| 382 | + r.index.add([file_name]) |
| 383 | + author = gitpython. Actor( "John", "[email protected]") |
| 384 | + r.index.commit("second commit", author=author) |
| 385 | + |
| 386 | + # Get the authors while ignoring [email protected] user |
| 387 | + repo_instance = repo.Repo() |
| 388 | + config = DEFAULT_CONFIG.copy() |
| 389 | + config[ 'ignore_authors'] = [ '[email protected]'] |
| 390 | + repo_instance.set_config(config) |
| 391 | + repo_instance.page(file_name) |
| 392 | + authors = repo_instance.get_authors() |
| 393 | + authors = util.page_authors(authors, file_name) |
| 394 | + authors[0]["last_datetime"] = None |
| 395 | + authors[1]["last_datetime"] = None |
| 396 | + |
| 397 | + assert authors == [ |
| 398 | + { |
| 399 | + "contribution": "0.0%", |
| 400 | + "contribution_all_pages": "0.0%", |
| 401 | + |
| 402 | + "last_datetime": None, |
| 403 | + "lines": 0, |
| 404 | + "lines_all_pages": 0, |
| 405 | + "name": "John" |
| 406 | + }, |
| 407 | + { |
| 408 | + "name": "Tim", |
| 409 | + |
| 410 | + "last_datetime": None, |
| 411 | + "lines": 2, |
| 412 | + "lines_all_pages": 2, |
| 413 | + "contribution": "100.0%", |
| 414 | + "contribution_all_pages": "100.0%", |
| 415 | + }, |
| 416 | + ] |
| 417 | + |
| 418 | + os.chdir(cwd) |
| 419 | + |
| 420 | + |
278 | 421 | def test_mkdocs_in_git_subdir(tmp_path):
|
279 | 422 | """
|
280 | 423 | Sometimes `mkdocs.yml` is not in the root of the repo.
|
|
0 commit comments