-
Notifications
You must be signed in to change notification settings - Fork 2
/
github_bot_brain.rb
37 lines (34 loc) · 1.18 KB
/
github_bot_brain.rb
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
# frozen_string_literal: true
class GithubBotBrain
attr_accessor :dummy_ci_projects
attr_accessor :backport_projects
attr_accessor :pull_requests_to_tg
attr_accessor :backport_failures_to_tg
attr_accessor :reviewers
def initialize
@dummy_ci_projects = ENV['GITHUB_DUMMY_CI_PROJECTS'].to_s.split(',')
@backport_projects = ENV['GITHUB_BACKPORT_PROJECTS'].to_s.split(',')
@pull_requests_to_tg = {}
@backport_failures_to_tg = {}
@reviewers = {}
ENV.each_pair do |k, v|
case k
when /\AGITHUB_PULL_REQUESTS_TO_TG_(_?\d+)\z/
chat_id = Regexp.last_match(1).gsub(/_/, '-').to_i
v.split(',').each do |project|
@pull_requests_to_tg[project] ||= []
@pull_requests_to_tg[project] << chat_id
end
when /\AGITHUB_BACKPORT_FAILURES_TO_TG_(_?\d+)\z/
chat_id = Regexp.last_match(1).gsub(/_/, '-').to_i
v.split(',').each do |project|
@backport_failures_to_tg[project] ||= []
@backport_failures_to_tg[project] << chat_id
end
when /\AGITHUB_REVIEWERS/
project, users = v.split(',', 2)
@reviewers[project] = users.split(',').shuffle
end
end
end
end