-
Notifications
You must be signed in to change notification settings - Fork 2
/
matching.go
61 lines (48 loc) · 1.18 KB
/
matching.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
package main
import (
"errors"
"log"
)
func (s *server) getHits(hits []string, key string) []string {
if len(s.mapping[key]) > 0 {
for _, hit := range s.mapping[key] {
hits = append(hits, hit)
}
}
return hits
}
func (s *server) matchMappingKeys(keys []string, filematch bool) ([]string, error) {
var hits []string
for _, key := range keys {
log.Print("searching mappings for key: ", key)
if len(s.mapping[key]) > 0 {
hits = s.getHits(hits, key)
} else if filematch {
for len(key) > 1 {
key = removeLastRune(key)
oldHitCount := len(hits)
hits = s.getHits(hits, key)
if len(hits) > oldHitCount {
break
}
}
}
}
if len(hits) == 0 {
return []string{}, errors.New("no mappings found")
}
log.Print("number of mappings found: ", len(hits))
return hits, nil
}
func (s *server) processMatching(repo, branch string, files []string) error {
keys := evalMappingKeys(repo, branch, files, s.param.proxy.FileMatching, s.param.proxy.SemanticRepo)
jobs, err := s.matchMappingKeys(keys, s.param.proxy.FileMatching)
if err != nil {
return err
}
for _, job := range jobs {
s.createTimer(job)
}
log.Print("end processing mappings")
return nil
}