send updates

Signed-off-by: Danilo Patrucco <danilo.patrucco@gmail.com>
pull/13205/head
Danilo Patrucco 1 year ago
parent 35874a3d8d
commit 9dfa76ee77

@ -83,77 +83,42 @@ func newLintCmd(out io.Writer) *cobra.Command {
vals, err := valueOpts.MergeValues(getter.All(settings)) vals, err := valueOpts.MergeValues(getter.All(settings))
if err != nil { if err != nil {
return err return err
print("this is the error\n")
} }
var ignorePatterns map[string][]string var ignorePatterns map[string][]string
if lintIgnoreFile == "" {
// Uncomment to debug:
// print("empty")
dir, err := os.Getwd()
if err != nil {
panic(err)
}
lintIgnoreFile = filepath.Join(dir, ".helmlintignore")
}
if lintIgnoreFile != "" { if lintIgnoreFile != "" {
fmt.Printf("\nthis is the path: %s\n", lintIgnoreFile) fmt.Printf("\nUsing ignore file: %s\n", lintIgnoreFile)
ignorePatterns, err := rules.ParseIgnoreFile(lintIgnoreFile) ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile)
// Uncomment to debug:
// fmt.Println("Patterns:", ignorePatterns)
// fmt.Println("Errors:", err)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse .helmlintignore file: %v", err) return fmt.Errorf("failed to parse .helmlintignore file: %v", err)
} }
fmt.Println("Ignore Patterns:", ignorePatterns)
} }
var message strings.Builder var message strings.Builder
failed := 0 failed := 0
errorsOrWarnings := 0
for _, path := range paths { for _, path := range paths {
result := client.Run([]string{path}, vals) result := client.Run([]string{path}, vals)
filteredResult := FilterIgnoredMessages(result, ignorePatterns) filteredResult := FilterIgnoredMessages(result, ignorePatterns)
hasWarningsOrErrors := len(filteredResult.Messages) > 0
if hasWarningsOrErrors {
errorsOrWarnings++
}
if client.Quiet && !hasWarningsOrErrors {
continue
}
fmt.Fprintf(&message, "==> Linting %s\n", path) fmt.Fprintf(&message, "==> Linting %s\n", path)
for _, msg := range filteredResult.Messages {
if len(result.Messages) == 0 { fmt.Fprintf(&message, "%s\n", msg)
for _, err := range result.Errors {
fmt.Fprintf(&message, "Error %s\n", err)
}
}
for _, msg := range result.Messages {
if !client.Quiet || msg.Severity > support.InfoSev {
fmt.Fprintf(&message, "%s\n", msg)
}
} }
if len(filteredResult.Errors) != 0 {
if len(result.Errors) != 0 {
failed++ failed++
for _, err := range filteredResult.Errors {
fmt.Fprintf(&message, "Error: %s\n", err)
}
} }
fmt.Fprint(&message, "\n") fmt.Fprint(&message, "\n")
} }
fmt.Fprint(out, message.String()) fmt.Fprint(out, message.String())
summary := fmt.Sprintf("%d chart(s) linted, %d chart(s) failed", len(paths), failed) summary := fmt.Sprintf("%d chart(s) linted, %d chart(s) failed", len(paths), failed)
if failed > 0 { if failed > 0 {
return errors.New(summary) return errors.New(summary)
} }
if !client.Quiet || errorsOrWarnings > 0 { fmt.Fprintln(out, summary)
fmt.Fprintln(out, summary)
}
return nil return nil
}, },
} }
@ -163,37 +128,35 @@ func newLintCmd(out io.Writer) *cobra.Command {
f.BoolVar(&client.WithSubcharts, "with-subcharts", false, "lint dependent charts") f.BoolVar(&client.WithSubcharts, "with-subcharts", false, "lint dependent charts")
f.BoolVar(&client.Quiet, "quiet", false, "print only warnings and errors") f.BoolVar(&client.Quiet, "quiet", false, "print only warnings and errors")
f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for capabilities and deprecation checks") f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for capabilities and deprecation checks")
f.StringVar(&lintIgnoreFile, "lint-ignore-file", "", "path to .helmlintignore file to specify ignore patterns") // Add the flag for .helmlintignore file f.StringVar(&lintIgnoreFile, "lint-ignore-file", "", "path to .helmlintignore file to specify ignore patterns")
addValueOptionsFlags(f, valueOpts)
return cmd return cmd
} }
// Need to figure out how to pull this function out of here
func FilterIgnoredMessages(result *action.LintResult, patterns map[string][]string) *action.LintResult { func FilterIgnoredMessages(result *action.LintResult, patterns map[string][]string) *action.LintResult {
filteredMessages := make([]support.Message, 0) filteredMessages := make([]support.Message, 0)
for _, msg := range result.Messages { for _, msg := range result.Messages {
ignore := false fmt.Printf("test-- ", msg, " --test")
for path, pathPatterns := range patterns { ignore := false
cleanedPath := filepath.Clean(path) for path, pathPatterns := range patterns {
if strings.Contains(msg.Path, cleanedPath) { // Check if the message path matches the ignored path fmt.Printf("test-- ", path, " --test")
for _, pattern := range pathPatterns { cleanedPath := filepath.Clean(path)
if strings.Contains(msg.Err.Error(), pattern) { // Assuming we are matching patterns against the error message if strings.Contains(msg.Path, cleanedPath) {
fmt.Printf("Ignoring message: [%s] %s\n", msg.Path, msg.Err.Error()) for _, pattern := range pathPatterns {
ignore = true if strings.Contains(msg.Err.Error(), pattern) {
break fmt.Printf("Ignoring message: [%s] %s\n", msg.Path, msg.Err.Error())
} ignore = true
} break
} }
if ignore { }
break }
} if ignore {
} break
if !ignore { }
filteredMessages = append(filteredMessages, msg) }
} if !ignore {
} filteredMessages = append(filteredMessages, msg)
return &action.LintResult{Messages: filteredMessages} }
}
return &action.LintResult{Messages: filteredMessages}
} }

Loading…
Cancel
Save