From: zeripath Date: Wed, 17 Aug 2022 22:36:56 +0000 (+0100) Subject: Check issue labels slice length before calling xorm Insert(#20655) (#20836) X-Git-Tag: v1.17.1~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b43d7e1254a79a0f9995aaf29a2eb33bbda2290f;p=gitea.git Check issue labels slice length before calling xorm Insert(#20655) (#20836) Backport #20655 Fix #20654 Co-authored-by: Gabriel Vasile Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH Co-authored-by: techknowlogick --- diff --git a/services/repository/template.go b/services/repository/template.go index a16284688b..b73abdce58 100644 --- a/services/repository/template.go +++ b/services/repository/template.go @@ -21,6 +21,11 @@ func GenerateIssueLabels(ctx context.Context, templateRepo, generateRepo *repo_m if err != nil { return err } + // Prevent insert being called with an empty slice which would result in + // err "no element on slice when insert". + if len(templateLabels) == 0 { + return nil + } newLabels := make([]*issues_model.Label, 0, len(templateLabels)) for _, templateLabel := range templateLabels {