From ac8a62a614a49bff53f84feeeef38bbadbe9ee0d Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 5 Feb 2023 21:51:58 +0100 Subject: [PATCH] Use proxy for pull mirror (#22771) - Backport #22771 - Use the proxy (if one is specified) for pull mirrors syncs. - Pulled the code from https://github.com/go-gitea/gitea/blob/c2774d9e80d9a436d9c2044960369c4db227e3a0/modules/git/repo.go#L164-L170 - Downstream issue: https://codeberg.org/forgejo/forgejo/issues/302 --- services/mirror/mirror_pull.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go index 6002e6b8edb2..41104d58504f 100644 --- a/services/mirror/mirror_pull.go +++ b/services/mirror/mirror_pull.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/process" + "code.gitea.io/gitea/modules/proxy" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" @@ -216,6 +217,13 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo return nil, false } + envs := []string{} + if strings.EqualFold(remoteURL.Scheme, "http") || strings.EqualFold(remoteURL.Scheme, "https") { + if proxy.Match(remoteURL.Host) { + envs = append(envs, fmt.Sprintf("https_proxy=%s", proxy.GetProxyURL())) + } + } + stdoutBuilder := strings.Builder{} stderrBuilder := strings.Builder{} if err := git.NewCommand(ctx, gitArgs...). @@ -223,6 +231,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo Run(&git.RunOpts{ Timeout: timeout, Dir: repoPath, + Env: envs, Stdout: &stdoutBuilder, Stderr: &stderrBuilder, }); err != nil {