aboutsummaryrefslogtreecommitdiffstats
path: root/models/webhook/webhook.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/webhook/webhook.go')
-rw-r--r--models/webhook/webhook.go25
1 files changed, 10 insertions, 15 deletions
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go
index b234d9ffee..7d4b2e2237 100644
--- a/models/webhook/webhook.go
+++ b/models/webhook/webhook.go
@@ -319,21 +319,16 @@ func UpdateWebhookLastStatus(ctx context.Context, w *Webhook) error {
// DeleteWebhookByID uses argument bean as query condition,
// ID must be specified and do not assign unnecessary fields.
func DeleteWebhookByID(ctx context.Context, id int64) (err error) {
- ctx, committer, err := db.TxContext(ctx)
- if err != nil {
- return err
- }
- defer committer.Close()
-
- if count, err := db.DeleteByID[Webhook](ctx, id); err != nil {
- return err
- } else if count == 0 {
- return ErrWebhookNotExist{ID: id}
- } else if _, err = db.DeleteByBean(ctx, &HookTask{HookID: id}); err != nil {
- return err
- }
-
- return committer.Commit()
+ return db.WithTx(ctx, func(ctx context.Context) error {
+ if count, err := db.DeleteByID[Webhook](ctx, id); err != nil {
+ return err
+ } else if count == 0 {
+ return ErrWebhookNotExist{ID: id}
+ } else if _, err = db.DeleteByBean(ctx, &HookTask{HookID: id}); err != nil {
+ return err
+ }
+ return nil
+ })
}
// DeleteWebhookByRepoID deletes webhook of repository by given ID.