简体   繁体   English

获取 Jira 问题的状态

[英]Get status of Jira issue

I'm using Python script to get jira issue status of list of issues from xlsx file.我正在使用 Python 脚本从 xlsx 文件中获取问题列表的 jira 问题状态。 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:该脚本返回存在问题的 jira 状态,但一旦问题不存在,它就会返回“不存在”但缺少正确的问题 ID,如示例中所示:

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')

When the exception occur, the issue variable not set with the new object value (from Jira) but still keep it's previous value.发生异常时,问题变量未设置为新对象值(来自 Jira),但仍保留其先前值。 I suggest you use the excel row value instead the issue value, at the exception handling section.我建议您在异常处理部分使用 excel 行值而不是问题值。 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM