From b580cffb6e498df87ad0e6f2d2f81df197773c6e Mon Sep 17 00:00:00 2001 From: Gabriel Vasile Date: Thu, 4 Aug 2022 06:20:22 +0300 Subject: [PATCH] Check issue labels slice length before calling xorm Insert(#20655) Backport #20655 Fix #20654 Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lauris BH Co-authored-by: techknowlogick --- services/repository/template.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/repository/template.go b/services/repository/template.go index a16284688b885..b73abdce587f7 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 {