1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-11-23 21:44:44 +02:00

Fix exclude path constraint behavior (#5042)

Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
This commit is contained in:
Ralf Haferkamp
2025-04-01 20:05:51 +02:00
committed by GitHub
parent 47e6d159d1
commit 8a432a6b83
2 changed files with 25 additions and 5 deletions

View File

@@ -388,14 +388,19 @@ func (c *Path) Includes(v []string) bool {
return false return false
} }
// Excludes returns true if the string matches any of the exclude patterns. // Excludes returns true if all of the strings match any of the exclude patterns.
func (c *Path) Excludes(v []string) bool { func (c *Path) Excludes(v []string) bool {
for _, pattern := range c.Exclude { for _, file := range v {
for _, file := range v { matched := false
for _, pattern := range c.Exclude {
if ok, _ := doublestar.Match(pattern, file); ok { if ok, _ := doublestar.Match(pattern, file); ok {
return true matched = true
break
} }
} }
if !matched {
return false
}
} }
return false return true
} }

View File

@@ -233,8 +233,23 @@ func TestConstraintList(t *testing.T) {
{ {
conf: "{ include: [ '*.md' ], exclude: [ CHANGELOG.md ] }", conf: "{ include: [ '*.md' ], exclude: [ CHANGELOG.md ] }",
with: []string{"README.md", "CHANGELOG.md"}, with: []string{"README.md", "CHANGELOG.md"},
want: true,
},
{
conf: "{ exclude: [ CHANGELOG.md ] }",
with: []string{"README.md", "CHANGELOG.md"},
want: true,
},
{
conf: "{ exclude: [ CHANGELOG.md, docs/**/*.md ] }",
with: []string{"docs/main.md", "CHANGELOG.md"},
want: false, want: false,
}, },
{
conf: "{ exclude: [ CHANGELOG.md, docs/**/*.md ] }",
with: []string{"docs/main.md", "CHANGELOG.md", "README.md"},
want: true,
},
// commit message ignore matches // commit message ignore matches
{ {
conf: "{ include: [ README.md ], ignore_message: '[ALL]' }", conf: "{ include: [ README.md ], ignore_message: '[ALL]' }",