From a722dd72db7fb6efd9ec0bf730d6b2364ef6337c Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 7 Sep 2020 04:53:42 +0100 Subject: [PATCH] Set setting.AppURL as GITEA_ROOT_URL environment variable during pushes (#12752) * Set setting.AppURL as GITEA_ROOT_URL environment variable during pushes Fix #11738 Signed-off-by: Andrew Thornton --- cmd/serv.go | 1 + models/helper_environment.go | 4 ++++ routers/repo/http.go | 1 + 3 files changed, 6 insertions(+) diff --git a/cmd/serv.go b/cmd/serv.go index 2c035111d..b6cdab833 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -218,6 +218,7 @@ func runServ(c *cli.Context) error { os.Setenv(models.EnvPRID, fmt.Sprintf("%d", 0)) os.Setenv(models.EnvIsDeployKey, fmt.Sprintf("%t", results.IsDeployKey)) os.Setenv(models.EnvKeyID, fmt.Sprintf("%d", results.KeyID)) + os.Setenv(models.EnvAppURL, setting.AppURL) //LFS token authentication if verb == lfsAuthenticateVerb { diff --git a/models/helper_environment.go b/models/helper_environment.go index f1c758d65..8924d0a28 100644 --- a/models/helper_environment.go +++ b/models/helper_environment.go @@ -8,6 +8,8 @@ import ( "fmt" "os" "strings" + + "code.gitea.io/gitea/modules/setting" ) // env keys for git hooks need @@ -23,6 +25,7 @@ const ( EnvIsDeployKey = "GITEA_IS_DEPLOY_KEY" EnvPRID = "GITEA_PR_ID" EnvIsInternal = "GITEA_INTERNAL_PUSH" + EnvAppURL = "GITEA_ROOT_URL" ) // InternalPushingEnvironment returns an os environment to switch off hooks on push @@ -62,6 +65,7 @@ func FullPushingEnvironment(author, committer *User, repo *Repository, repoName EnvPusherID+"="+fmt.Sprintf("%d", committer.ID), EnvRepoID+"="+fmt.Sprintf("%d", repo.ID), EnvPRID+"="+fmt.Sprintf("%d", prID), + EnvAppURL+"="+setting.AppURL, "SSH_ORIGINAL_COMMAND=gitea-internal", ) diff --git a/routers/repo/http.go b/routers/repo/http.go index d943cb2ae..0d5aa2e3e 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -268,6 +268,7 @@ func HTTP(ctx *context.Context) { models.EnvPusherName + "=" + authUser.Name, models.EnvPusherID + fmt.Sprintf("=%d", authUser.ID), models.EnvIsDeployKey + "=false", + models.EnvAppURL + "=" + setting.AppURL, } if !authUser.KeepEmailPrivate {