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
This commit is contained in:
@@ -109,11 +109,13 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
|
|||||||
print(f"No discord webhook URL found, skipping discord send")
|
print(f"No discord webhook URL found, skipping discord send")
|
||||||
return
|
return
|
||||||
|
|
||||||
content = io.StringIO()
|
|
||||||
count: int = 0
|
count: int = 0
|
||||||
|
|
||||||
for name, group in itertools.groupby(entries, lambda x: x["author"]):
|
for name, group in itertools.groupby(entries, lambda x: x["author"]):
|
||||||
|
count = 0
|
||||||
|
content = io.StringIO()
|
||||||
content.write(f"**{name}** updated:\n")
|
content.write(f"**{name}** updated:\n")
|
||||||
|
|
||||||
for entry in group:
|
for entry in group:
|
||||||
for change in entry["changes"]:
|
for change in entry["changes"]:
|
||||||
emoji = TYPES_TO_EMOJI.get(change['type'], "❓")
|
emoji = TYPES_TO_EMOJI.get(change['type'], "❓")
|
||||||
@@ -125,12 +127,6 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
|
|||||||
else:
|
else:
|
||||||
content.write(f"{emoji} - {message}\n")
|
content.write(f"{emoji} - {message}\n")
|
||||||
|
|
||||||
if count == 0:
|
|
||||||
print("Skipping discord push as no changelog entries found")
|
|
||||||
return
|
|
||||||
|
|
||||||
print(f"Posting {count} changelog entries to discord webhook")
|
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"content": content.getvalue(),
|
"content": content.getvalue(),
|
||||||
# Do not allow any mentions.
|
# Do not allow any mentions.
|
||||||
@@ -141,6 +137,13 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
|
|||||||
"flags": 1 << 2
|
"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 = requests.post(DISCORD_WEBHOOK_URL, json=body)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user