lita-github-pinger 0.6.6 → 0.7.0

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
- SHA1:
3
- metadata.gz: 662aea59222ac24d19a2b402c3e7710b02637c7e
4
- data.tar.gz: 8afb238ddbd88bc03b0a1305f820967c78ed70e7
2
+ SHA256:
3
+ metadata.gz: 4219c3fba527d10c59902d567b84ac3bf900cd90f34c5f41b85e3fc31263e5bb
4
+ data.tar.gz: 0bfe1ff5bb95fbb56a57fb0c6ea3135d2b2478b3d5b3ea5ef2c437374f38b053
5
5
  SHA512:
6
- metadata.gz: 42300f8b34f2b20cca88fe68dcbdc0272b8d5b47bb44270b8325c71b37c8ee8152836bcbd20684c9a651c664f242d536d64d81fd58aca18dbd33665244c4a8a5
7
- data.tar.gz: edfd401bf6276d7982bc3319b2130ccfaf65a72fe1bddb98b23a6f78d8daf168d128b97b42e5e4aae3a3490097774aec27e6bf60c79d76398122f7898f349759
6
+ metadata.gz: 92c0fb731b72c6463737c081e31398cf207677d85361ec8fb8367e9daa0c764e46faa9db48713e9734b5177dcaa3205a1af94cc1eb368a5947cb9666bf014ea6
7
+ data.tar.gz: 7a34c368801fd5cec786ba2c9e94190eb84930a5f399ac21078485adc9e39f9512074fa036833a91006dd02933444760a74e09cb053237fda3716e4fc69ae1a7
@@ -1,5 +1,7 @@
1
1
  module Lita
2
2
  module Handlers
3
+ RR_REDIS_KEY = 'lita-github-pinger:roundrobin'.freeze
4
+
3
5
  class GithubPinger < Handler
4
6
 
5
7
  ####
@@ -54,6 +56,10 @@ module Lita
54
56
  act_on_assign(body, response)
55
57
  end
56
58
 
59
+ if body["state"] && body["state"] == "opened"
60
+ act_on_pr_opened(body, response)
61
+ end
62
+
57
63
  if body["state"] && body["state"] == "success"
58
64
  act_on_build_success(body, response)
59
65
  end
@@ -92,13 +98,23 @@ module Lita
92
98
  end
93
99
 
94
100
  def act_on_assign(body, response)
95
- puts "Detected that someone got assigned to a pull request."
96
- assignee = find_engineer(github: body["pull_request"]["assignee"]["login"])
101
+ type = detect_type(body)
102
+
103
+ if type.nil?
104
+ puts 'Neither pull request or issue detected, exiting...'
105
+ return
106
+ end
107
+
108
+ puts "Detected that someone got assigned to a #{type.tr('_', ' ')}."
109
+
110
+ assignee_login = body[type]['assignee']['login']
111
+ assignee = find_engineer(github: assignee_login)
97
112
 
98
113
  puts "#{assignee} determined as the assignee."
99
114
 
100
- pr_url = body["pull_request"]["html_url"]
101
- message = "*Heads up!* You've been assigned to review a pull request:\n#{pr_url}"
115
+ url = body[type]['html_url']
116
+
117
+ message = "*Heads up!* You've been assigned to review a #{type.tr('_', ' ')}:\n#{url}"
102
118
 
103
119
  puts "Sending DM to #{assignee}..."
104
120
  send_dm(assignee[:usernames][:slack], message)
@@ -106,6 +122,47 @@ module Lita
106
122
  response
107
123
  end
108
124
 
