diff --git a/alerts/service_backends/discord.py b/alerts/service_backends/discord.py index c4d67bb..7c7b85e 100644 --- a/alerts/service_backends/discord.py +++ b/alerts/service_backends/discord.py @@ -1,3 +1,4 @@ +from urllib.parse import urlparse import json import requests from django.utils import timezone @@ -12,6 +13,16 @@ from bugsink.transaction import immediate_atomic from issues.models import Issue +def url_valid_according_to_discord(url): + # See https://github.com/bugsink/bugsink/issues/280 for "according to Discord" + parsed = urlparse(url) + return ( + parsed.scheme in ("http", "https") + and parsed.hostname is not None + and "." in parsed.hostname + ) + + class DiscordConfigForm(forms.Form): # NOTE: As of yet this code isn't plugged into the UI (because it requires dynamic loading of the config-specific # form) @@ -139,12 +150,14 @@ def discord_backend_send_alert( embed = { "title": issue_title, - "url": issue_url, "description": f"{alert_reason} issue", "color": color, "fields": [{"name": "Project", "value": issue.project.name, "inline": True}], } + if url_valid_according_to_discord(issue_url): + embed["url"] = issue_url + if unmute_reason: embed["fields"].append( {"name": "Unmute Reason", "value": unmute_reason, "inline": False}