Skip to content

Commit

Permalink
#3459 code quality improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Aug 30, 2016
1 parent 92fb30c commit 28cf0e6
Show file tree
Hide file tree
Showing 10 changed files with 991 additions and 763 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra

![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)

##### Current tip version: 0.9.93 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
##### Current tip version: 0.9.94 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)

| Web | UI | Preview |
|:-------------:|:-------:|:-------:|
Expand Down
9 changes: 5 additions & 4 deletions conf/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,11 @@ issues.create = Create Issue
issues.new_label = New Label
issues.new_label_placeholder = Label name...
issues.create_label = Create Label
issues.label_templates.title=Load a set of labels
issues.label_templates.info=There aren’t any labels. You can click on the "New Label" button above to create one or use a predefined set below.
issues.label_templates.helper=Select a label set
issues.label_templates.use=Use this label set
issues.label_templates.title = Load a predefined set of labels
issues.label_templates.info = There aren’t any labels yet. You can click on the "New Label" button above to create one or use a predefined set below.
issues.label_templates.helper = Select a label set
issues.label_templates.use = Use this label set
issues.label_templates.fail_to_load_file = Failed to load label template file '%s': %v
issues.open_tab = %d Open
issues.close_tab = %d Closed
issues.filter_label = Label
Expand Down
2 changes: 1 addition & 1 deletion gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)

const APP_VER = "0.9.93.0829"
const APP_VER = "0.9.94.0829"

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down
41 changes: 38 additions & 3 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package models
import (
"fmt"
"html/template"
"regexp"
"strconv"
"strings"

Expand All @@ -17,6 +18,40 @@ import (
"github.com/gogits/gogs/modules/base"
)

var labelColorPattern = regexp.MustCompile("#([a-fA-F0-9]{6})")

// GetLabelTemplateFile loads the label template file by given name,
// then parses and returns a list of name-color pairs.
func GetLabelTemplateFile(name string) ([][2]string, error) {
data, err := getRepoInitFile("label", name)
if err != nil {
return nil, fmt.Errorf("getRepoInitFile: %v", err)
}

lines := strings.Split(string(data), "\n")
list := make([][2]string, 0, len(lines))
for i := 0; i < len(lines); i++ {
line := strings.TrimSpace(lines[i])
if len(line) == 0 {
continue
}

fields := strings.SplitN(line, " ", 2)
if len(fields) != 2 {
return nil, fmt.Errorf("line is malformed: %s", line)
}

if !labelColorPattern.MatchString(fields[0]) {
return nil, fmt.Errorf("bad HTML color code in line: %s", line)
}

fields[1] = strings.TrimSpace(fields[1])
list = append(list, [2]string{fields[1], fields[0]})
}

return list, nil
}

// Label represents a label of repository for issues.
type Label struct {
ID int64 `xorm:"pk autoincr"`
Expand Down Expand Up @@ -62,9 +97,9 @@ func (l *Label) ForegroundColor() template.CSS {
return template.CSS("#000")
}

// NewLabel creates new label of repository.
func NewLabel(l *Label) error {
_, err := x.Insert(l)
// NewLabels creates new label(s) for a repository.
func NewLabels(labels ...*Label) error {
_, err := x.Insert(labels)
return err
}

Expand Down
2 changes: 0 additions & 2 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) bi
return validate(errs, ctx.Data, f, ctx.Locale)
}

// Label templates

type InitializeLabelsForm struct {
TemplateName string `binding:"Required"`
}
Expand Down
Loading

0 comments on commit 28cf0e6

Please sign in to comment.