有没有办法根据创建日期获取所有拉取请求

Is there any way to get all the pull request based on creation date

目前我正在使用下面的 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

任何其他更好的方法。

简短回答:不,API 资源不提供内置日期过滤器。您需要应用任何其他相关的过滤器(如果有的话)(例如涉及的分支、方向、状态等),然后在您自己的代码逻辑中应用任何进一步需要的过滤。

您是否有用于翻阅 API 的示例代码?如果您有代码片段可以分享,也许我们可以帮助您实现您的要求

您不能按创建日期过滤。您可以找到拉取请求 here

的完整 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