Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Jul 30, 2024
1 parent 7352367 commit cde5687
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
55 changes: 29 additions & 26 deletions cmd/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ var LvRegex = regexp.MustCompile(`(\D+)(\d(?:[\d\.]*\d)?)([\+-])?$`)

// Rules settings.
type Rules struct {
Path string `json:"path"`
Repository *api.Repository `json:"repository"`
Identity *api.Ref `json:"identity"`
Labels Labels `json:"labels"`
repositories []string
rules []string
Path string `json:"path"`
Repository *api.Repository `json:"repository"`
Identity *api.Ref `json:"identity"`
Labels Labels `json:"labels"`
rules []string
extract []string
}

// Build assets.
Expand All @@ -59,7 +59,7 @@ func (r *Rules) Build() (err error) {
if err != nil {
return
}
err = r.Labels.extract(r.repositories)
err = r.Labels.extract(r.extract)
if err != nil {
return
}
Expand Down Expand Up @@ -106,9 +106,14 @@ func (r *Rules) addFiles() (err error) {
return
}
}
n := 0
for _, ent := range entries {
p := path.Join(ruleDir, ent.Name())
r.append(p)
n++
}
if n > 0 {
r.extract = append(r.extract, ruleDir)
}
return
}
Expand Down Expand Up @@ -239,9 +244,7 @@ func (r *Rules) addRuleSetRepository(ruleset *api.RuleSet) (err error) {
return
}
ruleDir := path.Join(rootDir, ruleset.Repository.Path)
r.repositories = append(
r.repositories,
ruleDir)
r.extract = append(r.extract, ruleDir)
r.append(ruleDir)
return
}
Expand Down Expand Up @@ -274,9 +277,7 @@ func (r *Rules) addRepository() (err error) {
return
}
ruleDir := path.Join(rootDir, r.Repository.Path)
r.repositories = append(
r.repositories,
ruleDir)
r.extract = append(r.extract, ruleDir)
r.append(ruleDir)
return
}
Expand Down Expand Up @@ -442,18 +443,6 @@ func (r *Labels) extract(paths []string) (err error) {
}
return
}
addUnique := func(extracted ...string) (added []string) {
for _, s := range extracted {
for _, included := range r.Included {
if included == s {
return
}
}
added = append(added, s)
r.Included = append(r.Included, s)
}
return
}
ruleSelector := RuleSelector{Included: r.Included}
selector := ruleSelector.String()
if selector == "" {
Expand All @@ -464,7 +453,7 @@ func (r *Labels) extract(paths []string) (err error) {
if err != nil {
return
}
added := addUnique(extracted...)
added := r.addIncluded(extracted...)
addon.Log.Info(
"Extracted labels added.",
"ruleDir",
Expand All @@ -475,6 +464,20 @@ func (r *Labels) extract(paths []string) (err error) {
return
}

// addIncluded uniquely adds labels to the included set.
func (r *Labels) addIncluded(extracted ...string) (added []string) {
for _, s := range extracted {
for _, included := range r.Included {
if included == s {
return
}
}
added = append(added, s)
r.Included = append(r.Included, s)
}
return
}

// RuleSetMap is a map of labels mapped to ruleSets with those labels.
type RuleSetMap map[string][]api.RuleSet

Expand Down
1 change: 1 addition & 0 deletions hack/task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data:
excluded: []
included:
- konveyor.io/target=cloud-readiness
- konveyor.io/repository:ruleset=29
path: ""
tags:
excluded: []
Expand Down

0 comments on commit cde5687

Please sign in to comment.