Reputation: 19
I'm using Python script to get jira issue status of list of issues from xlsx file. the script return jira status of exist issue but once issue doesn't exist it returned "Does Not Exist" but missing the right issue ID as in the example:
xlsx file: (input issues file)
ER-8401
CORE-7981
KOKO:1223
FOFO:1223
Output:
ER-8401,Closed
CORE-7981,Submitted
CORE-7981:Does Not Exist
CORE-7981:Does Not Exist
The goal output file will look like:
ER-8401,Closed
CORE-7981,Submitted
KOKO:1223:Does Not Exist
FOFO:1223:Does Not Exist
Python Code:
from jira.client import JIRA
import openpyxl
jira_server = {'server': jira_server}
jira = JIRA(options=jira_server, basic_auth=(jira_user, jira_password))
wb = openpyxl.load_workbook('issues_status.xlsx')
ws = wb['Sheet1']
with open('output.txt', 'w') as f:
for row in ws.iter_rows():
try:
issue = jira.issue(row[0].value)
status = issue.fields.status
# print(issue,',',status)
f.write(str(issue))
f.write(',')
f.write(str(status))
f.write('\n')
except:
f.write(str(issue))
f.write(':Does Not Exist')
f.write('\n')
Upvotes: 0
Views: 1309
Reputation: 248
When the exception occur, the issue variable not set with the new object value (from Jira) but still keep it's previous value. I suggest you use the excel row value instead the issue value, at the exception handling section. like this:
...
...
with open('output.txt', 'w') as f:
for row in ws.iter_rows():
try:
issue = jira.issue(row[0].value)
status = issue.fields.status
# print(issue,',',status)
f.write(str(issue))
f.write(',')
f.write(str(status))
f.write('\n')
except:
f.write(row[0].value) # <=== suggested change is here
f.write(':Does Not Exist')
f.write('\n')
Upvotes: 1