Skip to content

Commit

Permalink
feat: notify submitter if watchers are missing
Browse files Browse the repository at this point in the history
closes: #407
With this accompanying change to Landing https://gitlab.cee.redhat.com/perfscale-infra/landing/-/merge_requests/33
should users whose emails fail to mapped to Jira users on request for access be notfied otf that.
On extension and expansion requests, if we fail to add watchers from the parent ticket, we notify
the submitter of that request.

Change-Id: I57c33be716c7f0ee376ed56e0d1332b26a0b8b55
  • Loading branch information
dominikvagner committed Oct 14, 2022
1 parent e0367b5 commit 1af1897
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
9 changes: 9 additions & 0 deletions quads/templates/watchers_fail
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Hello,

This is a message to alert you that on a request you made for an extension or an expansions, we failed to add watchers
from the main request for Scale Lab access to this new sub-task JIRA ticket.
To add yourself as a watcher and potentially others, try to please do so manually, the aforementioned ticket: https://issues.redhat.com/browse/SCALELAB-{{ ticket }}

Thank you for your attention.

Perf/Scale DevOps Team
3 changes: 3 additions & 0 deletions quads/tools/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ async def get_pending_tickets(self):
query = {"statusCategory": 4, "labels": "EXTENSION"}
logger.debug("GET pending tickets")
result = await self.search_tickets(query)
query_expand = {"statusCategory": 4, "labels": "EXPANSION"}
result_expand = await self.search_tickets(query_expand)
result["issues"] += result_expand["issues"]
if not result:
logger.error("Failed to get pending tickets")
return None
Expand Down
55 changes: 38 additions & 17 deletions quads/tools/jira_watchers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/usr/bin/env python3
import asyncio
import logging
import os
import sys

from datetime import timedelta
from jinja2 import Template
from quads.config import Config
from quads.model import Cloud, Schedule
from quads.tools.jira import Jira, JiraException
from quads.tools.postman import Postman

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format="%(levelname)s - %(message)s")
Expand Down Expand Up @@ -39,30 +42,48 @@ async def main(_loop):
f"Could not retrieve cloud name from ticket {ticket_key}"
)

cloud_obj = Cloud.objects(name=cloud).first()
schedules = Schedule.current_schedule(cloud=cloud_obj)
conflict = False
for schedule in schedules:
end_date = schedule.end + timedelta(weeks=2)
available = Schedule.is_host_available(
host=schedule.host.name, start=schedule.end, end=end_date
)
if not available:
conflict = True
await jira.add_label(ticket_key, no_extend_label)
logger.info(f"{cloud} labeled {no_extend_label}")
break
if "EXTENSION" in fields.get("labels"):
cloud_obj = Cloud.objects(name=cloud).first()
schedules = Schedule.current_schedule(cloud=cloud_obj)
conflict = False
for schedule in schedules:
end_date = schedule.end + timedelta(weeks=2)
available = Schedule.is_host_available(
host=schedule.host.name, start=schedule.end, end=end_date
)
if not available:
conflict = True
await jira.add_label(ticket_key, no_extend_label)
logger.info(f"{cloud} labeled {no_extend_label}")
break

if not conflict:
await jira.add_label(ticket_key, extend_label)
logger.info(f"{cloud} labeled {extend_label}")
if not conflict:
await jira.add_label(ticket_key, extend_label)
logger.info(f"{cloud} labeled {extend_label}")

parent = fields.get("parent")
if parent:
p_ticket_key = parent.get("key").split("-")[-1]
watchers = await jira.get_watchers(p_ticket_key)
failed_watchers = []
for watcher in watchers["watchers"]:
await jira.add_watcher(ticket_key, watcher["key"])
response = await jira.add_watcher(ticket_key, watcher["key"])
if not response:
failed_watchers.append(watcher["key"])
if len(failed_watchers) != 0 and "WATCHERS_MAP_FAIL_NOTIFIED" not in fields.get("labels"):
await jira.add_label(ticket_key, "WATCHERS_MAP_FAIL_NOTIFIED")
template_file = "watchers_fail"
with open(os.path.join(Config.TEMPLATES_PATH, template_file)) as _file:
template = Template(_file.read())
submitter = description.split("\n")[0].split()[-1]
parameters = {
"ticket": ticket_key,
}
content = template.render(**parameters)
subject = "Failed to add watchers from parent ticket ticket to the sub-task."
postman = Postman(subject, submitter, "", content)
postman.send_email()

return 0


Expand Down

0 comments on commit 1af1897

Please sign in to comment.