Skip to content

Commit

Permalink
Merge pull request openshift#1647 from jupierce/fix_linter
Browse files Browse the repository at this point in the history
Improve YAML header parsing
  • Loading branch information
openshift-merge-bot[bot] authored Jun 19, 2024
2 parents b9df937 + fb448e2 commit 721f10f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hack/Dockerfile.markdownlint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fedora
FROM fedora:38
WORKDIR /workdir
RUN dnf install -y git golang
COPY install-markdownlint.sh /tmp
Expand Down
10 changes: 9 additions & 1 deletion tools/enhancements/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package enhancements
import (
"fmt"
"net/url"
"strings"

"gopkg.in/yaml.v3"
)
Expand All @@ -21,7 +22,14 @@ type MetaData struct {
func NewMetaData(content []byte) (*MetaData, error) {
result := MetaData{}

err := yaml.Unmarshal(content, &result)
strContent := string(content)
parts := strings.Split(strContent, "---")
if len(parts) < 3 {
return nil, fmt.Errorf("could not extract meta data from header: yaml was not delineated by '---' per the template")
}
yamlContent := strings.TrimSpace(parts[1])
yamlBytes := []byte(yamlContent)
err := yaml.Unmarshal(yamlBytes, &result)
if err != nil {
return nil, fmt.Errorf("could not extract meta data from header: %w", err)
}
Expand Down

0 comments on commit 721f10f

Please sign in to comment.