summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-03-29 09:23:45 +0200
committerGitHub <noreply@github.com>2022-03-29 09:23:45 +0200
commit76aa33d884af283619054ed14a6137efc14b6d35 (patch)
tree238f2bc5add522767df93cd6064ed4037b0d3b1b /routers
parentMove organization related structs into sub package (#18518) (diff)
downloadforgejo-76aa33d884af283619054ed14a6137efc14b6d35.tar.xz
forgejo-76aa33d884af283619054ed14a6137efc14b6d35.zip
Move init repository related functions to modules (#19159)
* Move init repository related functions to modules * Fix lint * Use ctx but db.DefaultContext Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/org/label.go2
-rw-r--r--routers/api/v1/repo/label.go2
-rw-r--r--routers/web/org/org_labels.go9
-rw-r--r--routers/web/org/setting.go3
-rw-r--r--routers/web/repo/issue_label.go11
-rw-r--r--routers/web/repo/repo.go17
6 files changed, 24 insertions, 20 deletions
diff --git a/routers/api/v1/org/label.go b/routers/api/v1/org/label.go
index 7d4c12d364..d36b1d9a98 100644
--- a/routers/api/v1/org/label.go
+++ b/routers/api/v1/org/label.go
@@ -99,7 +99,7 @@ func CreateLabel(ctx *context.APIContext) {
OrgID: ctx.Org.Organization.ID,
Description: form.Description,
}
- if err := models.NewLabel(label); err != nil {
+ if err := models.NewLabel(ctx, label); err != nil {
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
return
}
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index 67682fc60d..ab559a2eed 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -161,7 +161,7 @@ func CreateLabel(ctx *context.APIContext) {
RepoID: ctx.Repo.Repository.ID,
Description: form.Description,
}
- if err := models.NewLabel(label); err != nil {
+ if err := models.NewLabel(ctx, label); err != nil {
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
return
}
diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go
index 0ec6c3ce3b..d79ffc597c 100644
--- a/routers/web/org/org_labels.go
+++ b/routers/web/org/org_labels.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
)
@@ -48,7 +49,7 @@ func NewLabel(ctx *context.Context) {
Description: form.Description,
Color: form.Color,
}
- if err := models.NewLabel(l); err != nil {
+ if err := models.NewLabel(ctx, l); err != nil {
ctx.ServerError("NewLabel", err)
return
}
@@ -100,9 +101,9 @@ func InitializeLabels(ctx *context.Context) {
return
}
- if err := models.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
- if models.IsErrIssueLabelTemplateLoad(err) {
- originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
+ if err := repo_module.InitializeLabels(ctx, ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
+ if repo_module.IsErrIssueLabelTemplateLoad(err) {
+ originalErr := err.(repo_module.ErrIssueLabelTemplateLoad).OriginalError
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
ctx.Redirect(ctx.Org.OrgLink + "/settings/labels")
return
diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go
index 72c25ec25d..7dd51b253b 100644
--- a/routers/web/org/setting.go
+++ b/routers/web/org/setting.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
user_setting "code.gitea.io/gitea/routers/web/user/setting"
@@ -232,6 +233,6 @@ func Labels(ctx *context.Context) {
ctx.Data["PageIsOrgSettings"] = true
ctx.Data["PageIsOrgSettingsLabels"] = true
ctx.Data["RequireTribute"] = true
- ctx.Data["LabelTemplates"] = models.LabelTemplates
+ ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
ctx.HTML(http.StatusOK, tplSettingsLabels)
}
diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go
index a8866fc072..289e870bb1 100644
--- a/routers/web/repo/issue_label.go
+++ b/routers/web/repo/issue_label.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
issue_service "code.gitea.io/gitea/services/issue"
@@ -28,7 +29,7 @@ func Labels(ctx *context.Context) {
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsLabels"] = true
ctx.Data["RequireTribute"] = true
- ctx.Data["LabelTemplates"] = models.LabelTemplates
+ ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
ctx.HTML(http.StatusOK, tplLabels)
}
@@ -40,9 +41,9 @@ func InitializeLabels(ctx *context.Context) {
return
}
- if err := models.InitializeLabels(ctx, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
- if models.IsErrIssueLabelTemplateLoad(err) {
- originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
+ if err := repo_module.InitializeLabels(ctx, ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
+ if repo_module.IsErrIssueLabelTemplateLoad(err) {
+ originalErr := err.(repo_module.ErrIssueLabelTemplateLoad).OriginalError
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
return
@@ -116,7 +117,7 @@ func NewLabel(ctx *context.Context) {
Description: form.Description,
Color: form.Color,
}
- if err := models.NewLabel(l); err != nil {
+ if err := models.NewLabel(ctx, l); err != nil {
ctx.ServerError("NewLabel", err)
return
}
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 8b03133611..989c1a565e 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/web"
@@ -129,10 +130,10 @@ func Create(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("new_repo")
// Give default value for template to render.
- ctx.Data["Gitignores"] = models.Gitignores
- ctx.Data["LabelTemplates"] = models.LabelTemplates
- ctx.Data["Licenses"] = models.Licenses
- ctx.Data["Readmes"] = models.Readmes
+ ctx.Data["Gitignores"] = repo_module.Gitignores
+ ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
+ ctx.Data["Licenses"] = repo_module.Licenses
+ ctx.Data["Readmes"] = repo_module.Readmes
ctx.Data["readme"] = "Default"
ctx.Data["private"] = getRepoPrivate(ctx)
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
@@ -197,10 +198,10 @@ func CreatePost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CreateRepoForm)
ctx.Data["Title"] = ctx.Tr("new_repo")
- ctx.Data["Gitignores"] = models.Gitignores
- ctx.Data["LabelTemplates"] = models.LabelTemplates
- ctx.Data["Licenses"] = models.Licenses
- ctx.Data["Readmes"] = models.Readmes
+ ctx.Data["Gitignores"] = repo_module.Gitignores
+ ctx.Data["LabelTemplates"] = repo_module.LabelTemplates
+ ctx.Data["Licenses"] = repo_module.Licenses
+ ctx.Data["Readmes"] = repo_module.Readmes
ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo()
ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit()