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 +4 -4
- data/lib/lita/handlers/github_pinger.rb +32 -43
- data/lita-github-pinger.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3881550e0e010490d7e8bb65230f550bc496b0d9
|
4
|
+
data.tar.gz: e0918ccf2c3de04898640fc82efec446bd24e4d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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 "
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
46
|
-
|
47
|
-
end
|
44
|
+
puts "Done. Got #{mentions}"
|
45
|
+
puts "Converting usernames to engineers..."
|
48
46
|
|
49
|
-
|
50
|
-
puts "Converting github usernames to slack usernames... "
|
47
|
+
mentioned_engineers = mentions.map { |username| find_engineer(github: username) }
|
51
48
|
|
52
|
-
|
53
|
-
usernames_to_ping.map! { |user| github_to_slack_username(user) }
|
49
|
+
puts "Done. Got #{mentioned_engineers}"
|
54
50
|
|
55
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
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
|
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 += "#{
|
71
|
-
send_dm(
|
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 = "@#{
|
75
|
-
public_message += "#{
|
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)
|
data/lita-github-pinger.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-github-pinger"
|
3
|
-
spec.version = "0.4.
|
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."
|