2013-07-01 68 views
2

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

df包含我要通过创建新问题向JIRA输入的13列数据。每一列代表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 T他三角洲将重置您断开每次...
3 NaN的
4它应该当CP需要到L即可登录...
5在经由生物医学菜单,次升级IDS ...
6在通过生物医学菜单升级IDS ...
7通过BioMed菜单升级IDS时,第...
8增加融合堆大小和SCC1 Initia ...
9使用build 142+重新检查,在Matt交付后...
10使用WPA2时,有EAPOL密钥交换去...
11使用WPA2时,有EA POL关键ECHANGE去...
12 NaN的
13 NaN的
14 NaN的 ...

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


问题1:
问题2:发现这个三角洲会泄露数据包接收地...
问题3:三角洲将重置您断开每次... ...

+0

尝试''对行df.itertrows()'',在这里看到:http://pandas.pydata.org/pandas-docs/dev/basics.html#iteration – Jeff

+0

它没有工作不幸的是,我得到了错误:AttributeError:'DataFrame'对象没有属性'itertrows'我相信这是jira.create_issue部分,根据我的语法来说,pandas导入部分不起作用。 – JMan

+0

错字! ''DF。iterrows()'' – Jeff

回答

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 
+0

它给了我错误:cqid = row ['ClearQuest ID'] TypeError:字符串索引必须是整数,而不是str ...........我相信这是jira.create_issue部分不工作,而不是熊猫的一部分,但我确实改变了循环部分,所以感谢代码部分的帮助 – JMan

+0

如果你真的包含了一些示例csv数据,它会帮助我们。 – eandersson

+0

@JMan我添加了一个新的解决方案。 – eandersson

相关问题