Merge pull request #2404 from alissonbrunosa/fix-repo-view-command-with-branch
Generate correct URL when branch option is passed in
This commit is contained in:
commit
6a0d38df44
2 changed files with 11 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"syscall"
|
||||
"text/template"
|
||||
|
|
@ -100,7 +101,7 @@ func viewRun(opts *ViewOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
openURL := ghrepo.GenerateRepoURL(toView, "")
|
||||
openURL := generateBranchURL(toView, opts.Branch)
|
||||
if opts.Web {
|
||||
if opts.IO.IsStdoutTTY() {
|
||||
fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", utils.DisplayURL(openURL))
|
||||
|
|
@ -201,3 +202,11 @@ func isMarkdownFile(filename string) bool {
|
|||
strings.HasSuffix(filename, ".mdown") ||
|
||||
strings.HasSuffix(filename, ".mkdown")
|
||||
}
|
||||
|
||||
func generateBranchURL(r ghrepo.Interface, branch string) string {
|
||||
if branch == "" {
|
||||
return ghrepo.GenerateRepoURL(r, "")
|
||||
}
|
||||
|
||||
return ghrepo.GenerateRepoURL(r, "tree/%s", url.QueryEscape(branch))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ func Test_ViewRun(t *testing.T) {
|
|||
|
||||
|
||||
|
||||
View this repository on GitHub: https://github.com/OWNER/REPO
|
||||
View this repository on GitHub: https://github.com/OWNER/REPO/tree/feat%2Fawesome
|
||||
`),
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue