Johannes Batzill 44ec7ceb07 [Webhook] Add API and DB Basics (#142)
This change introduces:
- webhook type / store / controller / handler
- webhookExecution type / store / controller / handler
- foreign key fix for sqlite3
2022-12-28 13:07:48 -08:00

35 lines
814 B
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
package webhook
import (
"context"
"github.com/harness/gitness/internal/auth"
"github.com/harness/gitness/types/enum"
)
// Delete deletes an existing webhook.
func (c *Controller) Delete(
ctx context.Context,
session *auth.Session,
repoRef string,
webhookID int64,
) error {
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoEdit)
if err != nil {
return err
}
// get the webhook and ensure it belongs to us
webhook, err := c.getWebhookVerifyOwnership(ctx, repo.ID, webhookID)
if err != nil {
return err
}
// delete webhook
return c.webhookStore.Delete(ctx, webhook.ID)
}