Skip to content

Commit

Permalink
adding ability to set the scope for the analysis command
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <shawn@hurley.page>
  • Loading branch information
shawn-hurley committed Dec 14, 2023
1 parent b9eb18a commit 5a3116e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
8 changes: 7 additions & 1 deletion cmd/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import (
"fmt"
"path"

"github.com/konveyor/tackle2-addon-analyzer/builder"
"github.com/konveyor/tackle2-addon/command"
"path"
)

type RuleError = builder.RuleError
Expand All @@ -23,6 +25,10 @@ func (r *Analyzer) Run() (b *builder.Issues, err error) {
}
b = &builder.Issues{Path: output}
err = cmd.Run()
if err != nil {
fmt.Printf("err: %v", err)
}
fmt.Printf("%q", cmd.Output)
return
}

Expand Down
44 changes: 38 additions & 6 deletions cmd/scope.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package main

import "github.com/konveyor/tackle2-addon/command"
import (
"fmt"

"github.com/konveyor/tackle2-addon/command"
)

const (
packageVar = "package"
)

// Scope settings.
type Scope struct {
Expand All @@ -18,11 +26,35 @@ func (r *Scope) AddOptions(options *command.Options) (err error) {
"--dep-label-selector",
"!konveyor.io/dep-source=open-source")
}
if len(r.Packages.Included) > 0 {
options.Add("--packages", r.Packages.Included...)
}
if len(r.Packages.Excluded) > 0 {
options.Add("--excludePackages", r.Packages.Excluded...)
addon.Activity("adding packages includeted and excluded", "included", r.Packages.Included, "excluded", r.Packages.Excluded)
if len(r.Packages.Excluded) > 0 || len(r.Packages.Included) > 0 {
filterString := ""
packageIncluded := false
if len(r.Packages.Included) > 0 {
filterString = fmt.Sprintf("(!%s", packageVar)
for _, i := range r.Packages.Included {
filterString = fmt.Sprintf("%s || %s=%s", filterString, packageVar, i)

}
filterString = fmt.Sprintf("%s)", filterString)
packageIncluded = true
}
if packageIncluded && len(r.Packages.Excluded) > 0 {
filterString = fmt.Sprintf("%s && (!%s", filterString, packageVar)
for _, i := range r.Packages.Excluded {
filterString = fmt.Sprintf("%s || !%s=%s", filterString, packageVar, i)
}
} else if len(r.Packages.Excluded) > 0 {
filterString = fmt.Sprintf("(!%s", packageVar)
for _, i := range r.Packages.Included {
filterString = fmt.Sprintf("%s || %s=%s", filterString, packageVar, i)

}
filterString = fmt.Sprintf("%s)", filterString)
}
if filterString != "" {
options.Add("--incident-selector", filterString)
}
}
return
}

0 comments on commit 5a3116e

Please sign in to comment.