build-buddy 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2e0974a582454abd083fe575b4269ea1450e756
4
- data.tar.gz: 498646e9e12f031b09ad62e5ba880c62e902ddbd
3
+ metadata.gz: bc533f6854862178451a21df0a4d84ae2061990b
4
+ data.tar.gz: be19e66a1a5dee3caf7dc857cf8960582331775a
5
5
  SHA512:
6
- metadata.gz: 30825c02f387e0ea0644307d9c19dd686919a6f13cb54afa2714a724ac4f6820024d9fd0827acffd01c5ed929c99176de17e02564fe01ac591ba8c32bdf5765e
7
- data.tar.gz: 0f4a15c1da473892e6fbef0158d7e09aaa83c4523f3578fd9cd02f74b0f30a491d832cae5229ea9514d0fbc1673218ec616052a44c2eb4305893f9946487ec97
6
+ metadata.gz: 462ec0136b74bafc5a3a93f8c1914ad1f6b39a2a7a90b34fdea196ee180e57e3a7c63a3e4b42762881cc791fea3c773da9f72e5e43600afd247abdd3199b5883
7
+ data.tar.gz: 8ba1d443cc60f29858b6dc5fa27b358c7d4b74a119ea46b1939a31afff428bc446d5c7345ff25cba07416974619c843ab84a3a165efe5c5e886f27741904df54
data/lib/build_buddy.rb CHANGED
@@ -9,5 +9,5 @@ require 'build_buddy/recorder'
9
9
  require 'build_buddy/build_data'
10
10
 
11
11
  module BuildBuddy
12
- VERSION = "1.7.1"
12
+ VERSION = "1.8.0"
13
13
  end
@@ -79,7 +79,7 @@ module BuildBuddy
79
79
 
80
80
  # Collect any data written to the build metrics YAML file
81
81
  begin
82
- metrics = Psych.load_file(@metrics_tempfile.path)
82
+ metrics = Psych.load_stream(File.read(@metrics_tempfile.path)).reduce({}, :merge)
83
83
  rescue Psych::SyntaxError => ex
84
84
  error "There was a problem collecting bulid metrics: #{ex.message}"
85
85
  end
@@ -14,9 +14,15 @@ module BuildBuddy
14
14
  info "Connected to Github"
15
15
  end
16
16
 
17
- def set_status(repo_full_name, repo_sha, status, description)
18
- @gh_client.create_status(
19
- repo_full_name, repo_sha, status.to_s, { :description => description.length > 140 ? "#{description[0..136]}..." : description})
17
+ def set_status(repo_full_name, repo_sha, status, description, target_url)
18
+ options = {
19
+ :description => description.length > 140 ? "#{description[0..136]}..." : description,
20
+ :context => 'build-buddy'
21
+ }
22
+ unless target_url.nil?
23
+ options[:target_url] = target_url
24
+ end
25
+ @gh_client.create_status(repo_full_name, repo_sha, status.to_s, options)
20
26
  end
21
27
  end
22
28
  end
@@ -28,15 +28,22 @@ module BuildBuddy
28
28
  else
29
29
  payload = JSON.parse(payload_text)
30
30
  pull_request = payload['pull_request']
31
- build_data = BuildData.new(
32
- :type => :pull_request,
33
- :pull_request => pull_request['number'],
34
- :flags => [],
35
- :repo_sha => pull_request['head']['sha'],
36
- :repo_full_name => pull_request['base']['repo']['full_name'])
37
- info "Got pull request #{build_data.pull_request} from GitHub"
38
- Celluloid::Actor[:scheduler].queue_a_build(build_data)
39
- request.respond 200
31
+ pull_request_action = pull_request['action']
32
+
33
+ case action
34
+ when 'opened', 'reopened', 'synchronize'
35
+ build_data = BuildData.new(
36
+ :type => :pull_request,
37
+ :pull_request => pull_request['number'],
38
+ :flags => [],
39
+ :repo_sha => pull_request['head']['sha'],
40
+ :repo_full_name => pull_request['base']['repo']['full_name'])
41
+ info "Got #{action} pull request #{build_data.pull_request} from GitHub"
42
+ Celluloid::Actor[:scheduler].queue_a_build(build_data)
43
+ request.respond 200, "Building"
44
+ else
45
+ request.respond 200, "Ignoring"
46
+ end
40
47
  end
41
48
  when 'ping'
42
49
  request.respond 200, "Running"
@@ -31,8 +31,10 @@ module BuildBuddy
31
31
 
32
32
  def self.get_build_flags message
33
33
  flags = []
