Skip to content

Commit

Permalink
Merge pull request #798 from ibuildthecloud/asterick
Browse files Browse the repository at this point in the history
chore: allow wildcard matching in metadata key names
  • Loading branch information
ibuildthecloud authored Aug 14, 2024
2 parents fa52ff4 + 538323b commit 23466fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"fmt"
"io"
"maps"
"path"
"regexp"
"slices"
"strconv"
Expand All @@ -16,7 +18,7 @@ import (
var (
sepRegex = regexp.MustCompile(`^\s*---+\s*$`)
strictSepRegex = regexp.MustCompile(`^---\n$`)
skipRegex = regexp.MustCompile(`^![-.:\w]+\s*$`)
skipRegex = regexp.MustCompile(`^![-.:*\w]+\s*$`)
)

func normalize(key string) string {
Expand Down Expand Up @@ -390,6 +392,16 @@ func assignMetadata(nodes []Node) (result []Node) {
for _, node := range nodes {
if node.ToolNode != nil {
node.ToolNode.Tool.MetaData = metadata[node.ToolNode.Tool.Name]
for wildcard := range metadata {
if strings.Contains(wildcard, "*") {
if m, err := path.Match(wildcard, node.ToolNode.Tool.Name); m && err == nil {
if node.ToolNode.Tool.MetaData == nil {
node.ToolNode.Tool.MetaData = map[string]string{}
}
maps.Copy(node.ToolNode.Tool.MetaData, metadata[wildcard])
}
}
}
}
result = append(result, node)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ asdf2
---
!metadata:first:requirements.txt
asdf
---
!metadata:f*r*:other
foo bar
`
tools, err := ParseTools(strings.NewReader(input))
require.NoError(t, err)
Expand All @@ -266,5 +271,6 @@ asdf
autogold.Expect(map[string]string{
"package.json": "foo=base\nf",
"requirements.txt": "asdf",
"other": "foo bar",
}).Equal(t, tools[0].MetaData)
}

0 comments on commit 23466fd

Please sign in to comment.