public class GitHubCli
extends java.lang.Object
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 and Description |
|---|
GitHubCli(GitHubLogger logger) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
authToken()
Reads the token the local CLI is signed in with, by running
gh auth token. |
boolean |
isAvailable()
Checks whether the
gh CLI can serve as the API transport, warning once when it cannot. |
boolean |
isPresent()
Checks whether the
gh CLI is installed and runnable. |
okhttp3.Response |
request(java.lang.String url,
java.lang.String method,
java.lang.String jsonBody)
Performs a GitHub REST request via
gh api and adapts the result into an OkHttp Response. |
public GitHubCli(GitHubLogger logger)
logger - the logger for diagnostics.public boolean isAvailable()
gh CLI can serve as the API transport, warning once when it cannot.gh --version succeeds.public boolean isPresent()
gh CLI is installed and runnable. The result is probed once and cached.gh --version succeeds.isAvailable() warns, because an absent CLI is only worth a
warning when cli.enabled asked for it as the transport. Borrowing its token is a
last-resort fallback nobody configured, so finding no CLI there is unremarkable.public java.lang.String authToken()
gh auth token.gh is absent, is signed out, or the call fails.public okhttp3.Response request(java.lang.String url,
java.lang.String method,
java.lang.String jsonBody)
throws java.io.IOException
gh api and adapts the result into an OkHttp Response.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.Response carrying the CLI's status code and body.java.io.IOException - if the CLI process cannot be started or its I/O fails.