Hüftl
Hüftl

Reputation: 231

Possibility to read out search filters using jira-python

Is there another possibility to gather information about issue search contents as stated below?

My first attempt was:

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

The index i resembles the issue name (e.g. JIR-001). When counting i it returned exactly 1000. So I guess the plugin can't return more issues, but my JIRA has way more issues related to that filter ID (thats why I chose 2500). Is there a way to get more without adding another loop where the startAt and maxResults is shifted to the next 1000 results (startAt=1000, maxResults=1999)? Because this increases the runtime of the script dramatically, whereas a search.issue access eats up around 9 seconds.

Maybe there is a much easier way for that problem, but the documentation of the package is quite sparsely about that specific problem.

Upvotes: 1

Views: 2112

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210862

It may be interesting for you to check the source code of jira.search_issues() function.

Here is a source code for version 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)

It has an interesting comment:

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

So you may want to check it.

You may also want to set maxResults = False

Documentation:

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

Upvotes: 1

Related Questions