org.kohsuke.github
Class GHRepository

java.lang.Object
  extended by org.kohsuke.github.GHRepository

public class GHRepository
extends Object

A repository on GitHub.

Author:
Kohsuke Kawaguchi

Constructor Summary
GHRepository()
           
 
Method Summary
 void addCollaborators(Collection<GHUser> users)
           
 void addCollaborators(GHUser... users)
           
 GHDeployKey addDeployKey(String title, String key)
           
 GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description)
           
 GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context)
          Creates a commit status
 GHContentUpdateResponse createContent(String content, String commitMessage, String path)
           
 GHContentUpdateResponse createContent(String content, String commitMessage, String path, String branch)
           
 GHHook createHook(String name, Map<String,String> config, Collection<GHEvent> events, boolean active)
          See https://api.github.com/hooks for possible names and their configuration scheme.
 GHIssueBuilder createIssue(String title)
           
 GHMilestone createMilestone(String title, String description)
           
 GHPullRequest createPullRequest(String title, String head, String base, String body)
          Creates a new pull request.
 GHRef createRef(String name, String sha)
          Creates a named ref, such as tag, branch, etc.
 GHReleaseBuilder createRelease(String tag)
           
 GHHook createWebHook(URL url)
           
 GHHook createWebHook(URL url, Collection<GHEvent> events)
           
 void delete()
          Deletes this repository.
 void enableDownloads(boolean v)
           
 void enableIssueTracker(boolean v)
          Enables or disables the issue tracker for this repository.
 void enableWiki(boolean v)
          Enables or disables Wiki for this repository.
 boolean equals(Object obj)
           
 GHRepository fork()
          Forks this repository as your repository.
 GHRepository forkTo(GHOrganization org)
          Forks this repository into an organization.
 Map<String,GHBranch> getBranches()
          Gets branches by their names.
 Set<String> getCollaboratorNames()
          Gets the names of the collaborators on this repository.
 GHPersonSet<GHUser> getCollaborators()
          Gets the collaborators on this repository.
 GHCommit getCommit(String sha1)
          Gets a commit object in this repository.
 GHCompare getCompare(GHBranch id1, GHBranch id2)
           
 GHCompare getCompare(GHCommit id1, GHCommit id2)
           
 GHCompare getCompare(String id1, String id2)
          Gets a comparison between 2 points in the repository.
 Date getCreatedAt()
           
 List<GHDeployKey> getDeployKeys()
           
 String getDescription()
           
 List<GHContent> getDirectoryContent(String path)
           
 List<GHContent> getDirectoryContent(String path, String ref)
           
 GHContent getFileContent(String path)
           
 GHContent getFileContent(String path, String ref)
           
 int getForks()
           
 String getGitTransportUrl()
          Gets the git:// URL to this repository, such as "git://github.com/kohsuke/jenkins.git" This URL is read-only.
 String getHomepage()
           
 GHHook getHook(int id)
           
 List<GHHook> getHooks()
          Retrieves the currently configured hooks.
 GHIssue getIssue(int id)
           
 List<GHIssue> getIssues(GHIssueState state)
           
 List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone)
           
 String getLanguage()
          Gets the primary programming language.
 GHCommitStatus getLastCommitStatus(String sha1)
          Gets the last status of this commit, which is what gets shown in the UI.
 String getMasterBranch()
          Returns the primary branch you'll configure in the "Admin > Options" config page.
 GHMilestone getMilestone(int number)
           
 Map<Integer,GHMilestone> getMilestones()
          Deprecated. Use listMilestones(GHIssueState)
 String getName()
          Short repository name without the owner.
 int getNetworkCount()
           
 int getOpenIssueCount()
           
 GHUser getOwner()
           
