Search code examples
pythonpython-3.xjirajqlpython-jira

Checking if epic issue exists and if not, make a new epic issue


So the problem is an IndexError, which makes sense considering there isn't supposed to be any results for that jql query.

epic_search = 'project = "EXM" and type = Epic and  summary ~ "summaryx" '
esearch = jira.search_issues(epic_search)

if esearch[0].key == None:
    epic_dict = {
            'project': {'key': 'EXM'},
            'customfield_12345': 'summaryx',
            'summary': 'summaryx',
            'issuetype': {'name': 'Epic'},
        }

new_epic = jira.create_issue(fields=epic_dict)
print (new_epic.key)

Is there a way I can check the jql results and if empty, create an epic?


Solution

  • Probably something like

    if (count(esearch) > 0):

    I assume this is python. I don't do python but there must be something like a count() or maybe esearch.length to tell you how many items are in there.