mirror of
https://github.com/karma-riuk/crab.git
synced 2025-07-05 05:28:13 +02:00
made stats for PRs better, because i was not
considering all edge cases
This commit is contained in:
@ -7,12 +7,15 @@ from github import Github
|
|||||||
# Initialize GitHub API client
|
# Initialize GitHub API client
|
||||||
g = Github(os.environ["GITHUB_AUTH_TOKEN_CRAB"])
|
g = Github(os.environ["GITHUB_AUTH_TOKEN_CRAB"])
|
||||||
|
|
||||||
|
def parse_date(date: str) -> datetime:
|
||||||
|
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, comments):
|
||||||
if not comments or not commits:
|
if not comments or not commits:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
commit_dates = [c.commit.author.date for c in commits]
|
commit_dates = [parse_date(c.commit.author.date) for c in commits]
|
||||||
comment_dates = [c.created_at for c in comments]
|
comment_dates = [parse_date(c.created_at) for c in comments]
|
||||||
|
|
||||||
commit_dates.sort()
|
commit_dates.sort()
|
||||||
comment_dates.sort()
|
comment_dates.sort()
|
||||||
@ -20,11 +23,19 @@ def has_only_1_round_of_comments(commits, comments):
|
|||||||
first_comment_time = comment_dates[0]
|
first_comment_time = comment_dates[0]
|
||||||
last_comment_time = comment_dates[-1]
|
last_comment_time = comment_dates[-1]
|
||||||
|
|
||||||
|
n_before = n_after = 0
|
||||||
for commit_time in commit_dates:
|
for commit_time in commit_dates:
|
||||||
|
if commit_time < first_comment_time:
|
||||||
|
n_before += 1
|
||||||
|
continue
|
||||||
|
if commit_time > last_comment_time:
|
||||||
|
n_after += 1
|
||||||
|
continue
|
||||||
|
|
||||||
if first_comment_time < commit_time < last_comment_time:
|
if first_comment_time < commit_time < last_comment_time:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return n_before >= 1 and n_after >= 1
|
||||||
|
|
||||||
def process_pull(repo, pull):
|
def process_pull(repo, pull):
|
||||||
commits = list(pull.get_commits())
|
commits = list(pull.get_commits())
|
||||||
|
Reference in New Issue
Block a user