fix: Check for existing webhook before creating it
When pushing an app, check if the webhook already exists before creating
it or it will crate a webhook for every push and consequently will trigger
the pipeline multiple times.
@@ -474,6 +474,19 @@ func (c *CarrierClient) createRepo(name string) error {
}
func (c *CarrierClient) createRepoWebhook(name string) error {
+ hooks, _, err := c.giteaClient.ListRepoHooks(c.config.Org, name, gitea.ListHooksOptions{})
+ if err != nil {
+ return errors.Wrap(err, "failed to list webhooks")
+ }
+
+ for _, hook := range hooks {
+ url := hook.Config["url"]
+ if url == StagingEventListenerURL {
+ c.ui.Normal().Msg("Webhook already exists.")
+ return nil
+ }
+ }
+
c.ui.Normal().Msg("Creating webhook in the repo...")
c.giteaClient.CreateRepoHook(c.config.Org, name, gitea.CreateHookOption{
