build-buddy 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/build_buddy.rb +1 -1
- data/lib/build_buddy/build_data.rb +5 -3
- data/lib/build_buddy/builder.rb +30 -10
- data/lib/build_buddy/config.rb +1 -0
- data/lib/build_buddy/recorder.rb +9 -2
- data/lib/build_buddy/scheduler.rb +3 -23
- data/lib/build_buddy/server.rb +4 -4
- data/lib/build_buddy/slacker.rb +196 -96
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81ee8f317ad72e56104078228407ee03776e40e4
|
4
|
+
data.tar.gz: ac43883aa9dd4188844043bb8370d178b5345348
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f4a4d782e9a013622f05680fdf9275f001953a3ad0e45ec8a0dd7f5318c92e73fa1fc779be56d7a4b836303c3a845a82d302756e51d976535a4c50aeae036ad
|
7
|
+
data.tar.gz: 14e79e052d4d1a771ea538532c257f60fe21e02195fdf687a22a9f343131d3b1a0886392e09fc33b4aec92e6e5aaf3c7f76e0a6b0cc31b7ad9700d8b325adc56
|
data/lib/build_buddy.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module BuildBuddy
|
2
2
|
class BuildData
|
3
3
|
attr_accessor :_id # Mongo ID
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :type # one of :master, :release or :pull_request
|
5
5
|
attr_accessor :repo_full_name
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :branch
|
7
7
|
attr_accessor :pull_request
|
8
8
|
attr_accessor :repo_full_name
|
9
9
|
attr_accessor :repo_sha
|
@@ -11,7 +11,9 @@ module BuildBuddy
|
|
11
11
|
attr_accessor :exit_code
|
12
12
|
attr_accessor :start_time
|
13
13
|
attr_accessor :end_time
|
14
|
-
attr_accessor :
|
14
|
+
attr_accessor :log_filename
|
15
|
+
attr_accessor :flags # :no_upload, :test_channel
|
16
|
+
attr_accessor :metrics
|
15
17
|
|
16
18
|
def initialize(args)
|
17
19
|
args.each do |key, value|
|
data/lib/build_buddy/builder.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
3
|
require 'celluloid'
|
4
|
+
require 'psych'
|
4
5
|
require_relative './watcher.rb'
|
5
6
|
require_relative './config.rb'
|
6
7
|
|
@@ -9,52 +10,59 @@ module BuildBuddy
|
|
9
10
|
include Celluloid
|
10
11
|
include Celluloid::Internals::Logger
|
11
12
|
|
12
|
-
# TODO: Respond to request to kill the build.
|
13
|
-
# TODO: Kill the build pid after a certain amount of time has elapsed and report.
|
14
|
-
|
15
13
|
def initialize
|
16
14
|
@pid = nil
|
17
15
|
@gid = nil
|
18
16
|
@watcher = nil
|
17
|
+
@metrics_tempfile = nil
|
19
18
|
end
|
20
19
|
|
21
20
|
def start_build(build_data)
|
22
21
|
@build_data = build_data
|
22
|
+
@metrics_tempfile = Tempfile.new('build-metrics')
|
23
|
+
@metrics_tempfile.close()
|
24
|
+
|
23
25
|
repo_parts = build_data.repo_full_name.split('/')
|
24
26
|
command = "bash "
|
25
27
|
env = {
|
26
28
|
"GIT_REPO_OWNER" => repo_parts[0],
|
27
29
|
"GIT_REPO_NAME" => repo_parts[1],
|
30
|
+
"METRICS_DATA_FILE" => @metrics_tempfile.path,
|
28
31
|
"RBENV_DIR" => nil,
|
29
32
|
"RBENV_VERSION" => nil,
|
30
33
|
"RBENV_HOOK_PATH" => nil,
|
31
34
|
"RBENV_ROOT" => nil,
|
32
35
|
"PATH" => ENV['PATH'].split(':').select { |v| !v.match(/\.rbenv\/versions|Cellar\/rbenv/) }.join(':')
|
33
36
|
}
|
37
|
+
unless build_data.flags.nil?
|
38
|
+
build_data.flags.each do |flag|
|
39
|
+
env["BUILD_FLAG_#{flag.to_s.upcase}"] = '1'
|
40
|
+
end
|
41
|
+
end
|
34
42
|
|
35
|
-
case build_data.
|
43
|
+
case build_data.type
|
36
44
|
when :pull_request
|
37
45
|
env["GIT_PULL_REQUEST"] = build_data.pull_request.to_s
|
38
46
|
command += Config.pull_request_build_script
|
39
47
|
when :master
|
40
48
|
command += Config.master_build_script
|
41
49
|
when :release
|
42
|
-
env["GIT_BRANCH"] = build_data.
|
50
|
+
env["GIT_BRANCH"] = build_data.branch
|
43
51
|
command += Config.release_build_script
|
44
52
|
else
|
45
53
|
raise "Unknown build type"
|
46
54
|
end
|
47
55
|
|
48
56
|
@build_data.start_time = Time.now.utc
|
49
|
-
|
50
|
-
"build_#{build_data.
|
51
|
-
@build_data.
|
57
|
+
log_filename = File.join(Config.build_log_dir,
|
58
|
+
"build_#{build_data.type.to_s}_#{build_data.start_time.strftime('%Y%m%d_%H%M%S')}.log")
|
59
|
+
@build_data.log_filename = log_filename
|
52
60
|
|
53
61
|
Bundler.with_clean_env do
|
54
|
-
@pid = Process.spawn(env, command, :pgroup => true, [:out, :err] =>
|
62
|
+
@pid = Process.spawn(env, command, :pgroup => true, [:out, :err] => log_filename)
|
55
63
|
@gid = Process.getpgid(@pid)
|
56
64
|
end
|
57
|
-
info "Running #{File.basename(command)} (pid #{@pid}, gid #{@gid}) : Log #{
|
65
|
+
info "Running #{File.basename(command)} (pid #{@pid}, gid #{@gid}) : Log #{log_filename}"
|
58
66
|
|
59
67
|
if @watcher
|
60
68
|
@watcher.terminate
|
@@ -68,6 +76,18 @@ module BuildBuddy
|
|
68
76
|
@build_data.end_time = Time.now.utc
|
69
77
|
@build_data.termination_type = (status.signaled? ? :killed : :exited)
|
70
78
|
@build_data.exit_code = (status.exited? ? status.exitstatus : -1)
|
79
|
+
|
80
|
+
# Collect any data written to the build metrics YAML file
|
81
|
+
begin
|
82
|
+
metrics = Psych.load_file(@metrics_tempfile.path)
|
83
|
+
rescue Psych::SyntaxError => ex
|
84
|
+
error "There was a problem collecting bulid metrics: #{ex.message}"
|
85
|
+
end
|
86
|
+
if !metrics
|
87
|
+
metrics = {}
|
88
|
+
end
|
89
|
+
@build_data.metrics = metrics
|
90
|
+
|
71
91
|
info "Process #{status.pid} #{@build_data.termination_type == :killed ? 'was terminated' : "exited (#{@build_data.exit_code})"}"
|
72
92
|
Celluloid::Actor[:scheduler].async.on_build_completed(@build_data)
|
73
93
|
@watcher.terminate
|
data/lib/build_buddy/config.rb
CHANGED
data/lib/build_buddy/recorder.rb
CHANGED
@@ -10,8 +10,10 @@ module BuildBuddy
|
|
10
10
|
include Celluloid::Internals::Logger
|
11
11
|
|
12
12
|
def initialize()
|
13
|
+
Mongo::Logger.logger.level = ::Logger::FATAL
|
13
14
|
@mongo ||= Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'build-buddy')
|
14
15
|
info "Connected to MongoDB"
|
16
|
+
@mongo[:builds].indexes.create_one({:start_time => -1}, :name => "reverse_build_order")
|
15
17
|
end
|
16
18
|
|
17
19
|
def record_build_data(build_data)
|
@@ -28,12 +30,17 @@ module BuildBuddy
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def get_build_data(id)
|
31
|
-
|
32
|
-
document = builds.find({ :_id => BSON::ObjectId.from_string(id) }, { :limit => 1 }).first
|
33
|
+
document = @mongo[:builds].find({ :_id => BSON::ObjectId.from_string(id) }, { :limit => 1 }).first
|
33
34
|
if document.nil?
|
34
35
|
return nil
|
35
36
|
end
|
36
37
|
BuildData.new(document)
|
37
38
|
end
|
39
|
+
|
40
|
+
def get_build_data_history(limit)
|
41
|
+
@mongo[:builds].find().sort(:start_time => -1).limit(limit).map do |document|
|
42
|
+
BuildData.new(document)
|
43
|
+
end
|
44
|
+
end
|
38
45
|
end
|
39
46
|
end
|
@@ -20,7 +20,7 @@ module BuildBuddy
|
|
20
20
|
def queue_a_build(build_data)
|
21
21
|
@build_queue.push(build_data)
|
22
22
|
|
23
|
-
case build_data.
|
23
|
+
case build_data.type
|
24
24
|
when :pull_request
|
25
25
|
Celluloid::Actor[:gitter].async.set_status(
|
26
26
|
build_data.repo_full_name, build_data.repo_sha, :pending, "This build is in the queue")
|
@@ -57,34 +57,14 @@ module BuildBuddy
|
|
57
57
|
build_data = @build_queue.pop()
|
58
58
|
@active_build = build_data
|
59
59
|
Celluloid::Actor[:recorder].async.record_build_data(build_data)
|
60
|
-
if build_data.
|
60
|
+
if build_data.type == :pull_request
|
61
61
|
Celluloid::Actor[:gitter].async.set_status(
|
62
62
|
build_data.repo_full_name, build_data.repo_sha, :pending, "This build has started")
|
63
63
|
end
|
64
64
|
Celluloid::Actor[:builder].async.start_build(build_data)
|
65
65
|
elsif @done_queue.length > 0
|
66
66
|
build_data = @done_queue.pop
|
67
|
-
|
68
|
-
status_message += '. '
|
69
|
-
|
70
|
-
if build_data.build_type == :pull_request
|
71
|
-
message = "The buddy build #{status_message}"
|
72
|
-
Celluloid::Actor[:gitter].async.set_status(
|
73
|
-
build_data.repo_full_name, build_data.repo_sha,
|
74
|
-
build_data.termination_type == :killed ? :failure : build_data.exit_code != 0 ? :error : :success,
|
75
|
-
message)
|
76
|
-
info "Pull request build #{status_message}"
|
77
|
-
else
|
78
|
-
status_message += "Log file at #{Config.server_base_uri + '/log/' + build_data._id.to_s}."
|
79
|
-
if build_data.build_type == :master
|
80
|
-
message = "A build of the `master` branch #{status_message}"
|
81
|
-
info "`master` branch build #{status_message}"
|
82
|
-
else
|
83
|
-
message = "A build of the `#{build_data.build_version}` branch #{status_message}"
|
84
|
-
info "Release branch build #{status_message}"
|
85
|
-
end
|
86
|
-
Celluloid::Actor[:slacker].async.notify_channel(message)
|
87
|
-
end
|
67
|
+
Celluloid::Actor[:slacker].async.notify_channel(build_data)
|
88
68
|
Celluloid::Actor[:recorder].async.update_build_data(build_data)
|
89
69
|
else
|
90
70
|
@build_timer.cancel
|
data/lib/build_buddy/server.rb
CHANGED
@@ -29,8 +29,9 @@ module BuildBuddy
|
|
29
29
|
payload = JSON.parse(payload_text)
|
30
30
|
pull_request = payload['pull_request']
|
31
31
|
build_data = BuildData.new(
|
32
|
-
:
|
32
|
+
:type => :pull_request,
|
33
33
|
:pull_request => pull_request['number'],
|
34
|
+
:flags => [],
|
34
35
|
:repo_sha => pull_request['head']['sha'],
|
35
36
|
:repo_full_name => pull_request['base']['repo']['full_name'])
|
36
37
|
info "Got pull request #{build_data.pull_request} from GitHub"
|
@@ -49,13 +50,12 @@ module BuildBuddy
|
|
49
50
|
case request.method
|
50
51
|
when 'GET'
|
51
52
|
build_data = Celluloid::Actor[:recorder].get_build_data($1)
|
52
|
-
|
53
|
-
if build_data.nil? or build_data.build_log_filename.nil? or !File.exist?(build_data.build_log_filename)
|
53
|
+
if build_data.nil? or build_data.log_filename.nil? or !File.exist?(build_data.log_filename)
|
54
54
|
sleep 1
|
55
55
|
request.respond 404, "Not found"
|
56
56
|
end
|
57
57
|
log_contents = 'Log file has been deleted.'
|
58
|
-
File.open(build_data.
|
58
|
+
File.open(build_data.log_filename) do |io|
|
59
59
|
log_contents = io.read
|
60
60
|
end
|
61
61
|
html = %Q(
|
data/lib/build_buddy/slacker.rb
CHANGED
@@ -25,7 +25,141 @@ module BuildBuddy
|
|
25
25
|
raise "Slack connection was closed"
|
26
26
|
end
|
27
27
|
@rt_client.start_async
|
28
|
-
@
|
28
|
+
@build_slack_channel = nil
|
29
|
+
@test_slack_channel = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_build_flags message
|
33
|
+
flags = []
|
34
|
+
message.split(',').each do |s|
|
35
|
+
flags.push(s.lstrip.rstrip.gsub(' ', '_').to_sym)
|
36
|
+
end
|
37
|
+
flags
|
38
|
+
end
|
39
|
+
|
40
|
+
def do_build(message, from_slack_channel, slack_user_name)
|
41
|
+
response = ''
|
42
|
+
sender_is_a_builder = (Config.slack_builders.nil? ? true : Config.slack_builders.include?('@' + slack_user_name))
|
43
|
+
unless sender_is_a_builder
|
44
|
+
if from_slack_channel
|
45
|
+
response = "I'm sorry @#{slack_user_name} you are not on my list of allowed builders."
|
46
|
+
else
|
47
|
+
response = "I'm sorry but you are not on my list of allowed builders."
|
48
|
+
end
|
49
|
+
else
|
50
|
+
scheduler = Celluloid::Actor[:scheduler]
|
51
|
+
|
52
|
+
case message
|
53
|
+
when /^master(?: with )?(?<flags>.*)?/i
|
54
|
+
flags = Slacker.get_build_flags($~[:flags])
|
55
|
+
response = "OK, I've queued a build of the `master` branch."
|
56
|
+
scheduler.queue_a_build(BuildData.new(
|
57
|
+
:type => :master,
|
58
|
+
:flags => flags,
|
59
|
+
:repo_full_name => Config.github_webhook_repo_full_name))
|
60
|
+
when /^(?<version>v\d+\.\d+)(?: with )?(?<flags>.*)?/
|
61
|
+
flags = Slacker.get_build_flags($~[:flags])
|
62
|
+
version = $~[:version]
|
63
|
+
if Config.valid_release_versions.include?(version)
|
64
|
+
response = "OK, I've queued a build of the `#{version}` branch."
|
65
|
+
scheduler.queue_a_build(BuildData.new(
|
66
|
+
:type => :release,
|
67
|
+
:branch => version,
|
68
|
+
:flags => flags,
|
69
|
+
:repo_full_name => Config.github_webhook_repo_full_name))
|
70
|
+
else
|
71
|
+
response = "I'm sorry, I am not allowed to build the `#{version}` release branch"
|
72
|
+
end
|
73
|
+
when /stop/i
|
74
|
+
if scheduler.stop_build
|
75
|
+
response = "OK, I stopped the currently running build."
|
76
|
+
else
|
77
|
+
response = "There is no build running to stop."
|
78
|
+
end
|
79
|
+
else
|
80
|
+
response = "Sorry#{from_slack_channel ? " <@#{data['user']}>" : ""}, I'm not sure if you want do a `master` or release branch build, or maybe `stop` any running build?"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
response
|
84
|
+
end
|
85
|
+
|
86
|
+
def do_status
|
87
|
+
scheduler = Celluloid::Actor[:scheduler]
|
88
|
+
build_data = scheduler.active_build
|
89
|
+
queue_length = scheduler.queue_length
|
90
|
+
response = ''
|
91
|
+
if build_data.nil?
|
92
|
+
response = "There is currently no build running"
|
93
|
+
if queue_length == 0
|
94
|
+
response += " and no builds in the queue."
|
95
|
+
else
|
96
|
+
response += " and #{queue_length} in the queue."
|
97
|
+
end
|
98
|
+
else
|
99
|
+
case build_data.type
|
100
|
+
when :pull_request
|
101
|
+
response = "There is a pull request build in progress for https://github.com/#{build_data.repo_full_name}/pull/#{build_data.pull_request}."
|
102
|
+
when :master
|
103
|
+
response = "There is a build of the `master` branch of https://github.com/#{build_data.repo_full_name} in progress."
|
104
|
+
when :release
|
105
|
+
response = "There is a build of the `#{build_data.branch}` branch of https://github.com/#{build_data.repo_full_name} in progress."
|
106
|
+
end
|
107
|
+
if queue_length == 1
|
108
|
+
response += " There is one build in the queue."
|
109
|
+
elsif queue_length > 1
|
110
|
+
response += " There are #{queue_length} builds in the queue."
|
111
|
+
end
|
112
|
+
end
|
113
|
+
response
|
114
|
+
end
|
115
|
+
|
116
|
+
def do_help
|
117
|
+
# TODO: The repository should be a link to GitHub
|
118
|
+
%Q(Hello#{from_slack_channel ? " <@#{data['user']}>" : ""}, I'm the *@#{@rt_client.self['name']}* build bot version #{BuildBuddy::VERSION}! I look after 3 types of build: pull request, master and release.
|
119
|
+
|
120
|
+
A pull request build happens when you make a pull request to the *#{Config.github_webhook_repo_full_name}* GitHub repository.
|
121
|
+
|
122
|
+
I can run builds of the master branch if you say `build master`. I can do builds of release branches, e.g. `build v2.3` but only for those branches that I am allowed to build.
|
123
|
+
|
124
|
+
I can stop any running build if you ask me to `stop build`, even pull request builds. I am configured to let the *#{Config.slack_build_channel}* channel know if master or release builds are stopped.
|
125
|
+
|
126
|
+
You can also ask me for `status` and I'll tell you what's being built and what's in the queue and `history` to get a list of recent builds.
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def do_history(message)
|
131
|
+
case message
|
132
|
+
when /([0-9]+)/
|
133
|
+
limit = $1
|
134
|
+
else
|
135
|
+
limit = 5
|
136
|
+
end
|
137
|
+
|
138
|
+
recorder = Celluloid::Actor[:recorder]
|
139
|
+
build_datas = recorder.get_build_data_history(limit)
|
140
|
+
|
141
|
+
if build_datas.count == 0
|
142
|
+
response = "No builds have performed yet"
|
143
|
+
else
|
144
|
+
response = "Here are the last #{build_datas.count} builds:\n"
|
145
|
+
build_datas.each do |build_data|
|
146
|
+
response += "A "
|
147
|
+
response += case build_data.type
|
148
|
+
when :master
|
149
|
+
"`master` branch build"
|
150
|
+
when :release
|
151
|
+
"`#{build_data.branch}` release branch build"
|
152
|
+
when :pull_request
|
153
|
+
"pull request `#{build_data.pull_request}` build"
|
154
|
+
end
|
155
|
+
response += " at #{build_data.start_time.to_s}. #{Config.server_base_uri + '/log/' + build_data._id.to_s}\n"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
response
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.get_channel_id(channel, map_channel_name_to_id, map_group_name_to_id)
|
162
|
+
(channel.start_with?('#') ? map_channel_name_to_id[channel[1..-1]] : map_group_name_to_id[channel])
|
29
163
|
end
|
30
164
|
|
31
165
|
def on_slack_hello
|
@@ -35,14 +169,21 @@ module BuildBuddy
|
|
35
169
|
|
36
170
|
map_channel_name_to_id = @rt_client.channels.map {|id, channel| [channel.name, id]}.to_h
|
37
171
|
map_group_name_to_id = @rt_client.groups.map {|id, group| [group.name, id]}.to_h
|
38
|
-
channel = Config.slack_build_channel
|
39
|
-
is_channel = (channel[0] == '#')
|
40
172
|
|
41
|
-
@
|
42
|
-
|
43
|
-
|
173
|
+
@build_slack_channel = Slacker.get_channel_id(Config.slack_build_channel, map_channel_name_to_id, map_group_name_to_id)
|
174
|
+
|
175
|
+
if @build_slack_channel.nil?
|
176
|
+
error "Unable to identify the build slack channel #{channel}"
|
177
|
+
else
|
178
|
+
info "Slack build notification channel is #{@build_slack_channel} (#{Config.slack_build_channel})"
|
179
|
+
end
|
180
|
+
|
181
|
+
@test_slack_channel = Slacker.get_channel_id(Config.slack_test_channel, map_channel_name_to_id, map_group_name_to_id)
|
182
|
+
|
183
|
+
if @test_slack_channel.nil?
|
184
|
+
error "Unable to identify the test slack channel #{channel}"
|
44
185
|
else
|
45
|
-
info "Slack notification channel is #{@
|
186
|
+
info "Slack test notification channel is #{@test_slack_channel} (#{Config.slack_test_channel})"
|
46
187
|
end
|
47
188
|
end
|
48
189
|
|
@@ -54,124 +195,83 @@ module BuildBuddy
|
|
54
195
|
return
|
55
196
|
end
|
56
197
|
|
57
|
-
|
198
|
+
slack_user_id = data['user']
|
58
199
|
|
59
200
|
# Only respond to messages from users and bots
|
60
|
-
if
|
201
|
+
if slack_user_id.nil?
|
61
202
|
if data['username'].nil? or data['subtype'] != 'bot_message'
|
62
203
|
return
|
63
204
|
end
|
64
|
-
|
205
|
+
slack_user_name = data['username']
|
65
206
|
else
|
66
207
|
map_user_id_to_name = @rt_client.users.map {|id, user| [id, user.name]}.to_h
|
67
|
-
|
208
|
+
slack_user_name = map_user_id_to_name[slack_user_id]
|
68
209
|
|
69
|
-
if
|
70
|
-
error "User #{
|
210
|
+
if slack_user_name.nil?
|
211
|
+
error "User #{slack_user_id} is not known"
|
71
212
|
return
|
72
213
|
end
|
73
214
|
end
|
74
215
|
|
75
216
|
# Don't respond if _we_ sent the message!
|
76
|
-
if
|
217
|
+
if slack_user_id == @rt_client.self['id']
|
77
218
|
return
|
78
219
|
end
|
79
220
|
|
80
|
-
sender_is_a_builder = (Config.slack_builders.nil? ? true : Config.slack_builders.include?('@' + sending_user_name))
|
81
|
-
|
82
221
|
c = data['channel'][0]
|
83
|
-
|
222
|
+
from_slack_channel = (c == 'C' || c == 'G')
|
84
223
|
|
85
224
|
# Don't respond if the message is to a channel and our name is not in the message
|
86
|
-
if
|
225
|
+
if from_slack_channel and !message.match(@rt_client.self['id'])
|
87
226
|
return
|
88
227
|
end
|
89
228
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
when /build/i
|
94
|
-
unless sender_is_a_builder
|
95
|
-
if in_channel
|
96
|
-
response = "I'm sorry @#{sending_user_name} you are not on my list of allowed builders."
|
97
|
-
else
|
98
|
-
response = "I'm sorry but you are not on my list of allowed builders."
|
99
|
-
end
|
100
|
-
else
|
101
|
-
case message
|
102
|
-
when /master/i
|
103
|
-
response = "OK, I've queued a build of the `master` branch."
|
104
|
-
scheduler.queue_a_build(BuildData.new(
|
105
|
-
:build_type => :master,
|
106
|
-
:repo_full_name => Config.github_webhook_repo_full_name))
|
107
|
-
when /(?<version>v\d+\.\d+)/
|
108
|
-
version = $~[:version]
|
109
|
-
if Config.valid_release_versions.include?(version)
|
110
|
-
response = "OK, I've queued a build of `#{version}` branch."
|
111
|
-
scheduler.queue_a_build(BuildData.new(
|
112
|
-
:build_type => :release,
|
113
|
-
:build_version => version,
|
114
|
-
:repo_full_name => Config.github_webhook_repo_full_name))
|
115
|
-
else
|
116
|
-
response = "I'm sorry, I cannot build the #{version} release branch"
|
117
|
-
end
|
118
|
-
when /stop/i
|
119
|
-
if scheduler.stop_build
|
120
|
-
response = "OK, I stopped the currently running build."
|
121
|
-
else
|
122
|
-
response = "There is no build running to stop."
|
123
|
-
end
|
124
|
-
else
|
125
|
-
response = "Sorry#{in_channel ? " <@#{data['user']}>" : ""}, I'm not sure if you want do a `master` or release branch build, or maybe `stop` any running build?"
|
126
|
-
end
|
127
|
-
end
|
229
|
+
response = case message
|
230
|
+
when /build (.*)/i
|
231
|
+
do_build $1, from_slack_channel, slack_user_name
|
128
232
|
when /status/i
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
response = "There is currently no build running"
|
133
|
-
if queue_length == 0
|
134
|
-
response += " and no builds in the queue."
|
135
|
-
else
|
136
|
-
response += " and #{queue_length} in the queue."
|
137
|
-
end
|
138
|
-
else
|
139
|
-
case build_data.build_type
|
140
|
-
when :pull_request
|
141
|
-
response = "There is a pull request build in progress for https://github.com/#{build_data.repo_full_name}/pull/#{build_data.pull_request}."
|
142
|
-
when :master
|
143
|
-
response = "There is a build of the `master` branch of https://github.com/#{build_data.repo_full_name} in progress."
|
144
|
-
when :release
|
145
|
-
response = "There is a build of the `#{build_data.build_version}` branch of https://github.com/#{build_data.repo_full_name} in progress."
|
146
|
-
end
|
147
|
-
if queue_length == 1
|
148
|
-
response += " There is one build in the queue."
|
149
|
-
elsif queue_length > 1
|
150
|
-
response += " There are #{queue_length} builds in the queue."
|
151
|
-
end
|
152
|
-
end
|
233
|
+
do_status
|
234
|
+
when /history (.*)/
|
235
|
+
do_history $1
|
153
236
|
when /help/i, /what can/i
|
154
|
-
|
155
|
-
response = %Q(Hello#{in_channel ? " <@#{data['user']}>" : ""}, I'm the *@#{@rt_client.self['name']}* build bot version #{BuildBuddy::VERSION}! I look after 3 types of build: pull request, master and release.
|
156
|
-
|
157
|
-
A pull request build happens when you make a pull request to the *#{Config.github_webhook_repo_full_name}* GitHub repository.
|
158
|
-
|
159
|
-
I can run builds of the master branch if you say `build master`. I can do builds of release branches, e.g. `build v2.3` but only for those branches that I am allowed to build.
|
160
|
-
|
161
|
-
I can stop any running build if you ask me to `stop build`, even pull request builds. I am configured to let the *#{Config.slack_build_channel}* channel know if master or release builds are stopped.
|
162
|
-
|
163
|
-
You can also ask me for `status` and I'll tell you what's being built and what's in the queue.
|
164
|
-
)
|
237
|
+
do_help
|
165
238
|
else
|
166
|
-
|
167
|
-
|
239
|
+
"Sorry#{from_slack_channel ? " <@#{data['user']}>" : ""}, I'm not sure how to respond."
|
240
|
+
end
|
168
241
|
@rt_client.message channel: data['channel'], text: response
|
169
242
|
info "Slack message '#{message}' from #{data['channel']} handled"
|
170
243
|
end
|
171
244
|
|
172
|
-
def notify_channel(
|
173
|
-
|
174
|
-
|
245
|
+
def notify_channel(build_data)
|
246
|
+
status_message = build_data.termination_type == :killed ? "was stopped" : build_data.exit_code != 0 ? "failed" : "succeeded"
|
247
|
+
status_message += '. '
|
248
|
+
|
249
|
+
if build_data.type == :pull_request
|
250
|
+
message = "The buddy build #{status_message}"
|
251
|
+
Celluloid::Actor[:gitter].async.set_status(
|
252
|
+
build_data.repo_full_name, build_data.repo_sha,
|
253
|
+
build_data.termination_type == :killed ? :failure : build_data.exit_code != 0 ? :error : :success,
|
254
|
+
message)
|
255
|
+
info "Pull request build #{status_message}"
|
256
|
+
else
|
257
|
+
status_message += "Log file at #{Config.server_base_uri + '/log/' + build_data._id.to_s}."
|
258
|
+
if build_data.type == :master
|
259
|
+
message = "A build of the `master` branch #{status_message}"
|
260
|
+
info "`master` branch build #{status_message}"
|
261
|
+
else
|
262
|
+
message = "A build of the `#{build_data.branch}` branch #{status_message}"
|
263
|
+
info "Release branch build #{status_message}"
|
264
|
+
end
|
265
|
+
|
266
|
+
if build_data.flags.include?(:test_channel)
|
267
|
+
unless @test_slack_channel.nil?
|
268
|
+
@rt_client.message(channel: @test_slack_channel, text: message)
|
269
|
+
end
|
270
|
+
else
|
271
|
+
unless @build_slack_channel.nil?
|
272
|
+
@rt_client.message(channel: @build_slack_channel, text: message)
|
273
|
+
end
|
274
|
+
end
|
175
275
|
end
|
176
276
|
end
|
177
277
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build-buddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Lyon-smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: timers
|