吉拉-获取自定义字段的先前值

时间:2019-06-11 12:18:32

标签: python python-3.x python-jira

我想要自定义字段值的历史记录。

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

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 上怎么做?

1 个答案:

答案 0 :(得分:0)

您处在正确的轨道上。您必须获取jira问题的变更日志条目,然后在该变更日志列表(属性称为历史记录)中获取与您的customfield有关的值的条目。在更改日志项的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