build-buddy 1.14.12 → 1.15.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: f4a53a52262ce0a6feb427789507488b1f6136db
4
- data.tar.gz: 7190fe0cbb248504e373477ced6e01956e49dc52
3
+ metadata.gz: b047d2b1bc2a825a18ba63df01115b0f7564a965
4
+ data.tar.gz: 02cfc587d188363d5e48aba4d7234e423498a129
5
5
  SHA512:
6
- metadata.gz: ce7839045e68f0e251a8e1d6ccb5964aa48ae128cea5767ddde92d462124788e492e6bb951622e5f939d08648ffd32c2800b3194e5de3aef735d9f75c2485f19
7
- data.tar.gz: b4791ee73bd087fd9bc371cdd7fd7f40df095415b8e371d1ee5f5173c9f2dec0fc0057fd9e5746a6883fe15cdb6e47a88494c921e37a4ab62a736898c2f27940
6
+ metadata.gz: 1fd06cea76d507a0e03d9248ae7f5f5d440071d9dcde85362d1736501634f32aa8b9c63049d287624a722af3a2898591e6bc74aba459038ab5caebb5a1d5adc5
7
+ data.tar.gz: d68577afdc4f51a768265c85b671a1374aed7c3aed6bd7b70c34d85cce3d00510efc3e255c5dbf5d99c7ff9fd98713d339c717a9ca19cac57ed8b5c1b3e39e52
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.14.12"
12
+ VERSION = "1.15.0"
13
13
  end
@@ -35,6 +35,8 @@ module BuildBuddy
35
35
  attr_accessor :flags
36
36
  attr_accessor :metrics
37
37
 
38
+ GITHUB_URL = "https://github.com"
39
+
38
40
  def initialize(args)
39
41
  args.each do |key, value|
40
42
  begin
@@ -72,14 +74,26 @@ module BuildBuddy
72
74
 
73
75
  def status_verb
74
76
  if @termination_type == :killed
75
- 'was stopped'
77
+ 'stopped'
76
78
  else
77
79
  @exit_code != 0 ? 'failed' : 'succeeded'
78
80
  end
79
81
  end
80
82
 
81
- def pull_request_uri
82
- "https://github.com/#{@repo_full_name}/pull/#{@pull_request}"
83
+ def url_and_branch_name
84
+ if @type == :branch
85
+ branch_name = "#{@repo_full_name}/#{@branch}"
86
+ url = "#{GITHUB_URL}/#{@repo_full_name}/tree/#{@branch}"
87
+ else
88
+ branch_name = "#{@repo_full_name}/pr/#{@pull_request}"
89
+ url = "#{GITHUB_URL}/#{@repo_full_name}/pull/#{@pull_request}"
90
+ end
91
+ [url, branch_name]
92
+ end
93
+
94
+ def run_time
95
+ end_time = @end_time.nil? ? Time.now.utc : @end_time
96
+ Time.at(end_time - @start_time).utc.strftime('%H:%M:%S.%L')
83
97
  end
84
98
  end
85
99
  end
@@ -3,7 +3,6 @@ require 'bundler'
3
3
  require 'celluloid'
4
4
  require 'mongo'
5
5
  require 'bson'
6
- require 'gruff'
7
6
  require 'securerandom'
8
7
  require_relative './config.rb'
9
8
 
@@ -110,24 +110,27 @@ module BuildBuddy
110
110
  response
111
111
  end
112
112
 
