From 8d0d6d0721f4e7e65f1426a95684f26a8d81dead Mon Sep 17 00:00:00 2001 From: Harrison Cook Date: Wed, 16 Oct 2024 21:36:29 +0100 Subject: [PATCH] Address linting issues --- Makefile | 2 +- contributors/contributor_stats.py | 4 +++- contributors/contributors.py | 6 ++---- contributors/env.py | 16 ++++++++-------- tests/test_auth.py | 1 - tests/test_contributor_stats.py | 6 +++++- tests/test_markdown.py | 24 ++++++++++++++++++++++-- 7 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 143a5ac..7aeae36 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ lint: isort --settings-file=.github/linters/.isort.cfg . pylint --rcfile=.github/linters/.python-lint --fail-under=9.0 contributors/*.py mypy --config-file=.github/linters/.mypy.ini contributors/*.py - black . + black . --line-length 120 diff --git a/contributors/contributor_stats.py b/contributors/contributor_stats.py index bf16b1c..7ed7bc6 100644 --- a/contributors/contributor_stats.py +++ b/contributors/contributor_stats.py @@ -59,7 +59,9 @@ def is_new_contributor(username: str, returning_contributors: list) -> bool: return True -def merge_contributors(contributors: list[list[ContributorStats]]) -> list[ContributorStats]: +def merge_contributors( + contributors: list[list[ContributorStats]], +) -> list[ContributorStats]: """ Merge contributors with the same username from multiple repositories. diff --git a/contributors/contributors.py b/contributors/contributors.py index a61ee52..d07d6bb 100644 --- a/contributors/contributors.py +++ b/contributors/contributors.py @@ -116,16 +116,14 @@ def get_all_contributors( all_contributors.append(repo_contributors) # Check for duplicates and merge when usernames are equal - all_contributors = contributor_stats.merge_contributors(all_contributors) - - return all_contributors + return contributor_stats.merge_contributors(all_contributors) def get_contributors( repo: github3.repos.Repository, start_date: str, end_date: str, -) -> list[contributor_stats.ContributorStats]: +) -> list[contributor_stats.ContributorStats] | None: """ Get contributors from a single repository and filter by start end dates if present. diff --git a/contributors/env.py b/contributors/env.py index 010d7d3..c5cbd18 100644 --- a/contributors/env.py +++ b/contributors/env.py @@ -75,8 +75,8 @@ class EnvironmentConfig: Environment Configuration """ - organization: str - repositories_list: list[str] + organization: str | None + repositories_list: list[str] | None gh_app_id: int | None gh_app_installation_id: int | None gh_app_private_key_bytes: bytes @@ -84,8 +84,8 @@ class EnvironmentConfig: ghe: str start_date: str end_date: str - sponsor_info: str - link_to_profile: str + sponsor_info: bool + link_to_profile: bool show_organisations_list: list[str] filename: str = "contributors" @@ -101,9 +101,9 @@ def get_env_vars( Returns: EnvironmentConfig: - organization, str: + organization, str | None: the organization to get contributor information for - repositories_list, List[str]: + repositories_list, List[str] | None: A list of the repositories to get contributor information for gh_app_id, int|None: the GitHub App ID to use for authentication @@ -119,9 +119,9 @@ def get_env_vars( the start date to get contributor information from end_date, str: the end date to get contributor information to. - sponsor_info, str: + sponsor_info, bool: whether to get sponsor information on the contributor - link_to_profile, str: + link_to_profile, bool: whether to link username to Github profile in markdown output show_organisations_list, list: Organisations to show in order of preference diff --git a/tests/test_auth.py b/tests/test_auth.py index 6ee813b..305024e 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -4,7 +4,6 @@ from unittest.mock import MagicMock, patch import github3.github - from contributors import auth diff --git a/tests/test_contributor_stats.py b/tests/test_contributor_stats.py index 43f3ee1..d43126f 100644 --- a/tests/test_contributor_stats.py +++ b/tests/test_contributor_stats.py @@ -2,7 +2,11 @@ import unittest -from contributors.contributor_stats import ContributorStats, is_new_contributor, merge_contributors +from contributors.contributor_stats import ( + ContributorStats, + is_new_contributor, + merge_contributors, +) class TestContributorStats(unittest.TestCase): diff --git a/tests/test_markdown.py b/tests/test_markdown.py index cb0e1c8..5070338 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -93,7 +93,17 @@ def test_write_to_markdown_with_sponsors(self, mock_file): person2, ] - write_to_markdown(collaborators, "filename", "2023-01-01", "2023-01-02", None, "org/repo", "true", "true", []) + write_to_markdown( + collaborators, + "filename", + "2023-01-01", + "2023-01-02", + None, + "org/repo", + "true", + "true", + [], + ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") mock_file().write.assert_any_call("# Contributors\n\n") @@ -136,7 +146,17 @@ def test_write_to_markdown_without_link_to_profile(self, mock_file): person2, ] - write_to_markdown(collaborators, "filename", "2023-01-01", "2023-01-02", None, "org/repo", "false", "false", []) + write_to_markdown( + collaborators, + "filename", + "2023-01-01", + "2023-01-02", + None, + "org/repo", + "false", + "false", + [], + ) mock_file.assert_called_once_with("filename", "w", encoding="utf-8") mock_file().write.assert_any_call("# Contributors\n\n")