Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 350
jmite Avatar asked Jul 07 '14 18:07

jmite


People also ask

How do I find my repository ID?

To determine the storage location of a repository, navigate to the repository in Bitbucket Server and select Settings. The location on disk will be displayed under Repository details. The numerical part of the path is the ID of the repository.

What is Travis API?

It is a discoverable and self-documenting RESTful API, and includes all the hypermedia features expected from a modern API. Our API can be used to automate many of your Travis CI build processes: get build info. get organization info. get nested resources.

How do I trigger a Travis build on GitHub?

Trigger Travis CI builds using the API V3 by sending a POST request to /repo/{slug|id}/requests : Get an API token from your Travis CI settings page. You'll need the token to authenticate most of these API requests.


2 Answers

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.

like image 171
kenorb Avatar answered Sep 20 '22 01:09

kenorb


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.

like image 30
Schwern Avatar answered Sep 21 '22 01:09

Schwern