[英]Jira - Get custom field's previous values
我想了解自定义字段值的历史。
下面的代码可以给我当前字段值的原始数据:
from jira import JIRA
jira_options = {'server': 'url'}
jira = JIRA(basic_auth=('user_name', 'password'), options = {'server': 'url'})
issue = jira.issue('id', expand='changelog')
customfield_name = issue.fields.customfield_10000
但是,我也想获得以前的价值观。
atlassian上发布的问题解释了ChangeHistoryManager
将有助于实现此任务。 如何在Python上完成相同的操作?
你走在正确的轨道上。 您必须获取jira问题的changelog条目,然后获取与该customfield相关的值的更改日志列表中的条目(属性称为历史记录)。 在changelog项的field
属性中找出您的自定义field
,然后仅筛选出与您的自定义field
历史记录项。
for entry in range(issue.changelog.startAt, issue.changelog.total):
# do your stuff, for example:
history_item = issue.changelog.histories[entry]
timestamp = history_item.created # get the created timestamp of the current changelog entry
author = history_item.author.displayName # get the person who did the change
print(f"The user {author} changed the following fields on {timestamp}:")
changed_items = history_item.items
for item in changed_items:
# depending on the field type, it might make more sense to
# use `item.from` and `item.to` instead of the fromString/toString properties
print(f"Field: {item.field} from {item.fromString} to {item.toString}")
您也可以在开头使用此for循环:
for entry in issue.changelog.histories:
# do your stuff
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.