113
- def do_show_help(is_from_slack_channel)
114
- %Q(Hello#{is_from_slack_channel ? " <@#{data['user']}>" : ""}, I'm the *@#{@rt_client.self['name']}* build bot version #{BuildBuddy::VERSION}!
113
+ def do_show_help(is_from_slack_channel, slack_user_name)
114
+ text_for_branch_list = Config.allowed_build_branches.count > 0 ? " or " + Config.allowed_build_branches.map { |branch| "`build #{branch}`"}.join(', ') : 0
115
115
 
116
- I understand types of build - pull requests and branch. A pull request build happens when you make a pull request to the https://github.com/#{Config.github_webhook_repo_full_name} GitHub repository.
116
+ %Q(Hello#{is_from_slack_channel ? '' : " <@#{slack_user_name}>"}, I'm the *@#{@rt_client.self['name']}* build bot v#{BuildBuddy::VERSION}!
117
117
 
118
- For branch builds, 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 in by configuration file.
118
+ I understand _pull requests_ and _branch builds_.
119
119
 
120
- I can stop any running build if you ask me to `stop build X`, even pull request builds if you give the id X from the `show status` or `show queue` command.
120
+ A _pull request_ build happens when you make a pull request to the `<#{BuildData::GITHUB_URL}/#{Config.github_webhook_repo_full_name}|#{Config.github_webhook_repo_full_name}>` GitHub repository. *TIP* you can restart a failed pull request by pushing more changes to the branch. Use `git commit --allow-empty` if you simply need to retry the build.
121
121
 
122
- I will let the *#{Config.slack_build_channel}* channel know about branch build activity and the *#{Config.slack_pr_channel} channel know about PR activity.
122
+ To do a _branch build_ you can tell me to `build master`#{text_for_branch_list}.
123
+
124
+ I will let the *#{Config.slack_build_channel}* channel know about _branch build_ activity and the *#{Config.slack_pr_channel}* channel know about _pull request_ activity.
123
125
 
124
126
  I have lots of `show` commands:
125
127
 
126
128
  - `show status` and I'll tell you what my status is
127
- - `show queue` and I will show you what is in the queue
128
- - `show options` to a see a list of build options
129
+ - `show queue` and I will show you what is in the queue to build
129
130
  - `show builds` to see the last 5 builds or `show last N builds` to see a list of the last N builds
130
- - `show report` to get a link to the latest build report
131
+ - `show report` to get a link to the latest build report, if there is one
132
+
133
+ Stop any running build with `stop build bb-xxx`. Use `show queue` to get a valid `bb-xxx` identifier.
131
134
  )
132
135
  end
133
136
 
@@ -155,30 +158,32 @@ I have lots of `show` commands:
155
158
  else
156
159
  response = ''
157
160
  if build_datas.count < limit
158
- response += "There have only been #{build_datas.count} builds:\n"
161
+ response += "There have only been #{build_datas.count} builds"
159
162
  else
160
- response += "Here are the last #{build_datas.count} builds:\n"
163
+ response += "Here are the last #{build_datas.count} builds"
161
164
  end
165
+ attachments = []
162
166
  build_datas.each do |build_data|
163
- response += "A "
164
- response += case build_data.type
165
- when :branch
166
- "`#{build_data.branch}` branch build"
167
- when :pull_request
168
- "pull request build #{build_data.pull_request_uri}"
169
- end
170
- response += " at #{build_data.start_time.to_s}. #{BuildData.server_log_uri(build_data._id)}"
167
+ text = "[`#{build_data.start_time.to_s}`]"
168
+ branch_url, branch_name = build_data.url_and_branch_name
169
+ text += " `<#{branch_url}|#{branch_name}>`"
170
+ text += "\n`<#{BuildData.server_log_uri(build_data._id)}|#{build_data._id.to_s}>`"
171
171
  unless build_data.started_by.nil?
172
- response += " started by #{build_data.started_by}"
172
+ text += " by *@#{build_data.started_by}*"
173
173
  end
174
- response += " #{build_data.status_verb}"
174
+ text += " #{build_data.status_verb}"
175
175
  unless build_data.stopped_by.nil?
176
- response += " by #{build_data.stopped_by}"
176
+ text += " by *@#{build_data.stopped_by}*"
177
177
  end
178
- response += ".\n"
178
+ text += " ran for `#{build_data.run_time}`"
179
+ attachments.push({
180
+ :mrkdwn_in => [ :text ],
181
+ :text => text,
182
+ :color => build_data.termination_type == :killed ? :warning : build_data.exit_code != 0 ? :danger : :good,
183
+ })
179
184
  end
180
185
  end
181
- response
186
+ [response, attachments]
182
187
  end
183
188
 
184
189
  def do_show_status
@@ -187,63 +192,51 @@ I have lots of `show` commands:
187
192
  queue_length = scheduler.queue_length
188
193
  response = ''
189
194
  if build_data.nil?
190
- response = "There is currently no build running"
195
+ response = "There are no builds running"
191
196
  if queue_length == 0
192
197
  response += " and no builds in the queue."
193
198
  else
194
199
  response += " and #{queue_length} in the queue."
195
200
  end
196
201
  else
197
- case build_data.type
198
- when :pull_request
199
- response = "There is a pull request build in progress for https://github.com/#{build_data.repo_full_name}/pull/#{build_data.pull_request} (#{build_data.bb_id})"
200
- when :branch
201
- response = "There is a build of the `#{build_data.branch}` branch of https://github.com/#{build_data.repo_full_name} in progress (#{build_data.bb_id})"
202
- end
202
+ branch_url, branch_name = build_data.url_and_branch_name
203
+ response = "`<#{branch_url}|#{branch_name}>` `<#{build_data.server_log_uri}|#{build_data._id.to_s}>` in progress (`#{build_data.bb_id}`)"
203
204
  unless build_data.started_by.nil?
204
- response += " started by " + build_data.started_by
205
- end
206
- unless build_data.stopped_by.nil?
207
- response += " stopped by #{build_data.stopped_by}"
205
+ response += " by *@#{build_data.started_by}*"
208
206
  end
209
- response += '.'
210
- if queue_length == 1
211
- response += " There is one build in the queue."
207
+ response += " running for `#{build_data.run_time}`."
208
+ if queue_length == 0
209
+ response += " No builds in the queue."
212
210
  elsif queue_length > 1
213
- response += " There are #{queue_length} builds in the queue."
211
+ response += " #{queue_length} build#{queue_length > 1 ? 's' : ''} in the queue."
214
212
  end
215
213
  end
216
214
  response
217
215
  end
218
216
 
219
- def do_show_options
220
- %Q(You can add the following options to builds:
221
- - *test channel* to have notifications go to the test channel
222
- - *no upload* to not have the build upload
223
- )
224
- end
225
-
226
217
  def do_show_queue
227
218
  build_datas = Celluloid::Actor[:scheduler].get_build_queue
228
- if build_datas.count == 0
219
+ queue_length = build_datas.count
220
+ if queue_length == 0
229
221
  response = "There are no builds in the queue."
230
222
  else
231
- response = 'The following builds are in the queue:\n'
223
+ response = "There are #{queue_length} build#{queue_length > 1 ? 's' : ''} in the queue"
224
+ attachments = []
232
225
  build_datas.each { |build_data|
233
- response += "- #{build_data.bb_id}, a "
234
- response += case build_data.type
235
- when :branch
236
- "`#{build_data.branch}` branch build"
237
- when :pull_request
238
- "pull request build #{build_data.pull_request_uri}"
239
- end
226
+ text = "`#{build_data.bb_id}`"
227
+ branch_url, branch_name = build_data.url_and_branch_name
228
+ text += " `<#{branch_url}|#{branch_name}>`"
240
229
  unless build_data.started_by.nil?
241
- response += " started by #{build_data.started_by}"
230
+ text += " by *@#{build_data.started_by}*"
242
231
  end
243
- response += ".\n"
232
+ attachments.push({
233
+ :mrkdwn_in => [ :text ],
234
+ :text => text,
235
+ :color => "#439FE0"
236
+ })
244
237
  }
245
238
  end
246
- response
239
+ [response, attachments]
247
240
  end
248
241
 
249
242
  def do_show_report
@@ -332,7 +325,7 @@ I have lots of `show` commands:
332
325
 
333
326
  message = message.strip
334
327
 
335
- response = case message
328
+ response, attachments = case message
336
329
  when /stop +build +(bb-\d+)/i
337
330
  do_stop $1, is_from_slack_channel, slack_user_name
338
331
  when /build +([a-z0-9\.]+)/i
@@ -349,49 +342,47 @@ I have lots of `show` commands:
349
342
  do_show_report
350
343
  when /show queue/
351
344
  do_show_queue
352
- when /show options/
353
- do_show_options
354
345
  when /help/i
355
- do_show_help is_from_slack_channel
346
+ do_show_help is_from_slack_channel, slack_user_name
356
347
  when /^relay(.*)/i # This must be sent directly to build-buddy
357
348
  do_relay $1, slack_user_name
358
349
  else
359
350
  "Sorry#{is_from_slack_channel ? ' ' + slack_user_name : ''}, I'm not sure how to respond."
360
- end
361
- @rt_client.message channel: data['channel'], text: response
351
+ end
352
+ @rt_client.web_client.chat_postMessage(channel: data['channel'], text: response, attachments: attachments, as_user: true)
353
+ #@rt_client.message channel: data['channel'], text: response
362
354
  info "Slack message '#{message}' from #{data['channel']} handled"
363
355
  end
364
356
 
365
357
  def notify_channel(build_data)
366
358
  status_verb = build_data.status_verb
359
+ attachment_message = ''
367
360
 
361
+ branch_url, branch_name = build_data.url_and_branch_name
368
362
  if build_data.type == :branch
369
- message = "A `#{build_data.branch}` branch build #{status_verb}"
370
- short_message = message
371
363
  info "Branch build #{status_verb}"
372
364
  else
373
- message = "Pull request <https://github.com/#{build_data.repo_full_name}/pull/#{build_data.pull_request}|#{build_data.pull_request_title}> build #{status_verb}"
374
- short_message = "Pull request #{build_data.pull_request} #{status_verb}"
365
+ attachment_message += "<#{branch_url}|*#{build_data.pull_request_title}*>"
375
366
  info "Pull request build #{status_verb}"
376
367
  end
377
368
 
369
+ message = "`<#{branch_url}|#{branch_name}>` build #{status_verb}"
378
370
  if build_data.termination_type == :killed and build_data.stopped_by != nil
379
- message += " by #{build_data.stopped_by}"
371
+ message += " by *@#{build_data.stopped_by}*"
380
372
  end
381
-
382
- message += ". Log file at #{build_data.server_log_uri}"
373
+ attachment_message += "\n`<#{build_data.server_log_uri}|#{build_data._id.to_s}>` ran for `#{build_data.run_time}`"
383
374
 
384
375
  # See https://api.slack.com/docs/attachments for more information about formatting Slack attachments
385
- attachments = [
386
- :title => build_data.type == :pull_request ? "Pull Request" : "Branch Build",
387
- :text => message,
376
+ attachments = [{
377
+ :mrkdwn_in => [ :text ],
378
+ :text => attachment_message,
388
379
  :color => build_data.termination_type == :killed ? :warning : build_data.exit_code != 0 ? :danger : :good,
389
- ]
380
+ }]
390
381
 
391
382
  if build_data.type == :branch
392
- @rt_client.web_client.chat_postMessage(channel: @build_channel_id, text: short_message, attachments: attachments, as_user: true) unless @build_channel_id.nil?
383
+ @rt_client.web_client.chat_postMessage(channel: @build_channel_id, text: message, attachments: attachments, as_user: true) unless @build_channel_id.nil?
393
384
  else
394
- @rt_client.web_client.chat_postMessage(channel: @pr_channel_id, text: short_message, attachments: attachments, as_user: true) unless @pr_channel_id.nil?
385
+ @rt_client.web_client.chat_postMessage(channel: @pr_channel_id, text: message, attachments: attachments, as_user: true) unless @pr_channel_id.nil?
395
386
  end
396
387
  end
397
388
  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.14.12
4
+ version: 1.15.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-10-25 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: timers
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2.2'
153
- - !ruby/object:Gem::Dependency
154
- name: gruff
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.7'
160
- type: :runtime
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.7'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: code-tools
169
155
  requirement: !ruby/object:Gem::Requirement