|
|
|
@ -14,6 +14,7 @@ import ( |
|
|
|
|
"code.gitea.io/gitea/modules/markup/markdown" |
|
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
|
|
"code.gitea.io/gitea/modules/util" |
|
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2" |
|
|
|
|
) |
|
|
|
@ -95,16 +96,29 @@ func unmarshal(filename string, content []byte) (*api.IssueTemplate, error) { |
|
|
|
|
}{} |
|
|
|
|
|
|
|
|
|
if typ := it.Type(); typ == api.IssueTemplateTypeMarkdown { |
|
|
|
|
templateBody, err := markdown.ExtractMetadata(string(content), it) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
if templateBody, err := markdown.ExtractMetadata(string(content), it); err != nil { |
|
|
|
|
// The only thing we know here is that we can't extract metadata from the content,
|
|
|
|
|
// it's hard to tell if metadata doesn't exist or metadata isn't valid.
|
|
|
|
|
// There's an example template:
|
|
|
|
|
//
|
|
|
|
|
// ---
|
|
|
|
|
// # Title
|
|
|
|
|
// ---
|
|
|
|
|
// Content
|
|
|
|
|
//
|
|
|
|
|
// It could be a valid markdown with two horizontal lines, or an invalid markdown with wrong metadata.
|
|
|
|
|
|
|
|
|
|
it.Content = string(content) |
|
|
|
|
it.Name = filepath.Base(it.FileName) |
|
|
|
|
it.About, _ = util.SplitStringAtByteN(it.Content, 80) |
|
|
|
|
} else { |
|
|
|
|
it.Content = templateBody |
|
|
|
|
if it.About == "" { |
|
|
|
|
if _, err := markdown.ExtractMetadata(string(content), compatibleTemplate); err == nil && compatibleTemplate.About != "" { |
|
|
|
|
it.About = compatibleTemplate.About |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else if typ == api.IssueTemplateTypeYaml { |
|
|
|
|
if err := yaml.Unmarshal(content, it); err != nil { |
|
|
|
|
return nil, fmt.Errorf("yaml unmarshal: %w", err) |
|
|
|
|