ClickHouse/tests/ci/rerun_helper.py

37 lines
1.2 KiB
Python
Raw Normal View History

2021-12-01 14:23:51 +00:00
#!/usr/bin/env python3
from typing import Optional
2021-12-01 14:23:51 +00:00
from commit_status_helper import get_commit, get_commit_filtered_statuses
from github import Github
from github.CommitStatus import CommitStatus
from pr_info import PRInfo
2021-12-01 14:23:51 +00:00
# TODO: move it to commit_status_helper
2021-12-01 14:23:51 +00:00
class RerunHelper:
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
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
self.statuses = get_commit_filtered_statuses(commit)
2021-12-01 14:23:51 +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:
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
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