From 00c5538c6b3fdc9586f3376b5acecddc664c0665 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:14:00 +1100 Subject: [PATCH] Split changelog entries for discord (#23832) * Split changelog entries for discord Not sure where best to split it, by entry in group or by author. * Formatting --- Tools/actions_changelogs_since_last_run.py | 43 ++++++++++++---------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Tools/actions_changelogs_since_last_run.py b/Tools/actions_changelogs_since_last_run.py index 10f76f7ff7..9fe99d66ec 100755 --- a/Tools/actions_changelogs_since_last_run.py +++ b/Tools/actions_changelogs_since_last_run.py @@ -109,11 +109,13 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None: print(f"No discord webhook URL found, skipping discord send") return - content = io.StringIO() count: int = 0 for name, group in itertools.groupby(entries, lambda x: x["author"]): + count = 0 + content = io.StringIO() content.write(f"**{name}** updated:\n") + for entry in group: for change in entry["changes"]: emoji = TYPES_TO_EMOJI.get(change['type'], "❓") @@ -124,25 +126,26 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None: content.write(f"{emoji} [-]({url}) {message}\n") else: content.write(f"{emoji} - {message}\n") + + body = { + "content": content.getvalue(), + # Do not allow any mentions. + "allowed_mentions": { + "parse": [] + }, + # SUPPRESS_EMBEDS + "flags": 1 << 2 + } + + # No entries? + if count == 0: + continue + + # Post per group to try to avoid discord character limits + print(f"Posting {count} changelog entries to discord webhook") + + response = requests.post(DISCORD_WEBHOOK_URL, json=body) + response.raise_for_status() - if count == 0: - print("Skipping discord push as no changelog entries found") - return - - print(f"Posting {count} changelog entries to discord webhook") - - body = { - "content": content.getvalue(), - # Do not allow any mentions. - "allowed_mentions": { - "parse": [] - }, - # SUPPRESS_EMBEDS - "flags": 1 << 2 - } - - response = requests.post(DISCORD_WEBHOOK_URL, json=body) - response.raise_for_status() - main()