Skip to content

fix browse of markdown files with line ranges#4310

Merged
mislav merged 7 commits intocli:trunkfrom
andrewhsu:browse-markdown
Sep 14, 2021
Merged

fix browse of markdown files with line ranges#4310
mislav merged 7 commits intocli:trunkfrom
andrewhsu:browse-markdown

Conversation

@andrewhsu
Copy link
Contributor

@andrewhsu andrewhsu commented Sep 11, 2021

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 parseFileArg as func genPath because had to add logic to change part of the url path from /tree/ to /blob/ for ?patch=1 to work on Markdown files.

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
Copy link

@soffieswan042 soffieswan042 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks for taking this on

andrewhsu and others added 3 commits September 13, 2021 14:31
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
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mislav mislav merged commit e13398f into cli:trunk Sep 14, 2021
@andrewhsu andrewhsu deleted the browse-markdown branch September 14, 2021 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unable to browse to line number if file is markdown

4 participants