@@ -751,12 +751,7 @@ func getFileContentFromDefaultBranch(repo *context.Repository, filename string)
751
751
return string (bytes ), true
752
752
}
753
753
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 ) {
760
755
// Add `possibleFiles` and each `{possibleDirs}/{template}` to `templateCandidates`
761
756
templateCandidates := make ([]string , 0 , len (possibleFiles ))
762
757
if template != "" {
@@ -771,29 +766,31 @@ func getTemplate(repo *context.Repository, template string, possibleDirs, possib
771
766
templateContent , found := getFileContentFromDefaultBranch (repo , filename )
772
767
if found {
773
768
meta := api.IssueTemplate {FileName : filename }
769
+ var templateBody string
770
+ var formTemplateBody * api.IssueFormTemplate
771
+ var err error
774
772
775
773
if strings .HasSuffix (filename , ".md" ) {
776
774
// Parse markdown template
777
- outTemplateBody , err = markdown .ExtractMetadata (templateContent , meta )
775
+ templateBody , err = markdown .ExtractMetadata (templateContent , meta )
778
776
} else if strings .HasSuffix (filename , ".yaml" ) || strings .HasSuffix (filename , ".yml" ) {
779
777
// 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 )
782
780
} else {
783
781
err = errors .New ("invalid template type" )
784
782
}
785
783
if err != nil {
786
784
log .Debug ("could not extract metadata from %s [%s]: %v" , filename , repo .Repository .FullName (), err )
787
- outTemplateBody = templateContent
785
+ templateBody = templateContent
788
786
err = nil
789
787
}
790
788
791
- outMeta = & meta
792
- return
789
+ return & meta , templateBody , formTemplateBody , err
793
790
}
794
791
}
795
- err = errors . New ( "no template found" )
796
- return
792
+
793
+ return nil , "" , nil , errors . New ( "no template found" )
797
794
}
798
795
799
796
func setTemplateIfExists (ctx * context.Context , ctxDataKey string , possibleDirs , possibleFiles []string ) {
@@ -833,7 +830,6 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs,
833
830
ctx .Data ["label_ids" ] = strings .Join (labelIDs , "," )
834
831
ctx .Data ["Reference" ] = templateMeta .Ref
835
832
ctx .Data ["RefEndName" ] = git .RefEndName (templateMeta .Ref )
836
- return
837
833
}
838
834
839
835
// NewIssue render creating issue page
@@ -1059,11 +1055,11 @@ func renderIssueFormValues(ctx *context.Context, form *url.Values) (string, erro
1059
1055
// Render values
1060
1056
result := ""
1061
1057
for _ , field := range formTemplateBody .Fields {
1062
- if field .Id != "" {
1058
+ if field .ID != "" {
1063
1059
// Get field label
1064
1060
label := field .Attributes ["label" ]
1065
1061
if label == "" {
1066
- label = field .Id
1062
+ label = field .ID
1067
1063
}
1068
1064
1069
1065
// Format the value into Markdown
@@ -1072,15 +1068,15 @@ func renderIssueFormValues(ctx *context.Context, form *url.Values) (string, erro
1072
1068
// Markdown blocks do not appear in output
1073
1069
case "input" , "textarea" , "dropdown" :
1074
1070
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 ))
1076
1072
} 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 ))
1078
1074
}
1079
1075
case "checkboxes" :
1080
1076
result += fmt .Sprintf ("### %s\n " , label )
1081
1077
for i , option := range field .Attributes ["options" ].([]interface {}) {
1082
1078
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" {
1084
1080
checked = "x"
1085
1081
}
1086
1082
result += fmt .Sprintf ("- [%s] %s\n " , checked , option .(map [interface {}]interface {})["label" ])
0 commit comments