Skip to content

Commit

Permalink
Ensures incident task assignees are up to date (#1420)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvilanova authored Jul 10, 2021
1 parent bfcf2df commit cacdb11
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/dispatch/plugins/dispatch_google/drive/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:copyright: (c) 2019 by Netflix Inc., see AUTHORS for more
:license: Apache, see LICENSE for more details.
.. moduleauthor:: Kevin Glisson <[email protected]>
.. moduleauthor:: Marc Vilanova <[email protected]>
"""
import re
import logging
Expand All @@ -17,16 +18,21 @@
log = logging.getLogger(__name__)


def get_assignees(content: str) -> List[str]:
def get_assignees(comment: Dict) -> List[str]:
"""Gets assignees from comment."""
regex = r"[+@]([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"

content = comment["content"]
if comment.get("replies"):
content = comment["replies"][-1]["content"]

matches = re.findall(regex, content)
return list(matches)


def parse_comment(content: str) -> Dict:
"""Parses a comment into it's various parts."""
assignees = get_assignees(content)
def parse_comment(comment: Dict) -> Dict:
"""Parses a comment's content into its various parts."""
assignees = get_assignees(comment)
return {"assignees": assignees}


Expand All @@ -46,7 +52,7 @@ def get_task_status(task: dict):

def filter_comments(comments: List[Any]):
"""Filters comments for tasks."""
return [c for c in comments if parse_comment(c["content"])["assignees"]]
return [c for c in comments if parse_comment(c)["assignees"]]


def find_urls(text: str) -> List[str]:
Expand Down Expand Up @@ -82,7 +88,7 @@ def list_tasks(client: Any, file_id: str):
tasks = []
for t in task_comments:
status = get_task_status(t)
assignees = [{"individual": {"email": x}} for x in get_assignees(t["content"])]
assignees = [{"individual": {"email": x}} for x in get_assignees(t)]
description = t.get("quotedFileContent", {}).get("value", "")
tickets = get_tickets(t["replies"])

Expand Down

0 comments on commit cacdb11

Please sign in to comment.