Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions files/sanitization.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,23 @@ func IsValidJson(data []byte) error {
var unMarshalled interface{}
return json.Unmarshal(data, &unMarshalled)
}

// StripLeadingComments removes leading comment lines (starting with #) and empty lines from YAML content.
func StripLeadingComments(yamlContent []byte) []byte {
lines := strings.Split(string(yamlContent), "\n")

// Find the first non-comment, non-empty line
for i, line := range lines {
trimmed := strings.TrimSpace(line)
// Skip empty lines and comment lines
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
continue
}
// Found the first non-comment, non-empty line, return the rest
result := strings.Join(lines[i:], "\n")
return []byte(result)
}

// All lines were comments or empty, return empty slice
return []byte{}
}
11 changes: 7 additions & 4 deletions generators/github/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

"github.com/meshery/meshkit/files"
"github.com/meshery/meshkit/utils"
"github.com/meshery/meshkit/utils/component"
"github.com/meshery/meshkit/utils/kubernetes"
Expand Down Expand Up @@ -47,7 +48,9 @@ func (gp GitHubPackage) GenerateComponents(group string) ([]_component.Component
errs := []error{}

for _, crd := range manifestBytes {
resource := string(crd)
// Strip leading comments (like copyright headers) from each YAML document
cleanedCrd := files.StripLeadingComments(crd)
resource := string(cleanedCrd)
include, err := component.IncludeComponentBasedOnGroup(resource, group)

if err != nil {
Expand All @@ -58,18 +61,18 @@ func (gp GitHubPackage) GenerateComponents(group string) ([]_component.Component
continue
}

isCrd := kubernetes.IsCRD(string(crd))
isCrd := kubernetes.IsCRD(resource)
if !isCrd {

comps, err := component.GenerateFromOpenAPI(string(crd), gp)
comps, err := component.GenerateFromOpenAPI(resource, gp)
if err != nil {
errs = append(errs, component.ErrGetSchema(err))
continue
}
components = append(components, comps...)
} else {

comp, err := component.Generate(string(crd))
comp, err := component.Generate(resource)
if err != nil {
continue
}
Expand Down
Loading