125
+ def act_on_pr_opened(body, response)
126
+ puts "Detected that someone opened a #{type.tr('_', ' ')}."
127
+ if type.nil?
128
+ puts 'Neither pull request or issue detected, exiting...'
129
+ return
130
+ end
131
+
132
+ if config.enable_round_robin
133
+ puts "round robin is enabled, selecting the next engineer.."
134
+
135
+ chosen_reviewer = redis.get(RR_REDIS_KEY)
136
+ engineers_with_rr_enabled = config.engineers.values.select { |eng| eng[:enable_round_robin] }
137
+
138
+ if chosen_reviewer.nil?
139
+ chosen_reviewer = engineers_with_rr_enabled[0][:usernames][:slack]
140
+ end
141
+
142
+ current_reviewer_index = engineers_with_rr_enabled.find_index do |eng|
143
+ eng[:usernames][:slack] == chosen_reviewer
144
+ end
145
+
146
+ next_reviewer_index = (current_reviewer_index + 1) % engineers_with_rr_enabled.length
147
+ next_reviewer = engineers_with_rr_enabled[next_reviewer_index][:usernames][:slack]
148
+
149
+ puts "#{chosen_reviewer} determined as the reviewer."
150
+ puts "#{next_reviewer} determined as the next reviewer"
151
+
152
+ puts "storing #{next_reviewer} in redis..."
153
+ redis.set(RR_REDIS_KEY, next_reviewer)
154
+
155
+ url = body[type]['html_url']
156
+
157
+ 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}"
158
+
159
+ puts "Sending DM to #{chosen_reviewer}..."
160
+ send_dm(chosen_reviewer, message)
161
+
162
+ response
163
+ end
164
+ end
165
+
109
166
  def act_on_comment(body, response)
110
167
  puts "Detected a comment. Extracting data... "
111
168
 
@@ -212,6 +269,14 @@ module Lita
212
269
  alert_eng_pr("Could not find user with name #{username}, please configure everbot.")
213
270
  end
214
271
  end
272
+
273
+ def detect_type(body)
274
+ if body['pull_request']
275
+ 'pull_request'
276
+ elsif body['issue']
277
+ 'issue'
278
+ end
279
+ end
215
280
  end
216
281
 
217
282
  Lita.register_handler(GithubPinger)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-github-pinger"
3
- spec.version = "0.6.6"
3
+ spec.version = "0.7.0"
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."
@@ -1,15 +1,16 @@
1
1
  require "spec_helper"
2
-
3
- # This file is out of date and will be fixed soon
2
+ require "json"
4
3
 
5
4
  describe Lita::Handlers::GithubPinger, lita_handler: true do
6
5
  before do
7
- registry.config.handlers.github_pinger.engineers = [
8
- {
9
- slack: "taylor",
10
- github: "taylorlapeyre"
11
- },
12
- ]
6
+ registry.config.handlers.github_pinger.engineers = {
7
+ 'Taylor' => {
8
+ usernames: {
9
+ slack: 'taylor',
10
+ github: 'taylorlapeyre'
11
+ }
12
+ }
13
+ }
13
14
  end
14
15
 
15
16
  it "will respond" do
@@ -21,4 +22,47 @@ describe Lita::Handlers::GithubPinger, lita_handler: true do
21
22
  response = http.post("/ghping", '{"hello": "world", "events": ["pull_request_review_comment"]}')
22
23
  expect(response.body).to_not be_nil
23
24
  end
25
+
26
+ describe 'act on assign' do
27
+ before do
28
+ Lita::Room.create_or_update(1, name: 'eng-pr')
29
+ Lita::User.create(1, name: 'taylorlapeyre')
30
+ end
31
+
32
+ context 'pull request' do
33
+ it 'sends direct message' do
34
+ fake_json_request = {
35
+ action: 'assigned',
36
+ pull_request: {
37
+ assignee: {
38
+ login: 'taylorlapeyre'
39
+ }
40
+ }
41
+ }.to_json
42
+
43
+ response = http.post('/ghping', fake_json_request)
44
+
45
+ expect(replies.first).to match("You've been assigned to review a pull request")
46
+ expect(response.status).to eq(200)
47
+ end
48
+ end
49
+
50
+ context 'issue' do
51
+ it 'sends direct message' do
52
+ fake_json_request = {
53
+ action: 'assigned',
54
+ issue: {
55
+ assignee: {
56
+ login: 'taylorlapeyre'
57
+ }
58
+ }
59
+ }.to_json
60
+
61
+ response = http.post('/ghping', fake_json_request)
62
+
63
+ expect(replies.first).to match("You've been assigned to review a issue")
64
+ expect(response.status).to eq(200)
65
+ end
66
+ end
67
+ end
24
68
  end
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.6.6
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Lapeyre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-18 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.5.1
137
+ rubygems_version: 2.7.6
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: A Lita handler that detects github comment notifications and regurgitates