Class GitHubHandler

java.lang.Object
javiergs.tulip.GitHubHandler

public class GitHubHandler extends Object
Lists files and folders in GitHub repositories and fetches file contents via the GitHub REST API.
Version:
3.0
Author:
javiergs
  • Constructor Details

    • GitHubHandler

      public GitHubHandler()
      Constructs a GitHubHandler that loads a GITHUB_TOKEN from the tulip.properties file in the application classpath.
    • GitHubHandler

      public GitHubHandler(String token)
      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

      public String getFileContentFromUrl(String fileUrl) throws IOException
      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

      public String getFileContent(String owner, String repo, String path, String ref) throws IOException
      Fetches the content of a file from a GitHub repository.
      Parameters:
      owner - Repository owner
      repo - Repository name
      path - Path to the file within the repository
      ref - 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

      public List<String> listFiles(String dirUrl) throws IOException
      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 owner
      repo - Repository name
      path - Path to the directory within the repository
      ref - 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

      public List<String> listFolders(String dirUrl) throws IOException
      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 owner
      repo - Repository name
      ref - 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

      public List<String> listFilesRecursive(String startDirUrl) throws IOException
      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 owner
      repo - Repository name
      ref - 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