MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / matchPatterns

Function matchPatterns

internal/aiagentconfig/discover.go:106–133  ·  view source on GitHub ↗

matchPatterns expands glob patterns relative to basePath and returns deduplicated, sorted discovered files.

(basePath string, patterns []patternDef)

Source from the content-addressed store, hash-verified

104// matchPatterns expands glob patterns relative to basePath and returns
105// deduplicated, sorted discovered files.
106func matchPatterns(basePath string, patterns []patternDef) ([]DiscoveredFile, error) {
107 seen := make(map[string]struct{})
108 var results []DiscoveredFile
109
110 for _, pd := range patterns {
111 absPattern := filepath.Join(basePath, pd.pattern)
112 matches, err := filepath.Glob(absPattern)
113 if err != nil {
114 return nil, err
115 }
116
117 for _, match := range matches {
118 rel, err := filepath.Rel(basePath, match)
119 if err != nil {
120 return nil, err
121 }
122
123 if _, ok := seen[rel]; !ok {
124 seen[rel] = struct{}{}
125 results = append(results, DiscoveredFile{Path: rel, Kind: pd.kind})
126 }
127 }
128 }
129
130 sort.Slice(results, func(i, j int) bool { return results[i].Path < results[j].Path })
131
132 return results, nil
133}

Callers 1

DiscoverAllFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected