Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/linters/.isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[settings]
profile = black
known_first_party = auth,contributor_stats,contributors,env,json_writer,markdown
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions contributor_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# ]


from typing import List

import requests


Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions contributors.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 5 additions & 3 deletions test_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading