Package javiergs.tulip
Class GitHubHandler
java.lang.Object
javiergs.tulip.GitHubHandler
Lists files and folders in GitHub repositories and fetches file contents
via the GitHub REST API.
- Version:
- 3.0
- Author:
- javiergs
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a GitHubHandler that loads a GITHUB_TOKEN from the tulip.properties file in the application classpath.GitHubHandler(String token) Constructs a GitHubHandler using the specified token. -
Method Summary
Modifier and TypeMethodDescriptiongetFileContent(String owner, String repo, String path, String ref) Fetches the content of a file from a GitHub repository.getFileContentFromUrl(String fileUrl) Fetches the content of a file from a GitHub URL.Lists files in a GitHub directory URL.Lists files in a GitHub repository directory.listFilesRecursive(String startDirUrl) Recursively lists all files in a GitHub directory URL and its subdirectories.listFilesRecursive(String owner, String repo, String ref, String path) Recursively lists all files in a GitHub repository directory and its subdirectories.listFolders(String dirUrl) Lists folders in a GitHub directory URL.listFolders(String owner, String repo, String ref, String path) Lists folders in a GitHub repository directory.
-
Constructor Details
-
GitHubHandler
public GitHubHandler()Constructs a GitHubHandler that loads a GITHUB_TOKEN from the tulip.properties file in the application classpath. -
GitHubHandler
Constructs a GitHubHandler using the specified token. Normally, the token should be provided through the tulip.properties file. This constructor is intended for programmatic use cases where the token must be supplied manually.- Parameters:
token- GitHub access token used for authenticated API requests
-
-
Method Details
-
getFileContentFromUrl
Fetches the content of a file from a GitHub URL.- Parameters:
fileUrl- URL of the file in the GitHub repository- Returns:
- Content of the file as a String
- Throws:
IOException- if an I/O error occurs during the API request
-
getFileContent
Fetches the content of a file from a GitHub repository.- Parameters:
owner- Repository ownerrepo- Repository namepath- Path to the file within the repositoryref- Branch, tag, or commit SHA (can be null to use default branch)- Returns:
- Content of the file as a String
- Throws:
IOException- if an I/O error occurs during the API request
-
listFiles
Lists files in a GitHub directory URL.- Parameters:
dirUrl- URL of the directory in the GitHub repository- Returns:
- List of file paths within the specified directory
- Throws:
IOException- if an I/O error occurs during the API request
-
listFiles
public List<String> listFiles(String owner, String repo, String path, String ref) throws IOException Lists files in a GitHub repository directory.- Parameters:
owner- Repository ownerrepo- Repository namepath- Path to the directory within the repositoryref- Branch, tag, or commit SHA (can be null to use default branch)- Returns:
- List of file paths within the specified directory
- Throws:
IOException- if an I/O error occurs during the API request
-
listFolders
Lists folders in a GitHub directory URL.- Parameters:
dirUrl- URL of the directory in the GitHub repository- Returns:
- List of folder paths within the specified directory
- Throws:
IOException- if an I/O error occurs during the API request
-
listFolders
public List<String> listFolders(String owner, String repo, String ref, String path) throws IOException Lists folders in a GitHub repository directory.- Parameters:
owner- Repository ownerrepo- Repository nameref- Branch, tag, or commit SHA (can be null to use default branch)path- Path to the directory within the repository- Returns:
- List of folder paths within the specified directory
- Throws:
IOException- if an I/O error occurs during the API request
-
listFilesRecursive
Recursively lists all files in a GitHub directory URL and its subdirectories.- Parameters:
startDirUrl- URL of the starting directory in the GitHub repository- Returns:
- List of all file paths within the directory and its subdirectories
- Throws:
IOException- if an I/O error occurs during the API request
-
listFilesRecursive
public List<String> listFilesRecursive(String owner, String repo, String ref, String path) throws IOException Recursively lists all files in a GitHub repository directory and its subdirectories.- Parameters:
owner- Repository ownerrepo- Repository nameref- Branch, tag, or commit SHA (can be null to use default branch)path- Path to the directory within the repository- Returns:
- List of all file paths within the directory and its subdirectories
- Throws:
IOException- if an I/O error occurs during the API request
-