lita-github-pinger 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fefae430e666059a708616ee469943a3f10b5b8f
4
- data.tar.gz: 52fb963fede4cbaf23eb14c17a19146f5637aeac
3
+ metadata.gz: 4f22d1757545c929eb8ce882ed716e5e478c9821
4
+ data.tar.gz: 9b73ca8d2da4bf7ec0d0ab0bc89893023cda6533
5
5
  SHA512:
6
- metadata.gz: e247d735dee12f913d0d6c7dbb09c7768295866dd5bce29553c98aa1ab06d7987e44b763f78b0565799ba00d3733163b9df7eff7176d217ec86480275a5a3c35
7
- data.tar.gz: e3177c0c6ad56b7e62440cea222021cdb5f22be4f15dd32a749e5a54a1b786d3d24bd46a12c3686012bbf0e702ec300cc78b8d3289d55f610037088f21969946
6
+ metadata.gz: 78eb95991b530696ab1a05314b4fdfde579be2c74bf3069e808ee93ab5e4b32fcc6db9a0557aac5f786a713eed0ed6c312faebec25823e8100e6de32cb4f3fb8
7
+ data.tar.gz: f1a2f74539ba843cbecbd1ffee3f2ff194e2334759a33790d0620780ffc5cef130100d29e314cb6db7e65fe389065068538ae9d1bf3814210ffae0af5f616391
@@ -60,8 +60,8 @@ module Lita
60
60
  act_on_assign(body, response)
61
61
  end
62
62
 
63
- if body["action"] && body["action"] == "opened"
64
- act_on_pr_opened(body, response)
63
+ if body["action"] && body["action"] == "labeled"
64
+ act_on_pr_labeled(body, response)
65
65
  end
66
66
 
67
67
  if body["state"] && body["state"] == "success"
@@ -126,49 +126,53 @@ module Lita
126
126
  response
127
127
  end
128
128
 
129
- def act_on_pr_opened(body, response)
129
+ def act_on_pr_labeled(body, response)
130
130
  type = detect_type(body)
131
- puts "Detected that someone opened a #{type.tr('_', ' ')}."
131
+ puts "Detected that someone labeled a #{type.tr('_', ' ')}."
132
+
132
133
  if type.nil?
133
134
  puts 'Neither pull request or issue detected, exiting...'
134
135
  return
135
136
  end
136
137
 
138
+ if body["labels"].none? { |label| label.name.downcase.include?('review') }
139
+ puts 'Labels do not include a review label, exiting...'
140
+ return
141
+ end
142
+
137
143
  if config.enable_round_robin
138
144
  puts "round robin is enabled, selecting the next engineer.."
139
145
 
140
- chosen_reviewer = redis.get(RR_REDIS_KEY)
141
- engineers_with_rr_enabled = config.engineers.values.select { |eng| eng[:enable_round_robin] }
146
+ chosen_reviewer = get_next_round_robin_reviewer
142
147
 
143
- if chosen_reviewer.nil?
144
- chosen_reviewer = engineers_with_rr_enabled[0][:usernames][:slack]
145
- end
148
+ pr_owner = find_engineer(github: body["pull_request"]["user"]["login"])
149
+ pr_owner = pr_owner[:usernames][:slack] unless pr_owner.nil?
146
150
 
147
- current_reviewer_index = engineers_with_rr_enabled.find_index do |eng|
148
- eng[:usernames][:slack] == chosen_reviewer
151
+ if chosen_reviewer === pr_owner
152
+ update_next_round_robin_reviewer
153
+ chosen_reviewer = get_next_round_robin_reviewer
149
154
  end
150
155
 
151
- next_reviewer_index = (current_reviewer_index + 1) % engineers_with_rr_enabled.length
152
- next_reviewer = engineers_with_rr_enabled[next_reviewer_index][:usernames][:slack]
153
-
154
156
  puts "#{chosen_reviewer} determined as the reviewer."
155
- puts "#{next_reviewer} determined as the next reviewer"
156
-
157
- puts "storing #{next_reviewer} in redis..."
158
- redis.set(RR_REDIS_KEY, next_reviewer)
159
157
 
160
158
  url = body[type]['html_url']
161
159
 
162
- message = "You're next in line to review a PR! Please review, or assign to an engineer with more context if you think you are unable to give a thorough review. \n#{url}"
160
+ message_for_reviewer = "You're next in line to review a PR! Please review, or assign to an engineer with more context if you think you are unable to give a thorough review. \n#{url}"
161
+ message_for_owner = "#{chosen_reviewer} has been notified via round-robin to review #{body["pull_request"]["html_url"]}"
163
162
 
164
163
  puts "Sending DM to #{chosen_reviewer}..."
165
164
  send_dm(chosen_reviewer, message)
166
165
 
167
- pr_owner = find_engineer(github: body["pull_request"]["user"]["login"])
168
- assignment_message = "#{chosen_reviewer} has been notified via round-robin to review #{body["pull_request"]["html_url"]}"
169
- puts "Notifying #{pr_owner} of assignment."
170
- send_dm(pr_owner[:usernames][:slack], assignment_message)
166
+ if pr_owner
167
+ puts "Notifying #{pr_owner} of assignment."
168
+ send_dm(pr_owner, assignment_message)
169
+ else
170
+ puts "Couldn't find a config for pr owner #{body["pull_request"]["user"]["login"]}. Make sure they are in the lita config!"
171
+ puts "Skipping notifying PR owner of RR assignment."
172
+ end
171
173
 
174
+ update_next_round_robin_reviewer
175
+
172
176
  response
173
177
  end
174
178
  end
@@ -247,6 +251,31 @@ module Lita
247
251
  response
248
252
  end
249
253
 
254
+ def get_next_round_robin_reviewer
255
+ engineers_with_rr_enabled = config.engineers.values.select { |eng| eng[:enable_round_robin] }
256
+ next_reviewer = redis.get(RR_REDIS_KEY)
257
+
258
+ if next_reviewer.nil?
259
+ next_reviewer = engineers_with_rr_enabled[0][:usernames][:slack]
260
+ end
261
+
262
+ next_reviewer
263
+ end
264
+
265
+ def update_next_round_robin_reviewer
266
+ engineers_with_rr_enabled = config.engineers.values.select { |eng| eng[:enable_round_robin] }
267
+ current_reviewer = get_next_round_robin_reviewer
268
+
269
+ current_reviewer_index = engineers_with_rr_enabled.find_index do |eng|
270
+ eng[:usernames][:slack] == current_reviewer
271
+ end
272
+
273
+ next_reviewer_index = (current_reviewer_index + 1) % engineers_with_rr_enabled.length
274
+ next_reviewer = engineers_with_rr_enabled[next_reviewer_index][:usernames][:slack]
275
+
276
+ redis.set(RR_REDIS_KEY, next_reviewer)
277
+ end
278
+
250
279
  def alert_eng_pr(message)
251
280
  puts "Alerting #eng-pr about content #{message[0..5]}... "
252
281
  room = Lita::Room.fuzzy_find("eng-pr")
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-github-pinger"
3
- spec.version = "0.7.5"
3
+ spec.version = "0.7.6"
4
4
  spec.authors = ["Taylor Lapeyre"]
5
5
  spec.email = ["taylorlapeyre@gmail.com"]
6
6
  spec.description = "A Lita handler that detects github comment notifications and regurgitates a ping to the correct slack username."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github-pinger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Lapeyre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita