-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Weblate Fedora Messaging schema #364
Add Weblate Fedora Messaging schema #364
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #364 +/- ##
===========================================
- Coverage 100.00% 98.25% -1.75%
===========================================
Files 3 5 +2
Lines 43 172 +129
===========================================
+ Hits 43 169 +126
- Misses 0 3 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Looks good for the body schema, now we need to wrap it in Python classes (see https://fedora-messaging.readthedocs.io/en/stable/user-guide/messages.html). Maybe header schema will be needed as well (I didn't investigate that). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some kind of testing that the message classes work on the expected payload?
weblate_schemas/message.py
Outdated
return "https://weblate.org/static/weblate-128.png" | ||
|
||
|
||
class WeblateMessage(BaseMessage): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should include versioning to allow future changes:
class WeblateMessage(BaseMessage): | |
class WeblateV1Message(BaseMessage): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to have it for the initial message schema, but will need that for any updated message schema. The first one could be WeblateMessage
, but the changed one would need to be WeblateV2Message
. Still a good idea to have the versioning in from start.
Keep in mind that you only need to do that if you are removing something from the message schema, adding things doesn't break anything.
weblate_schemas/message.py
Outdated
"""Initialize the WeblateMessage class with loading of the body_schema.""" | ||
super().__init__(**kwargs) | ||
self.body_schema = load_schema("weblate-messaging.schema.json") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least summary
should also be present, based on https://pagure.io/fedora-infrastructure/issue/8291#comment-857387.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also recommend to add properties that are used by FMN as usernames
and packages
. See https://fedora-messaging.readthedocs.io/en/stable/user-guide/messages.html#example-schema
Also each Fedora application should have app_name
property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments for the schema
weblate_schemas/message.py
Outdated
return "https://weblate.org/static/weblate-128.png" | ||
|
||
|
||
class WeblateMessage(BaseMessage): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to have it for the initial message schema, but will need that for any updated message schema. The first one could be WeblateMessage
, but the changed one would need to be WeblateV2Message
. Still a good idea to have the versioning in from start.
Keep in mind that you only need to do that if you are removing something from the message schema, adding things doesn't break anything.
weblate_schemas/message.py
Outdated
"""Initialize the WeblateMessage class with loading of the body_schema.""" | ||
super().__init__(**kwargs) | ||
self.body_schema = load_schema("weblate-messaging.schema.json") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also recommend to add properties that are used by FMN as usernames
and packages
. See https://fedora-messaging.readthedocs.io/en/stable/user-guide/messages.html#example-schema
Also each Fedora application should have app_name
property.
f045c55
to
5b03512
Compare
Hi everyone, thank you for your comments. The latest commit contains the following changes:
|
requirements.txt
Outdated
@@ -1,4 +1,5 @@ | |||
fedora-messaging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an optional dependency, there is no need to require it for somebody wanting other schemas.
requirements.txt
Outdated
fqdn | ||
jsonschema | ||
jsonschema[format] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this belongs to requirements-test.txt
?
setup.py
Outdated
@@ -11,4 +11,13 @@ | |||
with open("requirements.txt") as handle: | |||
REQUIRES = list(handle.read().splitlines()) | |||
|
|||
setup(install_requires=REQUIRES) | |||
setup( | |||
name="weblate_schemas", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already present in setup.cfg
.
setup.py
Outdated
"base.message=weblate_schemas.messages:BaseMessage", | ||
"weblate.message=weblate_schemas.messages:WeblateV1Message", | ||
] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go to setup.cfg
.
setup.py
Outdated
name="weblate_schemas", | ||
entry_points={ | ||
"fedora.messages": [ | ||
"base.message=weblate_schemas.messages:BaseMessage", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please prefix the key here with weblate.
. The base.message
key is already used by Fedora Messaging
setup.py
Outdated
entry_points={ | ||
"fedora.messages": [ | ||
"base.message=weblate_schemas.messages:BaseMessage", | ||
"weblate.message=weblate_schemas.messages:WeblateV1Message", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend suffixing this key with .v1
, as it is the version 1 of the schema.
weblate_schemas/messages.py
Outdated
|
||
def __init__(self, **kwargs) -> None: | ||
"""Initialize BaseMessage class.""" | ||
super().__init__(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block is not necessary, no need to redefine __init__
if you're just calling the superclass.
weblate_schemas/messages.py
Outdated
return self.body["user"] | ||
|
||
@property | ||
def id(self) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The id
property is reserved by Fedora Messaging. You can use something like change_id
if you want.
weblate_schemas/messages.py
Outdated
def usernames(self): | ||
"""Return the usernames involved.""" | ||
users = {self.body["author"], self.body["user"]} | ||
return list(users) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make testing easier if the list is sorted alphabetically, but this is just a non-blocking suggestion.
weblate_schemas/messages.py
Outdated
|
||
def __str__(self) -> str: | ||
"""Return a human-readable representation of the message.""" | ||
return f"{self.action} {self.timestamp}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the string representation of the message is what is going to be in the email body when people ask to be notified of these messages in FMN. You may want to put a little more text there, but it's just a non-blocking suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harriebird Can we have this covered by the tests? It would be annoying if it would break.
@abompard action
is a human-readable description of the action, so that looks okay. But I'm not sure whether to include the timestamp here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you can put the timestamp there, it's really up to you. I would set something more human readable though, or just make it return self.summary
if you can't or don't want to have a longer text.
c19c1d5
to
d31bf35
Compare
d31bf35
to
b0b129e
Compare
Hi everyone, I just updated the code based on your comments. Below are the changes made:
|
weblate_schemas/messages.py
Outdated
@property | ||
def agent_name(self) -> str: | ||
"""The username who cause the action.""" | ||
return self.body.get("user", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no agent name, it should be None
, not an empty string
weblate_schemas/messages.py
Outdated
@property | ||
def change_id(self) -> int: | ||
"""Return the change ID.""" | ||
return self.body.get("change_id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the JSON schema, change_id
is required, you can be sure it'll always be there, so you can use self.body["change_id"]
. (just a suggestion, get()
will work too)
weblate_schemas/messages.py
Outdated
@property | ||
def action(self) -> str: | ||
"""Return the change verbose name.""" | ||
return self.body.get("action") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the JSON schema, action
is required, you can be sure it'll always be there, so you can use self.body["action"]
.
weblate_schemas/messages.py
Outdated
@property | ||
def timestamp(self) -> datetime: | ||
"""Return the timestamp of the change.""" | ||
return self.body.get("timestamp") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the JSON schema, timestamp
is required, you can be sure it'll always be there, so you can use self.body["timestamp"]
.
weblate_schemas/messages.py
Outdated
def summary(self) -> str: | ||
"""Return the message summary.""" | ||
return "{} event{} occurred in {}.".format( | ||
self.body.get("action"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark here. By the way, you can use self.action
: if you end up moving the data in the dictionary, you'll only have to update it in one place.
weblate_schemas/messages.py
Outdated
" done by {}".format(self.body.get("user")) | ||
if self.body.get("user", None) | ||
else "", | ||
self.body.get("timestamp"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark here
weblate_schemas/messages.py
Outdated
"""Return the usernames involved.""" | ||
users = [] | ||
users += [self.author] if self.author else [] | ||
users += [self.user] if self.user else [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or something like:
users = list(sorted({name for name in (self.author, self.user) if name}))
(just a suggestion, not a blocker)
It is useful to convert to a list in the end, because sorted()
returns an iterator, not an actual list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
bd73b1a
to
c866110
Compare
c866110
to
5a629b9
Compare
weblate_schemas/messages.py
Outdated
|
||
def __str__(self) -> str: | ||
"""Return a human-readable representation of the message.""" | ||
return f"{self.action} {self.timestamp}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harriebird Can we have this covered by the tests? It would be annoying if it would break.
@abompard action
is a human-readable description of the action, so that looks okay. But I'm not sure whether to include the timestamp here.
I've scheduled this for merge because I want to release this package soon anyway. In case we hit some issues later, those can be fixed in the next release. |
Proposed changes
This adds a new schema for Weblate Fedora Messaging.
This solves issue fedora_messaging#268.
Checklist
Other information