mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Reuse code, do not update Mergeable Check unnecessary
This commit is contained in:
parent
0ab9d6787e
commit
067e656ff3
@ -3,7 +3,7 @@
|
||||
import csv
|
||||
import os
|
||||
import time
|
||||
from typing import List
|
||||
from typing import List, Literal
|
||||
import logging
|
||||
|
||||
from ci_config import CI_CONFIG, REQUIRED_CHECKS
|
||||
@ -15,6 +15,7 @@ from pr_info import PRInfo, SKIP_MERGEABLE_CHECK_LABEL
|
||||
|
||||
RETRY = 5
|
||||
CommitStatuses = List[CommitStatus]
|
||||
MERGEABLE_NAME = "Mergeable Check"
|
||||
|
||||
|
||||
def override_status(status: str, check_name: str, invert: bool = False) -> str:
|
||||
@ -102,26 +103,21 @@ def post_labels(gh: Github, pr_info: PRInfo, labels_names: List[str]) -> None:
|
||||
pull_request.add_to_labels(label)
|
||||
|
||||
|
||||
def fail_mergeable_check(commit: Commit, description: str) -> None:
|
||||
commit.create_status(
|
||||
context="Mergeable Check",
|
||||
description=description,
|
||||
state="failure",
|
||||
target_url=GITHUB_RUN_URL,
|
||||
)
|
||||
|
||||
|
||||
def format_description(description: str) -> str:
|
||||
if len(description) > 140:
|
||||
description = description[:137] + "..."
|
||||
return description
|
||||
|
||||
|
||||
def reset_mergeable_check(commit: Commit, description: str = "") -> None:
|
||||
def set_mergeable_check(
|
||||
commit: Commit,
|
||||
description: str = "",
|
||||
state: Literal["success", "failure"] = "success",
|
||||
) -> None:
|
||||
commit.create_status(
|
||||
context="Mergeable Check",
|
||||
context=MERGEABLE_NAME,
|
||||
description=description,
|
||||
state="success",
|
||||
state=state,
|
||||
target_url=GITHUB_RUN_URL,
|
||||
)
|
||||
|
||||
@ -133,32 +129,39 @@ def update_mergeable_check(gh: Github, pr_info: PRInfo, check_name: str) -> None
|
||||
logging.info("Update Mergeable Check by %s", check_name)
|
||||
|
||||
commit = get_commit(gh, pr_info.sha)
|
||||
checks = {
|
||||
check.context: check.state
|
||||
for check in filter(
|
||||
lambda check: (check.context in REQUIRED_CHECKS),
|
||||
# get_statuses() returns generator, which cannot be reversed - we need comprehension
|
||||
# pylint: disable=unnecessary-comprehension
|
||||
reversed([status for status in commit.get_statuses()]),
|
||||
)
|
||||
}
|
||||
statuses = get_commit_filtered_statuses(commit)
|
||||
|
||||
required_checks = [
|
||||
status for status in statuses if status.context in REQUIRED_CHECKS
|
||||
]
|
||||
|
||||
mergeable_status = None
|
||||
for status in statuses:
|
||||
if status.context == MERGEABLE_NAME:
|
||||
mergeable_status = status
|
||||
break
|
||||
|
||||
success = []
|
||||
fail = []
|
||||
for name, state in checks.items():
|
||||
if state == "success":
|
||||
success.append(name)
|
||||
for status in required_checks:
|
||||
if status.state == "success":
|
||||
success.append(status.context)
|
||||
else:
|
||||
fail.append(name)
|
||||
fail.append(status.context)
|
||||
|
||||
if fail:
|
||||
description = "failed: " + ", ".join(fail)
|
||||
if success:
|
||||
description += "; succeeded: " + ", ".join(success)
|
||||
description = format_description(description)
|
||||
fail_mergeable_check(commit, description)
|
||||
if mergeable_status is not None and mergeable_status.description == description:
|
||||
return
|
||||
set_mergeable_check(commit, description, "failure")
|
||||
return
|
||||
|
||||
description = ", ".join(success)
|
||||
description = format_description(description)
|
||||
reset_mergeable_check(commit, description)
|
||||
if mergeable_status is not None and mergeable_status.description == description:
|
||||
return
|
||||
|
||||
set_mergeable_check(commit, description)
|
||||
|
@ -11,7 +11,7 @@ from commit_status_helper import (
|
||||
get_commit,
|
||||
post_labels,
|
||||
remove_labels,
|
||||
reset_mergeable_check,
|
||||
set_mergeable_check,
|
||||
)
|
||||
from env_helper import GITHUB_RUN_URL, GITHUB_REPOSITORY, GITHUB_SERVER_URL
|
||||
from get_robot_token import get_best_robot_token
|
||||
@ -232,7 +232,7 @@ if __name__ == "__main__":
|
||||
if pr_labels_to_remove:
|
||||
remove_labels(gh, pr_info, pr_labels_to_remove)
|
||||
|
||||
reset_mergeable_check(commit, "skipped")
|
||||
set_mergeable_check(commit, "skipped")
|
||||
|
||||
if description_error:
|
||||
print(
|
||||
|
Loading…
Reference in New Issue
Block a user