Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the issue can't be closed, try to resolve and then close #58

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions hammer/library/jiraoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down