From 14ce1437e7a420a1541ee5e009b0f73faa8adf88 Mon Sep 17 00:00:00 2001 From: amoghjalan Date: Thu, 18 Apr 2024 17:49:57 +0530 Subject: [PATCH] Fix gh datetime in GitHub actions sync --- apiserver/dora/service/code/sync/etl_github_handler.py | 4 ++-- .../service/workflows/sync/etl_github_actions_handler.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apiserver/dora/service/code/sync/etl_github_handler.py b/apiserver/dora/service/code/sync/etl_github_handler.py index a039fa108..b8f0bceb0 100644 --- a/apiserver/dora/service/code/sync/etl_github_handler.py +++ b/apiserver/dora/service/code/sync/etl_github_handler.py @@ -29,7 +29,7 @@ ) from dora.store.repos.code import CodeRepoService from dora.store.repos.core import CoreRepoService -from dora.utils.time import time_now +from dora.utils.time import time_now, ISO_8601_DATE_FORMAT PR_PROCESSING_CHUNK_SIZE = 100 @@ -349,7 +349,7 @@ def _to_pr_commits( @staticmethod def _dt_from_github_dt_string(dt_string: str) -> datetime: - dt_without_timezone = datetime.strptime(dt_string, "%Y-%m-%dT%H:%M:%SZ") + dt_without_timezone = datetime.strptime(dt_string, ISO_8601_DATE_FORMAT) return dt_without_timezone.replace(tzinfo=pytz.UTC) diff --git a/apiserver/dora/service/workflows/sync/etl_github_actions_handler.py b/apiserver/dora/service/workflows/sync/etl_github_actions_handler.py index bd27e10c3..2ce3bd431 100644 --- a/apiserver/dora/service/workflows/sync/etl_github_actions_handler.py +++ b/apiserver/dora/service/workflows/sync/etl_github_actions_handler.py @@ -168,9 +168,8 @@ def _get_repo_workflow_run_duration( @staticmethod def _get_datetime_from_gh_datetime(datetime_str: str) -> datetime: - return datetime.strptime(datetime_str, ISO_8601_DATE_FORMAT).astimezone( - tz=pytz.UTC - ) + dt_without_timezone = datetime.strptime(datetime_str, ISO_8601_DATE_FORMAT) + return dt_without_timezone.replace(tzinfo=pytz.UTC) def get_github_actions_etl_handler(org_id):