2021-09-29 07:47:15 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import logging
|
2024-04-25 11:28:06 +00:00
|
|
|
import sys
|
2024-02-06 12:39:34 +00:00
|
|
|
|
2021-10-27 07:03:23 +00:00
|
|
|
from github import Github
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2024-04-17 13:11:42 +00:00
|
|
|
from ci_config import StatusNames
|
2023-04-06 09:40:32 +00:00
|
|
|
from commit_status_helper import (
|
|
|
|
get_commit,
|
|
|
|
get_commit_filtered_statuses,
|
|
|
|
post_commit_status,
|
2024-04-25 11:28:06 +00:00
|
|
|
set_mergeable_check,
|
2024-03-06 11:45:59 +00:00
|
|
|
trigger_mergeable_check,
|
2023-04-06 09:40:32 +00:00
|
|
|
)
|
2023-04-20 11:55:33 +00:00
|
|
|
from get_robot_token import get_best_robot_token
|
|
|
|
from pr_info import PRInfo
|
2024-02-06 12:39:34 +00:00
|
|
|
from report import PENDING, SUCCESS
|
2021-09-29 07:47:15 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2023-04-20 11:55:33 +00:00
|
|
|
def main():
|
2021-09-29 07:47:15 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2024-04-25 11:28:06 +00:00
|
|
|
has_failure = False
|
|
|
|
|
|
|
|
# FIXME: temporary hack to fail Mergeable Check in MQ if pipeline has any failed jobs
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "--pipeline-failure":
|
|
|
|
has_failure = True
|
|
|
|
|
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)
|
2024-04-25 11:28:06 +00:00
|
|
|
statuses = None
|
|
|
|
|
|
|
|
if pr_info.is_merge_queue:
|
|
|
|
# in MQ Mergeable check status must never be green if any failures in workflow
|
|
|
|
if has_failure:
|
|
|
|
set_mergeable_check(commit, "workflow failed", "failure")
|
|
|
|
else:
|
2024-04-25 15:05:02 +00:00
|
|
|
# This must be the only place where green MCheck is set in the MQ (in the end of CI) to avoid early merge
|
2024-04-25 11:28:06 +00:00
|
|
|
set_mergeable_check(commit, "workflow passed", "success")
|
|
|
|
else:
|
|
|
|
statuses = get_commit_filtered_statuses(commit)
|
|
|
|
trigger_mergeable_check(commit, statuses)
|
2024-03-06 11:45:59 +00:00
|
|
|
|
2024-04-17 13:11:42 +00:00
|
|
|
statuses = [s for s in statuses if s.context == StatusNames.CI]
|
2024-04-11 11:58:44 +00:00
|
|
|
if not statuses:
|
|
|
|
return
|
|
|
|
# Take the latest status
|
|
|
|
status = statuses[-1]
|
|
|
|
if status.state == PENDING:
|
|
|
|
post_commit_status(
|
|
|
|
commit,
|
|
|
|
SUCCESS,
|
|
|
|
status.target_url,
|
|
|
|
"All checks finished",
|
2024-04-17 13:11:42 +00:00
|
|
|
StatusNames.CI,
|
2024-04-11 11:58:44 +00:00
|
|
|
pr_info,
|
|
|
|
dump_to_file=True,
|
|
|
|
)
|
2023-04-20 11:55:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|