python - 可以使用 jira-python 读出搜索过滤器

标签 python jira python-jira

是否有另一种可能性来收集有关问题搜索内容的信息,如下所述?

我的第一次尝试是:

for i in jira.search_issues('filter=filterID', startAt=0, maxResults=2500):
    print(i.fields.duedate)

索引i类似于问题名称(例如 JIR-001)。计数时i它正好返回 1000。所以我猜这个插件不能返回更多问题,但我的 JIRA 有更多与该过滤器 ID 相关的问题(这就是我选择 2500 的原因)。有没有一种方法可以在不添加另一个循环的情况下获得更多,其中 startAtmaxResults是否转移到接下来的 1000 个结果 ( startAt=1000, maxResults=1999 )?因为这会显着增加脚本的运行时间,而 search.issue访问大约需要 9 秒。

也许有一个更简单的方法来解决这个问题,但是 documentation该包的内容很少涉及该特定问题。

最佳答案

您可能会对查看 jira.search_issues() 函数的源代码感兴趣。

这里是1.0.3版本的源代码:

def search_issues(self, jql_str, startAt=0, maxResults=50, validate_query=True, fields=None, expand=None,
                  json_result=None):
    """
    Get a ResultList of issue Resources matching a JQL search string.

    :param jql_str: the JQL search string to use
    :param startAt: index of the first issue to return
    :param maxResults: maximum number of issues to return. Total number of results
        is available in the ``total`` attribute of the returned ResultList.
        If maxResults evaluates as False, it will try to get all issues in batches of 50.
    :param fields: comma-separated string of issue fields to include in the results
    :param expand: extra information to fetch inside each resource
    """
    # TODO what to do about the expand, which isn't related to the issues?
    infinite = False
    maxi = 50
    idx = 0
    if fields is None:
        fields = []

    # If None is passed as parameter, this fetch all issues from the query
    if not maxResults:
        maxResults = maxi
        infinite = True

    search_params = {
        "jql": jql_str,
        "startAt": startAt,
        "maxResults": maxResults,
        "validateQuery": validate_query,
        "fields": fields,
        "expand": expand
    }
    if json_result:
        return self._get_json('search', params=search_params)

    resource = self._get_json('search', params=search_params)
    issues = [Issue(self._options, self._session, raw_issue_json)
              for raw_issue_json in resource['issues']]
    cnt = len(issues)
    total = resource['total']
    if infinite:
        while cnt == maxi:
            idx += maxi
            search_params["startAt"] = idx
            resource = self._get_json('search', params=search_params)
            issue_batch = [Issue(self._options, self._session, raw_issue_json) for raw_issue_json in
                           resource['issues']]
            issues.extend(issue_batch)
            cnt = len(issue_batch)
    return ResultList(issues, total)

它有一个有趣的评论:

Total number of results is available in the total attribute of the returned ResultList.

所以你可能想检查一下。

您可能还想设置maxResults = False

文档:

If maxResults evaluates as False, it will try to get all issues in batches.

关于python - 可以使用 jira-python 读出搜索过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35937718/

相关文章:

jira - 如何让某些 JIRA 问题只对一群人可见?

python - 使用python循环在jira中创建票据

python - 默认参数替代无?

python - 函数中的参数 (`_` ) 是什么?

python - 如何进行摊销计算

python - 当我尝试从 Python 调用 Jira 项目时,出现 JSON 错误

python - Postgres Python 查询导入 pg 与导入 psycopg2

c# - 使用 Jira 6.4.3 将附件发布到 Rest api

Jenkins:类路径包含多个 SLF4J 绑定(bind)