diff --git a/apiserver/dora/service/code/sync/etl_github_handler.py b/apiserver/dora/service/code/sync/etl_github_handler.py index aa0bf9809..b87584dc8 100644 --- a/apiserver/dora/service/code/sync/etl_github_handler.py +++ b/apiserver/dora/service/code/sync/etl_github_handler.py @@ -319,11 +319,12 @@ def _to_pr_commits( { 'sha': '123456789098765', - 'commit': {'author': {'name': 'abc', 'email': 'abc@midd.com', 'date': '2022-06-29T10:53:15Z'}, - 'committer': {'name': 'abc', 'email': 'abc@midd.com', 'date': '2022-06-29T10:53:15Z'}, - 'message': '[abc 315] avoid mapping edit state', - 'html_url': 'https://github.com/abc', - 'author': {'login': 'abc', 'id': 95607047, 'node_id': 'abc', 'avatar_url': ''}, + 'commit': { + 'author': {'name': 'abc', 'email': 'abc@midd.com', 'date': '2022-06-29T10:53:15Z'}, + 'committer': {'name': 'abc', 'email': 'abc@midd.com', 'date': '2022-06-29T10:53:15Z'}, + 'message': '[abc 315] avoid mapping edit state', + 'html_url': 'https://github.com/abc', + 'author': {'login': 'abc', 'id': 95607047, 'node_id': 'abc', 'avatar_url': ''}, } """ pr_commits: List[PullRequestCommit] = [] @@ -349,9 +350,8 @@ def _to_pr_commits( @staticmethod def _dt_from_github_dt_string(dt_string: str) -> datetime: - return datetime.strptime(dt_string, "%Y-%m-%dT%H:%M:%SZ").astimezone( - tz=pytz.UTC - ) + dt_without_timezone = datetime.strptime(dt_string, "%Y-%m-%dT%H:%M:%SZ") + return dt_without_timezone.replace(tzinfo=pytz.UTC) def get_github_etl_handler(org_id: str) -> GithubETLHandler: diff --git a/apiserver/tests/service/code/sync/test_etl_github_handler.py b/apiserver/tests/service/code/sync/test_etl_github_handler.py new file mode 100644 index 000000000..18c097cf5 --- /dev/null +++ b/apiserver/tests/service/code/sync/test_etl_github_handler.py @@ -0,0 +1,14 @@ +from datetime import datetime + +import pytz + +from dora.service.code.sync.etl_github_handler import GithubETLHandler +from dora.utils.string import uuid4_str + +ORG_ID = uuid4_str() + + +def test__dt_from_github_dt_string_given_date_string_returns_correct_datetime(): + date_string = "2024-04-18T10:53:15Z" + expected = datetime(2024, 4, 18, 10, 53, 15, tzinfo=pytz.UTC) + assert GithubETLHandler._dt_from_github_dt_string(date_string) == expected