diff --git a/.github/linters/.isort.cfg b/.github/linters/.isort.cfg index f238bf7..1d877d0 100644 --- a/.github/linters/.isort.cfg +++ b/.github/linters/.isort.cfg @@ -1,2 +1,3 @@ [settings] profile = black +known_first_party = auth,contributor_stats,contributors,env,json_writer,markdown diff --git a/.github/workflows/super-linter.yaml b/.github/workflows/super-linter.yaml index e556867..06b030d 100644 --- a/.github/workflows/super-linter.yaml +++ b/.github/workflows/super-linter.yaml @@ -39,7 +39,7 @@ jobs: - name: Install dependencies run: uv sync --frozen - name: Lint Code Base - uses: super-linter/super-linter@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0 + uses: super-linter/super-linter@2da136927bd4a73596db63044b504547c62cb854 # v9.0.0 env: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 5200cce..5195c31 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN uv sync --frozen --no-dev --no-editable \ # Add a simple healthcheck to satisfy container scanners HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ - CMD python3 -c "import os,sys; sys.exit(0 if os.path.exists('/action/workspace/contributors.py') else 1)" + CMD ["python3", "-c", "import os,sys; sys.exit(0 if os.path.exists('/action/workspace/contributors.py') else 1)"] ENV PYTHONUNBUFFERED=1 ENV UV_LINK_MODE=copy diff --git a/contributor_stats.py b/contributor_stats.py index e7ae283..65d1617 100644 --- a/contributor_stats.py +++ b/contributor_stats.py @@ -12,8 +12,6 @@ # ] -from typing import List - import requests @@ -101,7 +99,7 @@ def merge_contributors(contributors: list) -> list: Returns: merged_contributors (list): A list of ContributorStats objects with no duplicate usernames """ - merged_contributors: List[ContributorStats] = [] + merged_contributors: list[ContributorStats] = [] for contributor_list in contributors: for contributor in contributor_list: # if the contributor is already in the merged list, merge their relevant attributes diff --git a/contributors.py b/contributors.py index c71683c..ad790bb 100644 --- a/contributors.py +++ b/contributors.py @@ -1,8 +1,7 @@ # pylint: disable=broad-exception-caught """This file contains the main() and other functions needed to get contributor information from the organization or repository""" -from datetime import datetime -from typing import List +from datetime import datetime, timezone import auth import contributor_stats @@ -102,7 +101,7 @@ def main(): def get_all_contributors( organization: str, - repository_list: List[str], + repository_list: list[str], start_date: str, end_date: str, github_connection: object, @@ -166,8 +165,8 @@ def get_contributors(repo: object, start_date: str, end_date: str, ghe: str): avatars: dict[str, str] = {} counts: dict[str, int] = {} for commit in repo.get_commits( - since=datetime.fromisoformat(start_date), - until=datetime.fromisoformat(end_date), + since=datetime.fromisoformat(start_date).replace(tzinfo=timezone.utc), + until=datetime.fromisoformat(end_date).replace(tzinfo=timezone.utc), ): login = getattr(commit.author, "login", None) if not login or "[bot]" in login: @@ -201,7 +200,7 @@ def get_contributors(repo: object, start_date: str, end_date: str, ghe: str): "", ) contributors.append(contributor) - except Exception as e: + except Exception as e: # noqa: BLE001 print(f"Error getting contributors for repository: {repo.full_name}") print(e) return None diff --git a/env.py b/env.py index 8b7bf6c..a36c631 100644 --- a/env.py +++ b/env.py @@ -63,7 +63,9 @@ def validate_date_format(env_var_name: str) -> str: pattern = "%Y-%m-%d" try: - datetime.datetime.strptime(date_to_validate, pattern) + datetime.datetime.strptime(date_to_validate, pattern).replace( + tzinfo=datetime.timezone.utc + ) except ValueError as exc: raise ValueError( f"{env_var_name} environment variable not in the format YYYY-MM-DD" @@ -88,8 +90,16 @@ def validate_date_range(start_date: str, end_date: str) -> None: pattern = "%Y-%m-%d" try: - start = datetime.datetime.strptime(start_date, pattern).date() - end = datetime.datetime.strptime(end_date, pattern).date() + start = ( + datetime.datetime.strptime(start_date, pattern) + .replace(tzinfo=datetime.timezone.utc) + .date() + ) + end = ( + datetime.datetime.strptime(end_date, pattern) + .replace(tzinfo=datetime.timezone.utc) + .date() + ) except ValueError as exc: raise ValueError( "start_date and end_date must be in the format YYYY-MM-DD" diff --git a/markdown.py b/markdown.py index 08b9250..a40b276 100644 --- a/markdown.py +++ b/markdown.py @@ -187,12 +187,10 @@ def get_summary_table(collaborators, start_date, end_date, total_contributions): ) else: new_contributors_percentage = 0 - summary_table += f"| {str(len(collaborators))} | {str(total_contributions)} | {str(new_contributors_percentage)}% |\n\n" + summary_table += f"| {len(collaborators)!s} | {total_contributions!s} | {new_contributors_percentage!s}% |\n\n" else: summary_table = "| Total Contributors | Total Contributions |\n| --- | --- |\n" - summary_table += ( - f"| {str(len(collaborators))} | {str(total_contributions)} |\n\n" - ) + summary_table += f"| {len(collaborators)!s} | {total_contributions!s} |\n\n" return summary_table diff --git a/test_auth.py b/test_auth.py index 9b907a6..3c8102e 100644 --- a/test_auth.py +++ b/test_auth.py @@ -3,10 +3,11 @@ import unittest from unittest.mock import MagicMock, patch -import auth import requests from github import GithubException +import auth + class TestAuth(unittest.TestCase): """ diff --git a/test_contributors.py b/test_contributors.py index f15fd3f..a865344 100644 --- a/test_contributors.py +++ b/test_contributors.py @@ -2,7 +2,7 @@ import runpy import unittest -from datetime import datetime +from datetime import datetime, timezone from unittest.mock import MagicMock, patch import contributors as contributors_module @@ -34,7 +34,8 @@ def test_get_contributors(self, mock_contributor_stats): self.assertEqual(len(result), 1) mock_repo.get_commits.assert_called_once_with( - since=datetime(2022, 1, 1), until=datetime(2022, 12, 31) + since=datetime(2022, 1, 1, tzinfo=timezone.utc), + until=datetime(2022, 12, 31, tzinfo=timezone.utc), ) mock_contributor_stats.assert_called_once_with( "user", @@ -144,7 +145,8 @@ def test_get_contributors_with_single_commit(self, mock_contributor_stats): self.assertEqual(len(result), 1) mock_repo.get_commits.assert_called_once_with( - since=datetime(2022, 1, 1), until=datetime(2022, 12, 31) + since=datetime(2022, 1, 1, tzinfo=timezone.utc), + until=datetime(2022, 12, 31, tzinfo=timezone.utc), ) mock_contributor_stats.assert_called_once_with( "user",