Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

feat: exclude paths regex #932

Merged
merged 4 commits into from
May 10, 2023
Merged

feat: exclude paths regex #932

merged 4 commits into from
May 10, 2023

Conversation

Meyazhagan
Copy link
Contributor

related issues - #732

@adifayer
Copy link
Contributor

adifayer commented May 4, 2023

@Meyazhagan Thank you for raising this PR 🤩 We will review it in the upcoming days

var filePaths []string

excludeRe, err := regexp.Compile(excludePattern)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, but missing a more explicit validation in:

func (flags *TestCommandFlags) Validate() error {

the error message can be: "invalid --exclude flag: <THE_ERROR>"

@@ -55,16 +56,22 @@ func CreateFileReader(opts *FileReaderOptions) *FileReader {
return fileReader
}

func (fr *FileReader) FilterFiles(paths []string) ([]string, error) {
func (fr *FileReader) FilterFiles(paths []string, excludePattern string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some unit tests, I suggest starting with reader_test.go :)

var filePaths []string

excludeRe, err := regexp.Compile(excludePattern)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a suggestion :)

Suggested change
excludeRe, err := regexp.Compile(excludePattern)
excludeRegex, err := regexp.Compile(excludePattern)

cmd/test/main.go Outdated
@@ -262,6 +265,7 @@ func (flags *TestCommandFlags) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVarP(&flags.K8sVersion, "schema-version", "s", "", "Set kubernetes version to validate against. Defaults to 1.24.0")
cmd.Flags().StringVarP(&flags.PolicyName, "policy", "p", "", "Policy name to run against")
cmd.Flags().StringVarP(&flags.ExcludePattern, "exclude", "", "", "Exclude paths pattern")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmd.Flags().StringVarP(&flags.ExcludePattern, "exclude", "", "", "Exclude paths pattern")
cmd.Flags().StringVarP(&flags.ExcludePattern, "exclude", "", "", "Exclude paths pattern (regex)")

@royhadad
Copy link
Contributor

royhadad commented May 8, 2023

requested some minor changes, should be pretty straight forward :)

@Meyazhagan Meyazhagan changed the title feat:exclude paths regex feat: exclude paths regex May 9, 2023
@Meyazhagan
Copy link
Contributor Author

@royhadad I have made the changes. Take a look !

Copy link
Contributor

@royhadad royhadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good! 🚀🚀🚀

@royhadad royhadad merged commit ca2b4de into datreeio:main May 10, 2023
@royhadad
Copy link
Contributor

@Meyazhagan
This PR is included in the latest 1.9.0 release 🥳🥳, thank you for contributing! 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants