diff --git a/internal/services/gateway/command/project.go b/internal/services/gateway/command/project.go index 6ce5455..8a2a79a 100644 --- a/internal/services/gateway/command/project.go +++ b/internal/services/gateway/command/project.go @@ -17,6 +17,7 @@ package command import ( "context" "fmt" + "net/url" "path" "github.com/sorintlab/agola/internal/services/types" @@ -118,7 +119,14 @@ func (c *CommandHandler) SetupProject(ctx context.Context, rs *types.RemoteSourc return errors.Wrapf(err, "failed to extract public key") } - webhookURL := fmt.Sprintf("%s/webhooks?projectid=%s", c.apiExposedURL, project.ID) + webhookURL, err := url.Parse(fmt.Sprintf("%s/webhooks", c.apiExposedURL)) + if err != nil { + return errors.Wrapf(err, "failed to generate webhook url") + } + q := url.Values{} + q.Add("projectid", project.ID) + q.Add("agolaid", c.agolaID) + webhookURL.RawQuery = q.Encode() // generate deploy keys and webhooks containing the agola project id so we // can have multiple projects referencing the same remote repository and this @@ -129,11 +137,11 @@ func (c *CommandHandler) SetupProject(ctx context.Context, rs *types.RemoteSourc return errors.Wrapf(err, "failed to create deploy key") } c.log.Infof("deleting existing webhooks") - if err := gitsource.DeleteRepoWebhook(project.RepositoryPath, webhookURL); err != nil { + if err := gitsource.DeleteRepoWebhook(project.RepositoryPath, webhookURL.String()); err != nil { return errors.Wrapf(err, "failed to delete repository webhook") } c.log.Infof("creating webhook to url: %s", webhookURL) - if err := gitsource.CreateRepoWebhook(project.RepositoryPath, webhookURL, ""); err != nil { + if err := gitsource.CreateRepoWebhook(project.RepositoryPath, webhookURL.String(), ""); err != nil { return errors.Wrapf(err, "failed to create repository webhook") }