pull-request - 有什么方法可以根据创建日期获取所有拉取请求
问题描述
目前我正在使用下面的 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
任何其他更好的方法来做到这一点。
解决方案
您不能按创建日期过滤。您可以在此处找到拉取请求的完整 REST API 文档
不过,您正在做的事情可以得到改进,因为您是按创建日期对拉取请求进行排序的。一旦你找到一个在你的截止日期之前创建的拉取请求,你就可以保释并且不再继续翻阅你知道你不会想要的拉取请求。
可能是这样的(虽然我的 Python 生锈了,我还没有测试过这段代码,所以对任何错别字表示歉意)
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
past_date_arg = False
while is_last_page and not past_date_arg:
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)
for value in result['values']:
if value['createdDate'] >= date_arg:
pull_request_ids.append(value['id'])
else:
# This and any subsequent value is going to be too old to care about
past_date_arg = True
if not result['isLastPage']:
start += 100
else:
is_last_page = False
print "Size :",len(pull_request_ids)
return pull_request_ids
推荐阅读
- php - 从用于创建“过滤器按钮”的表中获取列表
- html - 使用 jQuery 将 id 添加到元素
- java - 当在它之前添加一个 Jlabel 时如何阻止 JButton 改变位置
- nunit - 如何在 Visual Studio 2017 的 Nunit 3 中使用 ITestEventListener
- node.js - 如何在 node.js 中包含多个 js 文件?
- oracle - 如何找到最大值,任何剩余的最大值和之前未使用的最后剩余最大值
- android - 为注释元素找到错误类型的数据 public abstract int[] butterknife.OnClick.value()
- typescript - 无法传递类型解析为不同重载的联合类型
- ruby - 在没有“下一步”的情况下实施“救援”
- javascript - 我在 Woocommerce 的结帐页面上的 Javascript 滚动功能没有移动到正确的位置