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
class EventFilter
attr_accessor :params
class << self
def default_filter
%w{ push issues merge_requests team}
end
def push
'push'
end
def merged
'merged'
end
def comments
'comments'
end
def team
'team'
end
end
def initialize(params)
@params = if params
params.dup
else
[]#EventFilter.default_filter
end
end
def apply_filter(events)
return events unless params.present?
filter = params.dup
actions = []
actions << Event::PUSHED if filter.include? 'push'
actions << Event::MERGED if filter.include? 'merged'
if filter.include? 'team'
actions << Event::JOINED
actions << Event::LEFT
end
actions << Event::COMMENTED if filter.include? 'comments'
events.where(action: actions)
end
def options(key)
filter = params.dup
if filter.include? key
filter.delete key
else
filter << key
end
filter
end
def active?(key)
params.include? key
end
end