Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Simplify use of the doublestar Match for ignore paths #5272

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/bmatcuk/doublestar/v4"
version "github.com/hashicorp/go-version"
"github.com/pkg/errors"
)

// RepoCfg is the atlantis.yaml config after it's been parsed and validated.
Expand Down Expand Up @@ -113,22 +112,19 @@ func (r RepoCfg) AutoDiscoverEnabled(defaultAutoDiscoverMode AutoDiscoverMode) b
return autoDiscoverMode == AutoDiscoverEnabledMode
}

func (r RepoCfg) IsPathIgnoredForAutoDiscover(path string) (bool, error) {
func (r RepoCfg) IsPathIgnoredForAutoDiscover(path string) bool {
if r.AutoDiscover == nil || r.AutoDiscover.IgnorePaths == nil {
return false, nil
return false
}
for i := 0; i < len(r.AutoDiscover.IgnorePaths); i++ {
matches, err := doublestar.Match(r.AutoDiscover.IgnorePaths[i], path)
if err != nil {
// Per documentation https://pkg.go.dev/github.com/bmatcuk/doublestar, this only
// occurs if the pattern itself is invalid, and we already checked this when parsing raw config
return false, errors.Wrap(err, "unexpectedly found invalid ignore pattern (this is a bug, should have been validated at startup)")
}
if matches {
return true, nil
// Per documentation https://pkg.go.dev/github.com/bmatcuk/doublestar, if you run ValidatePattern()
// against a pattern, which we do, you can run MatchUnvalidated for a slight performance gain,
// and also no need to explicitly check for an error
if doublestar.MatchUnvalidated(r.AutoDiscover.IgnorePaths[i], path) {
return true
}
}
return false, nil
return false
}

// validateWorkspaceAllowed returns an error if repoCfg defines projects in
Expand Down
5 changes: 2 additions & 3 deletions server/core/config/valid/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ func TestConfig_IsPathIgnoredForAutoDiscover(t *testing.T) {
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {

enabled, err := c.repoCfg.IsPathIgnoredForAutoDiscover(c.path)
Ok(t, err)
Equals(t, c.expIgnored, enabled)
ignored := c.repoCfg.IsPathIgnoredForAutoDiscover(c.path)
Equals(t, c.expIgnored, ignored)
})
}
}
6 changes: 1 addition & 5 deletions server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,7 @@ func (p *DefaultProjectCommandBuilder) getMergedProjectCfgs(ctx *command.Context
}
for _, mp := range allModifiedProjects {
path := filepath.Clean(mp.Path)
ignore, err := repoCfg.IsPathIgnoredForAutoDiscover(path)
if err != nil {
return nil, err
}
if ignore {
if repoCfg.IsPathIgnoredForAutoDiscover(path) {
continue
}
_, dirExists := configuredProjDirs[path]
Expand Down
Loading