Notify the maintainers even if issue already contains a comment
Ping the maintainers if there is no comment from toddler user present yet. This is a change from current behavior, when the comment was only done, when there was no comment on the issue altogether. Signed-off-by: Michal Konečný <mkonecny@redhat.com>
This commit is contained in:
parent
077a3f42a5
commit
401b425004
3 changed files with 93 additions and 18 deletions
|
@ -564,7 +564,13 @@ class TestCreateNewRepo:
|
||||||
issue = {
|
issue = {
|
||||||
"id": 100,
|
"id": 100,
|
||||||
"user": {"name": user},
|
"user": {"name": user},
|
||||||
"comments": [{"comment": "valid", "user": {"name": invalid_user}}],
|
"comments": [
|
||||||
|
{
|
||||||
|
"comment": "valid",
|
||||||
|
"user": {"name": invalid_user},
|
||||||
|
"notification": False,
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
repo = "repo"
|
repo = "repo"
|
||||||
|
@ -608,7 +614,9 @@ class TestCreateNewRepo:
|
||||||
issue = {
|
issue = {
|
||||||
"id": 100,
|
"id": 100,
|
||||||
"user": {"name": user},
|
"user": {"name": user},
|
||||||
"comments": [{"comment": "comment", "user": {"name": user}}],
|
"comments": [
|
||||||
|
{"comment": "comment", "user": {"name": user}, "notification": False}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
repo = "repo"
|
repo = "repo"
|
||||||
|
@ -687,6 +695,53 @@ class TestCreateNewRepo:
|
||||||
100, namespace=scm_request_processor.PROJECT_NAMESPACE, comment=message
|
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):
|
def test_create_new_repo_missing_bug_id(self):
|
||||||
"""
|
"""
|
||||||
Assert that ticket will be closed if Bugzilla bug id is not provided.
|
Assert that ticket will be closed if Bugzilla bug id is not provided.
|
||||||
|
@ -1054,7 +1109,9 @@ class TestCreateNewRepo:
|
||||||
issue = {
|
issue = {
|
||||||
"id": 100,
|
"id": 100,
|
||||||
"user": {"name": user},
|
"user": {"name": user},
|
||||||
"comments": [{"comment": "valid", "user": {"name": user}}],
|
"comments": [
|
||||||
|
{"comment": "valid", "user": {"name": user}, "notification": False}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
repo = "repo"
|
repo = "repo"
|
||||||
|
@ -1128,7 +1185,9 @@ class TestCreateNewRepo:
|
||||||
issue = {
|
issue = {
|
||||||
"id": 100,
|
"id": 100,
|
||||||
"user": {"name": user},
|
"user": {"name": user},
|
||||||
"comments": [{"comment": "valid", "user": {"name": user}}],
|
"comments": [
|
||||||
|
{"comment": "valid", "user": {"name": user}, "notification": False}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
repo = "repo"
|
repo = "repo"
|
||||||
|
|
|
@ -226,6 +226,8 @@ s390x = 's390x'
|
||||||
|
|
||||||
# Configuration section for scm_request_processor
|
# Configuration section for scm_request_processor
|
||||||
[consumer_config.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_url = "https://pagure.io"
|
||||||
pagure_api_key = "API token for pagure"
|
pagure_api_key = "API token for pagure"
|
||||||
# Monitoring choices for release-monitoring.org
|
# Monitoring choices for release-monitoring.org
|
||||||
|
|
|
@ -51,6 +51,7 @@ _log = logging.getLogger(__name__)
|
||||||
# When using this comment out the pdc.set_pdc line in process method
|
# When using this comment out the pdc.set_pdc line in process method
|
||||||
# from unittest.mock import Mock
|
# from unittest.mock import Mock
|
||||||
# pdc = Mock()
|
# pdc = Mock()
|
||||||
|
# pdc.get_branch.return_value = None
|
||||||
|
|
||||||
|
|
||||||
class SCMRequestProcessor(ToddlerBase):
|
class SCMRequestProcessor(ToddlerBase):
|
||||||
|
@ -100,6 +101,10 @@ class SCMRequestProcessor(ToddlerBase):
|
||||||
# Comment to sent when the ticket needs to be manually verified
|
# Comment to sent when the ticket needs to be manually verified
|
||||||
ping_comment: str = ""
|
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:
|
def accepts_topic(self, topic: str) -> bool:
|
||||||
"""Returns a boolean whether this toddler is interested in messages
|
"""Returns a boolean whether this toddler is interested in messages
|
||||||
from this specific topic.
|
from this specific topic.
|
||||||
|
@ -147,7 +152,7 @@ class SCMRequestProcessor(ToddlerBase):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.branch_slas = config.get("branch_slas", {})
|
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(
|
self.pagure_namespace_to_component = config.get(
|
||||||
"pagure_namespace_to_component", {}
|
"pagure_namespace_to_component", {}
|
||||||
)
|
)
|
||||||
|
@ -156,6 +161,7 @@ class SCMRequestProcessor(ToddlerBase):
|
||||||
self.requests_session = requests.make_session()
|
self.requests_session = requests.make_session()
|
||||||
self.validation_comment = config.get("validation_comment", "")
|
self.validation_comment = config.get("validation_comment", "")
|
||||||
self.ping_comment = config.get("ping_comment", "")
|
self.ping_comment = config.get("ping_comment", "")
|
||||||
|
self.pagure_user = config.get("pagure_user", "")
|
||||||
|
|
||||||
_log.info("Setting up PDC client")
|
_log.info("Setting up PDC client")
|
||||||
pdc.set_pdc(config)
|
pdc.set_pdc(config)
|
||||||
|
@ -408,26 +414,34 @@ class SCMRequestProcessor(ToddlerBase):
|
||||||
| set(contributors["users"]["commit"])
|
| set(contributors["users"]["commit"])
|
||||||
| set(contributors["users"]["ticket"])
|
| 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
|
# 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:
|
if len(issue["comments"]) > 0:
|
||||||
valid = False
|
|
||||||
_log.info("- Check for validation comment")
|
_log.info("- Check for validation comment")
|
||||||
for comment in issue["comments"]:
|
for comment in issue["comments"]:
|
||||||
if comment["comment"].strip() == self.validation_comment:
|
# Skip the notification comments
|
||||||
if comment["user"]["name"] in maintainers:
|
if not comment["notification"]:
|
||||||
_log.info(
|
if comment["comment"].strip() == self.validation_comment:
|
||||||
"- Ticket is validated by {}, continue processing".format(
|
if comment["user"]["name"] in maintainers:
|
||||||
comment["user"]["name"]
|
_log.info(
|
||||||
|
"- Ticket is validated by {}, continue processing".format(
|
||||||
|
comment["user"]["name"]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
valid = True
|
||||||
valid = True
|
# Toddler already commented on the ticket
|
||||||
break
|
if comment["user"]["name"] == self.pagure_user:
|
||||||
if not valid:
|
ping_comment = False
|
||||||
|
if not valid and not ping_comment:
|
||||||
_log.info("- Ticket is not yet validated. Skipping...")
|
_log.info("- Ticket is not yet validated. Skipping...")
|
||||||
return
|
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")
|
_log.info("- Notify the responsible users")
|
||||||
self.pagure_io.add_comment_to_issue(
|
self.pagure_io.add_comment_to_issue(
|
||||||
issue["id"],
|
issue["id"],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue