This repository was archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfilters.go
88 lines (71 loc) · 1.83 KB
/
filters.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
package main
import "strings"
type Filter interface {
// Filter returns true if a PR should be kept and false if it should be discarded
Filter(*PullRequest) bool
}
type Filters struct {
filters []Filter
filtered int
}
// Add adds a filter to the internal list of filters
func (f *Filters) Add(a Filter) {
f.filters = append(f.filters, a)
}
// Filter returns true if a PR should be kept and false if it should be discarded
func (f *Filters) Filter(p *PullRequest) bool {
for _, filter := range f.filters {
if !filter.Filter(p) {
f.filtered++
return false
}
}
return true
}
func (f *Filters) NumFiltered() int {
return f.filtered
}
// UserFilter filters out any PRs that is not authored or assigned to a user
type UserFilter []string
// Filter returns true if a PR should be kept and false if it should be discarded
func (users UserFilter) Filter(p *PullRequest) bool {
if len(users) == 0 {
return true
}
for _, user := range users {
if user == p.Author {
return true
}
if user == p.Assignee {
return true
}
}
return false
}
// WIPFilter checks if the PR has been marked as Work In Progress, typically by prefixing the title with "WIP"
type WIPFilter bool
// Filter returns true if a PR should be kept and false if it should be discarded
func (enabled WIPFilter) Filter(p *PullRequest) bool {
if !enabled {
return true
}
if p.Draft == true {
return false
}
if strings.Index(p.Title, "[WIP]") == 0 {
return false
}
if strings.Index(p.Title, "WIP") == 0 {
return false
}
return true
}
// ReviewFilter filters out any PR that had changes requested and haven't yet been approved
type ReviewFilter bool
// Filter returns true if a PR should be kept and false if it should be discarded
func (enabled ReviewFilter) Filter(p *PullRequest) bool {
if !enabled {
return true
}
return !p.RequiresChanges
}