Skip to content

Commit

Permalink
Check webhooks slice length before calling xorm (#20642)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed Aug 4, 2022
1 parent 6c218f7 commit cf06e20
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions models/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit cf06e20

Please sign in to comment.