protected  String getOwnerName()
           
 Set<URL> getPostCommitHooks()
          Deprecated. Use getHooks() and createHook(String, Map, Collection, boolean)
 GHPullRequest getPullRequest(int i)
          Retrieves a specified pull request.
 List<GHPullRequest> getPullRequests(GHIssueState state)
          Retrieves all the pull requests of a particular state.
 Date getPushedAt()
           
 GHContent getReadme()
           
 GHRef getRef(String refName)
          Retrive a ref of the given type for the current GitHub repository.
 GHRef[] getRefs()
          Retrieves all refs for the github repository.
 GHRef[] getRefs(String refType)
          Retrienved all refs of the given type for the current GitHub repository.
 List<GHRelease> getReleases()
          Deprecated. use listReleases()
 int getSize()
           
 String getSshUrl()
          Gets the SSH URL to access this repository, such as git@github.com:rails/rails.git
 int getSubscribersCount()
           
 String getSvnUrl()
          Gets the Subversion URL to access this repository: https://github.com/rails/rails
 Set<GHTeam> getTeams()
          If this repository belongs to an organization, return a set of teams.
 String getUrl()
          URL of this repository, like 'http://github.com/kohsuke/jenkins'
 int getWatchers()
           
 String gitHttpTransportUrl()
          Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git" This URL is read-only.
 boolean hasAdminAccess()
           
 boolean hasDownloads()
           
 int hashCode()
           
 boolean hasIssues()
           
 boolean hasPullAccess()
           
 boolean hasPushAccess()
           
 boolean hasWiki()
           
 boolean isFork()
           
 boolean isPrivate()
           
 PagedIterable<GHUser> listCollaborators()
          Lists up the collaborators on this repository.
 PagedIterable<GHCommitComment> listCommitComments()
          Lists up all the commit comments in this repository.
 PagedIterable<GHCommit> listCommits()
          Lists all the commits.
 PagedIterable<GHCommitStatus> listCommitStatuses(String sha1)
          Lists all the commit statues attached to the given commit, newer ones first.
 PagedIterable<GHEventInfo> listEvents()
          Lists repository events.
 PagedIterable<GHIssue> listIssues(GHIssueState state)
          Lists up all the issues in this repository.
 PagedIterable<GHMilestone> listMilestones(GHIssueState state)
          Lists up all the milestones in this repository.
 PagedIterable<GHPullRequest> listPullRequests(GHIssueState state)
          Retrieves all the pull requests of a particular state.
 PagedIterable<GHRelease> listReleases()
           
 PagedIterable<GHTag> listTags()
           
 GHCommitQueryBuilder queryCommits()
          Search commits by specifying filters through a builder pattern.
 void removeCollaborators(Collection<GHUser> users)
           
 void removeCollaborators(GHUser... users)
           
 void renameTo(String name)
          Rename this repository.
 void setDescription(String value)
           
 void setEmailServiceHook(String address)
           
 void setHomepage(String value)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GHRepository

public GHRepository()
Method Detail

getDescription

public String getDescription()

getHomepage

public String getHomepage()

getUrl

public String getUrl()
URL of this repository, like 'http://github.com/kohsuke/jenkins'


getGitTransportUrl

public String getGitTransportUrl()
Gets the git:// URL to this repository, such as "git://github.com/kohsuke/jenkins.git" This URL is read-only.


gitHttpTransportUrl

public String gitHttpTransportUrl()
Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git" This URL is read-only.


getSvnUrl

public String getSvnUrl()
Gets the Subversion URL to access this repository: https://github.com/rails/rails


getSshUrl

public String getSshUrl()
Gets the SSH URL to access this repository, such as git@github.com:rails/rails.git


getName

public String getName()
Short repository name without the owner. For example 'jenkins' in case of http://github.com/jenkinsci/jenkins


hasPullAccess

public boolean hasPullAccess()

hasPushAccess

public boolean hasPushAccess()

hasAdminAccess

public boolean hasAdminAccess()

getLanguage

public String getLanguage()
Gets the primary programming language.


getOwner

public GHUser getOwner()
                throws IOException
