This repository has been archived by the owner on Sep 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
107 lines (91 loc) · 2.05 KB
/
types.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import "regexp"
type Payload struct {
Commits []Commit `json:"commits"`
Sender struct {
AvatarUrl string `json:"avatar_url"`
} `json:"sender"`
}
type Commit struct {
Added []string `json:"added"`
Author User `json:"author"`
Committer User `json:"committer"`
ID string `json:"id"`
Message string `json:"message"`
Modified []string `json:"modified"`
Removed []string `json:"removed"`
Timestamp string `json:"timestamp"`
URL string `json:"url"`
}
type User struct {
Email string `json:"email"`
Name string `json:"name"`
Username string `json:"username"`
}
type Promotion struct {
Source string `json:"source"`
Username string `json:"user"`
AvatarUrl string `json:"avatar_url"`
Tag string `json:"tag"`
Points float64 `json:"points"`
}
type GithubCommit struct {
// Commit struct {
// Author struct {
// Name string
// Email string
// } `json:"author`
// Url string `json:"url"`
// } `json:"commit"`
Url string `json:"url"`
}
type GithubSingleCommit struct {
Commit struct {
Author struct {
Name string `json:"name"`
Email string `json:"email"`
}
} `json:"commit"`
Files []struct {
FileName string `json:"filename"`
Status string `json:"status"`
} `json:"files"`
}
type Rule struct {
Paths []string `yaml:"paths"`
Tag string `yaml:"tag"`
Points float64 `yaml:"points"`
initialized bool
regexps []*regexp.Regexp
}
func (this *Rule) Init() {
this.initialized = true
this.regexps = make([]*regexp.Regexp, len(this.Paths))
for i, path := range this.Paths {
this.regexps[i] = regexp.MustCompile(path)
}
}
func (this *Rule) Apply(c *Commit) bool {
if !this.initialized {
this.Init()
}
for _, fname := range c.Added {
if this.applyForFilename(fname) {
return true
}
}
for _, fname := range c.Modified {
if this.applyForFilename(fname) {
return true
}
}
return false
}
func (this *Rule) applyForFilename(name string) bool {
for _, r := range this.regexps {
if r.MatchString(name) {
return true
}
}
return false
}