@@ -17,10 +17,21 @@ func (e ContextMergeRequest) HasLabel(in string) bool {
17
17
return false
18
18
}
19
19
20
+ func (e ContextMergeRequest ) ModifiedFilesList (patterns ... string ) []string {
21
+ return e .findModifiedFiles (patterns ... )
22
+ }
23
+
20
24
// Partially lifted from https://github.com/hmarr/codeowners/blob/main/match.go
21
25
func (e ContextMergeRequest ) ModifiedFiles (patterns ... string ) bool {
26
+ return len (e .findModifiedFiles (patterns ... )) > 0
27
+ }
28
+
29
+ // Partially lifted from https://github.com/hmarr/codeowners/blob/main/match.go
30
+ func (e ContextMergeRequest ) findModifiedFiles (patterns ... string ) []string {
22
31
leftAnchoredLiteral := false
23
32
33
+ output := []string {}
34
+
24
35
for _ , pattern := range patterns {
25
36
if ! strings .ContainsAny (pattern , "*?\\ " ) && pattern [0 ] == '/' {
26
37
leftAnchoredLiteral = true
@@ -31,6 +42,7 @@ func (e ContextMergeRequest) ModifiedFiles(patterns ...string) bool {
31
42
panic (err )
32
43
}
33
44
45
+ NEXT_FILE:
34
46
for _ , changedFile := range e .DiffStats {
35
47
// Normalize Windows-style path separators to forward slashes
36
48
testPath := filepath .ToSlash (changedFile .Path )
@@ -45,27 +57,35 @@ func (e ContextMergeRequest) ModifiedFiles(patterns ...string) bool {
45
57
46
58
// If the pattern ends with a slash we can do a simple prefix match
47
59
if prefix [len (prefix )- 1 ] == '/' && strings .HasPrefix (testPath , prefix ) {
48
- return true
60
+ output = append (output , testPath )
61
+
62
+ continue NEXT_FILE
49
63
}
50
64
51
65
// If the strings are the same length, check for an exact match
52
66
if len (testPath ) == len (prefix ) && testPath == prefix {
53
- return true
67
+ output = append (output , testPath )
68
+
69
+ continue NEXT_FILE
54
70
}
55
71
56
72
// Otherwise check if the test path is a subdirectory of the pattern
57
73
if len (testPath ) > len (prefix ) && testPath [len (prefix )] == '/' && testPath [:len (prefix )] == prefix {
58
- return true
74
+ output = append (output , testPath )
75
+
76
+ continue NEXT_FILE
59
77
}
60
78
}
61
79
62
80
if regex .MatchString (testPath ) {
63
- return true
81
+ output = append (output , testPath )
82
+
83
+ continue NEXT_FILE
64
84
}
65
85
}
66
86
}
67
87
68
- return false
88
+ return output
69
89
}
70
90
71
91
// buildPatternRegex compiles a new regexp object from a gitignore-style pattern string
0 commit comments