diff --git a/client.go b/client.go index 7ceaa64..da456f3 100644 --- a/client.go +++ b/client.go @@ -90,9 +90,6 @@ func newClient(service string, gitHostURL string) interface{} { } // parseGitHostURL parses the git host URL if provided -// TODO: there is a chance, this parsing breaks more than -// one git service -// https://github.com/amitsaha/gitbackup/issues/195 func parseGitHostURL(gitHostURL string, service string) *url.URL { if len(gitHostURL) == 0 { return nil @@ -103,12 +100,12 @@ func parseGitHostURL(gitHostURL string, service string) *url.URL { log.Fatalf("Invalid git host URL: %s", gitHostURL) } - // temp fix for https://github.com/amitsaha/gitbackup/issues/193 - if service == "forgejo" { - return gitHostURLParsed + // Only GitLab requires /api/v4/ to be appended + if service == "gitlab" { + api, _ := url.Parse("api/v4/") + return gitHostURLParsed.ResolveReference(api) } - api, _ := url.Parse("api/v4/") - return gitHostURLParsed.ResolveReference(api) + return gitHostURLParsed } // newGitHubClient creates a new GitHub client diff --git a/client_test.go b/client_test.go index 28d8baf..49104fc 100644 --- a/client_test.go +++ b/client_test.go @@ -15,30 +15,30 @@ func TestNewClient(t *testing.T) { defer teardownRepositoryTests() customGitHost, _ := url.Parse("https://git.mycompany.com") - // http://stackoverflow.com/questions/23051339/how-to-avoid-end-of-url-slash-being-removed-when-resolvereference-in-go + // GitLab expects /api/v4/ appended api, _ := url.Parse("api/v4/") - expectedGitHostBaseURL := customGitHost.ResolveReference(api) + expectedGitLabBaseURL := customGitHost.ResolveReference(api) // Client for github.com client := newClient("github", "") client = client.(*github.Client) - // Client for Enterprise Github + // Client for Enterprise Github - should use the URL as-is, not append /api/v4/ client = newClient("github", customGitHost.String()) gotBaseURL := client.(*github.Client).BaseURL - if gotBaseURL.String() != expectedGitHostBaseURL.String() { - t.Errorf("Expected BaseURL to be: %v, Got: %v\n", expectedGitHostBaseURL, gotBaseURL) + if gotBaseURL.String() != customGitHost.String() { + t.Errorf("Expected BaseURL to be: %v, Got: %v\n", customGitHost, gotBaseURL) } // Client for gitlab.com client = newClient("gitlab", "") client = client.(*gitlab.Client) - // Client for custom gitlab installation + // Client for custom gitlab installation - should append /api/v4/ client = newClient("gitlab", customGitHost.String()) gotBaseURL = client.(*gitlab.Client).BaseURL() - if gotBaseURL.String() != expectedGitHostBaseURL.String() { - t.Errorf("Expected BaseURL to be: %v, Got: %v\n", expectedGitHostBaseURL, gotBaseURL) + if gotBaseURL.String() != expectedGitLabBaseURL.String() { + t.Errorf("Expected BaseURL to be: %v, Got: %v\n", expectedGitLabBaseURL, gotBaseURL) } // Client for bitbucket.com