Skip to content

Commit

Permalink
initial messages implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Lerch <[email protected]>
  • Loading branch information
ryanlerch committed Mar 18, 2024
1 parent c1a6d70 commit 645d42f
Show file tree
Hide file tree
Showing 9 changed files with 1,745 additions and 159 deletions.
232 changes: 232 additions & 0 deletions LICENSES/GPL-3.0-or-later.txt

Large diffs are not rendered by default.

190 changes: 189 additions & 1 deletion kerneltest_messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,192 @@
#
# SPDX-License-Identifier: LGPL-3.0-or-later

from .thing import NewThingV1
import typing

from fedora_messaging import message

TEST_SCHEMA = {
"type": "object",
"properties": {
"arch": {"type": "string"},
"authenticated": {"type": "boolean"},
"failed_tests": {"type": "string"},
"fedora_version": {"type": "string"},
"kernel_version": {"type": "string"},
"release": {"type": "string"},
"result": {"type": "string"},
"testdate": {"type": "string"},
"tester": {"type": "string"},
"testset": {"type": "string"},
},
"required": ["kernel_version"],
}

RELEASE_SCHEMA = {
"type": "object",
"properties": {
"support": {"type": "string"},
"release_num": {"type": "string"},
},
"required": ["support", "release_num"],
}


class KerneltestMessage(message.Message):
@property
def app_name(self):
"""
Return the name of the application that generated the message.
Returns:
the name of the application (kerneltest)
"""
return "kerneltest"

@property
def app_icon(self):
return "https://apps.fedoraproject.org/img/icons/kerneltest.png"

@property
def agent_name(self):
"""Return the agent's username for this message.
Returns:
The agent's username
"""
return self.body.get("agent")

@property
def usernames(self):
"""
List of users affected by the action that generated this message.
Returns:
A list of affected usernames.
"""
return []

@property
def groups(self):
"""
List of groups affected by the action that generated this message.
Returns:
A list of affected groups.
"""
return []

@property
def url(self):
return None

def __str__(self):
"""
Return a human-readable representation of this message.
This should provide a detailed representation of the message, much like the body
of an email.
Returns:
A human readable representation of this message.
"""
return self.summary


class UploadNewV1(KerneltestMessage):
"""The message sent when a user uploads a new kerneltest"""

@property
def summary(self):
"""
Return a short, human-readable representation of this message.
This should provide a short summary of the message, much like the subject line
of an email.
Returns:
A summary for this message.
"""
return (
f"{self.agent_name} uploaded new kernel test results for "
f"{self.body['test']['kernel_version']}"
)

topic = "kerneltest.upload.new"
body_schema: typing.ClassVar = {
"id": "http://fedoraproject.org/message-schema/noggin",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "The message sent when a user uploads a new kernel test report",
"type": "object",
"required": ["agent", "test"],
"properties": {
"test": TEST_SCHEMA,
"agent": {"type": "string"},
},
}


class ReleaseNewV1(KerneltestMessage):
"""The message sent when an admin creates a new release"""

@property
def summary(self):
"""
Return a short, human-readable representation of this message.
This should provide a short summary of the message, much like the subject line
of an email.
Returns:
A summary for this message.
"""
return (
f"{self.agent_name} created a new release {self.body['release']['release_num']}"
f" with status {self.body['release']['support']}"
)

topic = "kerneltest.release.new"
body_schema: typing.ClassVar = {
"id": "http://fedoraproject.org/message-schema/noggin",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "The message sent when an admin creates a new release",
"type": "object",
"required": ["agent", "release"],
"properties": {
"release": RELEASE_SCHEMA,
"agent": {"type": "string"},
},
}


class ReleaseEditV1(KerneltestMessage):
"""The message sent when an admin creates a new release"""

@property
def summary(self):
"""
Return a short, human-readable representation of this message.
This should provide a short summary of the message, much like the subject line
of an email.
Returns:
A summary for this message.
"""
return (
f"{self.agent_name} edited release {self.body['release']['release_num']}"
f" with status {self.body['release']['support']}"
)

topic = "kerneltest.release.edit"
body_schema: typing.ClassVar = {
"id": "http://fedoraproject.org/message-schema/noggin",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "The message sent when an admin edits a release",
"type": "object",
"required": ["agent", "release"],
"properties": {
"release": RELEASE_SCHEMA,
"agent": {"type": "string"},
},
}
77 changes: 0 additions & 77 deletions kerneltest_messages/base.py

This file was deleted.

39 changes: 0 additions & 39 deletions kerneltest_messages/thing.py

This file was deleted.

Loading

0 comments on commit 645d42f

Please sign in to comment.