mirror of
https://github.com/karma-riuk/crab.git
synced 2025-07-05 05:28:13 +02:00
updated the type annotations for the utils
functions, much better now
This commit is contained in:
59
utils.py
59
utils.py
@ -1,35 +1,22 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from github.Commit import Commit
|
||||||
|
from github.PaginatedList import PaginatedList
|
||||||
|
from github.PullRequestComment import PullRequestComment
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def parse_date(date: str) -> datetime:
|
def parse_date(date: str) -> datetime:
|
||||||
return datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
return datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
def has_only_1_round_of_comments(commits, comments):
|
def has_only_1_round_of_comments(commits: PaginatedList[Commit], comments: PaginatedList[PullRequestComment]):
|
||||||
if not comments or not commits:
|
if (
|
||||||
|
comments is None or commits is None
|
||||||
|
or comments.totalCount == 0 or commits.totalCount == 0
|
||||||
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
commit_dates = []
|
commit_dates = [commit.commit.author.date for commit in tqdm(commits, total=commits.totalCount, desc="Extracting date from commits", leave=False)]
|
||||||
for commit in commits:
|
comment_dates = [comment.created_at for comment in tqdm(comments, total=comments.totalCount, desc="Extracting date from comments", leave=False)]
|
||||||
if isinstance(commit.commit.author.date, str):
|
|
||||||
commit_dates.append(parse_date(commit.commit.author.date))
|
|
||||||
elif isinstance(commit.commit.author.date, datetime):
|
|
||||||
commit_dates.append(commit.commit.author.date)
|
|
||||||
else:
|
|
||||||
logging.warning(f"The commit {commit.sha} has an unexpected date format: {commit.commit.author.date}")
|
|
||||||
logging.warning(f"Tied to PR: {comments[0]['pull_request_url']}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
comment_dates = []
|
|
||||||
for comment in comments:
|
|
||||||
if isinstance(comment.created_at, str):
|
|
||||||
comment_dates.append(parse_date(comment.created_at))
|
|
||||||
elif isinstance(comment.created_at, datetime):
|
|
||||||
comment_dates.append(comment.created_at)
|
|
||||||
else:
|
|
||||||
logging.warning(f"The comment {comment['id']} has an unexpected date format: {comment['created_at']}")
|
|
||||||
logging.warning(f"Tied to PR: {comment['pull_request_url']}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
commit_dates.sort()
|
commit_dates.sort()
|
||||||
comment_dates.sort()
|
comment_dates.sort()
|
||||||
@ -51,29 +38,17 @@ def has_only_1_round_of_comments(commits, comments):
|
|||||||
|
|
||||||
return n_before >= 1 and n_after >= 1
|
return n_before >= 1 and n_after >= 1
|
||||||
|
|
||||||
def has_only_1_comment(commits, comments):
|
def has_only_1_comment(commits: PaginatedList[Commit], comments: PaginatedList[PullRequestComment]):
|
||||||
if not comments or not commits:
|
if (
|
||||||
|
comments is None or commits is None
|
||||||
|
or comments.totalCount == 0 or commits.totalCount == 0
|
||||||
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
commit_dates = []
|
commit_dates = [commit.commit.author.date for commit in tqdm(commits, total=commits.totalCount, desc="Extracting date from commits", leave=False)]
|
||||||
for commit in commits:
|
|
||||||
if isinstance(commit.commit.author.date, str):
|
|
||||||
commit_dates.append(parse_date(commit.commit.author.date))
|
|
||||||
elif isinstance(commit.commit.author.date, datetime):
|
|
||||||
commit_dates.append(commit.commit.author.date)
|
|
||||||
else:
|
|
||||||
logging.warning(f"The commit {commit.sha} has an unexpected date format: {commit.commit.author.date}")
|
|
||||||
logging.warning(f"Tied to PR: {comments[0]['pull_request_url']}")
|
|
||||||
return False
|
|
||||||
commit_dates.sort()
|
commit_dates.sort()
|
||||||
|
|
||||||
if isinstance(comments[0].created_at, datetime):
|
comment_date = comments[0].created_at
|
||||||
comment_date = comments[0].created_at
|
|
||||||
elif isinstance(comments[0].created_at, str):
|
|
||||||
comment_date = parse_date(comments[0].created_at)
|
|
||||||
else:
|
|
||||||
logging.warning(f"The comment {comments[0]['id']} has an unexpected date format: {comments[0]['created_at']}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
n_before = n_after = 0
|
n_before = n_after = 0
|
||||||
for commit_date in tqdm(commit_dates, desc="Checking for 1 comment", leave=False):
|
for commit_date in tqdm(commit_dates, desc="Checking for 1 comment", leave=False):
|
||||||
|
Reference in New Issue
Block a user