From 788f8db97467ef7198345648c34382dc41f505d2 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Wed, 5 Mar 2025 09:29:03 +0100 Subject: [PATCH] fixed the extraction of the date, because on the server, datetime.fromisoformat couldn't be parsed for some reason --- pull_requests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pull_requests.py b/pull_requests.py index 6364ee0..e200485 100644 --- a/pull_requests.py +++ b/pull_requests.py @@ -18,8 +18,11 @@ def get_commits(repo_url: str, pr_number: str) -> list[dict]: response = github_call(f'{repo_url}/pulls/{pr_number}/commits') return response.json() +def extract_date(date: str) -> datetime: + return datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ") + def get_first_comment_date(comments: list[dict]) -> datetime: - return min([datetime.fromisoformat(comment['created_at']) for comment in comments]) + return min([extract_date(comment['created_at']) for comment in comments]) def get_useful_commits(commits: list[dict], first_comment_date: datetime) -> list[dict]: ret = [] @@ -28,7 +31,7 @@ def get_useful_commits(commits: list[dict], first_comment_date: datetime) -> lis and "author" not in commit["author"] and "date" not in commit['commit']['author']): continue - commit_date = datetime.fromisoformat(commit['commit']['author']['date']) + commit_date = extract_date(commit['commit']['author']['date']) if commit_date > first_comment_date: ret.append(commit) return ret @@ -56,7 +59,8 @@ def process_pull_request(repo_url: str, pr_number: str) -> bool: and "author" not in commit["author"] and "date" not in commit['commit']['author']): continue - commit_date = datetime.fromisoformat(commit['commit']['author']['date']) + commit_date = extract_date(commit['commit']['author']['date']) + if commit_date > first_comment_date: actual_commits.append(commit)