fix browse of markdown files with line ranges#4310
Merged
Conversation
Fix tests so they trigger the error they were intending to trigger.
These new tests covers code that was not previously covered.
The Test_parseFileArg tests overlap code coverage of Test_runBrowse tests.
This fix changes the URL generated by `gh browse` so it will navigate the user to a page that properly displays highlighted lines for Markdown files. Changed `gh browse README.md:3-5` from generating URLs like this: https://github.com/cli/cli/tree/trunk/README.md#L3-L5 To this: https://github.com/cli/cli/blob/trunk/README.md?plain=1#L3-L5
mislav
suggested changes
Sep 13, 2021
Contributor
mislav
left a comment
There was a problem hiding this comment.
This is great! Thanks for taking this on
There are types of files other than Markdown that GitHub needs the `?plain=1` arg to show line numbers. Therefore, just add this arg to all URLs created from `browse` command.
The tests removed overlap code coverage for existing unit tests. Removing so they do not need to be maintained.
- Construct URLs all at once instead of piece-by-piece - Verify input formats before consulting the API
mislav
approved these changes
Sep 14, 2021
Contributor
mislav
left a comment
There was a problem hiding this comment.
Thank you! I've pushed changes to minimize the nesting depth and avoid using string builder to construct URLs since I find that brittle/hard to follow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4307
The first 3 commits clean up some related tests so we have thorough code coverage.
The significant patch for the issue is in f8989f4. Rewrote func
parseFileArgas funcgenPathbecause had to add logic to change part of the url path from/tree/to/blob/for?patch=1to work on Markdown files.