What is the “repository ID” discussed in the Travis-CI API?

萝らか妹 提交于 2020-01-02 04:35:09

问题


To get a list of builds using the TravisCI API described here, it says that you need to put the repository ID in the request address.

I'm wondering, what is this ID, and where do I find it? Does it differ from the repository slug, which is username/reponame?


回答1:


The repository ID is the repo key which is shown in Travis CI API responses.

This can be either retrieve by:

$ curl -L http://api.travis-ci.org/repos/user_name/repo_name

or if you've travis command installed, try:

$ travis show -r user_name/repo_name

Here is corresponding code in Ruby:

require 'travis'
repos = Travis::Repository.find_all(owner_name: 'user_name')
repos.each do |repo|
  puts repo.slug
end

In above examples, change user_name and repo_name into the right values.




回答2:


You can fetch the repository id from the payload for the repository you're looking at, see http://docs.travis-ci.com/api/#repositories. The id in the payload for this endpoint is the id you can then use for the /builds endpoint.

That said, you can use either a slug or an id to fetch the builds for that repository, so these two yield the same result: https://api.travis-ci.org/builds?repository_id=82 and https://api.travis-ci.org/repos/sinatra/sinatra/builds




回答3:


Reading through the TravisCI API, the repository ID is different from the slug. It is a number assigned to the repository by Travis and unrelated to the Github repository ID.

For example: curl https://api.travis-ci.org/repos/schwern/URI-Find will return...

{ "id":527875, "slug":"schwern/URI-Find", "description":"Perl module to find URIs in arbitrary text", "public_key":"...", "last_build_id":29287626, "last_build_number":"10", "last_build_status":0, "last_build_result":0, "last_build_duration":28, "last_build_language":null, "last_build_started_at":"2014-07-07T03:43:28Z", "last_build_finished_at":"2014-07-07T03:44:03Z" }

You can use the id to access the repository as well. curl https://api.travis-ci.org/repos/527875 will return the same thing.

As you can see with https://api.github.com/repos/schwern/URI-Find the Travis repository id differs from the Github repository id.

I assume the advantage of using the id vs the slug is the slug may change, repositories can be renamed and ownership transferred, but the id presumably will not.



来源:https://stackoverflow.com/questions/24617631/what-is-the-repository-id-discussed-in-the-travis-ci-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!