Skip to content

Commit

Permalink
Merge branch 'main' into skip_clone_no_changes_fork_prs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamengual authored Jan 24, 2025
2 parents d437256 + cbd70c9 commit f8c3658
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
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 @@ -423,11 +423,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

0 comments on commit f8c3658

Please sign in to comment.