Throws:
IOException

getIssue

public GHIssue getIssue(int id)
                 throws IOException
Throws:
IOException

createIssue

public GHIssueBuilder createIssue(String title)

getIssues

public List<GHIssue> getIssues(GHIssueState state)
                        throws IOException
Throws:
IOException

getIssues

public List<GHIssue> getIssues(GHIssueState state,
                               GHMilestone milestone)
                        throws IOException
Throws:
IOException

listIssues

public PagedIterable<GHIssue> listIssues(GHIssueState state)
Lists up all the issues in this repository.


createRelease

public GHReleaseBuilder createRelease(String tag)

createRef

public GHRef createRef(String name,
                       String sha)
                throws IOException
Creates a named ref, such as tag, branch, etc.

Parameters:
name - The name of the fully qualified reference (ie: refs/heads/master). If it doesn't start with 'refs' and have at least two slashes, it will be rejected.
sha - The SHA1 value to set this reference to
Throws:
IOException

getReleases

public List<GHRelease> getReleases()
                            throws IOException
Deprecated. use listReleases()

Throws:
IOException

listReleases

public PagedIterable<GHRelease> listReleases()
                                      throws IOException
Throws:
IOException

listTags

public PagedIterable<GHTag> listTags()
                              throws IOException
Throws:
IOException

getOwnerName

protected String getOwnerName()

hasIssues

public boolean hasIssues()

hasWiki

public boolean hasWiki()

isFork

public boolean isFork()

getForks

public int getForks()

isPrivate

public boolean isPrivate()

hasDownloads

public boolean hasDownloads()

getWatchers

public int getWatchers()

getOpenIssueCount

public int getOpenIssueCount()

getNetworkCount

public int getNetworkCount()

getSubscribersCount

public int getSubscribersCount()

getPushedAt

public Date getPushedAt()
Returns:
null if the repository was never pushed at.

getCreatedAt

public Date getCreatedAt()

getMasterBranch

public String getMasterBranch()
Returns the primary branch you'll configure in the "Admin > Options" config page.

Returns:
This field is null until the user explicitly configures the master branch.

getSize

public int getSize()

getCollaborators

@WithBridgeMethods(value=java.util.Set.class)
public GHPersonSet<GHUser> getCollaborators()
                                     throws IOException
Gets the collaborators on this repository. This set always appear to include the owner.

Throws:
IOException

listCollaborators

public PagedIterable<GHUser> listCollaborators()
                                        throws IOException
Lists up the collaborators on this repository.

Returns:
Users
Throws:
IOException

getCollaboratorNames

public Set<String> getCollaboratorNames()
                                 throws IOException
Gets the names of the collaborators on this repository. This method deviates from the principle of this library but it works a lot faster than getCollaborators().

Throws:
IOException

getTeams

public Set<GHTeam> getTeams()
                     throws IOException
If this repository belongs to an organization, return a set of teams.

Throws:
IOException

addCollaborators

public void addCollaborators(GHUser... users)
                      throws IOException
Throws:
IOException

addCollaborators

public void addCollaborators(Collection<GHUser> users)
                      throws IOException
Throws:
IOException

removeCollaborators

public void removeCollaborators(GHUser... users)
                         throws IOException
Throws:
IOException

removeCollaborators

public void removeCollaborators(Collection<GHUser> users)
                         throws IOException
Throws:
IOException

setEmailServiceHook

public void setEmailServiceHook(String address)
                         throws IOException
Throws:
IOException

enableIssueTracker

public void enableIssueTracker(boolean v)
                        throws IOException
Enables or disables the issue tracker for this repository.

Throws:
IOException

enableWiki

public void enableWiki(boolean v)
                throws IOException
Enables or disables Wiki for this repository.

Throws:
IOException

enableDownloads

public void enableDownloads(boolean v)
                     throws IOException
Throws:
IOException

renameTo

