Class GitHubCli

java.lang.Object
io.github.intisy.gradle.github.impl.GitHubCli

public class GitHubCli extends Object
Routes GitHub REST calls through the local gh CLI (gh api ...) instead of direct HTTP.

The CLI supplies its own authentication and higher (authenticated) rate limits, so no access token needs to be configured. Each call is adapted back into an OkHttp Response so the surrounding response-handling and JSON parsing in GitHub stay unchanged.

  • Constructor Details

    • GitHubCli

      public GitHubCli(Logger logger)
      Parameters:
      logger - the logger for diagnostics.
  • Method Details

    • isAvailable

      public boolean isAvailable()
      Checks whether the gh CLI is installed and runnable. The result is probed once and cached.
      Returns:
      true if gh --version succeeds.
    • request

      public okhttp3.Response request(String url, String method, String jsonBody) throws IOException
      Performs a GitHub REST request via gh api and adapts the result into an OkHttp Response.
      Parameters:
      url - the full GitHub API URL (also accepted as a bare path by gh api).
      method - the HTTP method, e.g. "GET" or "POST".
      jsonBody - the JSON request body for writes, or null for reads.
      Returns:
      a synthetic Response carrying the CLI's status code and body.
      Throws:
      IOException - if the CLI process cannot be started or its I/O fails.