首页 > 解决方案 > 如何在 JIRA 中将发布设置为“已发布”

问题描述

我有一个名为 ASDF 的板,在 Relaeses 选项卡下的那个板上,我有一个名为:QWER 的版本。这个版本有 3 个问题。

如果所有问题都处于“完成”状态,我想将版本的状态更改为“已发布”。我不知道如何将状态更改为“已发布”。

我正在尝试使用 JIRA-Python REST-API 来做到这一点。我也对 CLI 方法持开放态度。

标签: jirapython-jira

解决方案


完成此任务的最佳方法是通过Jira Automation Plugin。请记住,我与此插件没有任何关系;但是,我确实有使用它的经验,它非常适合这个目的。对于 python-jira 解决方案,请记住这将更加困难。首先,您必须检查所有问题是否已完成,这可以通过以下方式完成:

def version_count_unresolved_issues(self, id):
        """Get the number of unresolved issues for a version.

        :param id: ID of the version to count issues for
        """
        return self._get_json('version/' + id + '/unresolvedIssueCount')['issuesUnresolvedCount']

所以我们通过一些条件检查如下:

if not jira.version_count_unresolved_issues('QWER'):
    jira.move_version(...)

move_version函数如下所示:

def move_version(self, id, after=None, position=None):
        """Move a version within a project's ordered version list and return a new version Resource for it.

        One, but not both, of ``after`` and ``position`` must be specified.

        :param id: ID of the version to move
        :param after: the self attribute of a version to place the specified version after (that is, higher in the list)
        :param position: the absolute position to move this version to: must be one of ``First``, ``Last``,
            ``Earlier``, or ``Later``
        """
        data = {}
        if after is not None:
            data['after'] = after
        elif position is not None:
            data['position'] = position

        url = self._get_url('version/' + id + '/move')
        r = self._session.post(
            url, data=json.dumps(data))

        version = Version(self._options, self._session, raw=json_loads(r))
        return version

关于您的评论,请查看文档摘录:

from jira import JIRA
import re

# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details).
# Override this with the options parameter.
options = {
    'server': 'https://jira.atlassian.com'}
jira = JIRA(options)

您不会在任何地方传递 self ,您只需jira像这样调用实例的函数:

jira.version_count_unresolved_issues('QWER')

您根本不传递 self,jira 实例在幕后自动作为 self 传递,请查看 python-jira 文档以获取更多信息: https ://jira.readthedocs.io/en/master/examples .html


推荐阅读