Class GHRepository

java.lang.Object
org.kohsuke.github.GHObject
org.kohsuke.github.GHRepository

public class GHRepository extends GHObject
A repository on GitHub.
Author:
Kohsuke Kawaguchi
  • Constructor Details

    • GHRepository

      public GHRepository()
      Create default GHRepository instance
  • Method Details

    • createDeployment

      public GHDeploymentBuilder createDeployment(String ref)
      Create deployment gh deployment builder.
      Parameters:
      ref - the ref
      Returns:
      the gh deployment builder
    • listDeployments

      public PagedIterable<GHDeployment> listDeployments(String sha, String ref, String task, String environment)
      List deployments paged iterable.
      Parameters:
      sha - the sha
      ref - the ref
      task - the task
      environment - the environment
      Returns:
      the paged iterable
    • getDeployment

      public GHDeployment getDeployment(long id) throws IOException
      Obtains a single GHDeployment by its ID.
      Parameters:
      id - the id
      Returns:
      the deployment
      Throws:
      IOException - the io exception
    • getNodeId

      public String getNodeId()
      Gets node id.
      Overrides:
      getNodeId in class GHObject
      Returns:
      the node id
      See Also:
    • getDescription

      public String getDescription()
      Gets description.
      Returns:
      the description
    • getHomepage

      public String getHomepage()
      Gets homepage.
      Returns:
      the homepage
    • getGitTransportUrl

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

      public String getHttpTransportUrl()
      Gets the HTTPS URL to this repository, such as "https://github.com/kohsuke/jenkins.git" This URL is read-only.
      Returns:
      the http transport url
    • getSvnUrl

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

      public String getMirrorUrl()
      Gets the Mirror URL to access this repository: https://github.com/apache/tomee mirrored from git://git.apache.org/tomee.git
      Returns:
      the mirror url
    • getSshUrl

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

      public URL getHtmlUrl()
      Gets the html url.
      Returns:
      the html url
    • getName

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

      public String getFullName()
      Full repository name including the owner or organization. For example 'jenkinsci/jenkins' in case of http://github.com/jenkinsci/jenkins
      Returns:
      the full name
    • hasPullAccess

      public boolean hasPullAccess()
      Has pull access boolean.
      Returns:
      the boolean
    • hasPushAccess

      public boolean hasPushAccess()
      Has push access boolean.
      Returns:
      the boolean
    • hasAdminAccess

      public boolean hasAdminAccess()
      Has admin access boolean.
      Returns:
      the boolean
    • getLanguage

      public String getLanguage()
      Gets the primary programming language.
      Returns:
      the language
    • getOwner

      public GHUser getOwner() throws IOException
      Gets owner.
      Returns:
      the owner
      Throws:
      IOException - the io exception
    • getIssue

      public GHIssue getIssue(int id) throws IOException
      Gets issue.
      Parameters:
      id - the id
      Returns:
      the issue
      Throws:
      IOException - the io exception
    • createIssue

      public GHIssueBuilder createIssue(String title)
      Create issue gh issue builder.
      Parameters:
      title - the title
      Returns:
      the gh issue builder
    • getIssues

      public List<GHIssue> getIssues(GHIssueState state) throws IOException
      Gets issues.
      Parameters:
      state - the state
      Returns:
      the issues
      Throws:
      IOException - the io exception
    • getIssues

      public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException
      Gets issues.
      Parameters:
      state - the state
      milestone - the milestone
      Returns:
      the issues
      Throws:
      IOException - the io exception
    • queryIssues

      public GHIssueQueryBuilder.ForRepository queryIssues()
      Retrieves issues.
      Returns:
      the gh issue query builder
    • createRelease

      public GHReleaseBuilder createRelease(String tag)
      Create release gh release builder.
      Parameters:
      tag - the tag
      Returns:
      the gh release builder
    • 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/main). 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
      Returns:
      the gh ref
      Throws:
      IOException - the io exception
    • getRelease

      public GHRelease getRelease(long id) throws IOException
      Gets release.
      Parameters:
      id - the id
      Returns:
      the release
      Throws:
      IOException - the io exception
    • getReleaseByTagName

      public GHRelease getReleaseByTagName(String tag) throws IOException
      Gets release by tag name.
      Parameters:
      tag - the tag
      Returns:
      the release by tag name
      Throws:
      IOException - the io exception
    • getLatestRelease

      public GHRelease getLatestRelease() throws IOException
      Gets latest release.
      Returns:
      the latest release
      Throws:
      IOException - the io exception
    • listReleases

      public PagedIterable<GHRelease> listReleases() throws IOException
      List releases paged iterable.
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • listTags

      public PagedIterable<GHTag> listTags() throws IOException
      List tags paged iterable.
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • listLanguages

      public Map<String,Long> listLanguages() throws IOException
      List languages for the specified repository. The value on the right of a language is the number of bytes of code written in that language. { "C": 78769, "Python": 7769 }
      Returns:
      the map
      Throws:
      IOException - the io exception
    • getOwnerName

      public String getOwnerName()
      Gets owner name.
      Returns:
      the owner name
    • hasIssues

      public boolean hasIssues()
      Has issues boolean.
      Returns:
      the boolean
    • hasProjects

      public boolean hasProjects()
      Has projects boolean.
      Returns:
      the boolean
    • hasWiki

      public boolean hasWiki()
      Has wiki boolean.
      Returns:
      the boolean
    • isFork

      public boolean isFork()
      Is fork boolean.
      Returns:
      the boolean
    • isArchived

      public boolean isArchived()
      Is archived boolean.
      Returns:
      the boolean
    • isDisabled

      public boolean isDisabled()
      Is disabled boolean.
      Returns:
      the boolean
    • isAllowSquashMerge

      public boolean isAllowSquashMerge()
      Is allow squash merge boolean.
      Returns:
      the boolean
    • isAllowMergeCommit

      public boolean isAllowMergeCommit()
      Is allow merge commit boolean.
      Returns:
      the boolean
    • isAllowRebaseMerge

      public boolean isAllowRebaseMerge()
      Is allow rebase merge boolean.
      Returns:
      the boolean
    • isAllowForking

      public boolean isAllowForking()
      Is allow private forks
      Returns:
      the boolean
    • isDeleteBranchOnMerge

      public boolean isDeleteBranchOnMerge()
      Automatically deleting head branches when pull requests are merged.
      Returns:
      the boolean
    • getForksCount

      public int getForksCount()
      Returns the number of all forks of this repository. This not only counts direct forks, but also forks of forks, and so on.
      Returns:
      the forks
    • getStargazersCount

      public int getStargazersCount()
      Gets stargazers count.
      Returns:
      the stargazers count
    • isPrivate

      public boolean isPrivate()
      Is private boolean.
      Returns:
      the boolean
    • getVisibility

      public GHRepository.Visibility getVisibility()
      Gets the visibility of the repository.
      Returns:
      the visibility
    • isTemplate

      public boolean isTemplate()
      Is template boolean.
      Returns:
      the boolean
    • hasDownloads

      public boolean hasDownloads()
      Has downloads boolean.
      Returns:
      the boolean
    • hasPages

      public boolean hasPages()
      Has pages boolean.
      Returns:
      the boolean
    • getWatchersCount

      public int getWatchersCount()
      Gets the count of watchers.
      Returns:
      the watchers
    • getOpenIssueCount

      public int getOpenIssueCount()
      Gets open issue count.
      Returns:
      the open issue count
    • getSubscribersCount

      public int getSubscribersCount()
      Gets subscribers count.
      Returns:
      the subscribers count
    • getPushedAt

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

      public String getDefaultBranch()
      Returns the primary branch you'll configure in the "Admin > Options" config page.
      Returns:
      This field is null until the user explicitly configures the default branch.
    • getTemplateRepository

      public GHRepository getTemplateRepository()
      Get Repository template was the repository created from.
      Returns:
      the repository template
    • getSize

      public int getSize()
      Gets size.
      Returns:
      the size
    • getCollaborators

      public GHPersonSet<GHUser> getCollaborators() throws IOException
      Gets the collaborators on this repository. This set always appear to include the owner.
      Returns:
      the collaborators
      Throws:
      IOException - the io exception
    • listCollaborators

      public PagedIterable<GHUser> listCollaborators() throws IOException
      Lists up the collaborators on this repository.
      Returns:
      Users paged iterable
      Throws:
      IOException - the io exception
    • listCollaborators

      public PagedIterable<GHUser> listCollaborators(GHRepository.CollaboratorAffiliation affiliation) throws IOException
      Lists up the collaborators on this repository.
      Parameters:
      affiliation - Filter users by affiliation
      Returns:
      Users paged iterable
      Throws:
      IOException - the io exception
    • listAssignees

      public PagedIterable<GHUser> listAssignees() throws IOException
      Lists all the available assignees to which issues may be assigned.
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • hasAssignee

      public boolean hasAssignee(GHUser u) throws IOException
      Checks if the given user is an assignee for this repository.
      Parameters:
      u - the u
      Returns:
      the boolean
      Throws:
      IOException - the io exception
    • 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().
      Returns:
      the collaborator names
      Throws:
      IOException - the io exception
    • getCollaboratorNames

      public Set<String> getCollaboratorNames(GHRepository.CollaboratorAffiliation affiliation) 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().
      Parameters:
      affiliation - Filter users by affiliation
      Returns:
      the collaborator names
      Throws:
      IOException - the io exception
    • isCollaborator

      public boolean isCollaborator(GHUser user) throws IOException
      Checks if the given user is a collaborator for this repository.
      Parameters:
      user - a GHUser
      Returns:
      true if the user is a collaborator for this repository
      Throws:
      IOException - the io exception
    • getPermission

      public GHPermissionType getPermission(String user) throws IOException
      Obtain permission for a given user in this repository.
      Parameters:
      user - a GHPerson.getLogin()
      Returns:
      the permission
      Throws:
      IOException - the io exception
    • getPermission

      public GHPermissionType getPermission(GHUser u) throws IOException
      Obtain permission for a given user in this repository.
      Parameters:
      u - the user
      Returns:
      the permission
      Throws:
      IOException - the io exception
    • hasPermission

      public boolean hasPermission(String user, GHPermissionType permission) throws IOException
      Check if a user has at least the given permission in this repository.
      Parameters:
      user - a GHPerson.getLogin()
      permission - the permission to check
      Returns:
      true if the user has at least this permission level
      Throws:
      IOException - the io exception
    • hasPermission

      public boolean hasPermission(GHUser user, GHPermissionType permission) throws IOException
      Check if a user has at least the given permission in this repository.
      Parameters:
      user - the user
      permission - the permission to check
      Returns:
      true if the user has at least this permission level
      Throws:
      IOException - the io exception
    • getTeams

      public Set<GHTeam> getTeams() throws IOException
      If this repository belongs to an organization, return a set of teams.
      Returns:
      the teams
      Throws:
      IOException - the io exception
    • addCollaborators

      public void addCollaborators(GHOrganization.RepositoryRole permission, GHUser... users) throws IOException
      Add collaborators.
      Parameters:
      permission - the permission level
      users - the users
      Throws:
      IOException - the io exception
    • addCollaborators

      public void addCollaborators(GHUser... users) throws IOException
      Add collaborators.
      Parameters:
      users - the users
      Throws:
      IOException - the io exception
    • addCollaborators

      public void addCollaborators(Collection<GHUser> users) throws IOException
      Add collaborators.
      Parameters:
      users - the users
      Throws:
      IOException - the io exception
    • addCollaborators

      public void addCollaborators(Collection<GHUser> users, GHOrganization.RepositoryRole permission) throws IOException
      Add collaborators.
      Parameters:
      users - the users
      permission - the permission level
      Throws:
      IOException - the io exception
    • removeCollaborators

      public void removeCollaborators(GHUser... users) throws IOException
      Remove collaborators.
      Parameters:
      users - the users
      Throws:
      IOException - the io exception
    • removeCollaborators

      public void removeCollaborators(Collection<GHUser> users) throws IOException
      Remove collaborators.
      Parameters:
      users - the users
      Throws:
      IOException - the io exception
    • setEmailServiceHook

      public void setEmailServiceHook(String address) throws IOException
      Sets email service hook.
      Parameters:
      address - the address
      Throws:
      IOException - the io exception
    • enableIssueTracker

      public void enableIssueTracker(boolean v) throws IOException
      Enables or disables the issue tracker for this repository.
      Parameters:
      v - the v
      Throws:
      IOException - the io exception
    • enableProjects

      public void enableProjects(boolean v) throws IOException
      Enables or disables projects for this repository.
      Parameters:
      v - the v
      Throws:
      IOException - the io exception
    • enableWiki

      public void enableWiki(boolean v) throws IOException
      Enables or disables Wiki for this repository.
      Parameters:
      v - the v
      Throws:
      IOException - the io exception
    • enableDownloads

      public void enableDownloads(boolean v) throws IOException
      Enable downloads.
      Parameters:
      v - the v
      Throws:
      IOException - the io exception
    • renameTo

      public void renameTo(String name) throws IOException
      Rename this repository.
      Parameters:
      name - the name
      Throws:
      IOException - the io exception
    • setDescription

      public void setDescription(String value) throws IOException
      Sets description.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • setHomepage

      public void setHomepage(String value) throws IOException
      Sets homepage.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • setDefaultBranch

      public void setDefaultBranch(String value) throws IOException
      Sets default branch.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • setPrivate

      public void setPrivate(boolean value) throws IOException
      Sets private.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • setVisibility

      public void setVisibility(GHRepository.Visibility value) throws IOException
      Sets visibility.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • allowSquashMerge

      public void allowSquashMerge(boolean value) throws IOException
      Allow squash merge.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • allowMergeCommit

      public void allowMergeCommit(boolean value) throws IOException
      Allow merge commit.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • allowRebaseMerge

      public void allowRebaseMerge(boolean value) throws IOException
      Allow rebase merge.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • allowForking

      public void allowForking(boolean value) throws IOException
      Allow private fork.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • deleteBranchOnMerge

      public void deleteBranchOnMerge(boolean value) throws IOException
      After pull requests are merged, you can have head branches deleted automatically.
      Parameters:
      value - the value
      Throws:
      IOException - the io exception
    • delete

      public void delete() throws IOException
      Deletes this repository.
      Throws:
      IOException - the io exception
    • archive

      public void archive() throws IOException
      Will archive and this repository as read-only. When a repository is archived, any operation that can change its state is forbidden. This applies symmetrically if trying to unarchive it.

      When you try to do any operation that modifies a read-only repository, it returns the response:

       org.kohsuke.github.HttpException: {
           "message":"Repository was archived so is read-only.",
           "documentation_url":"https://developer.github.com/v3/repos/#edit"
       }
       
      Throws:
      IOException - In case of any networking error or error from the server.
    • update

      public GHRepository.Updater update()
      Creates a builder that can be used to bulk update repository settings.
      Returns:
      the repository updater
    • set

      public GHRepository.Setter set()
      Creates a builder that can be used to bulk update repository settings.
      Returns:
      the repository updater
    • listForks

      public PagedIterable<GHRepository> listForks()
      Lists all the direct forks of this repository, sorted by github api default, currently ForkSort.NEWEST*.
      Returns:
      the paged iterable
    • listForks

      Lists all the direct forks of this repository, sorted by the given sort order.
      Parameters:
      sort - the sort order. If null, defaults to github api default, currently ForkSort.NEWEST.
      Returns:
      the paged iterable
    • fork

      public GHRepository fork() throws IOException
      Forks this repository as your repository.
      Returns:
      Newly forked repository that belong to you.
      Throws:
      IOException - the io exception
    • sync

      public GHBranchSync sync(String branch) throws IOException
      Sync this repository fork branch
      Parameters:
      branch - the branch to sync
      Returns:
      The current repository
      Throws:
      IOException - the io exception
    • forkTo

      public GHRepository forkTo(GHOrganization org) throws IOException
      Forks this repository into an organization.
      Parameters:
      org - the org
      Returns:
      Newly forked repository that belong to you.
      Throws:
      IOException - the io exception
    • getPullRequest

      public GHPullRequest getPullRequest(int i) throws IOException
      Retrieves a specified pull request.
      Parameters:
      i - the
      Returns:
      the pull request
      Throws:
      IOException - the io exception
    • queryPullRequests

      public GHPullRequestQueryBuilder queryPullRequests()
      Retrieves pull requests.
      Returns:
      the gh pull request query builder
    • searchPullRequests

      public GHPullRequestSearchBuilder searchPullRequests()
      Retrieves pull requests according to search terms.
      Returns:
      gh pull request search builder for current repository
    • 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.
      Returns:
      the gh pull request
      Throws:
      IOException - the io exception
    • createPullRequest

      public GHPullRequest createPullRequest(String title, String head, String base, String body, boolean maintainerCanModify) throws IOException
      Creates a new pull request. Maintainer's permissions aware.
      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.
      maintainerCanModify - Indicates whether maintainers can modify the pull request.
      Returns:
      the gh pull request
      Throws:
      IOException - the io exception
    • createPullRequest

      public GHPullRequest createPullRequest(String title, String head, String base, String body, boolean maintainerCanModify, boolean draft) throws IOException
      Creates a new pull request. Maintainer's permissions and draft aware.
      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.
      maintainerCanModify - Indicates whether maintainers can modify the pull request.
      draft - Indicates whether to create a draft pull request or not.
      Returns:
      the gh pull request
      Throws:
      IOException - the io exception
    • getHooks

      public List<GHHook> getHooks() throws IOException
      Retrieves the currently configured hooks.
      Returns:
      the hooks
      Throws:
      IOException - the io exception
    • getHook

      public GHHook getHook(int id) throws IOException
      Gets hook.
      Parameters:
      id - the id
      Returns:
      the hook
      Throws:
      IOException - the io exception
    • deleteHook

      public void deleteHook(int id) throws IOException
      Deletes hook.
      Parameters:
      id - the id
      Throws:
      IOException - the io exception
    • setCompareUsePaginatedCommits

      public void setCompareUsePaginatedCommits(boolean value)
      Sets getCompare(String, String) to return a GHCompare that uses a paginated commit list instead of limiting to 250 results. By default, GHCompare returns all commits in the comparison as part of the request, limited to 250 results. More recently GitHub added the ability to return the commits as a paginated query allowing for more than 250 results.
      Parameters:
      value - true if you want commits returned in paginated form.
    • 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
      Gets compare.
      Parameters:
      id1 - the id 1
      id2 - the id 2
      Returns:
      the compare
      Throws:
      IOException - the io exception
    • getCompare

      public GHCompare getCompare(GHBranch id1, GHBranch id2) throws IOException
      Gets compare.
      Parameters:
      id1 - the id 1
      id2 - the id 2
      Returns:
      the compare
      Throws:
      IOException - the io exception
    • getRefs

      public GHRef[] getRefs() throws IOException
      Retrieves all refs for the github repository.
      Returns:
      an array of GHRef elements corresponding with the refs in the remote repository.
      Throws:
      IOException - on failure communicating with GitHub
    • listRefs

      public PagedIterable<GHRef> listRefs() throws IOException
      Retrieves all refs for the github repository.
      Returns:
      paged iterable of all refs
      Throws:
      IOException - on failure communicating with GitHub, potentially due to an invalid ref type being requested
    • getRefs

      public GHRef[] getRefs(String refType) throws IOException
      Retrieves 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
    • listRefs

      public PagedIterable<GHRef> listRefs(String refType) throws IOException
      Retrieves 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:
      paged iterable of all refs of the specified 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
      Retrieve 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
    • getTagObject

      public GHTagObject getTagObject(String sha) throws IOException
      Returns the annotated tag object. Only valid if the GHRef.getObject() has a GHRef.GHObject.getType() of tag.
      Parameters:
      sha - the sha of the tag object
      Returns:
      the annotated tag object
      Throws:
      IOException - the io exception
    • getTree

      public GHTree getTree(String sha) throws IOException
      Retrieve a tree of the given type for the current GitHub repository.
      Parameters:
      sha - sha number or branch name ex: "main"
      Returns:
      refs matching the request type
      Throws:
      IOException - on failure communicating with GitHub, potentially due to an invalid tree type being requested
    • createTree

      public GHTreeBuilder createTree()
      Create tree gh tree builder.
      Returns:
      the gh tree builder
    • getTreeRecursive

      public GHTree getTreeRecursive(String sha, int recursive) throws IOException
      Retrieves the tree for the current GitHub repository, recursively as described in here: https://developer.github.com/v3/git/trees/#get-a-tree-recursively
      Parameters:
      sha - sha number or branch name ex: "main"
      recursive - use 1
      Returns:
      the tree recursive
      Throws:
      IOException - on failure communicating with GitHub, potentially due to an invalid tree type being requested
    • getBlob

      public GHBlob getBlob(String blobSha) throws IOException
      Obtains the metadata & the content of a blob.

      This method retrieves the whole content in memory, so beware when you are dealing with large BLOB.

      Parameters:
      blobSha - the blob sha
      Returns:
      the blob
      Throws:
      IOException - the io exception
      See Also:
    • createBlob

      public GHBlobBuilder createBlob()
      Create blob gh blob builder.
      Returns:
      the gh blob builder
    • readBlob

      public InputStream readBlob(String blobSha) throws IOException
      Reads the content of a blob as a stream for better efficiency.
      Parameters:
      blobSha - the blob sha
      Returns:
      the input stream
      Throws:
      IOException - the io exception
      See Also:
    • getCommit

      public GHCommit getCommit(String sha1) throws IOException
      Gets a commit object in this repository.
      Parameters:
      sha1 - the sha 1
      Returns:
      the commit
      Throws:
      IOException - the io exception
    • createCommit

      public GHCommitBuilder createCommit()
      Create commit gh commit builder.
      Returns:
      the gh commit builder
    • listCommits

      public PagedIterable<GHCommit> listCommits()
      Lists all the commits.
      Returns:
      the paged iterable
    • queryCommits

      public GHCommitQueryBuilder queryCommits()
      Search commits by specifying filters through a builder pattern.
      Returns:
      the gh commit query builder
    • listCommitComments

      public PagedIterable<GHCommitComment> listCommitComments()
      Lists up all the commit comments in this repository.
      Returns:
      the paged iterable
    • listCommitComments

      public PagedIterable<GHCommitComment> listCommitComments(String commitSha)
      Lists all comments on a specific commit.
      Parameters:
      commitSha - the hash of the commit
      Returns:
      the paged iterable
    • getLicense

      public GHLicense getLicense() throws IOException
      Gets the basic license details for the repository.
      Returns:
      null if there's no license.
      Throws:
      IOException - as usual but also if you don't use the preview connector
    • getLicenseContent

      public GHContent getLicenseContent() throws IOException
      Retrieves the contents of the repository's license file - makes an additional API call.
      Returns:
      details regarding the license contents, or null if there's no license.
      Throws:
      IOException - as usual but also if you don't use the preview connector
    • listCommitStatuses

      public PagedIterable<GHCommitStatus> listCommitStatuses(String sha1) throws IOException
      /** Lists all the commit statuses attached to the given commit, newer ones first.
      Parameters:
      sha1 - the sha 1
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • getLastCommitStatus

      public GHCommitStatus getLastCommitStatus(String sha1) throws IOException
      Gets the last status of this commit, which is what gets shown in the UI.
      Parameters:
      sha1 - the sha 1
      Returns:
      the last commit status
      Throws:
      IOException - the io exception
    • getCheckRuns

      public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException
      Gets check runs for given ref.
      Parameters:
      ref - ref
      Returns:
      check runs for given ref
      Throws:
      IOException - the io exception
      See Also:
    • getCheckRuns

      public PagedIterable<GHCheckRun> getCheckRuns(String ref, Map<String,Object> params) throws IOException
      Gets check runs for given ref which validate provided parameters
      Parameters:
      ref - the Git reference
      params - a map of parameters to filter check runs
      Returns:
      check runs for the given ref
      Throws:
      IOException - the io exception
      See Also:
    • createCommitStatus

      public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException
      Creates a commit status.
      Parameters:
      sha1 - the sha 1
      state - the state
      targetUrl - Optional parameter that points to the URL that has more details.
      description - Optional short description.
      context - Optional commit status context.
      Returns:
      the gh commit status
      Throws:
      IOException - the io exception
    • createCommitStatus

      public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException
      Create commit status gh commit status.
      Parameters:
      sha1 - the sha 1
      state - the state
      targetUrl - the target url
      description - the description
      Returns:
      the gh commit status
      Throws:
      IOException - the io exception
      See Also:
    • createCheckRun

      @NonNull public GHCheckRunBuilder createCheckRun(@NonNull String name, @NonNull String headSHA)
      Creates a check run for a commit.
      Parameters:
      name - an identifier for the run
      headSHA - the commit hash
      Returns:
      a builder which you should customize, then call GHCheckRunBuilder.create()
    • updateCheckRun

      @NonNull public GHCheckRunBuilder updateCheckRun(long checkId)
      Updates an existing check run.
      Parameters:
      checkId - the existing checkId
      Returns:
      a builder which you should customize, then call GHCheckRunBuilder.create()
    • listEvents

      public PagedIterable<GHEventInfo> listEvents() throws IOException
      Lists repository events.
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • listLabels

      public PagedIterable<GHLabel> listLabels() throws IOException
      Lists labels in this repository.

      https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository

      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • getLabel

      public GHLabel getLabel(String name) throws IOException
      Gets label.
      Parameters:
      name - the name
      Returns:
      the label
      Throws:
      IOException - the io exception
    • createLabel

      public GHLabel createLabel(String name, String color) throws IOException
      Create label gh label.
      Parameters:
      name - the name
      color - the color
      Returns:
      the gh label
      Throws:
      IOException - the io exception
    • createLabel

      public GHLabel createLabel(String name, String color, String description) throws IOException
      Description is still in preview.
      Parameters:
      name - the name
      color - the color
      description - the description
      Returns:
      gh label
      Throws:
      IOException - the io exception
    • listInvitations

      public PagedIterable<GHInvitation> listInvitations()
      Lists all the invitations.
      Returns:
      the paged iterable
    • listSubscribers

      public PagedIterable<GHUser> listSubscribers()
      Lists all the subscribers (aka watchers.)

      https://developer.github.com/v3/activity/watching/

      Returns:
      the paged iterable
    • listStargazers2

      @Deprecated public PagedIterable<GHStargazer> listStargazers2()
      Deprecated.
      Lists all the users who have starred this repo based on new version of the API, having extended information like the time when the repository was starred.
      Returns:
      the paged iterable
    • listStargazers

      public PagedIterable<GHStargazer> listStargazers()
      Lists all the users who have starred this repo based on new version of the API, having extended information like the time when the repository was starred.
      Returns:
      the paged iterable
    • 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.
      active - the active
      Returns:
      the gh hook
      Throws:
      IOException - the io exception
    • createWebHook

      public GHHook createWebHook(URL url, Collection<GHEvent> events) throws IOException
      Create web hook gh hook.
      Parameters:
      url - the url
      events - the events
      Returns:
      the gh hook
      Throws:
      IOException - the io exception
    • createWebHook

      public GHHook createWebHook(URL url) throws IOException
      Create web hook gh hook.
      Parameters:
      url - the url
      Returns:
      the gh hook
      Throws:
      IOException - the io exception
    • getBranches

      public Map<String,GHBranch> getBranches() throws IOException
      Gets branches by their names.
      Returns:
      the branches
      Throws:
      IOException - the io exception
    • getBranch

      public GHBranch getBranch(String name) throws IOException
      Gets branch.
      Parameters:
      name - the name
      Returns:
      the branch
      Throws:
      IOException - the io exception
    • listMilestones

      public PagedIterable<GHMilestone> listMilestones(GHIssueState state)
      Lists up all the milestones in this repository.
      Parameters:
      state - the state
      Returns:
      the paged iterable
    • getMilestone

      public GHMilestone getMilestone(int number) throws IOException
      Gets milestone.
      Parameters:
      number - the number
      Returns:
      the milestone
      Throws:
      IOException - the io exception
    • getFileContent

      public GHContent getFileContent(String path) throws IOException
      Gets file content.
      Parameters:
      path - the path
      Returns:
      the file content
      Throws:
      IOException - the io exception
    • getFileContent

      public GHContent getFileContent(String path, String ref) throws IOException
      Gets file content.
      Parameters:
      path - the path
      ref - the ref
      Returns:
      the file content
      Throws:
      IOException - the io exception
    • getDirectoryContent

      public List<GHContent> getDirectoryContent(String path) throws IOException
      Gets directory content.
      Parameters:
      path - the path
      Returns:
      the directory content
      Throws:
      IOException - the io exception
    • getDirectoryContent

      public List<GHContent> getDirectoryContent(String path, String ref) throws IOException
      Gets directory content.
      Parameters:
      path - the path
      ref - the ref
      Returns:
      the directory content
      Throws:
      IOException - the io exception
    • getReadme

      public GHContent getReadme() throws IOException
      https://developer.github.com/v3/repos/contents/#get-the-readme
      Returns:
      the readme
      Throws:
      IOException - the io exception
    • createVariable

      public void createVariable(String name, String value) throws IOException
      Create a repository variable.
      Parameters:
      name - the variable name (e.g. test-variable)
      value - the value
      Throws:
      IOException - the io exception
    • getVariable

      public GHRepositoryVariable getVariable(String name) throws IOException
      Gets a repository variable.
      Parameters:
      name - the variable name (e.g. test-variable)
      Returns:
      the variable
      Throws:
      IOException - the io exception
    • createContent

      public GHContentBuilder createContent()
      Creates a new content, or update an existing content.
      Returns:
      the gh content builder
    • createMilestone

      public GHMilestone createMilestone(String title, String description) throws IOException
      Create milestone gh milestone.
      Parameters:
      title - the title
      description - the description
      Returns:
      the gh milestone
      Throws:
      IOException - the io exception
    • addDeployKey

      public GHDeployKey addDeployKey(String title, String key) throws IOException
      Add deploy key gh deploy key.
      Parameters:
      title - the title
      key - the key
      Returns:
      the gh deploy key
      Throws:
      IOException - the io exception
    • addDeployKey

      public GHDeployKey addDeployKey(String title, String key, boolean readOnly) throws IOException
      Add deploy key gh deploy key.
      Parameters:
      title - the title
      key - the key
      readOnly - read-only ability of the key
      Returns:
      the gh deploy key
      Throws:
      IOException - the io exception
    • getDeployKeys

      public List<GHDeployKey> getDeployKeys() throws IOException
      Gets deploy keys.
      Returns:
      the deploy keys
      Throws:
      IOException - the io exception
    • getSource

      public GHRepository getSource() throws IOException
      Forked repositories have a 'source' attribute that specifies the ultimate source of the forking chain.
      Returns:
      GHRepository that points to the root repository where this repository is forked (indirectly or directly) from. Otherwise null.
      Throws:
      IOException - the io exception
      See Also:
    • getParent

      public GHRepository getParent() throws IOException
      Forked repositories have a 'parent' attribute that specifies the repository this repository is directly forked from. If we keep traversing getParent() until it returns null, that is getSource().
      Returns:
      GHRepository that points to the repository where this repository is forked directly from. Otherwise null.
      Throws:
      IOException - the io exception
      See Also:
    • subscribe

      public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException
      Subscribes to this repository to get notifications.
      Parameters:
      subscribed - the subscribed
      ignored - the ignored
      Returns:
      the gh subscription
      Throws:
      IOException - the io exception
    • getSubscription

      public GHSubscription getSubscription() throws IOException
      Returns the current subscription.
      Returns:
      null if no subscription exists.
      Throws:
      IOException - the io exception
    • listCodeownersErrors

      public List<GHCodeownersError> listCodeownersErrors() throws IOException
      List errors in the CODEOWNERS file. Note that GitHub skips lines with incorrect syntax; these are reported in the web interface, but not in the API call which this library uses.
      Returns:
      the list of errors
      Throws:
      IOException - the io exception
    • listContributors

      public PagedIterable<GHRepository.Contributor> listContributors() throws IOException
      List contributors paged iterable.
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • getStatistics

      public GHRepositoryStatistics getStatistics()
      Returns the statistics for this repository.
      Returns:
      the statistics
    • createProject

      public GHProject createProject(String name, String body) throws IOException
      Create a project for this repository.
      Parameters:
      name - the name
      body - the body
      Returns:
      the gh project
      Throws:
      IOException - the io exception
    • listProjects

      public PagedIterable<GHProject> listProjects(GHProject.ProjectStateFilter status) throws IOException
      Returns the projects for this repository.
      Parameters:
      status - The status filter (all, open or closed).
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • listProjects

      public PagedIterable<GHProject> listProjects() throws IOException
      Returns open projects for this repository.
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • renderMarkdown

      public Reader renderMarkdown(String text, MarkdownMode mode) throws IOException
      Render a Markdown document.

      In GFM mode, issue numbers and user mentions are linked accordingly.

      Parameters:
      text - the text
      mode - the mode
      Returns:
      the reader
      Throws:
      IOException - the io exception
      See Also:
    • listNotifications

      public GHNotificationStream listNotifications()
      List all the notifications in a repository for the current user.
      Returns:
      the gh notification stream
    • getViewTraffic

      public GHRepositoryViewTraffic getViewTraffic() throws IOException
      Returns:
      the view traffic
      Throws:
      IOException - the io exception
    • getCloneTraffic

      public GHRepositoryCloneTraffic getCloneTraffic() throws IOException
      Returns:
      the clone traffic
      Throws:
      IOException - the io exception
    • hashCode

      public int hashCode()
      Hash code.
      Overrides:
      hashCode in class Object
      Returns:
      the int
    • equals

      public boolean equals(Object obj)
      Equals.
      Overrides:
      equals in class Object
      Parameters:
      obj - the obj
      Returns:
      true, if successful
    • listIssueEvents

      public PagedIterable<GHIssueEvent> listIssueEvents() throws IOException
      Get all issue events for this repository. See https://developer.github.com/v3/issues/events/#list-events-for-a-repository
      Returns:
      the paged iterable
      Throws:
      IOException - the io exception
    • getIssueEvent

      public GHIssueEvent getIssueEvent(long id) throws IOException
      Get a single issue event. See https://developer.github.com/v3/issues/events/#get-a-single-event
      Parameters:
      id - the id
      Returns:
      the issue event
      Throws:
      IOException - the io exception
    • listWorkflows

      public PagedIterable<GHWorkflow> listWorkflows()
      Lists all the workflows of this repository.
      Returns:
      the paged iterable
    • getWorkflow

      public GHWorkflow getWorkflow(long id) throws IOException
      Gets a workflow by id.
      Parameters:
      id - the id of the workflow run
      Returns:
      the workflow run
      Throws:
      IOException - the io exception
    • getWorkflow

      public GHWorkflow getWorkflow(String nameOrId) throws IOException
      Gets a workflow by name of the file.
      Parameters:
      nameOrId - either the name of the file (e.g. my-workflow.yml) or the id as a string
      Returns:
      the workflow run
      Throws:
      IOException - the io exception
    • queryWorkflowRuns

      public GHWorkflowRunQueryBuilder queryWorkflowRuns()
      Retrieves workflow runs.
      Returns:
      the workflow run query builder
    • getWorkflowRun

      public GHWorkflowRun getWorkflowRun(long id) throws IOException
      Gets a workflow run.
      Parameters:
      id - the id of the workflow run
      Returns:
      the workflow run
      Throws:
      IOException - the io exception
    • listArtifacts

      public PagedIterable<GHArtifact> listArtifacts()
      Lists all the artifacts of this repository.
      Returns:
      the paged iterable
    • getArtifact

      public GHArtifact getArtifact(long id) throws IOException
      Gets an artifact by id.
      Parameters:
      id - the id of the artifact
      Returns:
      the artifact
      Throws:
      IOException - the io exception
    • getWorkflowJob

      public GHWorkflowJob getWorkflowJob(long id) throws IOException
      Gets a job from a workflow run by id.
      Parameters:
      id - the id of the job
      Returns:
      the job
      Throws:
      IOException - the io exception
    • getPublicKey

      public GHRepositoryPublicKey getPublicKey() throws IOException
      Gets the public key for the given repo.
      Returns:
      the public key
      Throws:
      IOException - the io exception
    • listTopics

      public List<String> listTopics() throws IOException
      Return the topics for this repository. See https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
      Returns:
      the list
      Throws:
      IOException - the io exception
    • setTopics

      public void setTopics(List<String> topics) throws IOException
      Set the topics for this repository. See https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
      Parameters:
      topics - the topics
      Throws:
      IOException - the io exception
    • createSecret

      public void createSecret(String secretName, String encryptedValue, String publicKeyId) throws IOException
      Set/Update a repository secret "https://docs.github.com/rest/reference/actions#create-or-update-a-repository-secret"
      Parameters:
      secretName - the name of the secret
      encryptedValue - The encrypted value for this secret
      publicKeyId - The id of the Public Key used to encrypt this secret
      Throws:
      IOException - the io exception
    • createTag

      public GHTagObject createTag(String tag, String message, String object, String type) throws IOException
      Create a tag. See https://developer.github.com/v3/git/tags/#create-a-tag-object
      Parameters:
      tag - The tag's name.
      message - The tag message.
      object - The SHA of the git object this is tagging.
      type - The type of the object we're tagging: "commit", "tree" or "blob".
      Returns:
      The newly created tag.
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • readZip

      public <T> T readZip(InputStreamFunction<T> streamFunction, String ref) throws IOException
      Streams a zip archive of the repository, optionally at a given ref.
      Type Parameters:
      T - the type of result
      Parameters:
      streamFunction - The InputStreamFunction that will process the stream
      ref - if null the repository's default branch, usually main,
      Returns:
      the result of reading the stream.
      Throws:
      IOException - The IO exception.
    • readTar

      public <T> T readTar(InputStreamFunction<T> streamFunction, String ref) throws IOException
      Streams a tar archive of the repository, optionally at a given ref.
      Type Parameters:
      T - the type of result
      Parameters:
      streamFunction - The InputStreamFunction that will process the stream
      ref - if null the repository's default branch, usually main,
      Returns:
      the result of reading the stream.
      Throws:
      IOException - The IO exception.
    • dispatch

      public <T> void dispatch(String eventType, @Nullable T clientPayload) throws IOException
      Create a repository dispatch event, which can be used to start a workflow/action from outside github, as described on https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event
      Type Parameters:
      T - type of client payload
      Parameters:
      eventType - the eventType
      clientPayload - a custom payload , can be nullable
      Throws:
      IOException - the io exception
    • star

      public void star() throws IOException
      Star a repository.
      Throws:
      IOException - the io exception
    • unstar

      public void unstar() throws IOException
      Unstar a repository.
      Throws:
      IOException - the io exception
    • getTopReferralPaths

      public List<GHRepositoryTrafficTopReferralPath> getTopReferralPaths() throws IOException
      Get the top 10 popular contents over the last 14 days as described on https://docs.github.com/en/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-paths
      Returns:
      list of top referral paths
      Throws:
      IOException - the io exception
    • getTopReferralSources

      public List<GHRepositoryTrafficTopReferralSources> getTopReferralSources() throws IOException
      Get the top 10 referrers over the last 14 days as described on https://docs.github.com/en/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-sources
      Returns:
      list of top referrers
      Throws:
      IOException - the io exception
    • listRulesForBranch

      public PagedIterable<GHRepositoryRule> listRulesForBranch(String branch) throws IOException
      Get all active rules that apply to the specified branch (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-rules-for-a-branch).
      Parameters:
      branch - the branch
      Returns:
      the rules for branch
      Throws:
      IOException - the io exception
    • isVulnerabilityAlertsEnabled

      public boolean isVulnerabilityAlertsEnabled() throws IOException
      Check, if vulnerability alerts are enabled for this repository (https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#check-if-vulnerability-alerts-are-enabled-for-a-repository).
      Returns:
      true, if vulnerability alerts are enabled
      Throws:
      IOException - the io exception