java.lang.Object
io.github.coho04.githubapi.bases.GHBase
io.github.coho04.githubapi.bases.ClassBase
io.github.coho04.githubapi.entities.repositories.GHRepository
All Implemented Interfaces:
HttpRequestInterface, JSONHelper

public class GHRepository extends ClassBase
This class represents a GitHub repository. It provides methods for fetching and manipulating data about the repository such as its size, forks, license, name, owner, watchers, and more.
  • Constructor Details

    • GHRepository

      public GHRepository(org.json.JSONObject jsonObject, Github github)
      Constructs a new GHRepository instance with the provided JSON object and GitHub instance.
      Parameters:
      jsonObject - the JSON object containing the repository data
      github - the GitHub instance associated with this repository
  • Method Details

    • getRepository

      public static GHRepository getRepository(Github github, String owner, String name)
      Fetches and returns a GitHub repository based on the provided owner and name.
      Parameters:
      github - the GitHub instance associated with this repository
      owner - the username of the owner of the repository
      name - the name of the repository
      Returns:
      a GHRepository instance representing the fetched repository
    • createIssue

      public GHIssueBuilder createIssue(String title)
      Creates a new issue in this repository with the given title.
      Parameters:
      title - the title of the new issue
      Returns:
      a GHIssueBuilder instance for building the new issue
    • getBranches

      public Map<String,GHBranch> getBranches()
      Fetches the branches of this repository.
      Returns:
      a HashMap mapping branch names to GHBranch instances
    • getContributors

      public List<GHUser> getContributors()
      Fetches the contributors of this repository.
      Returns:
      a List of GHUser instances representing the contributors of this repository
    • getIssues

      public List<GHIssue> getIssues()
      Fetches the issues of this repository with the given state.
      Returns:
      a List of GHIssue instances representing the issues of this repository with the given state
    • getIssueById

      public GHIssue getIssueById(int id)
      Fetches the issue with the given ID in this repository.
      Parameters:
      id - the ID of the issue to fetch
      Returns:
      a GHIssue instance representing the fetched issue
    • addFile

      public GHFileBuilder addFile()
      Starts the process of adding a new file to this repository.
      Returns:
      a GHFileBuilder instance for building the new file
    • addFile

      public GHFileBuilder addFile(GHBranch branch)
      Starts the process of adding a new file to the given branch of this repository.
      Parameters:
      branch - the branch to add the new file to
      Returns:
      a GHFileBuilder instance for building the new file
    • addFile

      public GHFileBuilder addFile(GHBranch branch, String path, String content, String message)
      Starts the process of adding a new file with the given path, content, and commit message to the given branch of this repository.
      Parameters:
      branch - the branch to add the new file to
      path - the path of the new file
      content - the content of the new file
      message - the commit message for the new file
      Returns:
      a GHFileBuilder instance for building the new file
    • getAllFilenames

      public List<String> getAllFilenames()
      Fetches all filenames in this repository.
      Returns:
      a List of Strings representing all filenames in this repository
    • getDirectoryContent

      public List<GHFile> getDirectoryContent(String path)
      Fetches the content of the directory at the given path in this repository.
      Parameters:
      path - the path of the directory
      Returns:
      a List of GHFile instances representing the content of the directory
    • getDirectoryContentWithFileContent

      public List<GHFile> getDirectoryContentWithFileContent(String path)
      Fetches the content of the directory at the given path in this repository, including the content of each file.
      Parameters:
      path - the path of the directory
      Returns:
      a List of GHFile instances representing the content of the directory
    • getForks

      public int getForks()
      Returns the number of forks of this repository.
      Returns:
      the number of forks
    • getOpenIssuesCount

      public int getOpenIssuesCount()
      Returns the number of open issues in this repository.
      Returns:
      the number of open issues
    • getSize

      public int getSize()
      Returns the size of this repository.
      Returns:
      the size of the repository
    • getStargazersCount

      public int getStargazersCount()
      Returns the number of stargazers for this repository.
      Returns:
      the number of stargazers
    • getPermissions

      public Object getPermissions()
      Returns the permissions associated with this repository.
      Returns:
      the permissions
    • getPushedAt

      public OffsetDateTime getPushedAt()
      Returns the date and time when this repository was last pushed to.
      Returns:
      the date and time of the last push
    • getBranchesUrl

      public String getBranchesUrl()
      Returns the URL for fetching the branches of this repository.
      Returns:
      the branches URL
    • getIssueCommentUrl

      public String getIssueCommentUrl()
      Returns the URL for fetching issue comments in this repository.
      Returns:
      the issue comment URL
    • getArchiveUrl

      public String getArchiveUrl()
      Returns the URL for fetching the archive of this repository.
      Returns:
      the archive URL
    • getLabelsUrl

      public String getLabelsUrl()
      Returns the URL for fetching labels in this repository.
      Returns:
      the labels URL
    • getLanguage

      public String getLanguage()
      Returns the primary programming language used in this repository.
      Returns:
      the programming language
    • getReleasesUrl

      public String getReleasesUrl()
      Returns the URL for fetching releases in this repository.
      Returns:
      the releases URL
    • getSubscribersUrl

      public String getSubscribersUrl()
      Returns the URL for fetching subscribers of this repository.
      Returns:
      the subscribers URL
    • getSubscriptionUrl

      public String getSubscriptionUrl()
      Returns the URL for subscribing to this repository.
      Returns:
      the subscription URL
    • getForksUrl

      public String getForksUrl()
      Returns the URL for fetching forks of this repository.
      Returns:
      the forks URL
    • getGitRefsUrl

      public String getGitRefsUrl()
      Returns the URL for fetching git references in this repository.
      Returns:
      the git references URL
    • getWatchers

      public int getWatchers()
      Returns the number of watchers of this repository.
      Returns:
      the number of watchers
    • getSvnUrl

      public String getSvnUrl()
      Returns the SVN URL of this repository.
      Returns:
      the SVN URL
    • getCreatedAt

      public OffsetDateTime getCreatedAt()
      Returns the date and time when this repository was created.
      Returns:
      the creation date and time
    • getUpdatedAt

      public OffsetDateTime getUpdatedAt()
      Returns the date and time when this repository was last updated.
      Returns:
      the update date and time
    • getBlobsUrl

      public String getBlobsUrl()
      Returns the URL for fetching blobs in this repository.
      Returns:
      the blobs URL
    • getCloneUrl

      public String getCloneUrl()
      Returns the clone URL of this repository.
      Returns:
      the clone URL
    • getCollaboratorsUrl

      public String getCollaboratorsUrl()
      Returns the URL for fetching collaborators of this repository.
      Returns:
      the collaborators URL
    • getCommentsUrl

      public String getCommentsUrl()
      Returns the URL for fetching comments in this repository.
      Returns:
      the comments URL
    • getCommitsUrl

      public String getCommitsUrl()
      Returns the URL for fetching commits in this repository.
      Returns:
      the commits URL
    • getVisibility

      public String getVisibility()
      Returns the visibility of this repository.
      Returns:
      the visibility
    • getCompareUrl

      public String getCompareUrl()
      Returns the URL for comparing commits in this repository.
      Returns:
      the compare URL
    • getContentsUrl

      public String getContentsUrl()
      Returns the URL for fetching contents of this repository.
      Returns:
      the contents URL
    • getContributorsUrl

      public String getContributorsUrl()
      Returns the URL for fetching contributors to this repository.
      Returns:
      the contributors URL
    • getDefaultBranch

      public String getDefaultBranch()
      Returns the default branch of this repository.
      Returns:
      the default branch
    • getDeploymentsUrl

      public String getDeploymentsUrl()
      Returns the URL for fetching deployments in this repository.
      Returns:
      the deployments URL
    • getDescription

      public String getDescription()
      Returns the description of this repository.
      Returns:
      the description
    • getDownloadsUrl

      public String getDownloadsUrl()
      Returns the URL for fetching downloads in this repository.
      Returns:
      the downloads URL
    • getStatusesUrl

      public String getStatusesUrl()
      Returns the URL for fetching statuses in this repository.
      Returns:
      the statuses URL
    • getFullName

      public String getFullName()
      Returns the full name of this repository.
      Returns:
      the full name
    • getGitCommitsUrl

      public String getGitCommitsUrl()
      Returns the URL for fetching git commits in this repository.
      Returns:
      the git commits URL
    • getLanguagesUrl

      public String getLanguagesUrl()
      Returns the URL for fetching languages used in this repository.
      Returns:
      the languages URL
    • getGitTagsUrl

      public String getGitTagsUrl()
      Returns the URL for fetching git tags in this repository.
      Returns:
      the git tags URL
    • getGitUrl

      public String getGitUrl()
      Returns the git URL of this repository.
      Returns:
      the git URL
    • getSshUrl

      public String getSshUrl()
      Returns the SSH URL of this repository.
      Returns:
      the SSH URL
    • getAssigneesUrl

      public String getAssigneesUrl()
      Returns the URL for fetching assignees in this repository.
      Returns:
      the assignees URL
    • getOpenIssues

      public int getOpenIssues()
      Returns the number of open issues in this repository.
      Returns:
      the number of open issues
    • getWatchersCount

      public int getWatchersCount()
      Returns the number of watchers in this repository.
      Returns:
      the watchers count
    • getHooksUrl

      public String getHooksUrl()
      Returns the URL for fetching hooks in this repository.
      Returns:
      the hooks URL
    • getIssueEventsUrl

      public String getIssueEventsUrl()
      Returns the URL for fetching issue events in this repository.
      Returns:
      the issue events URL
    • getHomepage

      public String getHomepage()
      Returns the homepage URL of this repository.
      Returns:
      the homepage URL
    • getIssuesUrl

      public String getIssuesUrl()
      Returns the URL for fetching issues in this repository.
      Returns:
      the issues URL
    • getForksCount

      public int getForksCount()
      Returns the number of forks of this repository.
      Returns:
      the forks count
    • getKeysUrl

      public String getKeysUrl()
      Returns the URL for fetching keys in this repository.
      Returns:
      the keys URL
    • getMergesUrl

      public String getMergesUrl()
      Returns the URL for fetching merges in this repository.
      Returns:
      the merges URL
    • getMilestonesUrl

      public String getMilestonesUrl()
      Returns the URL for fetching milestones in this repository.
      Returns:
      the milestones URL
    • getMirrorUrl

      public String getMirrorUrl()
      Returns the mirror URL of this repository.
      Returns:
      the mirror URL
    • getName

      public String getName()
      Returns the name of this repository.
      Returns:
      the name
    • getNotificationsUrl

      public String getNotificationsUrl()
      Returns the URL for fetching notifications in this repository.
      Returns:
      the notifications URL
    • getPullsUrl

      public String getPullsUrl()
      Returns the URL for fetching pull requests in this repository.
      Returns:
      the pulls URL
    • getStargazersUrl

      public String getStargazersUrl()
      Returns the URL for fetching stargazers of this repository.
      Returns:
      the stargazers URL
    • getTagsUrl

      public String getTagsUrl()
      Returns the URL for fetching tags in this repository.
      Returns:
      the tags URL
    • getTeamsUrl

      public String getTeamsUrl()
      Returns the URL for fetching teams associated with this repository.
      Returns:
      the teams URL
    • getTreesUrl

      public String getTreesUrl()
      Returns the URL for fetching trees in this repository.
      Returns:
      the trees URL
    • isWebCommitSignoffRequired

      public boolean isWebCommitSignoffRequired()
      Returns whether web commit signoff is required for this repository.
      Returns:
      true if web commit signoff is required, false otherwise
    • isHasDiscussions

      public boolean isHasDiscussions()
      Returns whether this repository has discussions enabled.
      Returns:
      true if discussions are enabled, false otherwise
    • isAllowForking

      public boolean isAllowForking()
      Returns whether forking is allowed for this repository.
      Returns:
      true if forking is allowed, false otherwise
    • isTemplate

      public boolean isTemplate()
      Returns whether this repository is a template repository.
      Returns:
      true if this is a template repository, false otherwise
    • isArchived

      public boolean isArchived()
      Returns whether this repository is archived.
      Returns:
      true if this repository is archived, false otherwise
    • isDisabled

      public boolean isDisabled()
      Returns whether this repository is disabled.
      Returns:
      true if this repository is disabled, false otherwise
    • isFork

      public boolean isFork()
      Returns whether this repository is a fork.
      Returns:
      true if this repository is a fork, false otherwise
    • isHasPages

      public boolean isHasPages()
      Returns whether this repository has GitHub Pages enabled.
      Returns:
      true if GitHub Pages is enabled, false otherwise
    • isHasDownloads

      public boolean isHasDownloads()
      Returns whether this repository has downloads enabled.
      Returns:
      true if downloads are enabled, false otherwise
    • isHasProjects

      public boolean isHasProjects()
      Returns whether this repository has projects enabled.
      Returns:
      true if projects are enabled, false otherwise
    • isHasWiki

      public boolean isHasWiki()
      Returns whether this repository has a wiki enabled.
      Returns:
      true if the wiki is enabled, false otherwise
    • isPrivate

      public boolean isPrivate()
      Returns whether this repository is private.
      Returns:
      true if this repository is private, false otherwise
    • isHasIssues

      public boolean isHasIssues()
      Returns whether this repository has issues enabled.
      Returns:
      true if issues are enabled, false otherwise
    • getTopics

      public List<String> getTopics()
      Returns the list of topics associated with this repository.
      Returns:
      the list of topics
    • getLicense

      public GHLicense getLicense()
      Returns the license associated with this repository.
      Returns:
      the license
    • getOwner

      public GHUser getOwner()
      Returns the owner of this repository.
      Returns:
      the owner
    • listPullRequests

      public List<GHPullRequest> listPullRequests()
      Fetches the list of pull requests in this repository.
      Returns:
      a List of GHPullRequest instances representing the pull requests in this repository
    • hasPullRequestsWithState

      public boolean hasPullRequestsWithState(GHState state)
      Checks if this repository has any pull requests with the given state.
      Parameters:
      state - the state of the pull requests to check for
      Returns:
      true if this repository has any pull requests with the given state, false otherwise
    • updateTopics

      public void updateTopics(List<String> topics)
      Updates the topics of this repository.
      Parameters:
      topics - the new topics
    • updateHomePage

      public void updateHomePage(String homepageUrl)
      Updates the homepage of this repository.
    • listEvents

      public List<GHEvent> listEvents()
      Fetches the list of events in this repository.
      Returns:
      a List of GHEvent instances representing the events in this repository
    • listArtifacts

      public List<GHArtifact> listArtifacts()
      Fetches the list of artifacts in this repository.
      Returns:
      a List of GHArtifact instances representing the artifacts in this repository
    • getArtifact

      public GHArtifact getArtifact(int id)
      Fetches the artifact with the given ID in this repository.
      Parameters:
      id - the ID of the artifact
      Returns:
      a GHArtifact instance representing the artifact with the given ID
    • deleteArtifact

      public Boolean deleteArtifact(int id)
      Deletes the artifact with the given ID in this repository.
      Parameters:
      id - the ID of the artifact
      Returns:
      true if the artifact was successfully deleted, false otherwise
    • getCache

      public GHRepositoryCache getCache()
      Fetches the cache of this repository.
      Returns:
      a GHRepositoryCache instance representing the cache of this repository
    • listActionsCaches

      public List<GHActionsCache> listActionsCaches()
      Fetches the list of actions caches in this repository.
      Returns:
      a List of GHActionsCache instances representing the actions caches in this repository
    • deleteActionsCache

      public void deleteActionsCache(String key)
      Deletes the actions cache with the given key in this repository.
      Parameters:
      key - the key of the actions cache
    • deleteActionsCache

      public boolean deleteActionsCache(int id)
      Deletes the actions cache with the given ID in this repository.
      Parameters:
      id - the ID of the actions cache
      Returns:
      true if the actions cache was successfully deleted, false otherwise
    • listOrganisationSecrets

      public List<GHSecret> listOrganisationSecrets()
      Fetches the list of organisation secrets in this repository.
      Returns:
      a List of GHSecret instances representing the organisation secrets in this repository
    • listRepositorySecrets

      public List<GHSecret> listRepositorySecrets()
      Fetches the list of repository secrets in this repository.
      Returns:
      a List of GHSecret instances representing the repository secrets in this repository
    • getPublicKey

      public GHPublicKey getPublicKey()
      Fetches the public key of this repository.
      Returns:
      a GHPublicKey instance representing the public key of this repository
    • getSecret

      public GHSecret getSecret(String name)
      Fetches the secret with the given name in this repository.
      Parameters:
      name - the name of the secret
      Returns:
      a GHSecret instance representing the secret with the given name
    • listEnvironmentSecrets

      public List<GHSecret> listEnvironmentSecrets(String environment)
      Fetches the list of environment secrets in this repository.
      Parameters:
      environment - the name of the environment
      Returns:
      a List of GHSecret instances representing the environment secrets in this repository
    • getEnvironmentPublicKey

      public GHPublicKey getEnvironmentPublicKey(String environment)
      Fetches the public key of the given environment in this repository.
      Parameters:
      environment - the name of the environment
      Returns:
      a GHPublicKey instance representing the public key of the environment
    • getEnvironmentSecret

      public GHSecret getEnvironmentSecret(String environment, String name)
      Fetches the secret with the given name in the specified environment.
      Parameters:
      environment - the name of the environment
      name - the name of the secret
      Returns:
      a GHSecret instance representing the secret with the given name
    • listOrganisationVariables

      public List<GHVariable> listOrganisationVariables()
      Fetches the list of organisation variables in this repository.
      Returns:
      a List of GHVariable instances representing the organisation variables in this repository
    • listRepositoryVariables

      public List<GHVariable> listRepositoryVariables()
      Fetches the list of repository variables in this repository.
      Returns:
      a List of GHVariable instances representing the repository variables in this repository
    • getVariable

      public GHVariable getVariable(String name)
      Fetches the variable with the given name in this repository.
      Parameters:
      name - the name of the variable
      Returns:
      a GHVariable instance representing the variable with the given name
    • listEnvironmentVariables

      public List<GHVariable> listEnvironmentVariables(String environment)
      Fetches the list of environment variables in the specified environment.
      Parameters:
      environment - the name of the environment
      Returns:
      a List of GHVariable instances representing the environment variables
    • getEnvironmentVariable

      public GHVariable getEnvironmentVariable(String environment, String name)
      Fetches the variable with the given name in the specified environment.
      Parameters:
      environment - the name of the environment
      name - the name of the variable
      Returns:
      a GHVariable instance representing the variable with the given name
    • getJobFromWorkflowRun

      public GHWorkflowJob getJobFromWorkflowRun(int id)
      Fetches the workflow job with the given ID in this repository.
      Parameters:
      id - the ID of the workflow job
      Returns:
      a GHWorkflowJob instance representing the workflow job with the given ID
    • listJobsFromWorkflowRun

      public List<GHWorkflowJob> listJobsFromWorkflowRun(int id)
      Fetches the list of jobs in the specified workflow run.
      Parameters:
      id - the ID of the workflow run
      Returns:
      a List of GHWorkflowJob instances representing the jobs in the workflow run
    • listJobsForWorkflowAttempt

      public List<GHWorkflowJob> listJobsForWorkflowAttempt(int id, int attempt)
      Fetches the list of jobs for the specified workflow attempt.
      Parameters:
      id - the ID of the workflow run
      attempt - the attempt number
      Returns:
      a List of GHWorkflowJob instances representing the jobs for the workflow attempt
    • getWorkflowRun

      public GHWorkflowRun getWorkflowRun(int id)
      Fetches the workflow run with the given ID in this repository.
      Parameters:
      id - the ID of the workflow run
      Returns:
      a GHWorkflowRun instance representing the workflow run with the given ID
    • createProject

      public GHProjectBuilder createProject()
      Creates a project in the organization.
    • createProject

      public GHProject createProject(String name, String body)
      Creates a project in the organization.