0

我想了解自定义字段值的历史。

下面的代码可以给我当前字段值的原始数据:

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上做同样的事情?

4

1 回答 1

0

你在正确的轨道上。您必须获取 jira 问题的更改日志条目,然后获取该更改日志列表(属性称为历史记录)中与您的自定义字段相关的值的条目。在更改日志项的属性中找出您的自定义字段的名称,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
于 2019-08-22T15:21:19.960 回答