From c2883f73edbef7a53766ef884b83c9fbab83d776 Mon Sep 17 00:00:00 2001 From: Alaska Date: Mon, 28 Apr 2025 07:09:02 +0200 Subject: [PATCH] Release note tools: Shift commit fix overrides to a Gitea issue The list of bug fixes per release tool has a option to override which issue a commit fixed (Useful if someone accidentally put the wrong fix report number in their commit message). The way the feature was setup previously wasn't that great, requiring commiting information to the Blender repository, and it was prone to bad merge conflicts if multiple people worked on it. This commit fixes this issue by shifting the overrides list to a bug report in the Blender repository, detaching it from commits to the Blender repo, avoiding merge conflicts. Pull Request: https://projects.blender.org/blender/blender/pulls/136750 --- .../bug_fixes_per_major_release.py | 106 ++++++++++-------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/release/release_notes/bug_fixes_per_major_release.py b/release/release_notes/bug_fixes_per_major_release.py index 651ae44e1b1..4bbc3779931 100644 --- a/release/release_notes/bug_fixes_per_major_release.py +++ b/release/release_notes/bug_fixes_per_major_release.py @@ -40,12 +40,8 @@ Specifically the fixed issue listed in the commit message may be incorrect. In situations like this it can be easier to simply override the issue that -the commit claims to fix. This can be done by launching the script with: -`bug_fixes_per_major_release.py -o` - -The script will then ask for the commit hash, then the -issue number that commit actually fixes then will use that override -(and all other overrides you've setup) when you run the script again. +the commit claims to fix. This can be done by adding a entry to the overrides +issue: https://projects.blender.org/blender/blender/issues/137983 --- @@ -194,7 +190,6 @@ NEWER_VERION = "NEWER" SAME_VERION = "SAME" dir_of_script = Path(__file__).parent.resolve() -PATH_TO_OVERRIDES = dir_of_script.joinpath('overrides.json') PATH_TO_CACHED_COMMITS = dir_of_script.joinpath('cached_commits.json') del dir_of_script @@ -380,6 +375,9 @@ class CommitInfo: for report_number in self.fixed_reports: report_information = url_json_get(f"{BLENDER_API_URL}/repos/blender/blender/issues/{report_number}") + if report_information is None: + print(f"ERROR: Could not gather information from report number: {report_number}\n") + continue report_title = report_information['title'] module = self.get_module(report_information['labels']) @@ -442,9 +440,14 @@ class CommitInfo: self.needs_update = False - def read_from_override(self, override_data: list[str]) -> None: + def read_from_override(self, override_data: str) -> None: self.set_defaults() - self.fixed_reports = override_data + if "ignore" in override_data.lower(): + self.classification = IGNORED + self.needs_update = False + else: + self.fixed_reports = [override_data] + self.needs_update = True self.has_been_overwritten = True @@ -824,7 +827,7 @@ def print_release_notes(list_of_commits: list[CommitInfo]) -> None: print_list_of_commits("Commits that need manual sorting:", dict_of_sorted_commits[NEEDS_MANUAL_SORTING]) print_list_of_commits( - "Commits that need a override (launch this script with -o) as they claim to fix a PR:", + "Commits that need a override in https://projects.blender.org/blender/blender/issues/137983 as they claim to fix a PR:", dict_of_sorted_commits[FIXED_PR]) print_list_of_commits("Ignored commits:", dict_of_sorted_commits[IGNORED]) @@ -887,36 +890,57 @@ def cached_commits_store(list_of_commits: list[CommitInfo]) -> None: # ----------------------------------------------------------------------------- # Override Utilities -def overrides_load() -> dict[str, list[str]]: - override_data = {} - if PATH_TO_OVERRIDES.exists(): - with open(str(PATH_TO_OVERRIDES), 'r', encoding='utf-8') as file: - override_data = json.load(file) + +def overrides_read(silence: bool) -> dict[str, str]: + override_data: dict[str, str] = {} + override_report = url_json_get(f"{BLENDER_API_URL}/repos/blender/blender/issues/137983") + description = override_report["body"].splitlines() + + for line in description: + if "|" not in line: + continue + if line.startswith("| Commit"): + continue + if line.startswith("| -"): + continue + + split_line = line.split("|") + info: list[str] = [] + for entry in split_line: + # Remove empty strings and strip "#" off the issue number + entry = entry.strip().strip("#") + if len(entry) != 0: + info.append(entry) + + try: + hash = info[0] + fixed_issue = info[1] + if len(hash) < 10: + print("\n" * 3) + print(f"ERROR: Hash is too short in this override data: {info}") + if not silence: + input("Press enter to acknowledge: ") + continue + override_data[hash] = fixed_issue + except IndexError: + print("\n" * 3) + print(f"INDEX ERROR: Failed to process overrides with this data: {info}") + if not silence: + input("Press enter to acknowledge: ") return override_data -def overrides_store(override_data: dict[str, list[str]]) -> None: - with open(str(PATH_TO_OVERRIDES), 'w', encoding='utf-8') as file: - json.dump(override_data, file, indent=4) +def overrides_apply(list_of_commits: list[CommitInfo], silence: bool) -> None: + override_data = overrides_read(silence) + if len(override_data) == 0: + return - -def overrides_apply(list_of_commits: list[CommitInfo]) -> None: - override_data = overrides_load() - if len(override_data) > 0: + for commit_hash in override_data: for commit in list_of_commits: - if commit.hash in override_data: - commit.read_from_override(override_data[commit.hash]) - - -def create_override() -> None: - commit_hash = input("Please input the full hash of the commit you want to override: ") - issue_number = input("Please input the issue number you want to override it with: ") - - override_data = overrides_load() - override_data[commit_hash] = [issue_number] - - overrides_store(override_data) + if commit.hash.startswith(commit_hash): + commit.read_from_override(override_data[commit_hash]) + break # ----------------------------------------------------------------------------- @@ -928,14 +952,6 @@ def argparse_create() -> argparse.ArgumentParser: # Don't re-format multi-line text. formatter_class=argparse.RawTextHelpFormatter, ) - parser.add_argument( - "-o", - "--override", - action="store_true", - help=( - "Create a override for a commit." - ), - ) parser.add_argument( "-st", "--single-thread", @@ -1046,10 +1062,6 @@ def validate_arguments(args: argparse.Namespace) -> bool: def main() -> int: args = argparse_create().parse_args() - if args.override: - create_override() - return 0 - if not validate_arguments(args): return 0 @@ -1062,7 +1074,7 @@ def main() -> int: if args.cache: cached_commits_load(list_of_commits) - overrides_apply(list_of_commits) + overrides_apply(list_of_commits, args.silence) classify_commits( args.backport_tasks,