From 803cc3e2f58f6583c301717767af00851f7b9326 Mon Sep 17 00:00:00 2001 From: Oleksii Date: Thu, 18 Apr 2019 20:04:50 +0300 Subject: [PATCH] If the issue can't be closed, try to resolve and then close Vulnerability that is In Progress state can not be directly closed. But it is posible to resolve and then close. --- hammer/library/jiraoperations.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/hammer/library/jiraoperations.py b/hammer/library/jiraoperations.py index cc71c00e..828f7a80 100755 --- a/hammer/library/jiraoperations.py +++ b/hammer/library/jiraoperations.py @@ -338,6 +338,13 @@ def add_watcher(self, ticket_id, user): self.session.add_watcher(ticket_id, user) + def move_to_state(self, issue, transition_name): + for transition in self.session.transitions(issue): + if transition['name'] == transition_name: + self.session.transition_issue(issue.key, transition['id']) + return True + return False + def close_issue(self, ticket_id): """ Transition of ticket to `Closed` state. It checks if issue can be transitioned to `Closed` state. @@ -353,15 +360,15 @@ def close_issue(self, ticket_id): if issue.fields.status.name == "Closed": logging.debug(f"{ticket_id} is already closed") return - - for transition in self.session.transitions(issue): - if transition['name'] == 'Close Issue': - self.session.transition_issue(ticket_id, transition['id']) - logging.debug(f"Closed {ticket_id}") - break - else: + closed = self.move_to_state(issue, 'Close Issue') + if not closed: + if self.move_to_state(issue, 'Resolve Issue'): + closed = self.move_to_state(issue, 'Close Issue') + if not closed: logging.error(f"{self.ticket_url(ticket_id)} can't be closed") - return + else: + logging.debug(f"Resolved {ticket_id}") + return def resolve_issue(self, ticket_id): """