diff --git a/tests/plugins/test_scm_request_processor.py b/tests/plugins/test_scm_request_processor.py index 7f1273e..4b8d13f 100644 --- a/tests/plugins/test_scm_request_processor.py +++ b/tests/plugins/test_scm_request_processor.py @@ -564,7 +564,13 @@ class TestCreateNewRepo: issue = { "id": 100, "user": {"name": user}, - "comments": [{"comment": "valid", "user": {"name": invalid_user}}], + "comments": [ + { + "comment": "valid", + "user": {"name": invalid_user}, + "notification": False, + } + ], } repo = "repo" @@ -608,7 +614,9 @@ class TestCreateNewRepo: issue = { "id": 100, "user": {"name": user}, - "comments": [{"comment": "comment", "user": {"name": user}}], + "comments": [ + {"comment": "comment", "user": {"name": user}, "notification": False} + ], } repo = "repo" @@ -687,6 +695,53 @@ class TestCreateNewRepo: 100, namespace=scm_request_processor.PROJECT_NAMESPACE, comment=message ) + def test_create_new_repo_exception_not_valid_notification_comment_present(self): + """ + Assert that comment will not be added if the toddler already commented on the + ticket. + """ + # Preparation + user = "zlopez" + issue = { + "id": 100, + "user": {"name": user}, + "comments": [ + {"comment": "comment", "user": {"name": user}, "notification": False} + ], + } + + repo = "repo" + branch = "main" + namespace = "tests" + bug_id = "" + action = "new_repo" + sls = {branch: "2050-06-01"} + monitor = "monitor" + exception = False + json = { + "repo": repo, + "branch": branch, + "namespace": namespace, + "bug_id": bug_id, + "action": action, + "sls": sls, + "monitor": monitor, + "exception": exception, + } + self.toddler.pagure_io.get_project_contributors.return_value = { + "users": {"admin": ["Tzeentch"], "commit": [], "ticket": []} + } + self.toddler.pagure_user = user + self.toddler.create_new_repo(issue, json) + + # asserts + self.toddler.pagure_io.get_project_contributors.assert_called_with( + scm_request_processor.PROJECT_NAMESPACE.split("/")[0], + scm_request_processor.PROJECT_NAMESPACE.split("/")[1], + ) + + self.toddler.pagure_io.add_comment_to_issue.assert_not_called() + def test_create_new_repo_missing_bug_id(self): """ Assert that ticket will be closed if Bugzilla bug id is not provided. @@ -1054,7 +1109,9 @@ class TestCreateNewRepo: issue = { "id": 100, "user": {"name": user}, - "comments": [{"comment": "valid", "user": {"name": user}}], + "comments": [ + {"comment": "valid", "user": {"name": user}, "notification": False} + ], } repo = "repo" @@ -1128,7 +1185,9 @@ class TestCreateNewRepo: issue = { "id": 100, "user": {"name": user}, - "comments": [{"comment": "valid", "user": {"name": user}}], + "comments": [ + {"comment": "valid", "user": {"name": user}, "notification": False} + ], } repo = "repo" diff --git a/toddlers.toml.example b/toddlers.toml.example index c5a4f00..05b5af0 100644 --- a/toddlers.toml.example +++ b/toddlers.toml.example @@ -226,6 +226,8 @@ s390x = 's390x' # Configuration section for scm_request_processor [consumer_config.scm_request_processor] +# FAS username of the user that will comment on behalf of toddler +pagure_user = "username" pagure_url = "https://pagure.io" pagure_api_key = "API token for pagure" # Monitoring choices for release-monitoring.org diff --git a/toddlers/plugins/scm_request_processor.py b/toddlers/plugins/scm_request_processor.py index 048d8c7..4264363 100644 --- a/toddlers/plugins/scm_request_processor.py +++ b/toddlers/plugins/scm_request_processor.py @@ -51,6 +51,7 @@ _log = logging.getLogger(__name__) # When using this comment out the pdc.set_pdc line in process method # from unittest.mock import Mock # pdc = Mock() +# pdc.get_branch.return_value = None class SCMRequestProcessor(ToddlerBase): @@ -100,6 +101,10 @@ class SCMRequestProcessor(ToddlerBase): # Comment to sent when the ticket needs to be manually verified ping_comment: str = "" + # Pagure user that will be creating the comments on pagure + # for toddler + pagure_user: str = "" + def accepts_topic(self, topic: str) -> bool: """Returns a boolean whether this toddler is interested in messages from this specific topic. @@ -147,7 +152,7 @@ class SCMRequestProcessor(ToddlerBase): return self.branch_slas = config.get("branch_slas", {}) - self.monitoring_choices = config.get("monitoring_choices", []) + self.monitoring_choices = config.get("monitor_choices", []) self.pagure_namespace_to_component = config.get( "pagure_namespace_to_component", {} ) @@ -156,6 +161,7 @@ class SCMRequestProcessor(ToddlerBase): self.requests_session = requests.make_session() self.validation_comment = config.get("validation_comment", "") self.ping_comment = config.get("ping_comment", "") + self.pagure_user = config.get("pagure_user", "") _log.info("Setting up PDC client") pdc.set_pdc(config) @@ -408,26 +414,34 @@ class SCMRequestProcessor(ToddlerBase): | set(contributors["users"]["commit"]) | set(contributors["users"]["ticket"]) ) + # Ping the maintainers if toddler didn't comment on the ticket yet + ping_comment = True + # This is set to true if the validation comment is set by maintainer + valid = False # There is already a comment on this ticket, we should check if this is - # the validation ticket + # the validation ticket and if we already responded to the ticket if len(issue["comments"]) > 0: - valid = False _log.info("- Check for validation comment") for comment in issue["comments"]: - if comment["comment"].strip() == self.validation_comment: - if comment["user"]["name"] in maintainers: - _log.info( - "- Ticket is validated by {}, continue processing".format( - comment["user"]["name"] + # Skip the notification comments + if not comment["notification"]: + if comment["comment"].strip() == self.validation_comment: + if comment["user"]["name"] in maintainers: + _log.info( + "- Ticket is validated by {}, continue processing".format( + comment["user"]["name"] + ) ) - ) - valid = True - break - if not valid: + valid = True + # Toddler already commented on the ticket + if comment["user"]["name"] == self.pagure_user: + ping_comment = False + if not valid and not ping_comment: _log.info("- Ticket is not yet validated. Skipping...") return - # No comment on the ticket yet, the maintainers should be pinged - else: + + # We didn't commented on the ticket yet, ping the maintainers + if ping_comment and not valid: _log.info("- Notify the responsible users") self.pagure_io.add_comment_to_issue( issue["id"],