34
- message.split(',').each do |s|
35
- flags.push(s.lstrip.rstrip.gsub(' ', '_').to_sym)
34
+ unless message.nil?
35
+ message.split(',').each do |s|
36
+ flags.push(s.lstrip.rstrip.gsub(' ', '_').to_sym)
37
+ end
36
38
  end
37
39
  flags
38
40
  end
@@ -70,19 +72,25 @@ module BuildBuddy
70
72
  else
71
73
  response = "I'm sorry, I am not allowed to build the `#{version}` release branch"
72
74
  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
75
  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?"
76
+ response = "Sorry#{from_slack_channel ? " <@#{data['user']}>" : ""}, I'm not sure if you want do a `master` or release branch build"
81
77
  end
82
78
  end
83
79
  response
84
80
  end
85
81
 
82
+ def do_stop
83
+ scheduler = Celluloid::Actor[:scheduler]
84
+
85
+ if scheduler.stop_build
86
+ response = "OK, I stopped the currently running build."
87
+ else
88
+ response = "There is no build running to stop."
89
+ end
90
+
91
+ response
92
+ end
93
+
86
94
  def do_status
87
95
  scheduler = Celluloid::Actor[:scheduler]
88
96
  build_data = scheduler.active_build
@@ -123,37 +131,51 @@ I can run builds of the master branch if you say `build master`. I can do builds
123
131
 
124
132
  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
133
 
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.
134
+ You can also ask me for `status` and I'll tell you what's being built.
135
+
136
+ Ask me `what happened` to get a list of recent builds and log files and `what options` to see the list of options for running builds.
127
137
  )
128
138
  end
129
139
 
130
- def do_history(message)
131
- case message.lstrip.rstrip
132
- when /([0-9]+)/
133
- limit = $1.to_i
134
- else
135
- limit = 5
136
- end
140
+ def do_what(question)
141
+ question = question.lstrip.rstrip
137
142
 
138
- recorder = Celluloid::Actor[:recorder]
139
- build_datas = recorder.get_build_data_history(limit)
143
+ case question
144
+ when /happened/
145
+ case question
146
+ when /([0-9]+)/
147
+ limit = $1.to_i
148
+ else
149
+ limit = 5
150
+ end
140
151
 
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"
152
+ recorder = Celluloid::Actor[:recorder]
153
+ build_datas = recorder.get_build_data_history(limit)
154
+
155
+ if build_datas.count == 0
156
+ response = "No builds have performed yet"
157
+ else
158
+ response = "Here are the last #{build_datas.count} builds:\n"
159
+ build_datas.each do |build_data|
160
+ response += "A "
161
+ response += case build_data.type
162
+ when :master
163
+ "`master` branch build"
164
+ when :release
165
+ "`#{build_data.branch}` release branch build"
166
+ when :pull_request
167
+ "pull request `#{build_data.pull_request}` build"
168
+ end
169
+ response += " at #{build_data.start_time.to_s}. #{Config.server_base_uri + '/log/' + build_data._id.to_s}\n"
170
+ end
156
171
  end
172
+ when /options/
173
+ response = %Q(You can add the following options to builds:
174
+ - *test channel* to have notifications go to the test channel
175
+ - *no upload* to not have the build upload
176
+ )
177
+ else
178
+ response = "I'm not sure what to say..."
157
179
  end
158
180
  response
159
181
  end
@@ -231,10 +253,12 @@ You can also ask me for `status` and I'll tell you what's being built and what's
231
253
  do_build $1, from_slack_channel, slack_user_name
232
254
  when /status/i
233
255
  do_status
234
- when /history(.*)/
235
- do_history $1
256
+ when /what(.*)/
257
+ do_what $1
236
258
  when /help/i, /what can/i
237
259
  do_help from_slack_channel
260
+ when /stop/i
261
+ do_stop
238
262
  else
239
263
  "Sorry#{from_slack_channel ? " <@#{data['user']}>" : ""}, I'm not sure how to respond."
240
264
  end
@@ -248,10 +272,9 @@ You can also ask me for `status` and I'll tell you what's being built and what's
248
272
 
249
273
  if build_data.type == :pull_request
250
274
  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)
275
+ git_status = (build_data.termination_type == :killed ? :failure : build_data.exit_code != 0 ? :error : :success)
276
+ git_url = (git_status == :error ? "#{Config.server_base_uri + '/log/' + build_data._id.to_s}" : nil)
277
+ Celluloid::Actor[:gitter].async.set_status(build_data.repo_full_name, build_data.repo_sha, git_status, git_message, git_url)
255
278
  info "Pull request build #{status_message}"
256
279
  else
257
280
  status_message += "Log file at #{Config.server_base_uri + '/log/' + build_data._id.to_s}."
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.7.1
4
+ version: 1.8.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-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: timers