Merge pull request #266 from cli/non-github-remotes

Fix parsing non-GitHub remotes
This commit is contained in:
Nate Smith 2020-01-28 13:43:33 -06:00 committed by GitHub
commit 9345571ee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -81,6 +81,9 @@ func translateRemotes(gitRemotes git.RemoteSet, urlTranslate func(*url.URL) *url
if r.PushURL != nil && repo == nil {
repo, _ = ghrepo.FromURL(urlTranslate(r.PushURL))
}
if repo == nil {
continue
}
remotes = append(remotes, &Remote{
Remote: r,
Owner: repo.RepoOwner(),

View file

@ -2,6 +2,7 @@ package context
import (
"errors"
"net/url"
"testing"
"github.com/cli/cli/git"
@ -25,3 +26,34 @@ func Test_Remotes_FindByName(t *testing.T) {
_, err = list.FindByName("nonexist")
eq(t, err, errors.New(`no GitHub remotes found`))
}
func Test_translateRemotes(t *testing.T) {
publicURL, _ := url.Parse("https://github.com/monalisa/hello")
originURL, _ := url.Parse("http://example.com/repo")
gitRemotes := git.RemoteSet{
&git.Remote{
Name: "origin",
FetchURL: originURL,
},
&git.Remote{
Name: "public",
FetchURL: publicURL,
},
}
identityURL := func(u *url.URL) *url.URL {
return u
}
result := translateRemotes(gitRemotes, identityURL)
if len(result) != 1 {
t.Errorf("got %d results", len(result))
}
if result[0].Name != "public" {
t.Errorf("got %q", result[0].Name)
}
if result[0].RepoName() != "hello" {
t.Errorf("got %q", result[0].RepoName())
}
}