-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Describe the feature or problem you’d like to solve
Currently, when using gh repo view
, the CLI can display the repository’s README markdown in the terminal. However, this README content is not available as a structured field when using the --json
option.
For workflows that rely on parsing repository metadata (e.g., generating documentation, dashboards, or summaries of repositories), it would be valuable to programmatically access the README content alongside existing fields such as description
, licenseInfo
, or stargazerCount
.
At present, there’s no straightforward way to extract the README via gh repo view --json
, which forces users to either:
- Fetch the README separately through the GitHub API.
- eg.
gh api repos/OWNER/REPO/readme --jq '.content | @base64d'
- eg.
- Parse the rendered output of
gh repo view
manually.
Both approaches add unnecessary complexity and duplicate effort.
Proposed solution
Introduce support for retrieving README content directly through the --json
flag.
For example:
gh repo view --json name,description,readme
This would return a JSON object that includes a readme
field containing the raw markdown content of the repository’s README.
Example output
{
"name": "cli",
"description": "GitHub’s official command line tool",
"stargazerCount": 40000,
"readme": "# GitHub CLI\n\nGitHub CLI brings GitHub to your terminal..."
}
Current Workaround
gh api repos/OWNER/REPO/readme --jq '.content | @base64d'
Or as an all in one:
repo="OWNER/REPO"; jq -n \
--argjson base "$(gh repo view "$repo" --json name,description,stargazerCount -q '{name, description, stargazerCount}')" \
--arg readme "$(gh api repos/"$repo"/readme --jq '.content | @base64d')" \
'$base + {$readme}'
Additional context
- This would align with how
gh repo view
already surfaces the README to users interactively.