forked from jwplayer/buildpipe-buildkite-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
71 lines (63 loc) · 1.32 KB
/
project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"path"
"path/filepath"
"reflect"
"strings"
)
func Min(x, y int) int {
if x < y {
return x
}
return y
}
// https://github.com/go-yaml/yaml/issues/100
type StringArray []string
func (a *StringArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
var multi []string
err := unmarshal(&multi)
if err != nil {
var single string
err := unmarshal(&single)
if err != nil {
return err
}
*a = []string{single}
} else {
*a = multi
}
return nil
}
type Project struct {
Label string
Path StringArray
Skip StringArray
}
func (p *Project) getMainPath() string {
return p.Path[0]
}
func (p *Project) checkProjectRules(step map[interface{}]interface{}) bool {
for _, pattern := range p.Skip {
label := step["label"].(string)
if matched, _ := filepath.Match(pattern, label); matched {
return false
}
}
return true
}
func (p *Project) checkAffected(changedFiles []string) bool {
for _, filePath := range p.Path {
if filePath == "." {
return true
}
normalizedPath := path.Clean(filePath)
projectDirs := strings.Split(normalizedPath, "/")
for _, changedFile := range changedFiles {
changedDirs := strings.Split(changedFile, "/")
if reflect.DeepEqual(changedDirs[:Min(len(projectDirs), len(changedDirs))], projectDirs) {
return true
}
}
}
return false
}