From 19f48a0b52d30c3c0a2bf64d50db053193217c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kone=C4=8Dn=C3=BD?= Date: Thu, 21 Jul 2022 18:35:56 +0200 Subject: [PATCH] Use message agent value instead of checking for the latest comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The latest comment seems to be unreliable. We should use agent itself, this will skip all the messages that were generated by toddler itself. Signed-off-by: Michal Konečný --- tests/plugins/test_scm_request_processor.py | 10 ++++++---- toddlers/plugins/scm_request_processor.py | 22 ++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/plugins/test_scm_request_processor.py b/tests/plugins/test_scm_request_processor.py index c31f981..2d905d0 100644 --- a/tests/plugins/test_scm_request_processor.py +++ b/tests/plugins/test_scm_request_processor.py @@ -100,9 +100,9 @@ class TestProcess: caplog.records[-1].message == "The issue 100 is not open. Skipping message." ) - def test_process_comment_already_added(self, caplog, toddler): + def test_process_change_done_by_toddler(self, caplog, toddler): """ - Assert that toddler will ignore comments that were already commented on by it. + Assert that toddler will ignore messages that were emitted by it. """ caplog.set_level(logging.INFO) @@ -112,7 +112,8 @@ class TestProcess: msg = IssueCommentAddedV1() msg.body = { "project": {"fullname": scm_request_processor.PROJECT_NAMESPACE}, - "issue": {"status": "Open", "comments": [{"user": {"name": pagure_user}}]}, + "issue": {"status": "Open"}, + "agent": pagure_user, } with patch( @@ -124,7 +125,7 @@ class TestProcess: assert caplog.records[ -1 - ].message == "Last comment is from {0}. Ignoring the message.".format( + ].message == "Last change on the ticket was done by {0}. Ignoring the message.".format( pagure_user ) @@ -142,6 +143,7 @@ class TestProcess: msg.body = { "project": {"fullname": scm_request_processor.PROJECT_NAMESPACE}, "issue": issue, + "agent": "agent", } config = { "branch_slas": {}, diff --git a/toddlers/plugins/scm_request_processor.py b/toddlers/plugins/scm_request_processor.py index 4482e15..09cdec6 100644 --- a/toddlers/plugins/scm_request_processor.py +++ b/toddlers/plugins/scm_request_processor.py @@ -151,18 +151,6 @@ class SCMRequestProcessor(ToddlerBase): ) return - # Check if the latest comment isn't from the toddler - # Ignore the ticket if it is - if message.topic.endswith("comment.added"): - if len(issue["comments"]) > 0: - if issue["comments"][-1]["user"]["name"] == config.get("pagure_user"): - _log.info( - "Last comment is from {0}. Ignoring the message.".format( - config.get("pagure_user") - ) - ) - return - self.branch_slas = config.get("branch_slas", {}) self.monitoring_choices = config.get("monitor_choices", []) self.pagure_namespace_to_component = config.get( @@ -175,6 +163,16 @@ class SCMRequestProcessor(ToddlerBase): self.ping_comment = config.get("ping_comment", "") self.pagure_user = config.get("pagure_user", "") + # Check if the message isn't generated by toddler user + # Ignore the ticket if it is + if message.body["agent"] == self.pagure_user: + _log.info( + "Last change on the ticket was done by {0}. Ignoring the message.".format( + self.pagure_user + ) + ) + return + _log.info("Setting up PDC client") pdc.set_pdc(config)