You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Atlassian Stash REST API获取全部Pull Request ID?

获取全部Pull Request的解决方法

这问题我之前碰到好多次了,其实是Stash(现在也叫Bitbucket Server)的REST API有个单页最大返回限制——哪怕你把limit设到1000,它实际最多也只会返回100条数据,这就是为啥你看到响应里的limit是100而不是你设置的1000。

要拿到所有Pull Request,你得用它的分页查询机制,具体步骤如下:

  • 先搞懂分页参数的含义:
    • isLastPage:如果是false,说明还有未返回的PR;如果是true,就表示已经拿到全部数据了
    • nextPageStart:下一页数据的起始偏移量,每次请求都要把这个值传给start参数
  • 循环发起请求:
    1. 第一次请求用你原来的URL(默认start=0),拿到第一页的100条数据
    2. 检查响应里的isLastPage,如果是false,就用nextPageStart的值作为新的start参数,发起下一次请求,比如:
      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&start=100
      
    3. 重复步骤2,直到isLastPage变为true
  • 合并结果:把每次请求返回的values数组合并到一个总列表里,最后就是所有的Pull Request数据

如果你不想手动一次次请求,可以写个简单的脚本自动处理,比如用Python的requests库:

import requests

url_template = "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"
project_key = "你的项目Key"
repo_slug = "你的仓库Slug"

all_prs = []
start = 0
while True:
    response = requests.get(url_template.format(project_key, repo_slug) + f"&start={start}")
    data = response.json()
    all_prs.extend(data["values"])
    if data["isLastPage"]:
        break
    start = data["nextPageStart"]

print(f"总共获取到 {len(all_prs)} 条Pull Request")

内容的提问来源于stack exchange,提问作者PGS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:28:11