Skip to content

Commit c8912e6

Browse files
committed
fixes: Discord webhook now preserves HTTPS protocol in URLs
Two critical fixes to the Discord notification script: 1. Config parser: Changed sed regex from '.*:' (greedy) to '^[^:]*:' (non-greedy) to match only the FIRST colon (YAML key separator) instead of matching up to the LAST colon (in https:// protocol). This was stripping 'https:' from all URLs. 2. JSON builder: Replaced bash heredoc with Python json.dumps() for proper escaping of all fields, ensuring protocols and special characters are preserved correctly. Result: Discord webhooks now receive properly formatted URLs like 'https://www.curseforge.com/...' instead of malformed '//www.curseforge.com/...' protocol-relative URLs. Tested with Discord webhook: Success (HTTP 200) Files: .github/scripts/send-discord-notification.sh
1 parent e1229d6 commit c8912e6

1 file changed

Lines changed: 63 additions & 44 deletions

File tree

.github/scripts/send-discord-notification.sh

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ load_addon_config() {
4040

4141
log_info "Loading config from $config..."
4242
[ -z "$ADDON_NAME" ] && ADDON_NAME=$(grep "^addon-name:" "$config" | sed 's/^addon-name: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
43-
[ -z "$CF_URL" ] && CF_URL=$(grep " curseforge:" "$config" | sed 's/.*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
44-
[ -z "$WAGO_URL" ] && WAGO_URL=$(grep " wago:" "$config" | sed 's/.*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
45-
[ -z "$DISCORD_SUPPORT" ] && DISCORD_SUPPORT=$(grep " discord:" "$config" | sed 's/.*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
46-
[ -z "$GH_PROJECT" ] && GH_PROJECT=$(grep " roadmap:" "$config" | sed 's/.*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
43+
[ -z "$CF_URL" ] && CF_URL=$(grep " curseforge:" "$config" | sed 's/^[^:]*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
44+
[ -z "$WAGO_URL" ] && WAGO_URL=$(grep " wago:" "$config" | sed 's/^[^:]*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
45+
[ -z "$DISCORD_SUPPORT" ] && DISCORD_SUPPORT=$(grep " discord:" "$config" | sed 's/^[^:]*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
46+
[ -z "$GH_PROJECT" ] && GH_PROJECT=$(grep " roadmap:" "$config" | sed 's/^[^:]*: *"\{0,1\}\([^"]*\)"\{0,1\}/\1/' | sed 's/^ *//;s/ *$//')
4747
return 0
4848
}
4949

@@ -107,7 +107,6 @@ detect_version() {
107107
# === BUILD JSON PAYLOAD ===
108108
build_payload() {
109109
local description=$(build_description)
110-
local desc_json=$(json_escape "$description")
111110

112111
# Determine color and title based on release type
113112
local color=$COLOR_STABLE
@@ -124,56 +123,76 @@ build_payload() {
124123
# Get current timestamp
125124
local timestamp=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)
126125

127-
# Build download field value
128-
local download_value=""
126+
# Build download links array
127+
local download_links=()
129128
if [ -n "$CF_URL" ]; then
130-
download_value="[CurseForge]($CF_URL) (Recommended)"
129+
download_links+=("$CF_URL|CurseForge (Recommended)")
131130
fi
132131
if [ -n "$WAGO_URL" ]; then
133-
[ -n "$download_value" ] && download_value="$download_value\\n"
134-
download_value="${download_value}[Wago Addons]($WAGO_URL)"
132+
download_links+=("$WAGO_URL|Wago Addons")
135133
fi
136-
[ -n "$download_value" ] && download_value="$download_value\\n"
137-
download_value="${download_value}[GitHub Releases]($GH_RELEASES)"
134+
download_links+=("$GH_RELEASES|GitHub Releases")
138135

139-
# Build support field value
140-
local support_value=""
136+
# Build support links array
137+
local support_links=()
141138
if [ -n "$DISCORD_SUPPORT" ]; then
142-
support_value="[Discord]($DISCORD_SUPPORT)"
139+
support_links+=("$DISCORD_SUPPORT|Discord")
143140
fi
144-
[ -n "$support_value" ] && support_value="$support_value\\n"
145-
support_value="${support_value}[Report Issues]($GH_ISSUES)"
141+
support_links+=("$GH_ISSUES|Report Issues")
146142
if [ -n "$GH_PROJECT" ]; then
147-
support_value="$support_value\\n[Roadmap]($GH_PROJECT)"
143+
support_links+=("$GH_PROJECT|Roadmap")
148144
fi
149145

150-
# Build the JSON payload
151-
cat << EOJSON
152-
{
153-
"embeds": [{
154-
"title": "$title",
155-
"url": "$title_url",
156-
"description": $desc_json,
157-
"color": $color,
158-
"fields": [
159-
{
160-
"name": "Download",
161-
"value": "$download_value",
162-
"inline": true
163-
},
164-
{
165-
"name": "Support",
166-
"value": "$support_value",
167-
"inline": true
168-
}
169-
],
170-
"footer": {
171-
"text": "$ADDON_NAME - World of Warcraft"
172-
},
173-
"timestamp": "$timestamp"
174-
}]
146+
# Build the JSON payload using Python for proper escaping
147+
python3 -c "
148+
import json
149+
import sys
150+
151+
# Parse download links
152+
download_parts = '''${download_links[*]}'''.split()
153+
download_lines = []
154+
for part in download_parts:
155+
if '|' in part:
156+
url, label = part.split('|', 1)
157+
download_lines.append(f'[{label}]({url})')
158+
download_value = '\\n'.join(download_lines)
159+
160+
# Parse support links
161+
support_parts = '''${support_links[*]}'''.split()
162+
support_lines = []
163+
for part in support_parts:
164+
if '|' in part:
165+
url, label = part.split('|', 1)
166+
support_lines.append(f'[{label}]({url})')
167+
support_value = '\\n'.join(support_lines)
168+
169+
payload = {
170+
'embeds': [{
171+
'title': '''$title''',
172+
'url': '''$title_url''',
173+
'description': '''$description''',
174+
'color': $color,
175+
'fields': [
176+
{
177+
'name': 'Download',
178+
'value': download_value,
179+
'inline': True
180+
},
181+
{
182+
'name': 'Support',
183+
'value': support_value,
184+
'inline': True
185+
}
186+
],
187+
'footer': {
188+
'text': '''$ADDON_NAME - World of Warcraft'''
189+
},
190+
'timestamp': '''$timestamp'''
191+
}]
175192
}
176-
EOJSON
193+
194+
print(json.dumps(payload, ensure_ascii=False, indent=2))
195+
"
177196
}
178197

179198
# === CHANGELOG PROCESSING ===

0 commit comments

Comments
 (0)