Skip to content
Permalink
Browse files
[hotfix] pull up logic to handle stale tickets
  • Loading branch information
knaufk committed Apr 22, 2021
1 parent b342cb2 commit a6002490ef50be5f4b3c103ba80db0d90d307c97
Showing 4 changed files with 44 additions and 81 deletions.
@@ -114,6 +114,10 @@ def set_priority(self, key, priority):
def run(self):
return

@abc.abstractmethod
def handle_stale_ticket(self, key):
return

def mark_stale_tickets_stale(self, jql_query):

logging.info(f"Looking for stale tickets.")
@@ -141,3 +145,23 @@ def mark_stale_tickets_stale(self, jql_query):
f"Found https://issues.apache.org/jira/browse/{key}, but is has recently updated Subtasks. "
f"Ignoring for now."
)

def handle_tickets_marked_stale(self, jql_query):
logging.info(f"Looking for ticket previously marked as {self.warning_label}.")
issues = self.get_issues(jql_query)

for issue in issues:
key = issue["key"]
logging.info(
f"Found https://issues.apache.org/jira/browse/{key}. It is now processed as stale."
)

formatted_comment = self.done_comment.format(
warning_days=self.warning_days,
warning_label=self.warning_label,
done_label=self.done_label,
)

self.add_comment(key, formatted_comment)
self.replace_label(issue, self.warning_label, self.done_label)
self.handle_stale_ticket(key)
@@ -32,35 +32,14 @@ def __init__(self, jira_client, config, is_dry_run):
super().__init__(jira_client, config, is_dry_run)

def run(self):
self.unassign_tickets_marked_stale()
self.mark_stale_tickets_stale(
f"project = FLINK AND resolution = Unresolved AND assignee is not EMPTY "
f"AND updated < startOfDay(-{self.stale_days}d)"
)

def unassign_tickets_marked_stale(self):

assigned_tickets_marked_stale = (
self.handle_tickets_marked_stale(
f"project=FLINK AND resolution = Unresolved AND labels in "
f'("{self.warning_label}") AND updated < startOfDay(-{self.warning_days}d)'
)
logging.info(
f"Looking for assigned tickets, which were previously marked as {self.warning_label}."
self.mark_stale_tickets_stale(
f"project = FLINK AND resolution = Unresolved AND assignee is not EMPTY "
f"AND updated < startOfDay(-{self.stale_days}d)"
)
issues = self.get_issues(assigned_tickets_marked_stale)

for issue in issues:
key = issue["key"]
logging.info(
f"Found https://issues.apache.org/jira/browse/{key}. It is now unassigned due to inactivity."
)

formatted_comment = self.done_comment.format(
warning_days=self.warning_days,
warning_label=self.warning_label,
done_label=self.done_label,
)

self.add_comment(key, formatted_comment)
self.replace_label(issue, self.warning_label, self.done_label)
self.unassign(key)
def handle_stale_ticket(self, key):
self.unassign(key)
@@ -38,35 +38,15 @@ def __init__(self, jira_client, config, is_dry_run, priority):
LOWER_PRIORITIES = {"Blocker": "Critical", "Critical": "Major", "Major": "Minor"}

def run(self):
self.close_tickets_marked_stale()
self.handle_tickets_marked_stale(
f"project=FLINK AND Priority = {self.priority} AND resolution = Unresolved "
f'AND labels in ("{self.warning_label}") '
f"AND updated < startOfDay(-{self.warning_days}d)"
)
self.mark_stale_tickets_stale(
f"project=FLINK AND priority = {self.priority} AND resolution = Unresolved "
f"AND assignee is empty AND updated < startOfDay(-{self.stale_days}d)"
)

def close_tickets_marked_stale(self):

tickets_marked_stale = (
f"project=FLINK AND Priority = {self.priority} AND resolution = Unresolved AND labels in "
f'("{self.warning_label}") AND updated < startOfDay(-{self.warning_days}d)'
)
logging.info(
f"Looking for {self.priority} tickets, which were previously marked as {self.warning_label}."
)
issues = self.get_issues(tickets_marked_stale)

for issue in issues:
key = issue["key"]
logging.info(
f"Found https://issues.apache.org/jira/browse/{key}. It is now deprioritized due to inactivity."
)

formatted_comment = self.done_comment.format(
warning_days=self.warning_days,
warning_label=self.warning_label,
done_label=self.done_label,
)

self.add_comment(key, formatted_comment)
self.replace_label(issue, self.warning_label, self.done_label)
self.set_priority(key, self.LOWER_PRIORITIES[self.priority])
def handle_stale_ticket(self, key):
self.set_priority(key, self.LOWER_PRIORITIES[self.priority])
@@ -32,35 +32,15 @@ def __init__(self, jira_client, config, is_dry_run):
super().__init__(jira_client, config, is_dry_run)

def run(self):
self.close_tickets_marked_stale()
self.handle_tickets_marked_stale(
f"project=FLINK AND Priority = Minor AND resolution = Unresolved "
f'AND labels in ("{self.warning_label}") '
f"AND updated < startOfDay(-{self.warning_days}d)"
)
self.mark_stale_tickets_stale(
f"project = FLINK AND Priority = Minor AND resolution = Unresolved "
f"AND updated < startOfDay(-{self.stale_days}d)"
)

def close_tickets_marked_stale(self):

minor_tickets_marked_stale = (
f"project=FLINK AND Priority = Minor AND resolution = Unresolved AND labels in "
f'("{self.warning_label}") AND updated < startOfDay(-{self.warning_days}d)'
)
logging.info(
f"Looking for minor tickets, which were previously marked as {self.warning_label}."
)
issues = self.get_issues(minor_tickets_marked_stale)

for issue in issues:
key = issue["key"]
logging.info(
f"Found https://issues.apache.org/jira/browse/{key}. It is now closed due to inactivity."
)

formatted_comment = self.done_comment.format(
warning_days=self.warning_days,
warning_label=self.warning_label,
done_label=self.done_label,
)

self.add_comment(key, formatted_comment)
self.replace_label(issue, self.warning_label, self.done_label)
self.close_issue(key)
def handle_stale_ticket(self, key):
self.close_issue(key)

0 comments on commit a600249

Please sign in to comment.