-
Notifications
You must be signed in to change notification settings - Fork 6.9k
feat(browse): add blame flag #11486
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?
feat(browse): add blame flag #11486
Conversation
Thank you for your pull request! 🎉 This PR appears to fix the following issues that are not labeled with
help wanted
As outlined in our Contributing Guidelines, we expect that PRs are only created for issues that have been labeled While we appreciate your initiative, please note that:
What happens next:
Thank you for your understanding and contribution to the project! 🙏 This comment was automatically generated by cliAutomation. |
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 a --blame
flag to the gh browse
command to open GitHub's blame view for file paths, addressing the feature request in issue #2296.
- Adds a new
BlameFlag
field toBrowseOptions
struct - Implements validation to require a file path when using the
--blame
flag - Updates URL generation logic to use "blame" instead of "blob" in the path when the flag is set
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
pkg/cmd/browse/browse.go | Adds BlameFlag field, flag definition, validation logic, and URL generation for blame view |
pkg/cmd/browse/browse_test.go | Adds comprehensive test cases covering blame flag functionality with various scenarios |
@@ -266,9 +275,16 @@ func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error | |||
} else { | |||
rangeFragment = fmt.Sprintf("L%d", rangeStart) | |||
} | |||
if opts.BlameFlag { | |||
return fmt.Sprintf("blame/%s/%s#%s", escapePath(ref), escapePath(filePath), rangeFragment), nil | |||
} | |||
return fmt.Sprintf("blob/%s/%s?plain=1#%s", escapePath(ref), escapePath(filePath), rangeFragment), nil |
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.
When blame flag is true and a line range is specified, the code adds the ?plain=1
query parameter which is not valid for blame URLs. The blame URL should not include the ?plain=1
parameter.
Copilot uses AI. Check for mistakes.
Fixes #2296
Add a
--blame
flag togh browse
for file paths.This feature was requested in #2296 and closed as a duplicate of #217 but I don't think it was ever implemented in #217.
Usage: