Fix the PR body check for Reverts #number

This commit is contained in:
Mikhail f. Shiryaev 2023-08-01 17:06:23 +02:00
parent 1130904697
commit 79d49a006c
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
3 changed files with 6 additions and 8 deletions

View File

@ -323,7 +323,9 @@ def main(event):
if action == "edited": if action == "edited":
print("PR is edited, check if the body is correct") print("PR is edited, check if the body is correct")
error, category = check_pr_description(pull_request["body"]) error, _ = check_pr_description(
pull_request["body"], pull_request["base"]["repo"]["full_name"]
)
if error: if error:
print( print(
f"The PR's body is wrong, is going to comment it. The error is: {error}" f"The PR's body is wrong, is going to comment it. The error is: {error}"

View File

@ -101,7 +101,7 @@ LABELS = {
CATEGORY_TO_LABEL = {c: lb for lb, categories in LABELS.items() for c in categories} CATEGORY_TO_LABEL = {c: lb for lb, categories in LABELS.items() for c in categories}
def check_pr_description(pr_body: str) -> Tuple[str, str]: def check_pr_description(pr_body: str, repo_name: str) -> Tuple[str, str]:
"""The function checks the body to being properly formatted according to """The function checks the body to being properly formatted according to
.github/PULL_REQUEST_TEMPLATE.md, if the first returned string is not empty, .github/PULL_REQUEST_TEMPLATE.md, if the first returned string is not empty,
then there is an error.""" then there is an error."""
@ -109,11 +109,7 @@ def check_pr_description(pr_body: str) -> Tuple[str, str]:
lines = [re.sub(r"\s+", " ", line) for line in lines] lines = [re.sub(r"\s+", " ", line) for line in lines]
# Check if body contains "Reverts ClickHouse/ClickHouse#36337" # Check if body contains "Reverts ClickHouse/ClickHouse#36337"
if [ if [True for line in lines if re.match(rf"\AReverts {repo_name}#[\d]+\Z", line)]:
True
for line in lines
if re.match(r"\AReverts {GITHUB_REPOSITORY}#[\d]+\Z", line)
]:
return "", LABELS["pr-not-for-changelog"][0] return "", LABELS["pr-not-for-changelog"][0]
category = "" category = ""

View File

@ -108,7 +108,7 @@ def main():
gh = Github(get_best_robot_token(), per_page=100) gh = Github(get_best_robot_token(), per_page=100)
commit = get_commit(gh, pr_info.sha) commit = get_commit(gh, pr_info.sha)
description_error, category = check_pr_description(pr_info.body) description_error, category = check_pr_description(pr_info.body, GITHUB_REPOSITORY)
pr_labels_to_add = [] pr_labels_to_add = []
pr_labels_to_remove = [] pr_labels_to_remove = []
if ( if (