From 68dbd488a958fcb6b14412c3420b73aab1cae7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bogus=C5=82awski?= Date: Mon, 28 Jun 2021 19:28:18 +0200 Subject: [PATCH] Using configured server URL instead of obtained from request (#175) Woodpecker should use configured server URL when creating self URL-s for VCS UI and not depend on URL read from request. In case of internal calls like answers for webhooks from Gitea on backend, address in URL may be internal and this causes Gitea to display CI status for commit with intenal URL to woodpecker not external one. --- server/badge.go | 6 ++++-- server/build.go | 7 +++++-- server/hook.go | 5 ++++- server/rpc.go | 5 ++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server/badge.go b/server/badge.go index f9bcc9bab..938004cba 100644 --- a/server/badge.go +++ b/server/badge.go @@ -1,4 +1,5 @@ // Copyright 2018 Drone.IO Inc. +// Copyright 2021 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,6 +12,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k. package server @@ -21,7 +24,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/woodpecker-ci/woodpecker/model" - "github.com/woodpecker-ci/woodpecker/shared/httputil" "github.com/woodpecker-ci/woodpecker/store" ) @@ -92,7 +94,7 @@ func GetCC(c *gin.Context) { return } - url := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, builds[0].Number) + url := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, builds[0].Number) cc := model.NewCC(repo, builds[0], url) c.XML(200, cc) } diff --git a/server/build.go b/server/build.go index 28af79179..db983467b 100644 --- a/server/build.go +++ b/server/build.go @@ -1,4 +1,5 @@ // Copyright 2018 Drone.IO Inc. +// Copyright 2021 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,6 +12,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k. package server @@ -326,7 +329,7 @@ func PostApproval(c *gin.Context) { defer func() { for _, item := range buildItems { - uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number) + uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number) if len(buildItems) > 1 { err = remote_.Status(user, repo, build, uri, item.Proc) } else { @@ -367,7 +370,7 @@ func PostDecline(c *gin.Context) { return } - uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number) + uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number) err = remote_.Status(user, repo, build, uri, nil) if err != nil { logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err) diff --git a/server/hook.go b/server/hook.go index ff5d93cbd..b9abed9a4 100644 --- a/server/hook.go +++ b/server/hook.go @@ -1,4 +1,5 @@ // Copyright 2018 Drone.IO Inc. +// Copyright 2021 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,6 +12,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k. package server @@ -273,7 +276,7 @@ func PostHook(c *gin.Context) { defer func() { for _, item := range buildItems { - uri := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, build.Number) + uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number) if len(buildItems) > 1 { err = remote_.Status(user, repo, build, uri, item.Proc) } else { diff --git a/server/rpc.go b/server/rpc.go index 10bd312e4..bf3498b1f 100644 --- a/server/rpc.go +++ b/server/rpc.go @@ -1,4 +1,5 @@ // Copyright 2018 Drone.IO Inc. +// Copyright 2021 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,6 +12,8 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// +// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k. package server @@ -465,7 +468,7 @@ func (s *RPC) updateRemoteStatus(repo *model.Repo, build *model.Build, proc *mod s.store.UpdateUser(user) } } - uri := fmt.Sprintf("%s/%s/%d", s.host, repo.FullName, build.Number) + uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number) err = s.remote.Status(user, repo, build, uri, proc) if err != nil { logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err)