gateway: set agolaid query parameter in webhook url

This commit is contained in:
Simone Gotti 2019-04-30 12:13:51 +02:00
parent fefa2819c9
commit 1e1152cb1a
1 changed files with 11 additions and 3 deletions

View File

@ -17,6 +17,7 @@ package command
import ( import (
"context" "context"
"fmt" "fmt"
"net/url"
"path" "path"
"github.com/sorintlab/agola/internal/services/types" "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") 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 // generate deploy keys and webhooks containing the agola project id so we
// can have multiple projects referencing the same remote repository and this // 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") return errors.Wrapf(err, "failed to create deploy key")
} }
c.log.Infof("deleting existing webhooks") 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") return errors.Wrapf(err, "failed to delete repository webhook")
} }
c.log.Infof("creating webhook to url: %s", webhookURL) 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") return errors.Wrapf(err, "failed to create repository webhook")
} }