Python Atlassian JIRA 迭代下一页

问题描述 投票:0回答:1

我按照这里描述的例子: https://community.atlassian.com/t5/Jira-articles/Atlassian-Python-API-s/ba-p/2091355 编写一个玩具程序来通过 JIRA 列表。

from atlassian import Jira

jira = Jira(
    url='https://your-site.atlassian.net',
    username='email',
    password='token',
    cloud=True)

jql_request ='project = WSP AND issuetype = Story'
issues = jira.jql(jql_request)
print(issues)

但这并没有列出所有的 JIRA(只有前 50 个)。我想遍历下一批。 Iterating through Jira API Url post描述了如果我使用REST方法,参数startAt的设置。

我想知道如何使用 Python SDK 方法指定。更具体地说,API 文档中没有提到它:https://atlassian-python-api.readthedocs.io/jira.html#get-issues-from-jql-search-result-with-all-related-fields

python jira
1个回答
0
投票

如果有人正在寻找答案:

需要设置在

jira.jql(jql_request, start=<initial value>)
,然后根据得到的总结果不断更新

from atlassian import Jira

# Initialize Jira instance
jira = Jira(
    url='https://your-site.atlassian.net',
    username='email',
    password='token',
    cloud=True)

# Set the initial startAt value and maxResults value
start_at = 0
max_results = 50  # The maximum number of results per page, limited by Jira API

# Run a loop to retrieve all pages of search results
while True:
    # Make a JQL request with the start
    jql_request = 'project = WSP AND issuetype = Story'
    issues = jira.jql(jql_request, start=start_at)
    # print(issues)  # Process the retrieved issues as needed

    # Check if there are more issues beyond the current page
    if len(issues) < max_results:
        break  # Break the loop if no more issues are found

    # Increment the startAt value to retrieve the next page of results
    start_at += max_results
© www.soinside.com 2019 - 2024. All rights reserved.