Browse Source

Updated Discord integration to use discord.com instead of discordapp.com

pull/405/head
Pēteris Caune 4 years ago
parent
commit
589c0c0363
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 25 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +8
    -1
      hc/api/models.py
  3. +16
    -0
      hc/api/tests/test_notify.py

+ 1
- 0
CHANGELOG.md View File

@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- Indicate a started check with a progress spinner under status icon (#338) - Indicate a started check with a progress spinner under status icon (#338)
- Added "Docs > Reliability Tips" page - Added "Docs > Reliability Tips" page
- Spike.sh integration (#402) - Spike.sh integration (#402)
- Updated Discord integration to use discord.com instead of discordapp.com
### Bug Fixes ### Bug Fixes
- Removing Pager Team integration, project appears to be discontinued - Removing Pager Team integration, project appears to be discontinued


+ 8
- 1
hc/api/models.py View File

@ -585,7 +585,14 @@ class Channel(models.Model):
def discord_webhook_url(self): def discord_webhook_url(self):
assert self.kind == "discord" assert self.kind == "discord"
doc = json.loads(self.value) doc = json.loads(self.value)
return doc["webhook"]["url"]
url = doc["webhook"]["url"]
# Discord migrated to discord.com,
# and is dropping support for discordapp.com on 7 November 2020
if url.startswith("https://discordapp.com/"):
url = "https://discord.com/" + url[23:]
return url
@property @property
def discord_webhook_id(self): def discord_webhook_id(self):


+ 16
- 0
hc/api/tests/test_notify.py View File

@ -569,6 +569,22 @@ class NotifyTestCase(BaseTestCase):
fields = {f["title"]: f["value"] for f in attachment["fields"]} fields = {f["title"]: f["value"] for f in attachment["fields"]}
self.assertEqual(fields["Last Ping"], "an hour ago") self.assertEqual(fields["Last Ping"], "an hour ago")
@patch("hc.api.transports.requests.request")
def test_discord_rewrites_discordapp_com(self, mock_post):
v = json.dumps({"webhook": {"url": "https://discordapp.com/foo"}})
self._setup_data("discord", v)
mock_post.return_value.status_code = 200
self.channel.notify(self.check)
assert Notification.objects.count() == 1
args, kwargs = mock_post.call_args
url = args[1]
# discordapp.com is deprecated. For existing webhook URLs, wwe should
# rewrite discordapp.com to discord.com:
self.assertEqual(url, "https://discord.com/foo/slack")
@patch("hc.api.transports.requests.request") @patch("hc.api.transports.requests.request")
def test_pushbullet(self, mock_post): def test_pushbullet(self, mock_post):
self._setup_data("pushbullet", "fake-token") self._setup_data("pushbullet", "fake-token")


Loading…
Cancel
Save