2021-09-29 07:47:15 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import logging
|
2021-10-27 07:03:23 +00:00
|
|
|
from github import Github
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2022-03-24 14:37:53 +00:00
|
|
|
from env_helper import GITHUB_RUN_URL
|
2021-11-26 14:00:09 +00:00
|
|
|
from pr_info import PRInfo
|
2021-10-20 10:31:48 +00:00
|
|
|
from get_robot_token import get_best_robot_token
|
2021-11-12 12:36:25 +00:00
|
|
|
from commit_status_helper import get_commit
|
2021-09-29 07:47:15 +00:00
|
|
|
|
2022-07-21 11:10:22 +00:00
|
|
|
NAME = "Run Check"
|
2021-09-29 07:47:15 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2021-09-29 07:47:15 +00:00
|
|
|
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
|
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2021-09-29 07:47:15 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
pr_info = PRInfo(need_orgs=True)
|
2022-07-30 05:07:22 +00:00
|
|
|
gh = Github(get_best_robot_token(), per_page=100)
|
2021-09-29 07:47:15 +00:00
|
|
|
commit = get_commit(gh, pr_info.sha)
|
|
|
|
|
2022-03-24 14:37:53 +00:00
|
|
|
url = GITHUB_RUN_URL
|
2021-09-29 07:47:15 +00:00
|
|
|
statuses = filter_statuses(list(commit.get_statuses()))
|
|
|
|
if NAME in statuses and statuses[NAME].state == "pending":
|
2022-03-22 16:39:58 +00:00
|
|
|
commit.create_status(
|
|
|
|
context=NAME,
|
|
|
|
description="All checks finished",
|
|
|
|
state="success",
|
|
|
|
target_url=url,
|
|
|
|
)
|