Get Netrc machine from clone url (#800)

We previously got the machine hostname for Netrc from the url of the remote, but in cases where the clone-url does not match the api url this can lead to errors.
This commit is contained in:
Anbraten
2022-02-26 02:54:15 +01:00
committed by GitHub
parent 8ae124d5e6
commit 52d8097290
14 changed files with 97 additions and 85 deletions

View File

@@ -52,7 +52,6 @@ func Test_gogs(t *testing.T) {
PrivateMode: true,
})
g.Assert(remote.(*client).URL).Equal("http://localhost:8080")
g.Assert(remote.(*client).Machine).Equal("localhost")
g.Assert(remote.(*client).Username).Equal("someuser")
g.Assert(remote.(*client).Password).Equal("password")
g.Assert(remote.(*client).SkipVerify).Equal(true)
@@ -66,21 +65,18 @@ func Test_gogs(t *testing.T) {
g.Describe("Generating a netrc file", func() {
g.It("Should return a netrc with the user token", func() {
remote, _ := New(Opts{
URL: "http://gogs.com",
})
netrc, _ := remote.Netrc(fakeUser, nil)
remote, _ := New(Opts{})
netrc, _ := remote.Netrc(fakeUser, fakeRepo)
g.Assert(netrc.Machine).Equal("gogs.com")
g.Assert(netrc.Login).Equal(fakeUser.Token)
g.Assert(netrc.Password).Equal("x-oauth-basic")
})
g.It("Should return a netrc with the machine account", func() {
remote, _ := New(Opts{
URL: "http://gogs.com",
Username: "someuser",
Password: "password",
})
netrc, _ := remote.Netrc(nil, nil)
netrc, _ := remote.Netrc(nil, fakeRepo)
g.Assert(netrc.Machine).Equal("gogs.com")
g.Assert(netrc.Login).Equal("someuser")
g.Assert(netrc.Password).Equal("password")
@@ -185,6 +181,7 @@ var (
}
fakeRepo = &model.Repo{
Clone: "http://gogs.com/test_name/repo_name.git",
Owner: "test_name",
Name: "repo_name",
FullName: "test_name/repo_name",