Class GHFileBuilder

java.lang.Object
io.github.coho04.githubapi.bases.GHBase
io.github.coho04.githubapi.builders.GHFileBuilder
All Implemented Interfaces:
HttpRequestInterface, JSONHelper

public class GHFileBuilder extends GHBase
GHFileBuilder is a class that extends GHBase. It represents a builder for creating and committing files to a GitHub repository. It contains several properties such as branch, path, content, message, and repository. These properties are initialized through the constructor and can be set using the provided setter methods.
Since:
2024-1.2
Version:
1.0
Author:
Coho04
  • Constructor Details

    • GHFileBuilder

      public GHFileBuilder(GHRepository repository, Github github)
      Constructs a new GHFileBuilder object for a given repository.
      Parameters:
      repository - a GHRepository object representing the repository to which the file will be committed.
    • GHFileBuilder

      public GHFileBuilder(GHRepository repository, GHBranch branch, Github github)
      Constructs a new GHFileBuilder object for a given repository and branch.
      Parameters:
      repository - a GHRepository object representing the repository to which the file will be committed.
      branch - a GHBranch object representing the branch to which the file will be committed.
    • GHFileBuilder

      public GHFileBuilder(GHRepository repository, Github github, String sha)
      Constructs a new GHFileBuilder object for a given repository, GitHub instance, and SHA. This constructor is typically used when updating a file, as the SHA of the file is required.
      Parameters:
      repository - a GHRepository object representing the repository to which the file will be committed.
      github - a GitHub object representing the authenticated user's GitHub instance.
      sha - a String representing the SHA of the file to be updated.
    • GHFileBuilder

      public GHFileBuilder(GHRepository repository, GHBranch branch, String path, String content, String message, Github github)
      Constructs a new GHFileBuilder object with all properties set.
      Parameters:
      repository - a GHRepository object representing the repository to which the file will be committed.
      branch - a GHBranch object representing the branch to which the file will be committed.
      path - a String representing the path of the file.
      content - a String representing the content of the file.
      message - a String representing the commit message.
  • Method Details

    • setBranch

      public GHFileBuilder setBranch(GHBranch branch)
      Sets the branch to which the file will be committed.
      Parameters:
      branch - a GHBranch object representing the branch to which the file will be committed.
      Returns:
      the current GHFileBuilder object.
    • setBranch

      public GHFileBuilder setBranch(String branch)
      Sets the branch to which the file will be committed.
      Parameters:
      branch - a String representing the name of the branch to which the file will be committed.
      Returns:
      the current GHFileBuilder object.
    • setContent

      public GHFileBuilder setContent(String content)
      Sets the content of the file.
      Parameters:
      content - a String representing the content of the file.
      Returns:
      the current GHFileBuilder object.
    • setMessage

      public GHFileBuilder setMessage(String message)
      Sets the commit message.
      Parameters:
      message - a String representing the commit message.
      Returns:
      the current GHFileBuilder object.
    • setPath

      public GHFileBuilder setPath(String path)
      Sets the path of the file.
      Parameters:
      path - a String representing the path of the file.
      Returns:
      the current GHFileBuilder object.
    • getGithub

      public Github getGithub()
      Returns the GitHub instance associated with this file builder.
      Returns:
      the GitHub instance
    • getRepository

      public GHRepository getRepository()
      Returns the repository where this file will be committed.
      Returns:
      the GHRepository instance
    • getBranch

      public GHBranch getBranch()
      Returns the branch where this file will be committed.
      Returns:
      the GHBranch instance
    • getContent

      public String getContent()
      Returns the content of the file to be committed.
      Returns:
      the content of the file
    • getMessage

      public String getMessage()
      Returns the commit message for the file commit.
      Returns:
      the commit message
    • getPath

      public String getPath()
      Returns the path where the file will be committed.
      Returns:
      the path of the file
    • commit

      public void commit(String email, String name)
      Commits the file to the repository. This method is not yet implemented.
    • commit

      public void commit()
      Commits the file to the repository using the authenticated user's email and login as the committer's details. This method first sends a GET request to retrieve the authenticated user's email. Then, it calls the overloaded commit method with the retrieved email and the authenticated user's login.
    • getSha

      public String getSha()
      Returns the SHA of the file to be committed. The SHA is used when updating a file, as it is required to identify the file in the repository.
      Returns:
      the SHA of the file