diff --git a/tests/plugins/test_scm_request_processor.py b/tests/plugins/test_scm_request_processor.py index 547512b..c31f981 100644 --- a/tests/plugins/test_scm_request_processor.py +++ b/tests/plugins/test_scm_request_processor.py @@ -7,7 +7,7 @@ import re from unittest.mock import call, MagicMock, Mock, patch import arrow -from pagure_messages.issue_schema import IssueNewV1 +from pagure_messages.issue_schema import IssueCommentAddedV1, IssueNewV1 import pytest from toddlers.exceptions import ValidationError @@ -100,6 +100,34 @@ class TestProcess: caplog.records[-1].message == "The issue 100 is not open. Skipping message." ) + def test_process_comment_already_added(self, caplog, toddler): + """ + Assert that toddler will ignore comments that were already commented on by it. + """ + caplog.set_level(logging.INFO) + + pagure_user = "pagure_user" + config = {"pagure_user": pagure_user} + + msg = IssueCommentAddedV1() + msg.body = { + "project": {"fullname": scm_request_processor.PROJECT_NAMESPACE}, + "issue": {"status": "Open", "comments": [{"user": {"name": pagure_user}}]}, + } + + with patch( + "toddlers.plugins.scm_request_processor.SCMRequestProcessor.process_ticket" + ) as mock_process_ticket: + toddler.process(config, msg) + + mock_process_ticket.assert_not_called() + + assert caplog.records[ + -1 + ].message == "Last comment is from {0}. Ignoring the message.".format( + pagure_user + ) + @patch("toddlers.utils.pdc.set_pdc") @patch("toddlers.utils.pagure.set_pagure") @patch("toddlers.utils.fedora_account.set_fasjson") diff --git a/toddlers/plugins/scm_request_processor.py b/toddlers/plugins/scm_request_processor.py index dc0e9ab..4482e15 100644 --- a/toddlers/plugins/scm_request_processor.py +++ b/toddlers/plugins/scm_request_processor.py @@ -151,6 +151,18 @@ 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(