mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
DBContext is just a Context (#17100)
* DBContext is just a Context This PR removes some of the specialness from the DBContext and makes it context This allows us to simplify the GetEngine code to wrap around any context in future and means that we can change our loadRepo(e Engine) functions to simply take contexts. Signed-off-by: Andrew Thornton <art27@cantab.net> * fix unit tests Signed-off-by: Andrew Thornton <art27@cantab.net> * another place that needs to set the initial context Signed-off-by: Andrew Thornton <art27@cantab.net> * avoid race Signed-off-by: Andrew Thornton <art27@cantab.net> * change attachment error Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
@@ -7,6 +7,7 @@ package models
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -68,9 +69,9 @@ func (gt GiteaTemplate) Globs() []glob.Glob {
|
||||
}
|
||||
|
||||
// GenerateTopics generates topics from a template repository
|
||||
func GenerateTopics(ctx *db.Context, templateRepo, generateRepo *Repository) error {
|
||||
func GenerateTopics(ctx context.Context, templateRepo, generateRepo *Repository) error {
|
||||
for _, topic := range templateRepo.Topics {
|
||||
if _, err := addTopicByNameToRepo(ctx.Engine(), generateRepo.ID, topic); err != nil {
|
||||
if _, err := addTopicByNameToRepo(db.GetEngine(ctx), generateRepo.ID, topic); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -78,7 +79,7 @@ func GenerateTopics(ctx *db.Context, templateRepo, generateRepo *Repository) err
|
||||
}
|
||||
|
||||
// GenerateGitHooks generates git hooks from a template repository
|
||||
func GenerateGitHooks(ctx *db.Context, templateRepo, generateRepo *Repository) error {
|
||||
func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *Repository) error {
|
||||
generateGitRepo, err := git.OpenRepository(generateRepo.RepoPath())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -111,7 +112,7 @@ func GenerateGitHooks(ctx *db.Context, templateRepo, generateRepo *Repository) e
|
||||
}
|
||||
|
||||
// GenerateWebhooks generates webhooks from a template repository
|
||||
func GenerateWebhooks(ctx *db.Context, templateRepo, generateRepo *Repository) error {
|
||||
func GenerateWebhooks(ctx context.Context, templateRepo, generateRepo *Repository) error {
|
||||
templateWebhooks, err := ListWebhooksByOpts(&ListWebhookOptions{RepoID: templateRepo.ID})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -131,7 +132,7 @@ func GenerateWebhooks(ctx *db.Context, templateRepo, generateRepo *Repository) e
|
||||
Events: templateWebhook.Events,
|
||||
Meta: templateWebhook.Meta,
|
||||
}
|
||||
if err := createWebhook(ctx.Engine(), generateWebhook); err != nil {
|
||||
if err := createWebhook(db.GetEngine(ctx), generateWebhook); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -139,18 +140,18 @@ func GenerateWebhooks(ctx *db.Context, templateRepo, generateRepo *Repository) e
|
||||
}
|
||||
|
||||
// GenerateAvatar generates the avatar from a template repository
|
||||
func GenerateAvatar(ctx *db.Context, templateRepo, generateRepo *Repository) error {
|
||||
func GenerateAvatar(ctx context.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.Engine(), generateRepo, "avatar")
|
||||
return updateRepositoryCols(db.GetEngine(ctx), generateRepo, "avatar")
|
||||
}
|
||||
|
||||
// GenerateIssueLabels generates issue labels from a template repository
|
||||
func GenerateIssueLabels(ctx *db.Context, templateRepo, generateRepo *Repository) error {
|
||||
templateLabels, err := getLabelsByRepoID(ctx.Engine(), templateRepo.ID, "", ListOptions{})
|
||||
func GenerateIssueLabels(ctx context.Context, templateRepo, generateRepo *Repository) error {
|
||||
templateLabels, err := getLabelsByRepoID(db.GetEngine(ctx), templateRepo.ID, "", ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -162,7 +163,7 @@ func GenerateIssueLabels(ctx *db.Context, templateRepo, generateRepo *Repository
|
||||
Description: templateLabel.Description,
|
||||
Color: templateLabel.Color,
|
||||
}
|
||||
if err := newLabel(ctx.Engine(), generateLabel); err != nil {
|
||||
if err := newLabel(db.GetEngine(ctx), generateLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user