Skip to content

Commit

Permalink
Change configuration schema for failure comment
Browse files Browse the repository at this point in the history
Instead of having one value failure_comment_message, create a nested one
failure_comment.message so that failure_comment can be extended in the future
if needed. Related to packit/packit-service#1911
  • Loading branch information
lbarcziova committed Sep 12, 2023
1 parent 4296109 commit c763a0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
11 changes: 9 additions & 2 deletions packit/config/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ def __init__(self, successful_build: bool = False):
self.successful_build = successful_build


class FailureCommentNotificationsConfig:
"""Configuration of the failure comment."""

def __init__(self, message: Optional[str] = None):
self.message = message


class NotificationsConfig:
"""Configuration of notifications."""

def __init__(
self,
pull_request: Optional[PullRequestNotificationsConfig] = None,
failure_comment_message: Optional[str] = None,
failure_comment: Optional[FailureCommentNotificationsConfig] = None,
):
self.pull_request = pull_request or PullRequestNotificationsConfig()
self.failure_comment_message = failure_comment_message
self.failure_comment = failure_comment or FailureCommentNotificationsConfig()
17 changes: 15 additions & 2 deletions packit/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
JobConfigTriggerType,
get_default_jobs,
)
from packit.config.notifications import NotificationsConfig
from packit.config.notifications import (
NotificationsConfig,
FailureCommentNotificationsConfig,
)
from packit.config.notifications import PullRequestNotificationsConfig
from packit.config.sources import SourcesItem
from packit.constants import CHROOT_SPECIFIC_COPR_CONFIGURATION
Expand Down Expand Up @@ -174,11 +177,21 @@ def make_instance(self, data, **kwargs):
return PullRequestNotificationsConfig(**data)


class FailureCommentNotificationsSchema(Schema):
"""Configuration of commenting on failures."""

message = fields.String(missing=None)

@post_load
def make_instance(self, data, **kwargs):
return FailureCommentNotificationsConfig(**data)


class NotificationsSchema(Schema):
"""Configuration of notifications."""

pull_request = fields.Nested(PullRequestNotificationsSchema)
failure_comment_message = fields.String(missing=None)
failure_comment = fields.Nested(FailureCommentNotificationsSchema)

@post_load
def make_instance(self, data, **kwargs):
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/config/test_package_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def test_package_config_not_equal(not_equal_package_config):
"specfile_path": "fedora/package.spec",
"notifications": {
"pull_request": {"successful_build": False},
"failure_comment_message": "my comment",
"failure_comment": {"message": "my comment"},
},
},
True,
Expand All @@ -502,7 +502,7 @@ def test_package_config_not_equal(not_equal_package_config):
{
"downstream_package_name": "package",
"specfile_path": "fedora/package.spec",
"notifications": {"failure_comment_message": "my comment"},
"notifications": {"failure_comment": {"message": "my comment"}},
},
True,
),
Expand Down Expand Up @@ -1695,20 +1695,20 @@ def test_notifications_section():
{"specfile_path": "package.spec"}, repo_name="package"
)
assert not pc.notifications.pull_request.successful_build
assert pc.notifications.failure_comment_message is None
assert pc.notifications.failure_comment.message is None


def test_notifications_section_failure_comment_message():
message = "my message"
pc = PackageConfig.get_from_dict(
{
"specfile_path": "package.spec",
"notifications": {"failure_comment_message": message},
"notifications": {"failure_comment": {"message": message}},
},
repo_name="package",
)
assert not pc.notifications.pull_request.successful_build
assert pc.notifications.failure_comment_message == message
assert pc.notifications.failure_comment.message == message


def test_get_local_specfile_path():
Expand Down

0 comments on commit c763a0c

Please sign in to comment.