Skip to content

Commit a1ffde2

Browse files
Leon Sodhilkysow
Leon Sodhi
authored andcommitted
Make behaviour consistent
1 parent 9d0fa15 commit a1ffde2

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

server/events/project_finder.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ func (p *DefaultProjectFinder) DetermineProjectsViaConfig(log *logging.SimpleLog
8282
var projects []valid.Project
8383
for _, project := range config.Projects {
8484
log.Debug("checking if project at dir %q workspace %q was modified", project.Dir, project.Workspace)
85-
// Prepend project dir to when modified patterns because the patterns
86-
// are relative to the project dirs but our list of modified files is
87-
// relative to the repo root.
8885
var whenModifiedRelToRepoRoot []string
8986
for _, wm := range project.Autoplan.WhenModified {
90-
exclusion := false
9187
wm = strings.TrimSpace(wm)
92-
if wm == "" {
93-
continue
94-
}
95-
if wm[0] == '!' {
88+
// An exclusion uses a '!' at the beginning. If it's there, we need
89+
// to remove it, then add in the project path, then add it back.
90+
exclusion := false
91+
if wm != "" && wm[0] == '!' {
9692
wm = wm[1:]
9793
exclusion = true
9894
}
95+
96+
// Prepend project dir to when modified patterns because the patterns
97+
// are relative to the project dirs but our list of modified files is
98+
// relative to the repo root.
9999
wmRelPath := filepath.Join(project.Dir, wm)
100100
if exclusion {
101101
wmRelPath = "!" + wmRelPath

server/events/project_finder_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func TestDefaultProjectFinder_DetermineProjectsViaConfig(t *testing.T) {
397397
expProjPaths: []string{"project2"},
398398
},
399399
{
400-
description: "all files excluded",
400+
description: "file excluded",
401401
config: valid.RepoCfg{
402402
Projects: []valid.Project{
403403
{
@@ -428,6 +428,22 @@ func TestDefaultProjectFinder_DetermineProjectsViaConfig(t *testing.T) {
428428
modified: []string{"project1/exclude-me.tf", "project1/include-me.tf"},
429429
expProjPaths: []string{"project1"},
430430
},
431+
{
432+
description: "multiple dirs excluded",
433+
config: valid.RepoCfg{
434+
Projects: []valid.Project{
435+
{
436+
Dir: "project1",
437+
Autoplan: valid.Autoplan{
438+
Enabled: true,
439+
WhenModified: []string{"**/*.tf", "!subdir1/*", "!subdir2/*"},
440+
},
441+
},
442+
},
443+
},
444+
modified: []string{"project1/subdir1/main.tf", "project1/subdir2/main.tf"},
445+
expProjPaths: nil,
446+
},
431447
}
432448

433449
for _, c := range cases {

0 commit comments

Comments
 (0)