Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with markdown template without metadata #21639

Merged
merged 4 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions modules/issue/template/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,20 @@ 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
}
it.Content = templateBody
if it.About == "" {
if _, err := markdown.ExtractMetadata(string(content), compatibleTemplate); err == nil && compatibleTemplate.About != "" {
it.About = compatibleTemplate.About
if templateBody, err := markdown.ExtractMetadata(string(content), it); err != nil {
// can't extract metadata, so it could be a pure markdown.
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
it.Content = string(content)
it.Name = filepath.Base(it.FileName)
it.About = it.Content
if max, runes := 80, []rune(it.About); len(runes) > max {
it.About = string(runes[:max]) + "..."
}
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
} 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 {
Expand Down
4 changes: 2 additions & 2 deletions modules/structs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (it IssueTemplate) Type() IssueTemplateType {
if ext := filepath.Ext(it.FileName); ext == ".md" {
return IssueTemplateTypeMarkdown
} else if ext == ".yaml" || ext == ".yml" {
return "yaml"
return IssueTemplateTypeYaml
}
return IssueTemplateTypeYaml
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested whether the newly returned "" works (it might change some behaviors). I think it should be OK. So LGTM and let's try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 Don't worry, it should be return "", I wrote the wrong code with a drunk brain.

}