通过 Python 脚本创建 Jira 问题:组件、截止日期和修复版本字段出现问题已编辑

Creating Jira issues through Python script: trouble with component, duedate and fixversion field EDITED

我目前正在编写一个简单的 Python 脚本,它从 Excel sheet 中读取数据并根据该数据创建 Jira 任务。我已经让 Excel data-reading 部分正常工作,而且 Jira 任务创建也基本正常,但我在几个领域苦苦挣扎。

我们的 Jira 任务必须填写以下字段:

  1. 项目
  2. 问题类型
  3. 摘要
  4. parent 观察者(自定义字段)
  5. 优先级
  6. 外部出价(自定义字段)
  7. 修复version/s
  8. 组件
  9. 截止日期

我在 Python 中使用以下代码行得到了前六个:

issue = jira.create_issue(project=pro, summary=sum, issuetype=type, customfield_13700 = { "name": parent }, priority = {'name': priority}, customfield_12501 = external_bid )

但是,我不确定如何填写 jira.create_issue 函数的其他参数以修复 versions/s、组件和截止日期投标字段。

我尝试过很多不同的东西:

对于修复版本字段:

issue = jira.create_issue(fixversion=fixversion )
issue = jira.create_issue(fixversion = {'name': fixversion})
issue = jira.create_issue(fixversion = {'value': fixversion})

这都会导致以下错误: "errors":{"fixversion":"Field 'fixversion' cannot be set. It is not on the appropriate screen, or unknown."}}

对于组件字段:

issue = jira.create_issue(component = component )
issue = jira.create_issue(component = {'name': component} )
issue = jira.create_issue(fixversion = {'value': component})

这又会导致以下错误: 错误":{"component":"Field 'component' cannot be set. It is not on the appropriate screen, or unknown."}}

截止日期:

issue = jira.create_issue(duedate = duedate)
issue = jira.create_issue(duedate = {'name': duedate} )
issue = jira.create_issue(duedate = {'value': duedate} )

这给出了以下错误: TypeError: 'datetime' 类型的 Object 不是 JSON 可序列化的

在这一点上,我尝试了很多不同的东西并查找了一堆东西,其中大部分指向 this page

JIRA 项目可能包含许多不同的问题类型。一些问题屏幕对新问题中的字段有不同的要求。此信息可通过“createmeta”方法获得。更多示例可用 here.

这对我来说并不是很有帮助。有人知道如何最好地从这里开始吗?

当您尝试将日期时间对象序列化为 JSON 对象时出现错误 TypeError: Object of type 'datetime' is not JSON serializable

您使用的duedate值是一个日期时间对象。每当您尝试将包含日期时间对象的字典转储到 JSON 对象时,您都会遇到此错误。示例如下:

import datetime
test = {}
test['date'] = datetime.datetime.now()
import json
json.dumps(test)

为避免此错误,请将日期时间对象转换为 Javascript 对象表示法 (JSON) 标准接受的对象。比如字符串。

test['date'] = str(datetime.datetime.now()) 
json.dumps(test)

请注意,从日期时间对象直接转换可能不适合接受日期的 JIRA 格式。转换为字符串时使用正确的格式(查看 datetime 文档)