public void renameTo(String name)
              throws IOException
Rename this repository.

Throws:
IOException

setDescription

public void setDescription(String value)
                    throws IOException
Throws:
IOException

setHomepage

public void setHomepage(String value)
                 throws IOException
Throws:
IOException

delete

public void delete()
            throws IOException
Deletes this repository.

Throws:
IOException

fork

public GHRepository fork()
                  throws IOException
Forks this repository as your repository.

Returns:
Newly forked repository that belong to you.
Throws:
IOException

forkTo

public GHRepository forkTo(GHOrganization org)
                    throws IOException
Forks this repository into an organization.

Returns:
Newly forked repository that belong to you.
Throws:
IOException

getPullRequest

public GHPullRequest getPullRequest(int i)
                             throws IOException
Retrieves a specified pull request.

Throws:
IOException

getPullRequests

public List<GHPullRequest> getPullRequests(GHIssueState state)
                                    throws IOException
Retrieves all the pull requests of a particular state.

Throws:
IOException
See Also:
listPullRequests(GHIssueState)

listPullRequests

public PagedIterable<GHPullRequest> listPullRequests(GHIssueState state)
Retrieves all the pull requests of a particular state.


createPullRequest

public GHPullRequest createPullRequest(String title,
                                       String head,
                                       String base,
                                       String body)
                                throws IOException
Creates a new pull request.

Parameters:
title - Required. The title of the pull request.
head - Required. The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace head with a user like this: username:branch.
base - Required. The name of the branch you want your changes pulled into. This should be an existing branch on the current repository.
body - The contents of the pull request. This is the markdown description of a pull request.
Throws:
IOException

getHooks

public List<GHHook> getHooks()
                      throws IOException
Retrieves the currently configured hooks.

Throws:
IOException

getHook

public GHHook getHook(int id)
               throws IOException
Throws:
IOException

getCompare

public GHCompare getCompare(String id1,
                            String id2)
                     throws IOException
Gets a comparison between 2 points in the repository. This would be similar to calling git log id1...id2 against a local repository.

Parameters:
id1 - an identifier for the first point to compare from, this can be a sha1 ID (for a commit, tag etc) or a direct tag name
id2 - an identifier for the second point to compare to. Can be the same as the first point.
Returns:
the comparison output
Throws:
IOException - on failure communicating with GitHub

getCompare

public GHCompare getCompare(GHCommit id1,
                            GHCommit id2)
                     throws IOException
Throws:
IOException

getCompare

public GHCompare getCompare(GHBranch id1,
                            GHBranch id2)
                     throws IOException
Throws:
IOException

getRefs

public GHRef[] getRefs()
                throws IOException
Retrieves all refs for the github repository.

Returns:
an array of GHRef elements coresponding with the refs in the remote repository.
Throws:
IOException - on failure communicating with GitHub

getRefs

public GHRef[] getRefs(String refType)
                throws IOException
Retrienved all refs of the given type for the current GitHub repository.

Parameters:
refType - the type of reg to search for e.g. tags or commits
Returns:
an array of all refs matching the request type
Throws:
IOException - on failure communicating with GitHub, potentially due to an invalid ref type being requested

getRef

public GHRef getRef(String refName)
             throws IOException
Retrive a ref of the given type for the current GitHub repository.

Parameters:
refName - eg: heads/branch
Returns:
refs matching the request type
Throws:
IOException - on failure communicating with GitHub, potentially due to an invalid ref type being requested

getCommit

public GHCommit getCommit(String sha1)
                   throws IOException
Gets a commit object in this repository.

Throws:
IOException

listCommits

public PagedIterable<GHCommit> listCommits()
Lists all the commits.


queryCommits

public GHCommitQueryBuilder queryCommits()
Search commits by specifying filters through a builder pattern.


listCommitComments

public PagedIterable<GHCommitComment> listCommitComments()
Lists up all the commit comments in this repository.


