Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-27 20:26:09 +01:00

Check webhooks slice length before calling xorm (#20642) (#20768)

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>
Co-authored-by: Gabriel Vasile <gabriel.vasile@email.com>
This commit is contained in:
Lunny Xiao 2022-08-12 16:36:45 +08:00 committed by GitHub
parent f7c874cb1a
commit ac9792c0c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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)
} }