问题
I need to get the latest travis build status of a repo through their API. I need a behavior identical to that of build status badge i.e it shows passing when a "push" is passing, even if a newer "pull_request" is failing.
One way of achieving is to list all builds of a repo using this and then traverse in reverse direction until I find a build which is not a pull requests and then check its status.
However, there must be a short way of doing it because the same behavior is used by build status badge. Traversing the builds every time just to get the last build status seems like a pain.
What is the API endpoint use by build status batch to directly get the last "push" build status of a repo?
回答1:
The easiest solution is to not use Travis API but the build status badge. The test "passing" or "failing" is embedded as text in the SVG image:
curl -s 'https://api.travis-ci.org/$USER/$REPO.svg?branch=$BRANCH' | grep pass
curl -s 'https://api.travis-ci.org/$USER/$REPO.svg?branch=$BRANCH' | grep fail
回答2:
Unless you know the build.id, the best way I think is to use the API you are referring to and pass in the query parameter limit
. Something like this:
repo/{repository.id}/builds/builds?limit=1
repo/{+repository.slug}/builds/builds?limit=1
Response would still be an array but index 0 will be the most recent build. limit
is not documented but it is used by Travis for their pagination.
来源:https://stackoverflow.com/questions/30980874/get-latest-travis-build-status-of-a-repo-through-travis-api