Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading