aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2019-09-08 03:28:40 -0500
committerLauris BH <lauris.buksis@zzdats.lv>2019-09-08 11:28:40 +0300
commit0118b6aaf8ada3edd67cb975c776f6f124178ad2 (patch)
tree8e96203d74de6c4bc7f8eb2a5751a8d218f3ffd3 /routers/repo
parentd4e11ebb18df4bd01f509f673d536e093edb124a (diff)
downloadgitea-0118b6aaf8ada3edd67cb975c776f6f124178ad2.tar.gz
gitea-0118b6aaf8ada3edd67cb975c776f6f124178ad2.zip
Add option to initialize repository with labels (#6061)
* Add optional label sets on repo creation * Fix CRLF * Instead of hardcoding default, make it the helper * Move label set init out of repo init Add a new error for the router Combine router label init with repo creation label init Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add issue labels to Swagger for repo creation Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update models/issue_label.go Co-Authored-By: Lauris BH <lauris@nix.lv> * Update models/issue_label.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/issue_label.go23
-rw-r--r--routers/repo/repo.go3
2 files changed, 10 insertions, 16 deletions
diff --git a/routers/repo/issue_label.go b/routers/repo/issue_label.go
index cae6535c79..452a0a4c0c 100644
--- a/routers/repo/issue_label.go
+++ b/routers/repo/issue_label.go
@@ -33,24 +33,15 @@ func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
return
}
- list, err := models.GetLabelTemplateFile(form.TemplateName)
- if err != nil {
- ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, err))
- ctx.Redirect(ctx.Repo.RepoLink + "/labels")
- return
- }
- labels := make([]*models.Label, len(list))
- for i := 0; i < len(list); i++ {
- labels[i] = &models.Label{
- RepoID: ctx.Repo.Repository.ID,
- Name: list[i][0],
- Description: list[i][2],
- Color: list[i][1],
+ if err := models.InitalizeLabels(ctx.Repo.Repository.ID, form.TemplateName); err != nil {
+ if models.IsErrIssueLabelTemplateLoad(err) {
+ originalErr := err.(models.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
}
- }
- if err := models.NewLabels(labels...); err != nil {
- ctx.ServerError("NewLabels", err)
+ ctx.ServerError("InitalizeLabels", err)
return
}
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 53244f304c..b67384d721 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -115,6 +115,7 @@ func Create(ctx *context.Context) {
// 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["readme"] = "Default"
@@ -155,6 +156,7 @@ func CreatePost(ctx *context.Context, form auth.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
@@ -173,6 +175,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
Name: form.RepoName,
Description: form.Description,
Gitignores: form.Gitignores,
+ IssueLabels: form.IssueLabels,
License: form.License,
Readme: form.Readme,
IsPrivate: form.Private || setting.Repository.ForcePrivate,