Skip to content

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

masonmcelvain
Copy link

Fixes #2296

Add a --blame flag to gh 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:

gh browse pkg/cmd/browse/browse.go:269 --blame

@Copilot Copilot AI review requested due to automatic review settings August 9, 2025 14:26
@masonmcelvain masonmcelvain requested a review from a team as a code owner August 9, 2025 14:26
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Aug 9, 2025
Copy link

github-actions bot commented Aug 9, 2025

Thank you for your pull request! 🎉

This PR appears to fix the following issues that are not labeled with help wanted Contributions welcome :

As outlined in our Contributing Guidelines, we expect that PRs are only created for issues that have been labeled help wanted.

While we appreciate your initiative, please note that:

  • PRs for non-help wanted issues may not be reviewed immediately as they might not align with our current priorities
  • The issue might already be assigned to a team member or planned for a specific release
  • We may need to close this PR. For example, if it conflicts with ongoing work or architectural decisions

What happens next:

  • Our team will review this PR and the associated issues
  • We may add the help wanted label to the issues, if appropriate, and review this pull request
  • In some cases, we may need to close the PR. For example, if it doesn't fit our current roadmap

Thank you for your understanding and contribution to the project! 🙏

This comment was automatically generated by cliAutomation.

Copy link
Contributor

@Copilot Copilot AI left a 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 to BrowseOptions 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
Copy link
Preview

Copilot AI Aug 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'gh blame <path>' command to open blame view on GitHub
2 participants