-
Notifications
You must be signed in to change notification settings - Fork 167
/
seal.rb
executable file
·92 lines (76 loc) · 2.82 KB
/
seal.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
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
#!/usr/bin/env ruby
require 'yaml'
require './lib/github_fetcher.rb'
require './lib/message_builder.rb'
require './lib/slack_lib.rb'
# Entry point for the Seal!
class Seal
attr_reader :mode
def initialize(team, mode=nil)
@team = team
@mode = mode
end
def bark
teams.each { |team| bark_at(team) }
end
private
attr_accessor :mood
def teams
if @team.nil? && org_config
org_config.keys
else
[@team]
end
end
def bark_at(team)
message_builder = MessageBuilder.new(team_params(team), @mode)
message = message_builder.build
channel = ENV["SLACK_CHANNEL"] ? ENV["SLACK_CHANNEL"] : team_config(team)['channel']
slack = SlackLib.new(ENV['SLACK_WEBHOOK'], channel, message_builder.poster_mood)
slack.send_request(message)
end
def org_config
@org_config ||= YAML.load_file(configuration_filename) if File.exist?(configuration_filename)
end
def configuration_filename
@configuration_filename ||= "./config/#{ENV['SEAL_ORGANISATION']}.yml"
end
def team_params(team)
config = team_config(team)
if config
members = config['members']
use_labels = config['use_labels']
exclude_labels = config['exclude_labels']
exclude_titles = config['exclude_titles']
exclude_repos = config['exclude_repos']
include_repos = config['include_repos']
exclude_reviewed = config['exclude_reviewed']
@quotes = config['quotes']
else
members = ENV['GITHUB_MEMBERS'] ? ENV['GITHUB_MEMBERS'].split(',') : []
use_labels = ENV['GITHUB_USE_LABELS'] ? ENV['GITHUB_USE_LABELS'].split(',') : nil
exclude_labels = ENV['GITHUB_EXCLUDE_LABELS'] ? ENV['GITHUB_EXCLUDE_LABELS'].split(',') : nil
exclude_titles = ENV['GITHUB_EXCLUDE_TITLES'] ? ENV['GITHUB_EXCLUDE_TITLES'].split(',') : nil
exclude_repos = ENV['GITHUB_EXCLUDE_REPOS'] ? ENV['GITHUB_EXCLUDE_REPOS'].split(',') : nil
include_repos = ENV['GITHUB_INCLUDE_REPOS'] ? ENV['GITHUB_INCLUDE_REPOS'].split(',') : nil
exclude_reviewed = ENV['GITHUB_EXCLUDE_REVIEWED'] ? true : false
@quotes = ENV['SEAL_QUOTES'] ? ENV['SEAL_QUOTES'].split(',') : nil
end
return fetch_from_github(members, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos, exclude_reviewed) if @mode == nil
@quotes
end
def fetch_from_github(members, use_labels, exclude_labels, exclude_titles, exclude_repos, include_repos, exclude_reviewed)
git = GithubFetcher.new(members,
use_labels,
exclude_labels,
exclude_titles,
exclude_repos,
include_repos,
exclude_reviewed
)
git.list_pull_requests
end
def team_config(team)
org_config[team] if org_config
end
end