Skip to content

Commit

Permalink
Handle namespaced usernames
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard authored and praiskup committed Jan 18, 2024
1 parent 4cdae56 commit b88b7bd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions messaging/copr_messaging/private/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions messaging/copr_messaging/private/schema_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions messaging/copr_messaging/private/schema_stomp_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
6 changes: 6 additions & 0 deletions messaging/copr_messaging/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit b88b7bd

Please sign in to comment.