aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/ircbot/Sourcehut/plugin.py
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-07-14 18:30:54 +0200
committerRobin Jarry <robin@jarry.cc>2023-07-14 23:04:53 +0200
commit3a73ffb40ed1ddcb3ab3425ca79e12fca02949be (patch)
tree3ffd10179dc7b17e2b2d3a6a584890557561e434 /contrib/ircbot/Sourcehut/plugin.py
parentab3debc1fad99e7a10a530055eed185eb370be79 (diff)
downloadaerc-3a73ffb40ed1ddcb3ab3425ca79e12fca02949be.tar.gz
contrib: fix irc patchset hook when author is not registered
Avoid running into KeyError because the webhook payload does not have a submitter canonicalName field. { "data": { "webhook": { "uuid": "69635b8e-8af5-4292-866b-1e45f75c132a", "event": "PATCHSET_RECEIVED", "date": "2023-07-11T13:55:17.248351983Z", "patchset": { "id": 42569, "subject": "Commands: add :echo command", "version": 1, "prefix": "aerc", "list": { "name": "aerc-devel", "owner": { "canonicalName": "~rjarry" } }, "submitter": {} } } } } Add username and email as fallback values. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'contrib/ircbot/Sourcehut/plugin.py')
-rw-r--r--contrib/ircbot/Sourcehut/plugin.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/contrib/ircbot/Sourcehut/plugin.py b/contrib/ircbot/Sourcehut/plugin.py
index d66c1029..50128d79 100644
--- a/contrib/ircbot/Sourcehut/plugin.py
+++ b/contrib/ircbot/Sourcehut/plugin.py
@@ -8,6 +8,7 @@ class Sourcehut(callbacks.Plugin):
"""
Supybot plugin to receive Sourcehut webhooks
"""
+
def __init__(self, irc):
super().__init__(irc)
httpserver.hook("sourcehut", SourcehutServerCallback(self))
@@ -57,7 +58,13 @@ class SourcehutServerCallback(httpserver.SupyHTTPServerCallback):
raise ValueError("unknown list")
channel = f"#{patchset['list']['name']}"
channel = self.CHANS.get(channel, channel)
- submitter = patchset["submitter"]["canonicalName"]
+ try:
+ submitter = patchset["submitter"]["canonicalName"]
+ except KeyError:
+ try:
+ submitter = patchset["submitter"]["username"]
+ except KeyError:
+ submitter = patchset["submitter"]["email"]
msg = f"received {bold(subject)} from {italic(submitter)}: {underline(url)}"
self.plugin.announce(channel, msg)
handler.send_response(200)