From 02fd170ed731afb36f887c01a47a6dfcfeed7f3e Mon Sep 17 00:00:00 2001 From: Amit Saha Date: Tue, 3 Feb 2026 07:39:17 +1100 Subject: [PATCH] forgejo custom host: No append api/v4/ automatically Don't append /api path for forgejo as the SDK takes care of it. --- client.go | 13 +++++++++++-- git_repository_clone.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index fc88ea0..7ceaa64 100644 --- a/client.go +++ b/client.go @@ -73,7 +73,7 @@ func getToken(service string) (string, error) { } func newClient(service string, gitHostURL string) interface{} { - gitHostURLParsed := parseGitHostURL(gitHostURL) + gitHostURLParsed := parseGitHostURL(gitHostURL, service) switch service { case "github": @@ -90,7 +90,10 @@ func newClient(service string, gitHostURL string) interface{} { } // parseGitHostURL parses the git host URL if provided -func parseGitHostURL(gitHostURL string) *url.URL { +// 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 } @@ -99,6 +102,11 @@ func parseGitHostURL(gitHostURL string) *url.URL { if err != nil { log.Fatalf("Invalid git host URL: %s", gitHostURL) } + + // temp fix for https://github.com/amitsaha/gitbackup/issues/193 + if service == "forgejo" { + return gitHostURLParsed + } api, _ := url.Parse("api/v4/") return gitHostURLParsed.ResolveReference(api) } @@ -197,6 +205,7 @@ func newForgejoClient(gitHostURLParsed *url.URL) *forgejo.Client { url = gitHostURLParsed.String() } + log.Println("Creating forgejo client", url) client, err := forgejo.NewClient(url, forgejo.SetToken(forgejoToken), forgejo.SetForgejoVersion("")) if err != nil { log.Fatalf("Error creating forgejo client: %v", err) diff --git a/git_repository_clone.go b/git_repository_clone.go index 8af2912..f34d7c1 100644 --- a/git_repository_clone.go +++ b/git_repository_clone.go @@ -7,7 +7,7 @@ import ( ) // handleGitRepositoryClone clones or updates all repositories for the configured service -func handleGitRepositoryClone(client interface{}, c *appConfig) error { +func handleGitRepositoryClone(client any, c *appConfig) error { // Used for waiting for all the goroutines to finish before exiting var wg sync.WaitGroup