Merge pull request #46781 from ClickHouse/lazy-mergeable

Reduce updates of Mergeable Check
This commit is contained in:
Alexey Milovidov 2023-02-27 09:14:33 +03:00 committed by GitHub
commit 3f55782d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 51 deletions

View File

@ -9,7 +9,7 @@ from github import Github
from build_download_helper import get_build_name_for_check, read_build_urls from build_download_helper import get_build_name_for_check, read_build_urls
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status from commit_status_helper import format_description, post_commit_status
from docker_pull_helper import get_image_with_version from docker_pull_helper import get_image_with_version
from env_helper import ( from env_helper import (
GITHUB_REPOSITORY, GITHUB_REPOSITORY,
@ -145,11 +145,13 @@ if __name__ == "__main__":
with open( with open(
os.path.join(workspace_path, "description.txt"), "r", encoding="utf-8" os.path.join(workspace_path, "description.txt"), "r", encoding="utf-8"
) as desc_f: ) as desc_f:
description = desc_f.readline().rstrip("\n")[:140] description = desc_f.readline().rstrip("\n")
except: except:
status = "failure" status = "failure"
description = "Task failed: $?=" + str(retcode) description = "Task failed: $?=" + str(retcode)
description = format_description(description)
test_result = TestResult(description, "OK") test_result = TestResult(description, "OK")
if "fail" in status: if "fail" in status:
test_result.status = "FAIL" test_result.status = "FAIL"

View File

@ -3,7 +3,7 @@
import csv import csv
import os import os
import time import time
from typing import List from typing import List, Literal
import logging import logging
from github import Github from github import Github
@ -16,6 +16,7 @@ from pr_info import PRInfo, SKIP_MERGEABLE_CHECK_LABEL
RETRY = 5 RETRY = 5
CommitStatuses = List[CommitStatus] CommitStatuses = List[CommitStatus]
MERGEABLE_NAME = "Mergeable Check"
def override_status(status: str, check_name: str, invert: bool = False) -> str: def override_status(status: str, check_name: str, invert: bool = False) -> str:
@ -103,59 +104,69 @@ def post_labels(gh: Github, pr_info: PRInfo, labels_names: List[str]) -> None:
pull_request.add_to_labels(label) pull_request.add_to_labels(label)
def fail_mergeable_check(commit: Commit, description: str) -> None: def format_description(description: str) -> str:
commit.create_status( if len(description) > 140:
context="Mergeable Check", description = description[:137] + "..."
description=description, return description
state="failure",
target_url=GITHUB_RUN_URL,
)
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( commit.create_status(
context="Mergeable Check", context=MERGEABLE_NAME,
description=description, description=description,
state="success", state=state,
target_url=GITHUB_RUN_URL, target_url=GITHUB_RUN_URL,
) )
def update_mergeable_check(gh: Github, pr_info: PRInfo, check_name: str) -> None: def update_mergeable_check(gh: Github, pr_info: PRInfo, check_name: str) -> None:
if SKIP_MERGEABLE_CHECK_LABEL in pr_info.labels: not_run = (
pr_info.labels.intersection({SKIP_MERGEABLE_CHECK_LABEL, "release"})
or check_name not in REQUIRED_CHECKS
or pr_info.release_pr
or pr_info.number == 0
)
if not_run:
# Let's avoid unnecessary work
return return
logging.info("Update Mergeable Check by %s", check_name) logging.info("Update Mergeable Check by %s", check_name)
commit = get_commit(gh, pr_info.sha) commit = get_commit(gh, pr_info.sha)
checks = { statuses = get_commit_filtered_statuses(commit)
check.context: check.state
for check in filter( required_checks = [
lambda check: (check.context in REQUIRED_CHECKS), status for status in statuses if status.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()]), mergeable_status = None
) for status in statuses:
} if status.context == MERGEABLE_NAME:
mergeable_status = status
break
success = [] success = []
fail = [] fail = []
for name, state in checks.items(): for status in required_checks:
if state == "success": if status.state == "success":
success.append(name) success.append(status.context)
else: else:
fail.append(name) fail.append(status.context)
if fail: if fail:
description = "failed: " + ", ".join(fail) description = "failed: " + ", ".join(fail)
if success: if success:
description += "; succeeded: " + ", ".join(success) description += "; succeeded: " + ", ".join(success)
if len(description) > 140: description = format_description(description)
description = description[:137] + "..." if mergeable_status is None or mergeable_status.description != description:
fail_mergeable_check(commit, description) set_mergeable_check(commit, description, "failure")
return return
description = ", ".join(success) description = ", ".join(success)
if len(description) > 140: description = format_description(description)
description = description[:137] + "..." if mergeable_status is None or mergeable_status.description != description:
reset_mergeable_check(commit, description) set_mergeable_check(commit, description)

View File

@ -14,7 +14,7 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Union
from github import Github from github import Github
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status from commit_status_helper import format_description, post_commit_status
from env_helper import GITHUB_WORKSPACE, RUNNER_TEMP, GITHUB_RUN_URL from env_helper import GITHUB_WORKSPACE, RUNNER_TEMP, GITHUB_RUN_URL
from get_robot_token import get_best_robot_token, get_parameter_from_ssm from get_robot_token import get_best_robot_token, get_parameter_from_ssm
from pr_info import PRInfo from pr_info import PRInfo
@ -456,8 +456,7 @@ def main():
else: else:
description = "Nothing to update" description = "Nothing to update"
if len(description) >= 140: description = format_description(description)
description = description[:136] + "..."
with open(changed_json, "w", encoding="utf-8") as images_file: with open(changed_json, "w", encoding="utf-8") as images_file:
json.dump(result_images, images_file) json.dump(result_images, images_file)

View File

@ -10,7 +10,7 @@ from typing import List, Dict, Tuple
from github import Github from github import Github
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status from commit_status_helper import format_description, post_commit_status
from env_helper import RUNNER_TEMP from env_helper import RUNNER_TEMP
from get_robot_token import get_best_robot_token, get_parameter_from_ssm from get_robot_token import get_best_robot_token, get_parameter_from_ssm
from pr_info import PRInfo from pr_info import PRInfo
@ -218,8 +218,7 @@ def main():
else: else:
description = "Nothing to update" description = "Nothing to update"
if len(description) >= 140: format_description(description)
description = description[:136] + "..."
gh = Github(get_best_robot_token(), per_page=100) gh = Github(get_best_robot_token(), per_page=100)
post_commit_status(gh, pr_info.sha, NAME, description, status, url) post_commit_status(gh, pr_info.sha, NAME, description, status, url)

View File

@ -15,7 +15,7 @@ from github import Github
from build_check import get_release_or_pr from build_check import get_release_or_pr
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status from commit_status_helper import format_description, post_commit_status
from docker_images_check import DockerImage from docker_images_check import DockerImage
from env_helper import CI, GITHUB_RUN_URL, RUNNER_TEMP, S3_BUILDS_BUCKET, S3_DOWNLOAD from env_helper import CI, GITHUB_RUN_URL, RUNNER_TEMP, S3_BUILDS_BUCKET, S3_DOWNLOAD
from get_robot_token import get_best_robot_token, get_parameter_from_ssm from get_robot_token import get_best_robot_token, get_parameter_from_ssm
@ -369,8 +369,7 @@ def main():
description = f"Processed tags: {', '.join(tags)}" description = f"Processed tags: {', '.join(tags)}"
if len(description) >= 140: format_description(description)
description = description[:136] + "..."
gh = Github(get_best_robot_token(), per_page=100) gh = Github(get_best_robot_token(), per_page=100)
post_commit_status(gh, pr_info.sha, NAME, description, status, url) post_commit_status(gh, pr_info.sha, NAME, description, status, url)

View File

@ -18,7 +18,11 @@ from clickhouse_helper import (
mark_flaky_tests, mark_flaky_tests,
prepare_tests_results_for_clickhouse, prepare_tests_results_for_clickhouse,
) )
from commit_status_helper import post_commit_status, update_mergeable_check from commit_status_helper import (
format_description,
post_commit_status,
update_mergeable_check,
)
from compress_files import compress_fast from compress_files import compress_fast
from docker_pull_helper import get_image_with_version, DockerImage from docker_pull_helper import get_image_with_version, DockerImage
from env_helper import CI, TEMP_PATH as TEMP, REPORTS_PATH from env_helper import CI, TEMP_PATH as TEMP, REPORTS_PATH
@ -341,8 +345,7 @@ def main():
ch_helper = ClickHouseHelper() ch_helper = ClickHouseHelper()
mark_flaky_tests(ch_helper, args.check_name, test_results) mark_flaky_tests(ch_helper, args.check_name, test_results)
if len(description) >= 140: format_description(description)
description = description[:136] + "..."
post_commit_status(gh, pr_info.sha, args.check_name, description, state, report_url) post_commit_status(gh, pr_info.sha, args.check_name, description, state, report_url)

View File

@ -7,10 +7,11 @@ from typing import Tuple
from github import Github from github import Github
from commit_status_helper import ( from commit_status_helper import (
format_description,
get_commit, get_commit,
post_labels, post_labels,
remove_labels, remove_labels,
reset_mergeable_check, set_mergeable_check,
) )
from env_helper import GITHUB_RUN_URL, GITHUB_REPOSITORY, GITHUB_SERVER_URL from env_helper import GITHUB_RUN_URL, GITHUB_REPOSITORY, GITHUB_SERVER_URL
from get_robot_token import get_best_robot_token from get_robot_token import get_best_robot_token
@ -157,7 +158,7 @@ def check_pr_description(pr_info: PRInfo) -> Tuple[str, str]:
+ second_category + second_category
+ "'" + "'"
) )
return result_status[:140], category return result_status, category
elif re.match( elif re.match(
r"(?i)^[#>*_ ]*(short\s*description|change\s*log\s*entry)", lines[i] r"(?i)^[#>*_ ]*(short\s*description|change\s*log\s*entry)", lines[i]
@ -231,7 +232,7 @@ if __name__ == "__main__":
if pr_labels_to_remove: if pr_labels_to_remove:
remove_labels(gh, pr_info, 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: if description_error:
print( print(
@ -249,7 +250,7 @@ if __name__ == "__main__":
) )
commit.create_status( commit.create_status(
context=NAME, context=NAME,
description=description_error[:139], description=format_description(description_error),
state="failure", state="failure",
target_url=url, target_url=url,
) )

View File

@ -10,7 +10,7 @@ from github import Github
from build_download_helper import get_build_name_for_check, read_build_urls from build_download_helper import get_build_name_for_check, read_build_urls
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status from commit_status_helper import format_description, post_commit_status
from docker_pull_helper import get_image_with_version from docker_pull_helper import get_image_with_version
from env_helper import ( from env_helper import (
GITHUB_REPOSITORY, GITHUB_REPOSITORY,
@ -171,11 +171,13 @@ def main():
with open( with open(
os.path.join(workspace_path, "description.txt"), "r", encoding="utf-8" os.path.join(workspace_path, "description.txt"), "r", encoding="utf-8"
) as desc_f: ) as desc_f:
description = desc_f.readline().rstrip("\n")[:140] description = desc_f.readline().rstrip("\n")
except: except:
# status = "failure" # status = "failure"
description = "Task failed: $?=" + str(retcode) description = "Task failed: $?=" + str(retcode)
format_description(description)
report_url = upload_results( report_url = upload_results(
s3_helper, s3_helper,
pr_info.number, pr_info.number,