mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Add typing to rerun and commit_status helpers
This commit is contained in:
parent
142f7d4b44
commit
db0653758e
@ -1,10 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import time
|
||||
import os
|
||||
import csv
|
||||
from env_helper import GITHUB_REPOSITORY, GITHUB_RUN_URL
|
||||
import os
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from ci_config import CI_CONFIG
|
||||
from env_helper import GITHUB_REPOSITORY, GITHUB_RUN_URL
|
||||
from github import Github
|
||||
from github.Commit import Commit
|
||||
from pr_info import SKIP_SIMPLE_CHECK_LABEL
|
||||
|
||||
RETRY = 5
|
||||
@ -22,7 +26,9 @@ def override_status(status, check_name, invert=False):
|
||||
return status
|
||||
|
||||
|
||||
def get_commit(gh, commit_sha, retry_count=RETRY):
|
||||
def get_commit(
|
||||
gh: Github, commit_sha: str, retry_count: int = RETRY
|
||||
) -> Optional[Commit]:
|
||||
for i in range(retry_count):
|
||||
try:
|
||||
repo = gh.get_repo(GITHUB_REPOSITORY)
|
||||
|
@ -1,33 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
from typing import List, Optional
|
||||
|
||||
from commit_status_helper import get_commit
|
||||
from github import Github
|
||||
from github.CommitStatus import CommitStatus
|
||||
from pr_info import PRInfo
|
||||
|
||||
|
||||
def _filter_statuses(statuses):
|
||||
"""
|
||||
Squash statuses to latest state
|
||||
1. context="first", state="success", update_time=1
|
||||
2. context="second", state="success", update_time=2
|
||||
3. context="first", stat="failure", update_time=3
|
||||
=========>
|
||||
1. context="second", state="success"
|
||||
2. context="first", stat="failure"
|
||||
"""
|
||||
filt = {}
|
||||
for status in sorted(statuses, key=lambda x: x.updated_at):
|
||||
filt[status.context] = status
|
||||
return filt.values()
|
||||
CommitStatuses = List[CommitStatus]
|
||||
|
||||
|
||||
class RerunHelper:
|
||||
def __init__(self, gh, pr_info, check_name):
|
||||
def __init__(self, gh: Github, pr_info: PRInfo, check_name: str):
|
||||
self.gh = gh
|
||||
self.pr_info = pr_info
|
||||
self.check_name = check_name
|
||||
self.pygh_commit = get_commit(gh, self.pr_info.sha)
|
||||
self.statuses = _filter_statuses(self.pygh_commit.get_statuses())
|
||||
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 = self.ger_filtered_statuses()
|
||||
|
||||
def is_already_finished_by_status(self):
|
||||
def is_already_finished_by_status(self) -> bool:
|
||||
# currently we agree even for failed statuses
|
||||
for status in self.statuses:
|
||||
if self.check_name in status.context and status.state in (
|
||||
@ -37,8 +30,25 @@ class RerunHelper:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_finished_status(self):
|
||||
def get_finished_status(self) -> Optional[CommitStatus]:
|
||||
for status in self.statuses:
|
||||
if self.check_name in status.context:
|
||||
return status
|
||||
return None
|
||||
|
||||
def ger_filtered_statuses(self) -> CommitStatuses:
|
||||
"""
|
||||
Squash statuses to latest state
|
||||
1. context="first", state="success", update_time=1
|
||||
2. context="second", state="success", update_time=2
|
||||
3. context="first", stat="failure", update_time=3
|
||||
=========>
|
||||
1. context="second", state="success"
|
||||
2. context="first", stat="failure"
|
||||
"""
|
||||
filt = {}
|
||||
for status in sorted(
|
||||
self.pygh_commit.get_statuses(), key=lambda x: x.updated_at
|
||||
):
|
||||
filt[status.context] = status
|
||||
return list(filt.values())
|
||||
|
Loading…
Reference in New Issue
Block a user