Class GHFileBuilder
java.lang.Object
io.github.coho04.githubapi.bases.GHBase
io.github.coho04.githubapi.builders.GHFileBuilder
- All Implemented Interfaces:
HttpRequestInterface
,JSONHelper
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.github.coho04.githubapi.interfaces.JSONHelper
JSONHelper.JSONToObject<T>
-
Constructor Summary
ConstructorsConstructorDescriptionGHFileBuilder
(GHRepository repository, GHBranch branch, Github github) Constructs a new GHFileBuilder object for a given repository and branch.GHFileBuilder
(GHRepository repository, GHBranch branch, String path, String content, String message, Github github) Constructs a new GHFileBuilder object with all properties set.GHFileBuilder
(GHRepository repository, Github github) Constructs a new GHFileBuilder object for a given repository.GHFileBuilder
(GHRepository repository, Github github, String sha) Constructs a new GHFileBuilder object for a given repository, GitHub instance, and SHA. -
Method Summary
Modifier and TypeMethodDescriptionvoid
commit()
Commits the file to the repository using the authenticated user's email and login as the committer's details.void
Commits the file to the repository.Returns the branch where this file will be committed.Returns the content of the file to be committed.Returns the GitHub instance associated with this file builder.Returns the commit message for the file commit.getPath()
Returns the path where the file will be committed.Returns the repository where this file will be committed.getSha()
Returns the SHA of the file to be committed.Sets the branch to which the file will be committed.Sets the branch to which the file will be committed.setContent
(String content) Sets the content of the file.setMessage
(String message) Sets the commit message.Sets the path of the file.Methods inherited from class io.github.coho04.githubapi.bases.GHBase
fetchArrayData, fetchArrayData, fetchPaginatedData, fetchPaginatedData, fetchPaginatedData, getBaseUrl, toJSONObject
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.coho04.githubapi.interfaces.HttpRequestInterface
extractNextPageUrl, sendDeleteRequest, sendDeleteRequestWithResponseCode, sendGetRequest, sendGetRequestWithLinkHeader, sendGetRequestWithResponseCode, sendPatchRequest, sendPostRequest, sendPutRequest
Methods inherited from interface io.github.coho04.githubapi.interfaces.JSONHelper
getArrayOrNull, getBooleanOrNull, getIntOrNull, getJSONArrayToStringList, getJSONObjectOrNull, getLocalDateOrNull, getLongOrNull, getStringOrNull
-
Constructor Details
-
GHFileBuilder
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
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
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
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
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
Sets the content of the file.- Parameters:
content
- a String representing the content of the file.- Returns:
- the current GHFileBuilder object.
-
setMessage
Sets the commit message.- Parameters:
message
- a String representing the commit message.- Returns:
- the current GHFileBuilder object.
-
setPath
Sets the path of the file.- Parameters:
path
- a String representing the path of the file.- Returns:
- the current GHFileBuilder object.
-
getGithub
Returns the GitHub instance associated with this file builder.- Returns:
- the GitHub instance
-
getRepository
Returns the repository where this file will be committed.- Returns:
- the GHRepository instance
-
getBranch
Returns the branch where this file will be committed.- Returns:
- the GHBranch instance
-
getContent
Returns the content of the file to be committed.- Returns:
- the content of the file
-
getMessage
Returns the commit message for the file commit.- Returns:
- the commit message
-
getPath
Returns the path where the file will be committed.- Returns:
- the path of the file
-
commit
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
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
-