func()

in internal/cssc/cssc.go [138:181]


func (filter *Filter) ValidateFilter() error {
	fmt.Println("Validating filter...")
	const versionV1 = "v1"
	if filter.Version == "" || filter.Version != versionV1 {
		return errors.New("Version is required in the filter and should be " + versionV1)
	}
	if len(filter.Repositories) == 0 {
		return errors.New("Repositories is required in the filter")
	}
	if filter.TagConvention != "" {
		err := filter.TagConvention.IsValid()
		if err != nil {
			return err
		}
	}

	allErrors := []string{}
	for _, repo := range filter.Repositories {
		if repo.Repository == "" {
			return errors.New("Repository is required in the filter")
		}
		if repo.Tags == nil || len(repo.Tags) == 0 {
			return errors.New("Tags is required in the filter")
		}

		incorrectTags := []string{}
		for _, tag := range repo.Tags {
			if tag == "" {
				return errors.New("Tag is required in the filter")
			}
			if endsWithIncrementalOrFloatingPattern(tag) {
				incorrectTags = append(incorrectTags, tag)
			}
		}
		if len(incorrectTags) > 0 {
			allErrors = append(allErrors, fmt.Sprintf("Repo:%s Invalid Tag(s): %s", repo.Repository, strings.Join(incorrectTags, ", ")))
		}
	}
	if len(allErrors) > 0 {
		allErrors = append(allErrors, "Tags in filter json should not end with -1 to -999 or -patched")
		return errors.New(strings.Join(allErrors, "\n"))
	}
	return nil
}