From ac9792c0c771fcc5f629af3a25ff9287f8327d87 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 12 Aug 2022 16:36:45 +0800 Subject: [PATCH] Check webhooks slice length before calling xorm (#20642) (#20768) Fixes: #20641 Co-authored-by: Lauris BH Co-authored-by: John Olheiser Co-authored-by: Lunny Xiao Co-authored-by: Gabriel Vasile --- models/webhook/webhook.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go index 1b79a414ade..478a6a29ff2 100644 --- a/models/webhook/webhook.go +++ b/models/webhook/webhook.go @@ -399,6 +399,10 @@ func CreateWebhook(ctx context.Context, w *Webhook) error { // CreateWebhooks creates multiple web hooks func CreateWebhooks(ctx context.Context, ws []*Webhook) error { + // xorm returns err "no element on slice when insert" for empty slices. + if len(ws) == 0 { + return nil + } for i := 0; i < len(ws); i++ { ws[i].Type = strings.TrimSpace(ws[i].Type) }