使用Python REST API在JIRA中创建问题和自定义字段

时间:2013-07-01 20:56:26

标签: python api rest pandas jira

我正在使用JIRA Python模块,它是REST API的扩展,用于自动化在JIRA中删除和创建问题的过程。我试图在我的python脚本中使用'for'循环在JIRA中创建问题,该循环使用从另一个数据库收集的导入数据。我需要在创建问题时格式化字段,以便我拥有的数据可以与JIRA中的相应字段正确对齐。我的Python代码如下所示,用于创建问题并将数据存储到JIRA中,JIRA存储在自定义变量中:

df包含13列数据,我想通过创建新问题将其输入到JIRA中。每列代表JIRA中问题的不同字段。在JIRA中创建的每个新问题都应该从每个列中获取信息:

from jira.client import JIRA
import pandas as pd

# Now we input the issues from the export.csv CSV file into the fields
# of new issues that are being created in JIRA to replace the old ones that were 
# deleted

df = pd.read_csv('C:\\Python27\\scripts\\export.csv')

# Set the column names from the export.csv file equal to variables using the      
# pandas python module

# Now do the actual loop to create new issues

for row in df:
    cqid = df['ClearQuest ID']
    summ = str(df.Summary)
    datecreated = df['Date Created']
    dateresolved = df['Date Resolved']
    wistate = df['WI State']
    res = df.Resolution
    affected = df['Affected version/s']
    fixed = df['Fix version/s']
    issue_type = df['Issue Type']
    priority = df.Priority
    comments = str(df.Comments)
    jira.create_issue(project={'key': 'DEL'}, wistate={'customfield_1001': 'WI State'}, res={'customfield_1001': 'Resolution'}, cqid={'customfield_1001': 'ClearQuest ID'}, datecreated={'customfield_1001': 'Date Created'}, dateresolved={'customfield_1001': 'Date Resolved'}, priority={'customfield_1001': 'Priority'}, fixed={'customfield_1001': 'Fixed Version'}, affected={'customfield_10004': 'affected'}, summary=summ, description=comments, issuetype={'name': 'Defect'})

它给出错误:

JIRAError: HTTP 400: "{u'cqid': u"Field 'cqid' cannot be set. It is not on the   appropriate screen, or unknown.", u'wistate': u"Field 'wistate' cannot be set. It is not on the appropriate screen, or unknown.", u'dateresolved': u"Field 'dateresolved' cannot be set. It is not on the appropriate screen, or unknown.", u'res': u"Field 'res' cannot be set. It is not on the appropriate screen, or unknown.", u'datecreated': u"Field 'datecreated' cannot be set. It is not on the appropriate screen, or unknown.", u'affected': u"Field 'affected' cannot be set. It is not on the appropriate screen, or unknown.", u'fixed': u"Field 'fixed' cannot be set. It is not on the appropriate screen, or unknown."}"

以下是在JIRA中针对在评论字段中创建的每个问题显示的一些示例数据:

问题1:
0 NaN
1发现三角洲会泄漏包裹...
2每次断开连接时,Delta都会重置......
3 NaN
4当CP需要时,它应该被记录...
5通过BioMed菜单升级IDS后,...
6通过BioMed菜单升级IDS后,...
7通过BioMed菜单升级IDS后,...
8增加Fusion堆大小和SCC1 Initia ......
9在Matt交付之后,使用build 142+重新检查......
10使用WPA2时,有EAPOL密钥交换...
11使用WPA2时,有EAPOL密钥交换...
12 NaN
13 NaN
14 NaN ...

我只希望每个问题都有自己的字符串值,而不是像这样显示的索引号或NaN:


问题1:
问题2:发现Delta会泄漏数据包接收...
问题3:每次断开连接时Delta会重置...... ...

1 个答案:

答案 0 :(得分:1)

您的代码的一个主要缺陷是您在循环之前分配数据。

df = pd.read_csv('C:\\Python27\\scripts\\export.csv')

for row in df:
    cqid = row['ClearQuest ID']
    summary = row.Summary
    jira.create_issue(...)

你很可能需要这样做。

for row in df.values:
    cqid , summary , value3, value4, value5 = row