Skip to content

Commit

Permalink
Add ci dependency path filter and negation to paths and types options
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Jul 6, 2021
1 parent 323bb86 commit 4e7ea23
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cmd/deps/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

var ciManual bool
var ciTypes []string
var ciPaths []string
var ciQuiet bool

var ciCMD = &cobra.Command{
Expand All @@ -20,7 +21,7 @@ var ciCMD = &cobra.Command{
}

auto := !ciManual
if err := runner.CI(auto, ciTypes); err != nil {
if err := runner.CI(auto, ciTypes, ciPaths); err != nil {
printErrAndExitFailure(err)
}
},
Expand All @@ -29,6 +30,7 @@ var ciCMD = &cobra.Command{
func init() {
ciCMD.Flags().BoolVarP(&ciManual, "manual", "m", false, "do not automatically configure repo")
ciCMD.Flags().BoolVarP(&ciQuiet, "quiet", "q", false, "disable verbose output")
ciCMD.Flags().StringArrayVarP(&ciTypes, "type", "t", []string{}, "only run on specified dependency types")
ciCMD.Flags().StringArrayVarP(&ciTypes, "type", "t", []string{}, "only run on specified dependency types (use ! to negate)")
ciCMD.Flags().StringArrayVarP(&ciPaths, "path", "p", []string{}, "only run on specified dependency paths (use ! to negate)")
rootCmd.AddCommand(ciCMD)
}
4 changes: 2 additions & 2 deletions internal/runner/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type updateResult struct {
err error
}

func CI(autoconfigure bool, types []string) error {
func CI(autoconfigure bool, types []string, paths []string) error {

api, err := billing.NewAPI()
if err != nil {
Expand Down Expand Up @@ -79,7 +79,7 @@ func CI(autoconfigure bool, types []string) error {
return err
}

allUpdates, err := collectUpdates(cfg, types)
allUpdates, err := collectUpdates(cfg, types, paths)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Local() error {
return err
}

allUpdates, err := collectUpdates(cfg, []string{})
allUpdates, err := collectUpdates(cfg, []string{}, []string{})
if err != nil {
return err
}
Expand Down
26 changes: 23 additions & 3 deletions internal/runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,40 @@ func organizeUpdates(updates Updates) (Updates, Updates, Updates, error) {
return newUpdates, outdatedUpdates, existingUpdates, nil
}

func collectUpdates(cfg *config.Config, types []string) (Updates, error) {
func collectUpdates(cfg *config.Config, types []string, paths []string) (Updates, error) {
if len(types) > 0 {
output.Event("Only collecting types: %s", strings.Join(types, ", "))
}
typesMap := map[string]bool{}
for _, t := range types {
typesMap[t] = true
if strings.HasPrefix(t, "!") {
typesMap[t[1:]] = false
} else {
typesMap[t] = true
}
}

if len(paths) > 0 {
output.Event("Only collecting paths: %s", strings.Join(paths, ", "))
}
pathsMap := map[string]bool{}
for _, p := range paths {
if strings.HasPrefix(p, "!") {
pathsMap[p[1:]] = false
} else {
pathsMap[p] = true
}
}

updates := Updates{}

for index, dependencyConfig := range cfg.Dependencies {

if _, ok := typesMap[dependencyConfig.Type]; len(typesMap) > 0 && !ok {
if enabled, ok := typesMap[dependencyConfig.Type]; len(typesMap) > 0 && (!ok || !enabled) {
continue
}

if enabled, ok := pathsMap[dependencyConfig.Path]; len(pathsMap) > 0 && (!ok || !enabled) {
continue
}

Expand Down

0 comments on commit 4e7ea23

Please sign in to comment.