-
Notifications
You must be signed in to change notification settings - Fork 7.2k
feat: add inline comment viewing support to pr diff and view commands #11793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
- Add --comments/-c flag to 'gh pr diff' to show inline comments overlaid on diff - Add --inline/-i flag to 'gh pr view' to show structured inline comments with code context - Extend GraphQL queries to fetch review threads and inline comment data - Display code context with line numbers and syntax highlighting for commented lines
Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive inline comment viewing functionality to the GitHub CLI by extending both gh pr diff
and gh pr view
commands with new flags to display inline comments with code context.
- Adds
--comments
flag togh pr diff
to overlay inline comments on diff output - Adds
--inline
flag togh pr view
to display structured inline comments with code context - Implements GraphQL query extensions and API structures for fetching review thread data
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
api/queries_pr.go | Defines new API structures for PullRequestReviewThread and PullRequestReviewComment with Comment interface implementation |
api/query_builder.go | Adds GraphQL query fragment for reviewThreads and includes it in PullRequestFields |
pkg/cmd/pr/diff/diff.go | Implements diff parsing and inline comment overlay functionality for --comments flag |
pkg/cmd/pr/diff/diff_test.go | Adds test coverage for diff with inline comments functionality |
pkg/cmd/pr/view/view.go | Implements structured inline comment viewing with code context fetching via GitHub API |
pkg/cmd/pr/view/view_test.go | Adds test coverage for --inline flag parsing and reviewThreads field inclusion |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
func fetchFileContent(client *http.Client, repo ghrepo.Interface, path, ref string) (string, error) { | ||
url := fmt.Sprintf("%srepos/%s/contents/%s?ref=%s", | ||
ghinstance.RESTPrefix(repo.RepoHost()), | ||
ghrepo.FullName(repo), | ||
path, | ||
ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to d 8000 escribe this comment to others. Learn more.
The file path parameter is directly concatenated into the URL without proper encoding, which could lead to path traversal vulnerabilities if the path contains special characters like '../'. Use url.PathEscape() or proper URL construction to encode the path parameter.
Copilot uses AI. Check for mistakes.
if useColor { | ||
fmt.Fprintf(w, "\x1b[36m") // Cyan color for comment indicator | ||
} | ||
fmt.Fprintf(w, " 💬 %s", comment.AuthorLogin()) | ||
if useColor { | ||
fmt.Fprintf(w, "\x1b[m") // Reset color | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded ANSI escape sequences should be replaced with color constants or a color scheme for better maintainability. Consider using the existing color constants (colorHeader, colorAddition, etc.) or defining new ones for consistency.
Copilot uses AI. Check for mistakes.
markdown.WithTheme("dark"), | ||
markdown.WithWrap(0)) // No wrap for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The markdown theme is hard-coded to 'dark' and wrap is hard-coded to 0. Consider using the terminal theme from opts.IO.TerminalTheme() and opts.IO.TerminalWidth() for consistency with other parts of the application.
markdown.WithTheme("dark"), | |
markdown.WithWrap(0)) // No wrap for now | |
markdown.WithTheme(opts.IO.TerminalTheme()), | |
markdown.WithWrap(opts.IO.TerminalWidth())) |
Copilot uses AI. Check for mistakes.
// Calculate context range (show 2 lines above and below) | ||
contextLines := 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of context lines is hard-coded as a magic number. Consider defining this as a constant at the package level or making it configurable for better maintainability.
Copilot uses AI. Check for mistakes.
Summary
This PR adds comprehensive inline comment viewing functionality to the GitHub CLI:
New Features
gh pr diff --comments
(-c
): View pull request diff with inline comments overlaid at their respective line positionsgh pr view --inline
(-i
): Structured view of inline comments organized by file with actual code contextKey Capabilities
Implementation
reviewThreads
dataPullRequestReviewThread
andPullRequestReviewComment
Usage Examples
This enhancement significantly improves the code review experience by bringing inline comment context directly to the CLI.
Test Plan