lita-github-pinger 0.4.6 → 0.4.7

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: ee333fa793da79fbf68506127e4453e9a4c25614
4
- data.tar.gz: d7070b91880ed8225c9c21e4801f72da0e3075bb
3
+ metadata.gz: 3881550e0e010490d7e8bb65230f550bc496b0d9
4
+ data.tar.gz: e0918ccf2c3de04898640fc82efec446bd24e4d7
5
5
  SHA512:
6
- metadata.gz: cbb4e43c5c0b9d26f9a6a456d8dfbac360970885fec086eec941d277eef14d283717f67d687ff70c3aa0ee0bed8c3e770643d2215ecedd6f3ba82b9bc9baac09
7
- data.tar.gz: b2324a92932621300555c55d1d854468a7c8e34dffc5fde981ba181698b41b902c7b7ee5d9ae80f9d07091c01a971cf3735b88ddc6b89b1e3d7e58eddc48c871
6
+ metadata.gz: 235893973dc19de4627bf66b17a875e7a6ce6d989233f73bd1cf1b79841a9d43b3d25943108b171306c0c5b30b1e27be79469346c57042941ad4ed1d8f544098
7
+ data.tar.gz: ddf57b7532389122ab973e1d6269545f20153141a48edf98a84b88981f2bf3750a1c862ec6bcc73fa0e4a386ca32076dca2dc9156ee89f8148f1908cdb369145
@@ -7,75 +7,69 @@ module Lita
7
7
  http.post("/ghping", :ghping)
8
8
 
9
9
  def ghping(request, response)
10
-
11
10
  puts "########## New GH PR Event! ##########"
12
- body = MultiJson.load(request.body)
13
11
 
12
+ body = MultiJson.load(request.body)
14
13
  if body["comment"]
15
14
  puts "Detected a comment. Extracting data... "
16
15
 
17
- thing = body["pull_request"] || body["issue"]
18
- pr_url = thing["html_url"]
19
- comment = body["comment"]["body"]
20
- commenter = body["comment"]["user"]["login"]
21
- pr_owner = thing["user"]["login"]
16
+ comment_url = body["comment"]["html_url"]
17
+ comment = body["comment"]["body"]
18
+ context = body["pull_request"] || body["issue"]
19
+
20
+ commenter = find_engineer(github: body["comment"]["user"]["login"])
21
+ pr_owner = find_engineer(github: context["user"]["login"])
22
22
 
23
- puts "Found PR #{pr_url}"
23
+ puts "Reacting to PR comment #{comment_url}"
24
24
  puts "Found commenter #{commenter}"
25
25
  puts "Found pr owner #{pr_owner}"
26
26
 
27
- usernames_to_ping = []
27
+ engineers_to_ping = []
28
28
  # automatically include the creator of the PR, unless he's
29
29
  # commenting on his own PR
30
- if commenter != pr_owner
31
- puts "Commenter is not the pr owner. Adding to list of usernames to ping."
32
- usernames_to_ping << pr_owner
33
- end
34
30
 
35
- puts "So far, github usernames to ping: #{usernames_to_ping}"
31
+ if commenter != pr_owner && ["all_discussion", nil].include?(pr_owner[:frequency])
32
+ puts "PR owner was not the commenter, and has a :frequency of 'all_discussion' or nil"
33
+ puts "Therefore, adding the PR owner to list of engineers to ping."
34
+ engineers_to_ping << pr_owner
35
+ end
36
36
 
37
37
  # Is anyone mentioned in this comment?
38
38
  if comment.include?("@")
39
39
  puts "Found @mentions in the body of the comment! Extracting usernames... "
40
40
 
41
- # get each @mentioned username in the comment
41
+ # get each @mentioned engineer in the comment
42
42
  mentions = comment.split("@")[1..-1].map { |snip| snip.split(" ").first }
43
- puts "Done. (Got #{mentions})"
44
43
 
45
- # add them to the list of usernames to ping
46
- usernames_to_ping = usernames_to_ping.concat(mentions).uniq
47
- end
44
+ puts "Done. Got #{mentions}"
45
+ puts "Converting usernames to engineers..."
48
46
 
49
- puts "New list of github usernames to ping: #{usernames_to_ping}."
50
- puts "Converting github usernames to slack usernames... "
47
+ mentioned_engineers = mentions.map { |username| find_engineer(github: username) }
51
48
 
52
- # slackify all of the users
53
- usernames_to_ping.map! { |user| github_to_slack_username(user) }
49
+ puts "Done. Got #{mentioned_engineers}"
54
50
 
55
- puts "Done. (Got #{usernames_to_ping})"
51
+ # add them to the list of usernames to ping
52
+ engineers_to_ping = engineers_to_ping.concat(mentioned_engineers).uniq.compact
53
+ end
56
54
 
55
+ puts "New list of engineers to ping: #{engineers_to_ping}."
57
56
  puts "Starting pinging process for each engineer..."
58
- usernames_to_ping.compact.each do |user|
59
-
60
- pref = find_engineer(slack: user)[:preference]
61
-
62
- puts "Found preference #{pref.inspect} for user #{user}"
57
+ engineers_to_ping.each do |engineer|
58
+ puts "looking at #{engineer}'s preferences..'"
59
+ next if engineer[:frequency] == "off"
63
60
 
64
- case pref
65
- when "off"
66
- puts "Preference was 'off', so doing nothing."
61
+ case engineer[:ping_location]
67
62
  when "dm", nil
68
63
  puts "Preference was either 'dm' or nil, so sending DM."
69
- private_message = "New PR comment from @#{commenter}:\n"
70
- private_message += "#{pr_url}\n#{comment}"
71
- send_dm(user, private_message)
64
+ private_message = "New PR comment from @#{commenter[:slack]}:\n"
65
+ private_message += "#{comment_url}\n#{comment}"
66
+ send_dm(engineer[:slack], private_message)
72
67
  when "eng-pr", "eng_pr"
73
68
  puts "Preference was either 'eng-pr' or 'eng_pr', so alerting #eng-pr."
74
- public_message = "@#{user}, new PR mention: "
75
- public_message += "#{pr_url}\n#{comment}" if user == usernames_to_ping.last
69
+ public_message = "@#{engineer[:slack]}, new PR mention: "
70
+ public_message += "#{comment_url}\n#{comment}"
76
71
  alert_eng_pr(public_message)
77
72
  end
78
-
79
73
  end
80
74
 
81
75
  puts "GitHub Hook successfully processed."
@@ -102,11 +96,6 @@ module Lita
102
96
  end.first
103
97
  end
104
98
 
105
- def github_to_slack_username(github_username)
106
- engineer = find_engineer(github: github_username)
107
- engineer[:slack] if engineer
108
- end
109
-
110
99
  def send_dm(username, content)
111
100
  puts "Sending DM to #{username} with content #{content[0..5]}... "
112
101
  if user = Lita::User.fuzzy_find(username)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-github-pinger"
3
- spec.version = "0.4.6"
3
+ spec.version = "0.4.7"
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github-pinger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Lapeyre