diff --git a/utils/generate_release_notes.py b/utils/generate_release_notes.py index 1c2e31ed11a..d63006542fd 100755 --- a/utils/generate_release_notes.py +++ b/utils/generate_release_notes.py @@ -66,7 +66,7 @@ def split_to_categories(changes, categories): def print_section_heading_2(text, file=None): - print(f"### {text}\n", file=file) + print(f"## {text}\n", file=file) def print_section_heading_3(text, file=None): @@ -123,11 +123,35 @@ def print_by_category(changes, categories, file=None): def binder_badge(tag): """Get mybinder Binder badge from a given tag, hash, or branch""" - binder_image_url = "https://camo.githubusercontent.com/581c077bdbc6ca6899c86d0acc6145ae85e9d80e6f805a1071793dbe48917982/68747470733a2f2f6d7962696e6465722e6f72672f62616467655f6c6f676f2e737667" # noqa + binder_image_url = "https://mybinder.org/badge_logo.svg" binder_url = f"https://mybinder.org/v2/gh/OSGeo/grass/{tag}?urlpath=lab%2Ftree%2Fdoc%2Fnotebooks%2Fjupyter_example.ipynb" # noqa return f"[![Binder]({binder_image_url})]({binder_url})" +def adjust_after(lines): + """Adjust new contributor lines in the last part of the generated notes""" + bot_file = Path("utils") / "known_bot_names.txt" + known_bot_names = bot_file.read_text().splitlines() + new_lines = [] + for line in lines: + if line.startswith("* @"): + unused, username, text = line.split(" ", maxsplit=2) + username = username.replace("@", "") + if username in known_bot_names: + continue + output = subprocess.run( + ["gh", "api", f"users/{username}"], + capture_output=True, + text=True, + check=True, + ).stdout + name = json.loads(output)["name"] + if name and name != username: + line = f"* {name} (@{username}) {text}" + new_lines.append(line) + return new_lines + + def print_notes( start_tag, end_tag, changes, categories, before=None, after=None, file=None ): @@ -145,6 +169,8 @@ def print_notes( if before: print(before) + print_section_heading_2("Highlights", file=file) + print("* _Put handcrafted list of items here._\n") print_section_heading_2("What's Changed", file=file) changes_by_category = split_to_categories(changes, categories=categories) print_by_category(changes_by_category, categories=categories, file=file) @@ -185,12 +211,13 @@ def notes_from_gh_api(start_tag, end_tag, branch, categories, exclude): else: changes.append(change) changes = remove_excluded_changes(changes=changes, exclude=exclude) + after = adjust_after(lines[end_whats_changed + 1 :]) print_notes( start_tag=start_tag, end_tag=end_tag, changes=changes, before="\n".join(lines[:start_whats_changed]), - after="\n".join(lines[end_whats_changed + 1 :]), + after="\n".join(after), categories=categories, )