code.gitea.io/gitea@v1.21.7/services/packages/container/common.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package container 5 6 import ( 7 "context" 8 "strings" 9 10 packages_model "code.gitea.io/gitea/models/packages" 11 user_model "code.gitea.io/gitea/models/user" 12 container_module "code.gitea.io/gitea/modules/packages/container" 13 ) 14 15 // UpdateRepositoryNames updates the repository name property for all packages of the specific owner 16 func UpdateRepositoryNames(ctx context.Context, owner *user_model.User, newOwnerName string) error { 17 ps, err := packages_model.GetPackagesByType(ctx, owner.ID, packages_model.TypeContainer) 18 if err != nil { 19 return err 20 } 21 22 newOwnerName = strings.ToLower(newOwnerName) 23 24 for _, p := range ps { 25 if err := packages_model.DeletePropertyByName(ctx, packages_model.PropertyTypePackage, p.ID, container_module.PropertyRepository); err != nil { 26 return err 27 } 28 29 if _, err := packages_model.InsertProperty(ctx, packages_model.PropertyTypePackage, p.ID, container_module.PropertyRepository, newOwnerName+"/"+p.LowerName); err != nil { 30 return err 31 } 32 } 33 34 return nil 35 }