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

时间:2016-03-11 10:26:21

标签: 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的软件包对这个特定的问题非常稀少。

1 个答案:

答案 0 :(得分: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,它将尝试获取所有问题   批次。