Skip to content

Commit

Permalink
update code flow for pruning annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
  • Loading branch information
ashutosh-narkar committed Feb 22, 2024
1 parent 5165a1d commit 4badf68
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions compile/compile.go
Expand Up @@ -743,22 +743,23 @@ func pruneBundleAnnotations(b *bundle.Bundle) error {
for _, annotation := range mf.Parsed.Annotations {
p := annotation.GetTargetPath()

found := false
for _, rule := range mf.Parsed.Rules {
if p.Equal(rule.Ref()) {
annotations = append(annotations, annotation)
found = true
break
}
}

// Prune annotations of non-existing rules, but not packages, as the Rego file is retained
if p.Equal(mf.Parsed.Package.Path) {
annotations = append(annotations, annotation)
} else if !found {
prunedAnnotations = append(prunedAnnotations, annotation)
}
} else {
found := false
for _, rule := range mf.Parsed.Rules {
if p.Equal(rule.Ref()) {
annotations = append(annotations, annotation)
found = true
break
}
}

if !found {
prunedAnnotations = append(prunedAnnotations, annotation)
}
}
}

// Drop comments associated with pruned annotations
Expand Down

0 comments on commit 4badf68

Please sign in to comment.