From d8afd62e4cb3d493ef3a477dcd9cb52edeea715b Mon Sep 17 00:00:00 2001 From: dj-34 Date: Sun, 13 Oct 2024 19:26:49 +0500 Subject: [PATCH 1/4] Skips changelog validation if NPFC present in PR body --- tools/changelog/check_changelog.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/changelog/check_changelog.py b/tools/changelog/check_changelog.py index 4b72cd0bc0b1..6d45ef1f7dd5 100644 --- a/tools/changelog/check_changelog.py +++ b/tools/changelog/check_changelog.py @@ -2,7 +2,7 @@ DO NOT MANUALLY RUN THIS SCRIPT. --------------------------------- -Expected envrionmental variables: +Expected environmental variables: ----------------------------------- GITHUB_REPOSITORY: Github action variable representing the active repo (Action provided) BOT_TOKEN: A repository account token, this will allow the action to push the changes (Action provided) @@ -37,6 +37,13 @@ def build_changelog(pr: dict) -> dict: + # Check for the presence of :cl: or πŸ†‘ tags in the PR body + if not (":cl:" in pr.body or "πŸ†‘" in pr.body): + # Check if "NPFC" is in the PR body + if "NPFC" in pr.body: + pr.add_to_labels(CL_NOT_NEEDED) + raise Exception("Changelog tags (:cl: or πŸ†‘) are missing, but 'NPFC' is present. Skipping changelog validation.") + changelog = parse_changelog(pr.body) changelog["author"] = changelog["author"] or pr.user.login return changelog @@ -146,7 +153,7 @@ def parse_changelog(message: str) -> dict: cl_required = False if not cl_required: - # remove invalid, remove valid + # Remove invalid, remove valid if has_invalid_label: pr.remove_from_labels(CL_INVALID) if has_valid_label: @@ -162,14 +169,14 @@ def parse_changelog(message: str) -> dict: print("Changelog parsing error:") print(e) - # add invalid, remove valid + # Add invalid, remove valid if not has_invalid_label: pr.add_to_labels(CL_INVALID) if has_valid_label: pr.remove_from_labels(CL_VALID) exit(1) -# remove invalid, add valid +# Remove invalid, add valid if has_invalid_label: pr.remove_from_labels(CL_INVALID) if not has_valid_label: From 5fb9ed17551ac687d4fdea86ae0c74adc91aa968 Mon Sep 17 00:00:00 2001 From: dj-34 Date: Sun, 13 Oct 2024 19:35:36 +0500 Subject: [PATCH 2/4] Maybe this? --- tools/changelog/check_changelog.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/changelog/check_changelog.py b/tools/changelog/check_changelog.py index 6d45ef1f7dd5..edfd88d0ab75 100644 --- a/tools/changelog/check_changelog.py +++ b/tools/changelog/check_changelog.py @@ -42,7 +42,8 @@ def build_changelog(pr: dict) -> dict: # Check if "NPFC" is in the PR body if "NPFC" in pr.body: pr.add_to_labels(CL_NOT_NEEDED) - raise Exception("Changelog tags (:cl: or πŸ†‘) are missing, but 'NPFC' is present. Skipping changelog validation.") + print("Changelog tags (:cl: or πŸ†‘) are missing, but 'NPFC' is present. Skipping changelog validation.") + return None # Return None to truly skip changelog generation changelog = parse_changelog(pr.body) changelog["author"] = changelog["author"] or pr.user.login @@ -162,6 +163,9 @@ def parse_changelog(message: str) -> dict: try: cl = build_changelog(pr) + if cl is None: + exit(0) + cl_emoji = emojify_changelog(cl) cl_emoji["author"] = cl_emoji["author"] or pr_author validate_changelog(cl_emoji) From 413b03b91d6e2ae6b9277ab1264ea3e6be52e61d Mon Sep 17 00:00:00 2001 From: dj-34 Date: Mon, 14 Oct 2024 05:02:26 +0500 Subject: [PATCH 3/4] Review update Co-Authored-By: Mikhail Dzianishchyts --- tools/changelog/check_changelog.py | 35 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tools/changelog/check_changelog.py b/tools/changelog/check_changelog.py index edfd88d0ab75..ea95a21e97c1 100644 --- a/tools/changelog/check_changelog.py +++ b/tools/changelog/check_changelog.py @@ -37,15 +37,11 @@ def build_changelog(pr: dict) -> dict: - # Check for the presence of :cl: or πŸ†‘ tags in the PR body - if not (":cl:" in pr.body or "πŸ†‘" in pr.body): - # Check if "NPFC" is in the PR body - if "NPFC" in pr.body: - pr.add_to_labels(CL_NOT_NEEDED) - print("Changelog tags (:cl: or πŸ†‘) are missing, but 'NPFC' is present. Skipping changelog validation.") - return None # Return None to truly skip changelog generation - - changelog = parse_changelog(pr.body) + # Returns the result of changelog parsing through parse_changelog + changelog = parse_changelog(pr.body, pr) + if changelog["changes"] is None: + # If there are no changes (e.g., "NPFC" or no tags), return None + return None changelog["author"] = changelog["author"] or pr.user.login return changelog @@ -66,19 +62,29 @@ def validate_changelog(changelog: dict): if not changelog["author"]: raise Exception("The changelog has no author.") if len(changelog["changes"]) == 0: - raise Exception("No changes found in the changelog. Use special label if changelog is not expected.") + raise Exception("No changes found in the changelog. Use special label, or write 'NPFC' in PR's Changelog body if changelog is not expected.") message = "\n".join(map(lambda change: f"{change['tag']} {change['message']}", changelog["changes"])) if len(message) > DISCORD_EMBED_DESCRIPTION_LIMIT: raise Exception(f"The changelog exceeds the length limit ({DISCORD_EMBED_DESCRIPTION_LIMIT}). Shorten it.") -def parse_changelog(message: str) -> dict: +def parse_changelog(message: str, pr: dict) -> dict: + # Check for the presence of :cl: or πŸ†‘ tags in the PR body + if not (":cl:" in message or "πŸ†‘" in message): + if "NPFC" in message: + pr.add_to_labels(CL_NOT_NEEDED) + print("Changelog tags (:cl: or πŸ†‘) are missing, but 'NPFC' is present. Skipping changelog validation.") + # Return changes=None if changelog is not required + return {"author": None, "changes": None} + with open(Path.cwd().joinpath("tags.yml")) as file: yaml = YAML(typ = 'safe', pure = True) tags_config = yaml.load(file) + cl_parse_result = CL_BODY.search(message) if cl_parse_result is None: raise Exception("Failed to parse the changelog. Check changelog format.") + cl_changes = [] for cl_line in cl_parse_result.group("content").splitlines(): if not cl_line: @@ -99,7 +105,6 @@ def parse_changelog(message: str) -> dict: "tag": tags_config['tags'][tag], "message": message }) - # Append line without tag to the previous change else: if len(cl_changes): prev_change = cl_changes[-1] @@ -109,8 +114,9 @@ def parse_changelog(message: str) -> dict: if len(cl_changes) == 0: raise Exception("No changes found in the changelog. Use special label if changelog is not expected.") + return { - "author": str.strip(cl_parse_result.group("author") or "") or None, # I want this to be None, not empty + "author": str.strip(cl_parse_result.group("author") or "") or None, # I want this to be None, not empty "changes": cl_changes } @@ -164,6 +170,9 @@ def parse_changelog(message: str) -> dict: try: cl = build_changelog(pr) if cl is None: + pr.remove_from_labels(CL_INVALID) + pr.remove_from_labels(CL_VALID) + pr.add_to_labels(CL_NOT_NEEDED) exit(0) cl_emoji = emojify_changelog(cl) From 6a49929e22d8542e5f3362140c25c99f38128b17 Mon Sep 17 00:00:00 2001 From: dj-34 Date: Mon, 14 Oct 2024 05:22:46 +0500 Subject: [PATCH 4/4] Add check for nanomap-render (probably wont work xdd) --- tools/changelog/check_changelog.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/changelog/check_changelog.py b/tools/changelog/check_changelog.py index ea95a21e97c1..81404b85bd79 100644 --- a/tools/changelog/check_changelog.py +++ b/tools/changelog/check_changelog.py @@ -136,6 +136,7 @@ def parse_changelog(message: str, pr: dict) -> dict: pr_body = pr.body or "" pr_author = pr.user.login pr_labels = pr.labels +pr_branch = pr.head.ref CL_INVALID = ":scroll: CL Π½Π΅Π²Π°Π»ΠΈΠ΄Π΅Π½" CL_VALID = ":scroll: CL Π²Π°Π»ΠΈΠ΄Π΅Π½" @@ -159,6 +160,9 @@ def parse_changelog(message: str, pr: dict) -> dict: if pr_is_mirror: cl_required = False +if pr_branch == "nanomap-render": + cl_required = False + if not cl_required: # Remove invalid, remove valid if has_invalid_label: