Skip to content

Commit 88bf8b8

Browse files
committed
Fix lint issues
1 parent a45f362 commit 88bf8b8

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

modules/context/repo.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ package context
88
import (
99
"context"
1010
"fmt"
11-
"gopkg.in/yaml.v2"
1211
"html"
1312
"io"
1413
"net/http"
1514
"net/url"
1615
"path"
1716
"strings"
1817

18+
"gopkg.in/yaml.v2"
19+
1920
"code.gitea.io/gitea/models"
2021
"code.gitea.io/gitea/models/db"
2122
git_model "code.gitea.io/gitea/models/git"
@@ -1033,8 +1034,9 @@ func UnitTypes() func(ctx *Context) {
10331034
}
10341035
}
10351036

1036-
func ExtractTemplateFromYaml(templateContent []byte, meta *api.IssueTemplate) (tmpl *api.IssueFormTemplate, err error) {
1037-
err = yaml.Unmarshal(templateContent, &tmpl)
1037+
func ExtractTemplateFromYaml(templateContent []byte, meta *api.IssueTemplate) (*api.IssueFormTemplate, error) {
1038+
var tmpl *api.IssueFormTemplate
1039+
err := yaml.Unmarshal(templateContent, &tmpl)
10381040
if err != nil {
10391041
return nil, err
10401042
}
@@ -1049,7 +1051,7 @@ func ExtractTemplateFromYaml(templateContent []byte, meta *api.IssueTemplate) (t
10491051
meta.Ref = tmpl.Ref
10501052
}
10511053

1052-
return
1054+
return tmpl, nil
10531055
}
10541056

10551057
// IssueTemplatesFromDefaultBranch checks for issue templates in the repo's default branch

modules/structs/issue_form.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "strings"
88

99
type FormField struct {
1010
Type string `yaml:"type"`
11-
Id string `yaml:"id"`
11+
ID string `yaml:"id"`
1212
Attributes map[string]interface{} `yaml:"attributes"`
1313
Validations map[string]interface{} `yaml:"validations"`
1414
}
@@ -33,7 +33,7 @@ func (it IssueFormTemplate) Valid() bool {
3333
}
3434

3535
for _, field := range it.Fields {
36-
if strings.TrimSpace(field.Id) == "" {
36+
if strings.TrimSpace(field.ID) == "" {
3737
// TODO: add IDs should be optional, maybe generate slug from label? or use numberic id
3838
return false
3939
}

routers/web/repo/issue.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,7 @@ func getFileContentFromDefaultBranch(repo *context.Repository, filename string)
751751
return string(bytes), true
752752
}
753753

754-
func getTemplate(repo *context.Repository, template string, possibleDirs, possibleFiles []string) (
755-
outMeta *api.IssueTemplate,
756-
outTemplateBody string,
757-
outFormTemplateBody *api.IssueFormTemplate,
758-
err error,
759-
) {
754+
func getTemplate(repo *context.Repository, template string, possibleDirs, possibleFiles []string) (*api.IssueTemplate, string, *api.IssueFormTemplate, error) {
760755
// Add `possibleFiles` and each `{possibleDirs}/{template}` to `templateCandidates`
761756
templateCandidates := make([]string, 0, len(possibleFiles))
762757
if template != "" {
@@ -771,29 +766,31 @@ func getTemplate(repo *context.Repository, template string, possibleDirs, possib
771766
templateContent, found := getFileContentFromDefaultBranch(repo, filename)
772767
if found {
773768
meta := api.IssueTemplate{FileName: filename}
769+
var templateBody string
770+
var formTemplateBody *api.IssueFormTemplate
771+
var err error
774772

775773
if strings.HasSuffix(filename, ".md") {
776774
// Parse markdown template
777-
outTemplateBody, err = markdown.ExtractMetadata(templateContent, meta)
775+
templateBody, err = markdown.ExtractMetadata(templateContent, meta)
778776
} else if strings.HasSuffix(filename, ".yaml") || strings.HasSuffix(filename, ".yml") {
779777
// Parse yaml (form) template
780-
outFormTemplateBody, err = context.ExtractTemplateFromYaml([]byte(templateContent), &meta)
781-
outFormTemplateBody.FileName = path.Base(filename)
778+
formTemplateBody, err = context.ExtractTemplateFromYaml([]byte(templateContent), &meta)
779+
formTemplateBody.FileName = path.Base(filename)
782780
} else {
783781
err = errors.New("invalid template type")
784782
}
785783
if err != nil {
786784
log.Debug("could not extract metadata from %s [%s]: %v", filename, repo.Repository.FullName(), err)
787-
outTemplateBody = templateContent
785+
templateBody = templateContent
788786
err = nil
789787
}
790788

791-
outMeta = &meta
792-
return
789+
return &meta, templateBody, formTemplateBody, err
793790
}
794791
}
795-
err = errors.New("no template found")
796-
return
792+
793+
return nil, "", nil, errors.New("no template found")
797794
}
798795

799796
func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs, possibleFiles []string) {
@@ -833,7 +830,6 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs,
833830
ctx.Data["label_ids"] = strings.Join(labelIDs, ",")
834831
ctx.Data["Reference"] = templateMeta.Ref
835832
ctx.Data["RefEndName"] = git.RefEndName(templateMeta.Ref)
836-
return
837833
}
838834

839835
// NewIssue render creating issue page
@@ -1059,11 +1055,11 @@ func renderIssueFormValues(ctx *context.Context, form *url.Values) (string, erro
10591055
// Render values
10601056
result := ""
10611057
for _, field := range formTemplateBody.Fields {
1062-
if field.Id != "" {
1058+
if field.ID != "" {
10631059
// Get field label
10641060
label := field.Attributes["label"]
10651061
if label == "" {
1066-
label = field.Id
1062+
label = field.ID
10671063
}
10681064

10691065
// Format the value into Markdown
@@ -1072,15 +1068,15 @@ func renderIssueFormValues(ctx *context.Context, form *url.Values) (string, erro
10721068
// Markdown blocks do not appear in output
10731069
case "input", "textarea", "dropdown":
10741070
if renderType, ok := field.Attributes["render"]; ok {
1075-
result += fmt.Sprintf("### %s\n```%s\n%s\n```\n\n", label, renderType, form.Get("form-field-"+field.Id))
1071+
result += fmt.Sprintf("### %s\n```%s\n%s\n```\n\n", label, renderType, form.Get("form-field-"+field.ID))
10761072
} else {
1077-
result += fmt.Sprintf("### %s\n%s\n\n", label, form.Get("form-field-"+field.Id))
1073+
result += fmt.Sprintf("### %s\n%s\n\n", label, form.Get("form-field-"+field.ID))
10781074
}
10791075
case "checkboxes":
10801076
result += fmt.Sprintf("### %s\n", label)
10811077
for i, option := range field.Attributes["options"].([]interface{}) {
10821078
checked := " "
1083-
if form.Get(fmt.Sprintf("form-field-%s-%d", field.Id, i)) == "on" {
1079+
if form.Get(fmt.Sprintf("form-field-%s-%d", field.ID, i)) == "on" {
10841080
checked = "x"
10851081
}
10861082
result += fmt.Sprintf("- [%s] %s\n", checked, option.(map[interface{}]interface{})["label"])

templates/repo/issue/comment_tab.tmpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
{{else if eq .Type "input"}}
1010
<input type="text"
1111
aria-labelledby="form-label-{{$field_idx}}"
12-
name="form-field-{{$field.Id}}"
13-
id="form-field-{{$field.Id}}"
12+
name="form-field-{{$field.ID}}"
13+
id="form-field-{{$field.ID}}"
1414
placeholder="{{$field.Attributes.placeholder}}"
1515
value="{{$field.Attributes.value}}"
1616
{{- if .Validations.required}}required{{end}} />
1717
{{else if eq .Type "textarea"}}
1818
{{- if .Attributes.render}}
19-
<input type="hidden" name="attrs-form-field-{{$field.Id}}" value="{&quot;render&quot;: &quot;{{.Attributes.render}}&quot;}">
19+
<input type="hidden" name="attrs-form-field-{{$field.ID}}" value="{&quot;render&quot;: &quot;{{.Attributes.render}}&quot;}">
2020
{{end}}
2121
<textarea aria-labelledby="form-label-{{$field_idx}}"
22-
name="form-field-{{$field.Id}}"
23-
id="form-field-{{$field.Id}}"
22+
name="form-field-{{$field.ID}}"
23+
id="form-field-{{$field.ID}}"
2424
placeholder="{{$field.Attributes.placeholder}}"
2525
{{- if .Attributes.render}}class="no-easymde"{{end}}
2626
{{- if .Validations.required}}required{{end}}>{{$field.Attributes.value}}</textarea>
2727
{{else if eq .Type "dropdown"}}
2828
{{/* TODO: work with .Attribtes.multiple */}}
2929
<select aria-labelledby="form-label-{{$field_idx}}"
30-
name="form-field-{{$field.Id}}"
31-
id="form-field-{{$field.Id}}"
30+
name="form-field-{{$field.ID}}"
31+
id="form-field-{{$field.ID}}"
3232
{{- if .Validations.required}}required{{end}}>
3333
{{range $field.Attributes.options}}
3434
<option value="{{.}}">{{.}}</option>
@@ -38,8 +38,8 @@
3838
{{range $chk_id, $chk := $field.Attributes.options}}
3939
<label>
4040
<input type="checkbox"
41-
name="form-field-{{$field.Id}}-{{$chk_id}}"
42-
id="form-field-{{$field.Id}}-{{$chk_id}}"
41+
name="form-field-{{$field.ID}}-{{$chk_id}}"
42+
id="form-field-{{$field.ID}}-{{$chk_id}}"
4343
{{if .checked}}checked{{end}}
4444
{{if .required}}required{{end}} />
4545
{{.label}}{{if .required}} <span style="color: orangered;">*</span>{{end}}

0 commit comments

Comments
 (0)