|
|
@ -11,8 +11,6 @@ import ( |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"path" |
|
|
|
|
|
|
|
"regexp" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
@ -22,7 +20,6 @@ import ( |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/base" |
|
|
|
"github.com/gogits/gogs/modules/base" |
|
|
|
"github.com/gogits/gogs/modules/bindata" |
|
|
|
|
|
|
|
"github.com/gogits/gogs/modules/context" |
|
|
|
"github.com/gogits/gogs/modules/context" |
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
"github.com/gogits/gogs/modules/markdown" |
|
|
|
"github.com/gogits/gogs/modules/markdown" |
|
|
@ -945,51 +942,30 @@ func Labels(ctx *context.Context) { |
|
|
|
ctx.HTML(200, LABELS) |
|
|
|
ctx.HTML(200, LABELS) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getLabelTemplateFile(name string) ([]byte, error) { |
|
|
|
|
|
|
|
relPath := path.Join("conf/label", strings.TrimLeft(name, "./")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use custom file when available.
|
|
|
|
|
|
|
|
customPath := path.Join(setting.CustomPath, relPath) |
|
|
|
|
|
|
|
if com.IsFile(customPath) { |
|
|
|
|
|
|
|
return ioutil.ReadFile(customPath) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return bindata.Asset(relPath) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) { |
|
|
|
func InitializeLabels(ctx *context.Context, form auth.InitializeLabelsForm) { |
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string)) |
|
|
|
|
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/labels") |
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/labels") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
data, err := getLabelTemplateFile(form.TemplateName) |
|
|
|
list, err := models.GetLabelTemplateFile(form.TemplateName) |
|
|
|
if err != nil { |
|
|
|
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") |
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/labels") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
r, _ := regexp.Compile("#([a-fA-F0-9]{6})") |
|
|
|
|
|
|
|
for i, line := range strings.Split(string(data), "\n") { |
|
|
|
labels := make([]*models.Label, len(list)) |
|
|
|
if len(line) > 0 { |
|
|
|
for i := 0; i < len(list); i++ { |
|
|
|
line_x := strings.SplitN(strings.Trim(line, " \t"), " ", 2) |
|
|
|
labels[i] = &models.Label{ |
|
|
|
if len(line_x) == 2 && len(line_x[1]) > 0 { |
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
if r.MatchString(line_x[0]) { |
|
|
|
Name: list[i][0], |
|
|
|
l := &models.Label{ |
|
|
|
Color: list[i][1], |
|
|
|
RepoID: ctx.Repo.Repository.ID, |
|
|
|
|
|
|
|
Name: line_x[1], |
|
|
|
|
|
|
|
Color: line_x[0], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := models.NewLabel(l); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "InitializeLabelsFromTemplate", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.Warn("Line %d on the label template file '%s': Bad HTML color code", i+1, form.TemplateName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
log.Warn("Line %d on the label template file '%s': Line is malformed", i+1, form.TemplateName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := models.NewLabels(labels...); err != nil { |
|
|
|
|
|
|
|
ctx.Handle(500, "NewLabels", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/labels") |
|
|
|
ctx.Redirect(ctx.Repo.RepoLink + "/labels") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1008,7 +984,7 @@ func NewLabel(ctx *context.Context, form auth.CreateLabelForm) { |
|
|
|
Name: form.Title, |
|
|
|
Name: form.Title, |
|
|
|
Color: form.Color, |
|
|
|
Color: form.Color, |
|
|
|
} |
|
|
|
} |
|
|
|
if err := models.NewLabel(l); err != nil { |
|
|
|
if err := models.NewLabels(l); err != nil { |
|
|
|
ctx.Handle(500, "NewLabel", err) |
|
|
|
ctx.Handle(500, "NewLabel", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|