【发布时间】:2013-07-01 20:56:25
【问题描述】:
我正在使用 JIRA Python 模块,它是 REST API 的扩展,可自动执行在 JIRA 中删除和创建问题的过程。我正在尝试在我的 python 脚本中使用“for”循环在 JIRA 中创建问题,该循环使用从另一个数据库收集的导入数据。我需要在创建问题时格式化字段,以便我拥有的数据可以与 JIRA 中的相应字段正确对齐。下面是我的 Python 代码,用于创建问题并将数据存储到存储在自定义变量中的 JIRA 中:
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 中针对 cmets 字段中创建的每个问题显示的一些示例数据:
问题 1:
0 南
1 发现Delta会泄露数据包接收...
2 每次断开连接时,Delta 都会重置...
3 南
4 它应该在 CP 到 l 时被记录...
5 通过 BioMed 菜单升级 IDS 后,...
6 通过 BioMed 菜单升级 IDS 后,...
7 通过 BioMed 菜单升级 IDS 后,...
8 增加 Fusion 堆大小和 SCC1 初始...
9 在 Matt 交付后,使用 build 142+ 重新检查...
10 使用WPA2时,有EAPOL key echange go...
11 使用WPA2时,有EAPOL key echange go...
12 南
13 南
14 南
...
我只希望每个问题都有自己的字符串值,而不是像这样显示的索引号或 NaN:
第一期:
问题2:发现Delta会泄露数据包接收...
问题 3:每次断开连接时 Delta 都会重置...
...
【问题讨论】:
-
试试
for row in df.itertrows(),看这里:pandas.pydata.org/pandas-docs/dev/basics.html#iteration -
不幸的是,它没有用,我收到错误消息:AttributeError: 'DataFrame' object has no attribute 'itertrows' 我相信这是 jira.create_issue 部分在我的情况下不起作用字段的语法,熊猫导入部分有效。
-
错字!
df.iterrows() -
你到底想做什么?请显示 df,我怎么看不到你在任何地方使用 row?
-
df 包含我想通过创建新问题输入到 JIRA 的 13 列数据。每列代表 JIRA 中问题的不同字段。在 JIRA 中创建的每个新问题都应该从每一列中获取信息。
标签: python api rest pandas jira