【发布时间】:2018-05-14 07:11:12
【问题描述】:
目前我正在使用以下 API 来获取分支的拉取请求。
https://stash.net/rest/api/1.0/projects/{}/repos/{}/pull-requests?
at=refs/heads/release-18&state=ALL&order=OLDEST&withAttributes=false
&withProperties=true&limit=100
我需要获取基于 createdDate 创建的所有拉取请求。 bitbucket 是否提供任何 API?
目前我正在检查创建日期并对其进行过滤。
def get_pullrequest_date_based():
"""
Get all the pull requests raised and filter the based on date
:return: List of pull request IDs
"""
pull_request_ids = []
start = 0
is_last_page = True
while is_last_page:
url = STASH_REST_API_URL + "/pull-requests?state=MERGED&order=NEWEST&withAttributes=false&withProperties=true" + "/results&limit=100&start="+str(start)
result = make_request(url)
pull_request_ids.append([value['id'] for value in result['values'] if value['createdDate'] >= date_arg])
if not result['isLastPage']:
start += 100
else:
is_last_page = False
print "Size :",len(pull_request_ids)
return pull_request_ids
任何其他更好的方法。
【问题讨论】:
-
您的
is_last_page变量似乎命名不当 -is_last_page在逻辑上为假,直到您到达最后一页,此时它变为真。该代码仍然可以工作,它可能只是让其他阅读它的人感到困惑。更简单的方法可能是取消并运行一个无限循环,while True,然后是if result['isLastPage']: break
标签: pull-request bitbucket-server