可以使用 jira-python 读出搜索过滤器
Possibility to read out search filters using jira-python
是否有另一种可能收集有关问题搜索内容的信息,如下所述?
我的第一次尝试是:
for i in jira.search_issues('filter=filterID', startAt=0, maxResults=2500):
print(i.fields.duedate)
索引 i
类似于问题名称(例如 JIR-001)。当计算 i
时,它 return 恰好是 1000。所以我猜插件不能 return 更多问题,但我的 JIRA 有更多与该过滤器 ID 相关的问题(这就是我选择的原因2500)。有没有办法在不添加另一个循环的情况下获得更多结果,其中 startAt
和 maxResults
被转移到下一个 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.
是否有另一种可能收集有关问题搜索内容的信息,如下所述?
我的第一次尝试是:
for i in jira.search_issues('filter=filterID', startAt=0, maxResults=2500):
print(i.fields.duedate)
索引 i
类似于问题名称(例如 JIR-001)。当计算 i
时,它 return 恰好是 1000。所以我猜插件不能 return 更多问题,但我的 JIRA 有更多与该过滤器 ID 相关的问题(这就是我选择的原因2500)。有没有办法在不添加另一个循环的情况下获得更多结果,其中 startAt
和 maxResults
被转移到下一个 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.