def transition_issue(parsed_params, conf_map): _, issue_key, status = parsed_params project = issue_key.split('-')[0] issue = jira.issue(issue_key) project_issue_transition.transition_to(conf=conf_map[project], issue=issue, goal_status=status) return issue, status
def transition_to(conf, issue, goal_status): start_status = issue.fields.status.name transition_statuses = \ conf['planning_workflow_statuses'] + \ conf['wip_workflow_statuses'] + \ [conf['completed_status']] transition_statuses = transition_statuses[transition_statuses.index( start_status):transition_statuses.index(goal_status) + 1] status = issue.fields.status.name current_ind = transition_statuses.index(status) while status != goal_status: possible_transitions = [(t['name'], t['to']['name']) for t in jira.transitions(issue)] # find the transition that will get us the furthest to the goal max_ind = float("-inf") selected_transition = None selected_status_name = None for transition_name, status_name in possible_transitions: if status_name in transition_statuses: t_ind = transition_statuses.index(status_name) if t_ind > max_ind: max_ind = t_ind selected_transition = transition_name selected_status_name = status_name # break if we're not getting anywhere if max_ind < current_ind: logger.error( "Could not find transition for issue %s to status %s!" % (issue.key, goal_status)) break # perform that transition jira.transition_issue(issue, selected_transition) logger.info('Requested transition %s %s to "%s" via "%s"' % (issue.fields.issuetype.name, issue.key, selected_status_name, selected_transition)) # update status and ind issue = jira.issue(issue.key) # break if the transition failed if issue.fields.status.name == status: logger.error("Transition failed for issue %s to status %s!" % (issue.key, selected_status_name)) break status = issue.fields.status.name current_ind = transition_statuses.index(status)
def delete_issue(parsed_params): _, issue_key = parsed_params issue = jira.issue(issue_key) issue.delete() return issue