Use message agent value instead of checking for the latest comment

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ý <mkonecny@redhat.com>
This commit is contained in:
Michal Konečný 2022-07-21 18:35:56 +02:00
parent d23aa93424
commit 19f48a0b52
2 changed files with 16 additions and 16 deletions

View file

@ -100,9 +100,9 @@ class TestProcess:
caplog.records[-1].message == "The issue 100 is not open. Skipping message." 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) caplog.set_level(logging.INFO)
@ -112,7 +112,8 @@ class TestProcess:
msg = IssueCommentAddedV1() msg = IssueCommentAddedV1()
msg.body = { msg.body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE}, "project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": {"status": "Open", "comments": [{"user": {"name": pagure_user}}]}, "issue": {"status": "Open"},
"agent": pagure_user,
} }
with patch( with patch(
@ -124,7 +125,7 @@ class TestProcess:
assert caplog.records[ assert caplog.records[
-1 -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 pagure_user
) )
@ -142,6 +143,7 @@ class TestProcess:
msg.body = { msg.body = {
"project": {"fullname": scm_request_processor.PROJECT_NAMESPACE}, "project": {"fullname": scm_request_processor.PROJECT_NAMESPACE},
"issue": issue, "issue": issue,
"agent": "agent",
} }
config = { config = {
"branch_slas": {}, "branch_slas": {},

View file

@ -151,18 +151,6 @@ class SCMRequestProcessor(ToddlerBase):
) )
return 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.branch_slas = config.get("branch_slas", {})
self.monitoring_choices = config.get("monitor_choices", []) self.monitoring_choices = config.get("monitor_choices", [])
self.pagure_namespace_to_component = config.get( self.pagure_namespace_to_component = config.get(
@ -175,6 +163,16 @@ class SCMRequestProcessor(ToddlerBase):
self.ping_comment = config.get("ping_comment", "") self.ping_comment = config.get("ping_comment", "")
self.pagure_user = config.get("pagure_user", "") 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") _log.info("Setting up PDC client")
pdc.set_pdc(config) pdc.set_pdc(config)