Skip to content

Commit

Permalink
fix(release.py): Do not attach changelog to announcement anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Bengejd committed Jun 12, 2024
1 parent e4fa4dc commit 78a10fe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Markdown/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PDKP Change Log

## v5.0.0
## v5.0.3
### Features
- Added Cataclysm bosses & raids

Expand Down
78 changes: 41 additions & 37 deletions scripts/post_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,59 +50,63 @@ def get_newest_changelog():
exit(20)

def get_pretty_changelog(currTag, prevTag):
if len(changelog) == 0:
return "No changelog attached"
else:
s = changelog
prev_tag = f'## {prevTag}'.encode()
curr_tag = f'## {currTag}'.encode()
return s[s.find(curr_tag)+len(curr_tag):s.rfind(prev_tag)].decode().replace('### ', '\n').replace('\n\n', '\n').strip()
return "No changelog attached"
# if len(changelog) == 0:
# return "No changelog attached"
# else:
# s = changelog
# prev_tag = f'## {prevTag}'.encode()
# curr_tag = f'## {currTag}'.encode()
# return s[s.find(curr_tag)+len(curr_tag):s.rfind(prev_tag)].decode().replace('### ', '\n').replace('\n\n', '\n').strip()

def split_longer_embed(changelog):
line = changelog
n = 1000
return [line[i:i+n] for i in range(0, len(line), n)]

def create_embeds(releases, pretty_changelog, author):
embeds = []
base_embed = Embed(
title=releases[0]["name"],
try:
author = releases[0]["author"]["login"]
body = releases[0]["body"]
multibody = None
if len(body) > 1000:
multibody = body.split("\r\n\r\n")

tag = releases[0]["tag_name"]
prev_tag = releases[1]["tag_name"]
name = releases[0]["name"]
prerelease = releases[0]["prerelease"]

pretty_changelog = get_pretty_changelog(tag, prev_tag)

embed = Embed(
title=name,
color=14464841,
description="_This is a beta version and may still contain bugs_" if releases[0]["prerelease"] else None
description="_This is a beta version and may still contain bugs_" if prerelease else None
)
base_embed.set_author(name="PantheonDKP has been updated!")
base_embed.set_footer(text="Released by " + author + " (Neekio)")
embed.set_author(name="PantheonDKP has been updated!")
embed.set_footer(text="Released by " + author + " (Neekio)")

if len(pretty_changelog) > 1000:
multibody = split_longer_embed(pretty_changelog)

if multibody is not None:
first = True
for body in multibody:
embed = base_embed.copy()
title = "**CHANGELOG**" if first else "\u200b"
embed.add_field(name=title, value="```" + body + "```", inline=False)
embeds.append(embed)
first = False
if len(body) > 0:
title = "**CHANGELOG**" if first else "\u200b"
embed.add_field(name=title, value="```" + body + "```", inline=False)
first = False
else:
embed = base_embed.copy()
embed.add_field(name="**CHANGELOG**", value="```" + pretty_changelog + "```", inline=False)
embeds.append(embed)

return embeds

try:
author = releases[0]["author"]["login"]
tag = releases[0]["tag_name"]
prev_tag = releases[1]["tag_name"]

pretty_changelog = get_pretty_changelog(tag, prev_tag)
embeds = create_embeds(releases, pretty_changelog, author)
if len(body) > 0:
embed.add_field(name="**CHANGELOG**", value="```" + body + "```", inline=False)
else:
embed.add_field(name="CHANGELOG", value="`" + pretty_changelog + "`", inline=False)

webhook = SyncWebhook.from_url(sys.argv[1])
for embed in embeds:
if releases[0]["prerelease"]:
webhook.send(embed=embed)
else:
webhook.send(content="@everyone", embed=embed)
if prerelease:
webhook.send(embed=embed)
else:
webhook.send(content="@everyone", embed=embed)

except Exception as e:
print(str(e))
Expand Down

0 comments on commit 78a10fe

Please sign in to comment.