From 3a73ffb40ed1ddcb3ab3425ca79e12fca02949be Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Fri, 14 Jul 2023 18:30:54 +0200 Subject: 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 Acked-by: Bence Ferdinandy --- contrib/ircbot/Sourcehut/plugin.py | 9 ++++++++- contrib/ircbot/install-webhook.sh | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) 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) diff --git a/contrib/ircbot/install-webhook.sh b/contrib/ircbot/install-webhook.sh index 4d737f5b..3c0c5bcb 100755 --- a/contrib/ircbot/install-webhook.sh +++ b/contrib/ircbot/install-webhook.sh @@ -27,6 +27,8 @@ query { submitter { ... on User { canonicalName + username + email } } } -- cgit