1

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

我的第一次尝试是:

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

该索引i类似于问题名称(例如 JIR-001)。当计算i它返回准确 1000。所以我猜插件不能返回更多问题,但我的 JIRA 有更多与该过滤器 ID 相关的问题(这就是我选择 2500 的原因)。有没有办法在不添加另一个循环的情况下获得更多,并且将startAtandmaxResults转移到下一个 1000 个结果(startAt=1000, maxResults=1999)?因为这会显着增加脚本的运行时间,而search.issue访问会消耗大约 9 秒。

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

4

1 回答 1

1

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返回的 ResultList的属性中提供了结果总数。

所以你可能想检查一下。

您可能还想设置maxResults = False

文档:

如果 maxResults 评估为 False,它将尝试批量获取所有问题。

于 2016-03-11T10:44:41.840 回答