listCommitStatuses

public PagedIterable<GHCommitStatus> listCommitStatuses(String sha1)
                                                 throws IOException
Lists all the commit statues attached to the given commit, newer ones first.

Throws:
IOException

getLastCommitStatus

public GHCommitStatus getLastCommitStatus(String sha1)
                                   throws IOException
Gets the last status of this commit, which is what gets shown in the UI.

Throws:
IOException

createCommitStatus

public GHCommitStatus createCommitStatus(String sha1,
                                         GHCommitState state,
                                         String targetUrl,
                                         String description,
                                         String context)
                                  throws IOException
Creates a commit status

Parameters:
targetUrl - Optional parameter that points to the URL that has more details.
description - Optional short description.
context - Optinal commit status context.
Throws:
IOException

createCommitStatus

public GHCommitStatus createCommitStatus(String sha1,
                                         GHCommitState state,
                                         String targetUrl,
                                         String description)
                                  throws IOException
Throws:
IOException
See Also:
#createCommitStatus(String, GHCommitState,String,String,String) createCommitStatus}

listEvents

public PagedIterable<GHEventInfo> listEvents()
                                      throws IOException
Lists repository events.

Throws:
IOException

createHook

public GHHook createHook(String name,
                         Map<String,String> config,
                         Collection<GHEvent> events,
                         boolean active)
                  throws IOException
See https://api.github.com/hooks for possible names and their configuration scheme. TODO: produce type-safe binding

Parameters:
name - Type of the hook to be created. See https://api.github.com/hooks for possible names.
config - The configuration hash.
events - Can be null. Types of events to hook into.
Throws:
IOException

createWebHook

public GHHook createWebHook(URL url,
                            Collection<GHEvent> events)
                     throws IOException
Throws:
IOException

createWebHook

public GHHook createWebHook(URL url)
                     throws IOException
Throws:
IOException

getPostCommitHooks

public Set<URL> getPostCommitHooks()
Deprecated. Use getHooks() and createHook(String, Map, Collection, boolean)

Returns a set that represents the post-commit hook URLs. The returned set is live, and changes made to them are reflected to GitHub.


getBranches

public Map<String,GHBranch> getBranches()
                                 throws IOException
Gets branches by their names.

Throws:
IOException

getMilestones

public Map<Integer,GHMilestone> getMilestones()
                                       throws IOException
Deprecated. Use listMilestones(GHIssueState)

Throws:
IOException

listMilestones

public PagedIterable<GHMilestone> listMilestones(GHIssueState state)
Lists up all the milestones in this repository.


getMilestone

public GHMilestone getMilestone(int number)
                         throws IOException
Throws:
IOException

getFileContent

public GHContent getFileContent(String path)
                         throws IOException
Throws:
IOException

getFileContent

public GHContent getFileContent(String path,
                                String ref)
                         throws IOException
Throws:
IOException

getDirectoryContent

public List<GHContent> getDirectoryContent(String path)
                                    throws IOException
Throws:
IOException

getDirectoryContent

public List<GHContent> getDirectoryContent(String path,
                                           String ref)
                                    throws IOException
Throws:
IOException

getReadme

public GHContent getReadme()
                    throws Exception
Throws:
Exception

createContent

public GHContentUpdateResponse createContent(String content,
                                             String commitMessage,
                                             String path)
                                      throws IOException
Throws:
IOException

createContent

public GHContentUpdateResponse createContent(String content,
                                             String commitMessage,
                                             String path,
                                             String branch)
                                      throws IOException
Throws:
IOException

createMilestone

public GHMilestone createMilestone(String title,
                                   String description)
                            throws IOException
Throws:
IOException

addDeployKey

public GHDeployKey addDeployKey(String title,
                                String key)
                         throws IOException
Throws:
IOException

getDeployKeys

public List<GHDeployKey> getDeployKeys()
                                throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2014. All rights reserved.