diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-09-19 19:49:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 19:49:59 +0800 |
commit | a4bfef265d9e512830350635a0489c2cdcd6508f (patch) | |
tree | 1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/repo_generate.go | |
parent | 462306e263db5a809dbe2cdf62e99307aeff28de (diff) | |
download | gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip |
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db
* Fix lint
* Fix lint
* Fix test
* Fix lint
* Fix lint
* revert unnecessary change
* Fix test
* Fix wrong replace string
* Use *Context
* Correct committer spelling and fix wrong replaced words
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/repo_generate.go')
-rw-r--r-- | models/repo_generate.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/models/repo_generate.go b/models/repo_generate.go index 66682903f1..e5f5c7e7fe 100644 --- a/models/repo_generate.go +++ b/models/repo_generate.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/storage" @@ -67,9 +68,9 @@ func (gt GiteaTemplate) Globs() []glob.Glob { } // GenerateTopics generates topics from a template repository -func GenerateTopics(ctx DBContext, templateRepo, generateRepo *Repository) error { +func GenerateTopics(ctx *db.Context, templateRepo, generateRepo *Repository) error { for _, topic := range templateRepo.Topics { - if _, err := addTopicByNameToRepo(ctx.e, generateRepo.ID, topic); err != nil { + if _, err := addTopicByNameToRepo(ctx.Engine(), generateRepo.ID, topic); err != nil { return err } } @@ -77,7 +78,7 @@ func GenerateTopics(ctx DBContext, templateRepo, generateRepo *Repository) error } // GenerateGitHooks generates git hooks from a template repository -func GenerateGitHooks(ctx DBContext, templateRepo, generateRepo *Repository) error { +func GenerateGitHooks(ctx *db.Context, templateRepo, generateRepo *Repository) error { generateGitRepo, err := git.OpenRepository(generateRepo.RepoPath()) if err != nil { return err @@ -110,7 +111,7 @@ func GenerateGitHooks(ctx DBContext, templateRepo, generateRepo *Repository) err } // GenerateWebhooks generates webhooks from a template repository -func GenerateWebhooks(ctx DBContext, templateRepo, generateRepo *Repository) error { +func GenerateWebhooks(ctx *db.Context, templateRepo, generateRepo *Repository) error { templateWebhooks, err := ListWebhooksByOpts(&ListWebhookOptions{RepoID: templateRepo.ID}) if err != nil { return err @@ -130,7 +131,7 @@ func GenerateWebhooks(ctx DBContext, templateRepo, generateRepo *Repository) err Events: templateWebhook.Events, Meta: templateWebhook.Meta, } - if err := createWebhook(ctx.e, generateWebhook); err != nil { + if err := createWebhook(ctx.Engine(), generateWebhook); err != nil { return err } } @@ -138,18 +139,18 @@ func GenerateWebhooks(ctx DBContext, templateRepo, generateRepo *Repository) err } // GenerateAvatar generates the avatar from a template repository -func GenerateAvatar(ctx DBContext, templateRepo, generateRepo *Repository) error { +func GenerateAvatar(ctx *db.Context, templateRepo, generateRepo *Repository) error { generateRepo.Avatar = strings.Replace(templateRepo.Avatar, strconv.FormatInt(templateRepo.ID, 10), strconv.FormatInt(generateRepo.ID, 10), 1) if _, err := storage.Copy(storage.RepoAvatars, generateRepo.CustomAvatarRelativePath(), storage.RepoAvatars, templateRepo.CustomAvatarRelativePath()); err != nil { return err } - return updateRepositoryCols(ctx.e, generateRepo, "avatar") + return updateRepositoryCols(ctx.Engine(), generateRepo, "avatar") } // GenerateIssueLabels generates issue labels from a template repository -func GenerateIssueLabels(ctx DBContext, templateRepo, generateRepo *Repository) error { - templateLabels, err := getLabelsByRepoID(ctx.e, templateRepo.ID, "", ListOptions{}) +func GenerateIssueLabels(ctx *db.Context, templateRepo, generateRepo *Repository) error { + templateLabels, err := getLabelsByRepoID(ctx.Engine(), templateRepo.ID, "", ListOptions{}) if err != nil { return err } @@ -161,7 +162,7 @@ func GenerateIssueLabels(ctx DBContext, templateRepo, generateRepo *Repository) Description: templateLabel.Description, Color: templateLabel.Color, } - if err := newLabel(ctx.e, generateLabel); err != nil { + if err := newLabel(ctx.Engine(), generateLabel); err != nil { return err } } |