github-content
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Content Fetching
GitHub 内容获取
When to activate:
- User pastes a GitHub URL (issue, PR, repo, or source file)
- User asks about PR comments, reviews, or discussions
- User wants to browse or search code in a GitHub repository
- User references a GitHub issue or PR by number and repo
Why use gh CLI instead of web fetching:
GitHub's web interface relies heavily on JavaScript to load comments, reviews, and discussions. Web fetching often retrieves only partial content. The CLI accesses the API directly and returns complete data.
gh激活场景:
- 用户粘贴GitHub链接(issue、PR、仓库或源文件)
- 用户询问PR评论、评审或讨论相关内容
- 用户想要浏览或搜索GitHub仓库中的代码
- 用户通过编号和仓库引用GitHub issue或PR
为什么选择gh CLI而非网页抓取:
GitHub的网页界面严重依赖JavaScript加载评论、评审和讨论内容。网页抓取通常只能获取部分内容,而 CLI直接调用API,可返回完整数据。
ghIssues
Issues
View an issue with all comments:
bash
gh issue view <number> --repo owner/repo --comments查看包含所有评论的issue:
bash
gh issue view <number> --repo owner/repo --commentsPull Requests
Pull Requests
View a PR with comments and review status:
bash
gh pr view <number> --repo owner/repo --commentsView the diff for a PR:
bash
gh pr diff <number> --repo owner/repoView PR review comments (inline code comments):
bash
gh api repos/owner/repo/pulls/<number>/commentsList files changed in a PR:
bash
gh pr view <number> --repo owner/repo --json files --jq '.files[].path'查看包含评论和评审状态的PR:
bash
gh pr view <number> --repo owner/repo --comments查看PR的差异对比:
bash
gh pr diff <number> --repo owner/repo查看PR评审评论(行内代码评论):
bash
gh api repos/owner/repo/pulls/<number>/comments列出PR中变更的文件:
bash
gh pr view <number> --repo owner/repo --json files --jq '.files[].path'Repository Browsing
仓库浏览
List contents of a directory (defaults to root):
bash
gh api repos/owner/repo/contents/path/to/dirView a specific file's contents:
bash
gh api repos/owner/repo/contents/path/to/file --jq '.content' | base64 -dGet the full repository tree (all files):
bash
gh api repos/owner/repo/git/trees/main?recursive=1 --jq '.tree[] | select(.type=="blob") | .path'Replace with the appropriate branch name if needed.
main列出目录内容(默认根目录):
bash
gh api repos/owner/repo/contents/path/to/dir查看指定文件的内容:
bash
gh api repos/owner/repo/contents/path/to/file --jq '.content' | base64 -d获取完整仓库树(所有文件):
bash
gh api repos/owner/repo/git/trees/main?recursive=1 --jq '.tree[] | select(.type=="blob") | .path'如果需要,将替换为对应分支名称。
mainCode Search
代码搜索
Search for code within a specific repository:
bash
gh search code "search query" --repo owner/repoSearch with language filter:
bash
gh search code "search query" --repo owner/repo --language pythonSearch with path filter:
bash
gh search code "search query" --repo owner/repo --path "src/"View search results with more context:
bash
gh search code "search query" --repo owner/repo --json path,repository,textMatches在指定仓库中搜索代码:
bash
gh search code "search query" --repo owner/repo按语言过滤搜索:
bash
gh search code "search query" --repo owner/repo --language python按路径过滤搜索:
bash
gh search code "search query" --repo owner/repo --path "src/"查看包含更多上下文的搜索结果:
bash
gh search code "search query" --repo owner/repo --json path,repository,textMatchesParsing GitHub URLs
解析GitHub链接
Extract owner/repo from common URL patterns:
| URL Pattern | Example |
|---|---|
| |
| Issue #123 in that repo |
| PR #456 in that repo |
| Source file at path |
| Directory at path |
从常见链接格式中提取owner/repo:
| 链接格式 | 示例 |
|---|---|
| |
| 该仓库中的Issue #123 |
| 该仓库中的PR #456 |
| 指定路径下的源文件 |
| 指定路径下的目录 |
Tips
提示
- For large outputs, pipe through or use
head -n 100to filter--jq - Use flag with
--jsonorgh pr viewfor structured datagh issue view - For private repos, ensure shows you're authenticated
gh auth status - When browsing files, the API returns base64-encoded content that needs decoding
- 对于大体积输出,可通过进行管道处理,或使用
head -n 100进行过滤--jq - 在或
gh pr view中使用gh issue view标志获取结构化数据--json - 对于私有仓库,确保显示已完成身份验证
gh auth status - 浏览文件时,API返回的是base64编码的内容,需要进行解码