-
Notifications
You must be signed in to change notification settings - Fork 6
/
matcher.go
69 lines (56 loc) · 1.44 KB
/
matcher.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
package affected_apps
import (
"context"
"path"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
)
type AffectedItems struct {
Applications []v1alpha1.Application
ApplicationSets []ApplicationSet
}
func (ai AffectedItems) Union(other AffectedItems) AffectedItems {
// merge apps
appNameSet := make(map[string]struct{})
for _, app := range ai.Applications {
appNameSet[app.Name] = struct{}{}
}
for _, app := range other.Applications {
if _, ok := appNameSet[app.Name]; ok {
continue
}
ai.Applications = append(ai.Applications, app)
}
// merge appsets
appSetNameSet := make(map[string]struct{})
for _, appSet := range ai.ApplicationSets {
appSetNameSet[appSet.Name] = struct{}{}
}
for _, appSet := range other.ApplicationSets {
if _, ok := appSetNameSet[appSet.Name]; ok {
continue
}
ai.ApplicationSets = append(ai.ApplicationSets, appSet)
}
// return the merge
return ai
}
type ApplicationSet struct {
Name string
}
type Matcher interface {
AffectedApps(ctx context.Context, changeList []string, targetBranch string) (AffectedItems, error)
}
// modifiedDirs filters a list of changed files down to a list
// the unique dirs containing the changed files
func modifiedDirs(changeList []string) []string {
dirMap := map[string]bool{}
for _, file := range changeList {
dir := path.Dir(file)
dirMap[dir] = true
}
dirs := []string{}
for k := range dirMap {
dirs = append(dirs, k)
}
return dirs
}