Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/interactor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewInteractor(c *InteractorConfig) *Interactor {
i.LockInteractor = (*LockInteractor)(i.common)
i.RepoInteractor = &RepoInteractor{
service: i.common,
WebhookURL: fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost),
WebhookURL: c.BuildWebhookURL(),
WebhookSSL: c.ServerProxyProto == "https",
WebhookSecret: c.WebhookSecret,
}
Expand Down Expand Up @@ -112,3 +112,11 @@ func NewInteractor(c *InteractorConfig) *Interactor {

return i
}

func (c *InteractorConfig) BuildWebhookURL() string {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
}

return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
}
31 changes: 31 additions & 0 deletions internal/interactor/interactor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package interactor_test

import (
"testing"

i "github.com/gitploy-io/gitploy/internal/interactor"
)

func TestInteractorConfig_BuildWebhookURL(t *testing.T) {
t.Run("Return the webhook URL built with the proxy host.", func(t *testing.T) {
c := &i.InteractorConfig{
ServerProxyHost: "hook.cloud.gitploy.io",
ServerProxyProto: "https",
}
wanted := "https://hook.cloud.gitploy.io/hooks"
if ret := c.BuildWebhookURL(); ret != wanted {
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
}
})

t.Run("Return the webhook URL built with the server host.", func(t *testing.T) {
c := &i.InteractorConfig{
ServerHost: "cloud.gitploy.io",
ServerProto: "https",
}
wanted := "https://cloud.gitploy.io/hooks"
if ret := c.BuildWebhookURL(); ret != wanted {
t.Fatalf("BuildWebhookURL = %v, wanted %v", ret, wanted)
}
})
}