Soham Soham - 2 years ago 80
Java Question

How to get branch and tag contents with egit Github plugin?

I am using egit-github API for going over github repositories. I am trying to get content of branches and tags for a particular repository.

With Repository Service you can get hold of the branches and tags; as of type RepositoryBranch or RepositoryTag respectively.

However if I want to inspect the contents of branches or tags, I do not know how to get them. For example you can use ContentsService; but you need a type IRepositoryIdProvider; and its not clear how to get that from branches or tags in this API.

So how do I traverse the contents of the branches and tags using egit-github API. Do I have to use some other API; or parse JSON responses from GitHub myself.

Answer Source

The Javadoc for egit-github is a bit sparse; and is just a Java wrapper for Github API. So reading the REST API documentation from Github would be recommended.

For finding content of branches or tags of a certain repository, the API provides a string argument ref that could be used to supply both tag name and branch name. It also has a path variable which is a way of getting the contents of a certain directory in a repository. If you do not provide it then by default the contents of the root folder of the repository for the tag or the branch are sent back.

In the egit Java API the contents for the branch or the tag can be accessed using the getContents(IRepositoryIdProvider repository, String path, String ref) method of the ContentsService class. Just pass the respective branch or tag name, along with path of the directory to which you are looking for contents, or just null in case you want only the contents of the root directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download