mirror of
1
Fork 0

Check webhooks slice length before calling xorm (#20642)

xorm.db.Insert errors for empty slices. Fixes: #20641

Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Gabriel Vasile 2022-08-04 07:22:50 +03:00 committed by GitHub
parent 6c218f7a5c
commit cf06e20c0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -399,6 +399,10 @@ func CreateWebhook(ctx context.Context, w *Webhook) error {
// CreateWebhooks creates multiple web hooks // CreateWebhooks creates multiple web hooks
func CreateWebhooks(ctx context.Context, ws []*Webhook) error { 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++ { for i := 0; i < len(ws); i++ {
ws[i].Type = strings.TrimSpace(ws[i].Type) ws[i].Type = strings.TrimSpace(ws[i].Type)
} }