]> source.dussan.org Git - gitea.git/commitdiff
Check issue labels slice length before calling xorm Insert(#20655) (#20836)
authorzeripath <art27@cantab.net>
Wed, 17 Aug 2022 22:36:56 +0000 (23:36 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Aug 2022 22:36:56 +0000 (23:36 +0100)
Backport #20655

Fix #20654

Co-authored-by: Gabriel Vasile <gabriel.vasile@email.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
services/repository/template.go

index a16284688b8859632ec116b803ff73600de0fd1b..b73abdce587f7aa9eeca605b7933d835cf1b1410 100644 (file)
@@ -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 {