Skip to content

Commit

Permalink
contributing: Refine generated release notes (#3876)
Browse files Browse the repository at this point in the history
* Show name, not just username, for new contributors if available and different from the username using GitHub API.
* Fix heading level for What's changed section.
* Add empty Highlights section with a call to fill it.
* Update to the current badge image for Binder badge.
  • Loading branch information
wenzeslaus authored and neteler committed Jun 20, 2024
1 parent cf5f150 commit 2e6d8a4
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions utils/generate_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
):
Expand All @@ -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)
Expand Down Expand Up @@ -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,
)

Expand Down

0 comments on commit 2e6d8a4

Please sign in to comment.