2021-12-01 14:23:51 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-09-14 14:00:46 +00:00
|
|
|
from typing import Optional
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2022-09-14 14:00:46 +00:00
|
|
|
from commit_status_helper import get_commit, get_commit_filtered_statuses
|
2022-07-21 16:12:07 +00:00
|
|
|
from github import Github
|
|
|
|
from github.CommitStatus import CommitStatus
|
|
|
|
from pr_info import PRInfo
|
2021-12-01 14:23:51 +00:00
|
|
|
|
|
|
|
|
2022-09-14 14:00:46 +00:00
|
|
|
# TODO: move it to commit_status_helper
|
2021-12-01 14:23:51 +00:00
|
|
|
class RerunHelper:
|
2022-07-21 16:12:07 +00:00
|
|
|
def __init__(self, gh: Github, pr_info: PRInfo, check_name: str):
|
2021-12-01 14:23:51 +00:00
|
|
|
self.gh = gh
|
|
|
|
self.pr_info = pr_info
|
|
|
|
self.check_name = check_name
|
2022-07-21 16:12:07 +00:00
|
|
|
commit = get_commit(gh, self.pr_info.sha)
|
|
|
|
if commit is None:
|
|
|
|
raise ValueError(f"unable to receive commit for {pr_info.sha}")
|
|
|
|
self.pygh_commit = commit
|
2022-09-14 14:00:46 +00:00
|
|
|
self.statuses = get_commit_filtered_statuses(commit)
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2022-07-21 16:12:07 +00:00
|
|
|
def is_already_finished_by_status(self) -> bool:
|
2021-12-01 14:23:51 +00:00
|
|
|
# currently we agree even for failed statuses
|
|
|
|
for status in self.statuses:
|
2022-03-22 16:39:58 +00:00
|
|
|
if self.check_name in status.context and status.state in (
|
|
|
|
"success",
|
|
|
|
"failure",
|
|
|
|
):
|
2021-12-01 14:23:51 +00:00
|
|
|
return True
|
|
|
|
return False
|
2022-07-18 00:22:32 +00:00
|
|
|
|
2022-07-21 16:12:07 +00:00
|
|
|
def get_finished_status(self) -> Optional[CommitStatus]:
|
2022-07-18 00:22:32 +00:00
|
|
|
for status in self.statuses:
|
|
|
|
if self.check_name in status.context:
|
|
|
|
return status
|
|
|
|
return None
|