Skip to content

Commit

Permalink
Messaging: Set the agent_name and usernames properties
Browse files Browse the repository at this point in the history
This sets a couple properties that are standard in Fedora Messaging schemas
and will allow notifications to be emitted by FMN.

Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Jan 12, 2024
1 parent e174d37 commit 7b2f173
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions messaging/copr_messaging/private/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ def package_full_name(self):
release=release,
)

@property
def usernames(self):
"""
List of usernames that are affected by the action that caused this message.
Those users will be notified by FMN if they chose to receive their notifications.
"""
usernames = [self.submitter, self.body.get("owner")]
# filter out nones and groups and deduplicate
usernames = set(u for u in usernames if isinstance(u, str) and not u.startswith("@"))
# return it sorted
return list(sorted(usernames))


class _BuildChrootMessage(_BuildMessage):
@property
Expand Down
5 changes: 5 additions & 0 deletions messaging/copr_messaging/private/schema_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ def status(self):
def package_name(self):
return self.body.get('pkg')

@property
def submitter(self):
"""The username of the person who submitted the build."""
return self.body.get('user')

def _evr(self):
evr = self.body.get('version')
if not evr:
Expand Down
5 changes: 5 additions & 0 deletions messaging/copr_messaging/private/schema_stomp_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ def _evr(self):
def package_name(self):
name, _, _, _ = self._nevr()
return name

@property
def submitter(self):
"""The username of the person who submitted the build."""
return self.body.get('submitter')
13 changes: 13 additions & 0 deletions messaging/copr_messaging/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def __str__(self):
self.status,
)

@property
def agent_name(self):
"""The username who caused the action that generated this message."""
if self.status == "canceled":
return self.submitter
# The other statuses are not caused by the user who started the build
return None


class BuildChrootStarted(_BuildChrootMessage):
"""
Expand All @@ -58,6 +66,11 @@ def __str__(self):
self.chroot,
)

@property
def agent_name(self):
"""The username who caused the action that generated this message."""
return self.submitter


class BuildChrootStartedV1(_PreFMBuildMessage, BuildChrootStarted):
"""
Expand Down
30 changes: 30 additions & 0 deletions messaging/copr_messaging/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def test_nevr(self):
assert message.package_release == '1.fc31'
assert message.package_epoch is None

def test_agent_name(self):
message = self.msg_class(body=self.fedmsg_message["msg"])
assert message.agent_name == "churchyard"

def test_usernames(self):
message = self.msg_class(body=self.fedmsg_message["msg"])
assert message.usernames == ["churchyard"]


class BuildChrootEndedV1Test(BuildChrootStartedV1Test):
msg_class = schema.BuildChrootEndedV1
Expand Down Expand Up @@ -150,6 +158,20 @@ def test_nevr(self):
assert message.package_release == '1.fc30'
assert message.package_epoch is None

def test_agent_name(self):
message = self.msg_class(body=self.fedmsg_message["msg"])
assert message.agent_name is None

def test_agent_name_canceled(self):
body = copy.deepcopy(self.fedmsg_message["msg"])
body["status"] = 2
message = self.msg_class(body=body)
assert message.agent_name == "kbaig"

def test_usernames(self):
message = self.msg_class(body=self.fedmsg_message["msg"])
assert message.usernames == ["kbaig"]


class BuildChrootStartedV1DontUseTest(BuildChrootStartedV1Test):
msg_class = schema.BuildChrootStartedV1DontUse
Expand Down Expand Up @@ -192,6 +214,14 @@ def test_nevr(self):
assert message.package_release == "0"
assert message.package_epoch == '10'

def test_agent_name(self):
message = self.msg_class(body=self.fedmsg_message["msg"])
assert message.agent_name == "praiskup"

def test_usernames(self):
message = self.msg_class(body=self.fedmsg_message["msg"])
assert message.usernames == ["praiskup"]


class BuildChrootStompOldStartTest(unittest.TestCase):
msg_class = schema.BuildChrootStartedV1Stomp
Expand Down

0 comments on commit 7b2f173

Please sign in to comment.