Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit ad80e06

Browse files
author
Noah Lee
authored
Fix to build the webhook URL with the proxy host (#360)
1 parent 6323529 commit ad80e06

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Diff for: internal/interactor/interactor.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func NewInteractor(c *InteractorConfig) *Interactor {
8383
i.LockInteractor = (*LockInteractor)(i.common)
8484
i.RepoInteractor = &RepoInteractor{
8585
service: i.common,
86-
WebhookURL: fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost),
86+
WebhookURL: c.BuildWebhookURL(),
8787
WebhookSSL: c.ServerProxyProto == "https",
8888
WebhookSecret: c.WebhookSecret,
8989
}
@@ -112,3 +112,11 @@ func NewInteractor(c *InteractorConfig) *Interactor {
112112

113113
return i
114114
}
115+
116+
func (c *InteractorConfig) BuildWebhookURL() string {
117+
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
118+
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
119+
}
120+
121+
return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
122+
}

Diff for: internal/interactor/interactor_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package interactor_test
2+
3+
import (
4+
"testing"
5+
6+
i "github.com/gitploy-io/gitploy/internal/interactor"
7+
)
8+
9+
func TestInteractorConfig_BuildWebhookURL(t *testing.T) {
10+
t.Run("Return the webhook URL built with the proxy host.", func(t *testing.T) {
11+
c := &i.InteractorConfig{
12+
ServerProxyHost: "hook.cloud.gitploy.io",
13+
ServerProxyProto: "https",
14+
}
15+
wanted := "https://hook.cloud.gitploy.io/hooks"
16+
if ret := c.BuildWebhookURL(); ret != wanted {
17+
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
18+
}
19+
})
20+
21+
t.Run("Return the webhook URL built with the server host.", func(t *testing.T) {
22+
c := &i.InteractorConfig{
23+
ServerHost: "cloud.gitploy.io",
24+
ServerProto: "https",
25+
}
26+
wanted := "https://cloud.gitploy.io/hooks"
27+
if ret := c.BuildWebhookURL(); ret != wanted {
28+
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
29+
}
30+
})
31+
}

0 commit comments

Comments
 (0)