3131 old_data = json.loads(old_content)
3232 new_data = json.loads(new_content)
3333
34- # Turn lists into dicts keyed by repository URL
3534 old_dict = {item['url']: item['commits'] for item in old_data}
3635 new_dict = {item['url']: item['commits'] for item in new_data}
3736
@@ -46,15 +45,28 @@ jobs:
4645 if old_sha != new_sha:
4746 plugin_name = url.split('/')[-1]
4847
49- # Build comparison link (or a fallback direct commit link if it's a new version)
50- if old_sha:
48+ if old_sha is not None:
49+ # Case 1: An existing version key was updated directly
5150 changelog_url = f"{url}/compare/{old_sha}...{new_sha}"
51+ display_text = f"Update ({new_sha[:7]})"
5252 else:
53- changelog_url = f"{url}/commit/{new_sha}"
53+ # Case 2: A brand new version key was added
54+ if old_commits:
55+ # Grab the very last version name and its corresponding real hash
56+ prev_version = list(old_commits.keys())[-1]
57+ prev_sha = old_commits[prev_version]
58+
59+ changelog_url = f"{url}/compare/{prev_sha}...{new_sha}"
60+ display_text = f"{prev_version}...{version}"
61+ else:
62+ # Fallback for the first ever release of a plugin
63+ changelog_url = f"{url}/commit/{new_sha}"
64+ display_text = f"Initial Commit ({new_sha[:7]})"
5465
5566 with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
5667 f.write(f"plugin_name={plugin_name}\n")
5768 f.write(f"changelog_url={changelog_url}\n")
69+ f.write(f"display_text={display_text}\n")
5870 found = True
5971 break
6072 if found:
@@ -67,13 +79,14 @@ jobs:
6779 CHANNEL_ID : ${{ secrets.DISCORD_CHANNEL_ID }}
6880 PLUGIN_NAME : ${{ steps.diff.outputs.plugin_name }}
6981 CHANGELOG_URL : ${{ steps.diff.outputs.changelog_url }}
82+ DISPLAY_TEXT : ${{ steps.diff.outputs.display_text }}
7083 run : |
71- # Build a clean Markdown payload safe from string-breaking characters
84+ # Formats as [1.5.0-beta.13...1.5.0-beta.14](<URL>)
85+ # The < > inside the markdown parenthesis cleanly suppresses the Discord embed preview!
7286 PAYLOAD=$(jq -n \
73- --arg msg "# 🎉 $PLUGIN_NAME updated"$'\n\n'"Changelog: $ CHANGELOG_URL" \
87+ --arg msg "# 🎉 $PLUGIN_NAME updated"$'\n\n'"Changelog: [$DISPLAY_TEXT](<$ CHANGELOG_URL>) " \
7488 '{content: $msg}')
7589
76- # Send payload directly to the Discord API using Bot authentication
7790 curl -X POST \
7891 -H "Authorization: Bot $BOT_TOKEN" \
7992 -H "Content-Type: application/json" \
0 commit comments