如何通过 Travis API 列出给定项目的所有构建?

How to list all builds of a given project through Travis API?

Travis 文档不清楚我们是否可以浏览构建。终点:

https://api.travis-ci.org/repos/caelum/vraptor4/builds

显示最近 50 个版本。

但是如何获取整个历史记录呢?

构建是分页的,因此您需要使用多个请求进行提取。

端点支持 after_number 参数,该参数是先前获取的页面中最后一个版本的版本号(字段 number)。

因此,如果您的第一个结果集的最后一个构建条目的构建号为 2669(这是 https://api.travis-ci.org/repos/caelum/vraptor4/builds 页面上的当前最后一个构建号),您将使用此 URL:

https://api.travis-ci.org/repos/caelum/vraptor4/builds?after_number=2669

这样您就可以遍历构建而不是一次获取数千个构建。

对于API V3,我们应该使用offset,参见https://developer.travis-ci.com/pagination

例如,https://api.travis-ci.org/repo/expertiza%2Fexpertiza/builds?limit=5&offset=5