Skip to content

Commit 743a747

Browse files
authored
Use go-gh for SSH hostname alias translation (cli#5654)
1 parent 39dd3e6 commit 743a747

File tree

6 files changed

+26
-335
lines changed

6 files changed

+26
-335
lines changed

context/remote.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ func (r Remote) RepoHost() string {
8989
return r.Repo.RepoHost()
9090
}
9191

92-
// TODO: accept an interface instead of git.RemoteSet
93-
func TranslateRemotes(gitRemotes git.RemoteSet, urlTranslate func(*url.URL) *url.URL) (remotes Remotes) {
92+
type Translator interface {
93+
Translate(*url.URL) *url.URL
94+
}
95+
96+
func TranslateRemotes(gitRemotes git.RemoteSet, translator Translator) (remotes Remotes) {
9497
for _, r := range gitRemotes {
9598
var repo ghrepo.Interface
9699
if r.FetchURL != nil {
97-
repo, _ = ghrepo.FromURL(urlTranslate(r.FetchURL))
100+
repo, _ = ghrepo.FromURL(translator.Translate(r.FetchURL))
98101
}
99102
if r.PushURL != nil && repo == nil {
100-
repo, _ = ghrepo.FromURL(urlTranslate(r.PushURL))
103+
repo, _ = ghrepo.FromURL(translator.Translate(r.PushURL))
101104
}
102105
if repo == nil {
103106
continue

context/remote_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ func Test_Remotes_FindByName(t *testing.T) {
2828
assert.Error(t, err, "no GitHub remotes found")
2929
}
3030

31+
type identityTranslator struct{}
32+
33+
func (it identityTranslator) Translate(u *url.URL) *url.URL {
34+
return u
35+
}
36+
3137
func Test_translateRemotes(t *testing.T) {
3238
publicURL, _ := url.Parse("https://github.com/monalisa/hello")
3339
originURL, _ := url.Parse("http://example.com/repo")
@@ -43,10 +49,7 @@ func Test_translateRemotes(t *testing.T) {
4349
},
4450
}
4551

46-
identityURL := func(u *url.URL) *url.URL {
47-
return u
48-
}
49-
result := TranslateRemotes(gitRemotes, identityURL)
52+
result := TranslateRemotes(gitRemotes, identityTranslator{})
5053

5154
if len(result) != 1 {
5255
t.Errorf("got %d results", len(result))

git/ssh_config.go

Lines changed: 0 additions & 171 deletions
This file was deleted.

git/ssh_config_test.go

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)