class GitHub extends Object
A simple class to interact with the GitHub API for only the parts I need.
To run this example, clone Jervis and execute ./gradlew console to bring up a Groovy Console with the classpath set up.
import net.gleske.jervis.remotes.GitHub
def x = new GitHub()
println 'Print each branch.'
x.branches('samrocketman/jervis').each{ println it }
println 'Print the contents of .travis.yml from the master branch.'
println x.getFile('samrocketman/jervis','.travis.yml','master')| Type Params | Return Type | Name and description |
|---|---|---|
|
List |
branches(String project)Get a list of branches for a project. |
|
Object |
fetch(String path)Fetches a URL from GitHub API. |
|
String |
getCloneUrl()Get the contents of gh_clone. |
|
String |
getFile(String project, String file_path, String ref = '')Get the contents of a file from a project. |
|
ArrayList |
getFolderListing(String project, String dir_path = '/', String ref = '')Get the directory listing of a path from a project. |
|
String |
getWebUrl()Get the contents of gh_web. |
|
boolean |
isUser(String user)Check with the GitHub API and determine if the passed in user is a User or an Organization. |
|
void |
setGh_api(String gh_api)Sets the gh_api property. |
|
void |
setGh_clone(String gh_clone)Sets the gh_clone property. |
|
void |
setGh_token(String gh_token)Sets the gh_token property. |
|
void |
setGh_web(String gh_web)Sets the gh_web and gh_api properties. |
|
String |
toString()Get a human readable string for this type of remote. |
URL to the GitHub API. For GitHub Enterprise it should be gh_web + 'api/v3/'. Default: https://api.github.com/
The base clone URI in which repositories will be cloned. Default: https://github.com/
The API token, which can be used to communicate with GitHub using authentication. Default: null
URL to the GitHub web interface. Default: https://github.com/
Get a list of branches for a project. This is meant to be a standard function for Jervis to interact with remotes. All remotes are required to have this function.
project - A GitHub project including the org. e.g. "samrocketman/jervis"Fetches a URL from GitHub API. This is mostly used by other functions to provide minimum functionality defined in JervisRemote. It can be used for general GitHub API communication.
path - A GitHub API path to fetch. The URL must return JSON content.
e.g. user/repos.Get the contents of gh_clone. This is meant to be a standard function for Jervis to interact with remotes. All remotes are required to have this function.
Get the contents of a file from a project. This is meant to be a standard function for Jervis to interact with remotes. All remotes are required to have this function.
project - A GitHub project including the org. e.g. "samrocketman/jervis"file_path - A path to a file relative to the root of the Git repository. e.g. ".travis.yml"ref - A git reference such as a branch, tag, or SHA1 hash. e.g. "master". This option is optional. If not specified the default branch is selected.Get the directory listing of a path from a project. This is meant to be a standard function for Jervis to interact with remotes. All remotes are required to have this function.
project - A GitHub project including the org. e.g. samrocketman/jervisdir_path - A path to a directory relative to the root of the Git repository. This is optional. By default is / (the repository root).ref - A git reference such as a branch, tag, or SHA1 hash. e.g. master. This option is optional.Get the contents of gh_web. This is meant to be a standard function for Jervis to interact with remotes. All remotes are required to have this function.
Check with the GitHub API and determine if the passed in user is a User or an Organization.
user - A user name or organization name to test if it is a user.Sets the gh_web and gh_api properties. This automatically sets gh_api based on gh_web.
Get a human readable string for this type of remote. This is meant to be a standard function for Jervis to interact with remotes. All remotes are required to have this function.