|
NAMEgh-api - Make an authenticated GitHub API requestSYNOPSISgh api <endpoint> [flags]DESCRIPTIONMakes an authenticated HTTP request to the GitHub API and prints the response.The endpoint argument should either be a path of a GitHub API v3 endpoint, or "graphql" to access the GitHub API v4. Placeholder values "{owner}", "{repo}", and "{branch}" in the endpoint argument will get replaced with values from the repository of the current directory or the repository specified in the GH_REPO environment variable. Note that in some shells, for example PowerShell, you may need to enclose any value that contains "{...}" in quotes to prevent the shell from applying special meaning to curly braces. The default HTTP request method is "GET" normally and "POST" if any parameters were added. Override the method with --method. Pass one or more -f/--raw-field values in "key=value" format to add static string parameters to the request payload. To add non-string or otherwise dynamic values, see --field below. Note that adding request parameters will automatically switch the request method to POST. To send the parameters as a GET query string instead, use --method GET. The -F/--field flag has magic type conversion based on the format of the value:
For GraphQL requests, all fields other than "query" and "operationName" are interpreted as GraphQL variables. Raw request body may be passed from the outside via a file specified by --input. Pass "-" to read from standard input. In this mode, parameters specified via --field flags are serialized into URL query parameters. In --paginate mode, all pages of results will sequentially be requested until there are no more pages of results. For GraphQL requests, this requires that the original query accepts an $endCursor: String variable and that it fetches the pageInfo{ hasNextPage, endCursor } set of fields from a collection. OPTIONS
EXAMPLE# list releases in the current repository $ gh api repos/{owner}/{repo}/releases # post an issue comment $ gh api repos/{owner}/{repo}/issues/123/comments -f body='Hi from CLI' # add parameters to a GET request $ gh api -X GET search/issues -f q='repo:cli/cli is:open remote' # set a custom HTTP header $ gh api -H 'Accept: application/vnd.github.v3.raw+json' ... # opt into GitHub API previews $ gh api --preview baptiste,nebula ... # print only specific fields from the response $ gh api repos/{owner}/{repo}/issues --jq '.[].title' # use a template for the output $ gh api repos/{owner}/{repo}/issues --template \ '{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " | color "yellow"}}){{"\n"}}{{end}}' # list releases with GraphQL $ gh api graphql -F owner='{owner}' -F name='{repo}' -f query=' query($name: String!, $owner: String!) { repository(owner: $owner, name: $name) { releases(last: 3) { nodes { tagName } } } } # list all repositories for a user $ gh api graphql --paginate -f query=' query($endCursor: String) { viewer { repositories(first: 100, after: $endCursor) { nodes { nameWithOwner } pageInfo { hasNextPage endCursor } } } } SEE ALSOgh(1)
Visit the GSP FreeBSD Man Page Interface. |