From b88b7bdda39b127bd16547bce8b3dbc46ccce091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bompard?= Date: Wed, 17 Jan 2024 13:16:49 +0100 Subject: [PATCH] Handle namespaced usernames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aurélien Bompard --- messaging/copr_messaging/private/hierarchy.py | 9 +++++++++ messaging/copr_messaging/private/schema_old.py | 4 ++-- messaging/copr_messaging/private/schema_stomp_old.py | 4 ++-- messaging/copr_messaging/tests/test_schema.py | 6 ++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/messaging/copr_messaging/private/hierarchy.py b/messaging/copr_messaging/private/hierarchy.py index 981fd1bfd..4d792cc85 100644 --- a/messaging/copr_messaging/private/hierarchy.py +++ b/messaging/copr_messaging/private/hierarchy.py @@ -159,6 +159,15 @@ def package_full_name(self): release=release, ) + @property + def submitter(self): + """The username of the person who submitted the build.""" + username = self._raw_submitter + if isinstance(username, str) and ":" in username: + # This is namespaced, such as github.com:foobar + return None + return username + @property def usernames(self): """ diff --git a/messaging/copr_messaging/private/schema_old.py b/messaging/copr_messaging/private/schema_old.py index 9da5181ee..239cccbdb 100644 --- a/messaging/copr_messaging/private/schema_old.py +++ b/messaging/copr_messaging/private/schema_old.py @@ -129,8 +129,8 @@ def package_name(self): return self.body.get('pkg') @property - def submitter(self): - """The username of the person who submitted the build.""" + def _raw_submitter(self): + """The username of the person who submitted the build. May be namespaced.""" return self.body.get('user') def _evr(self): diff --git a/messaging/copr_messaging/private/schema_stomp_old.py b/messaging/copr_messaging/private/schema_stomp_old.py index 681fa7db8..ee9c1f3bf 100644 --- a/messaging/copr_messaging/private/schema_stomp_old.py +++ b/messaging/copr_messaging/private/schema_stomp_old.py @@ -141,6 +141,6 @@ def package_name(self): return name @property - def submitter(self): - """The username of the person who submitted the build.""" + def _raw_submitter(self): + """The username of the person who submitted the build. May be namespaced.""" return self.body.get('submitter') diff --git a/messaging/copr_messaging/tests/test_schema.py b/messaging/copr_messaging/tests/test_schema.py index bad24f838..f353b11a1 100644 --- a/messaging/copr_messaging/tests/test_schema.py +++ b/messaging/copr_messaging/tests/test_schema.py @@ -112,6 +112,12 @@ def test_agent_name(self): message = self.msg_class(body=self.fedmsg_message["msg"]) assert message.agent_name == "churchyard" + def test_agent_name_namespaced(self): + body = copy.deepcopy(self.fedmsg_message["msg"]) + body["user"] = "github.com:churchyard" + message = self.msg_class(body=body) + assert message.agent_name is None + def test_usernames(self): message = self.msg_class(body=self.fedmsg_message["msg"]) assert message.usernames == ["churchyard"]