lita-github-pinger 0.4.7 → 0.4.8

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: 3881550e0e010490d7e8bb65230f550bc496b0d9
4
- data.tar.gz: e0918ccf2c3de04898640fc82efec446bd24e4d7
3
+ metadata.gz: c9a67b40aebdeb0cbae576e8296372045398781a
4
+ data.tar.gz: d3876e419ef7b89c484b816fdaa69947ab305798
5
5
  SHA512:
6
- metadata.gz: 235893973dc19de4627bf66b17a875e7a6ce6d989233f73bd1cf1b79841a9d43b3d25943108b171306c0c5b30b1e27be79469346c57042941ad4ed1d8f544098
7
- data.tar.gz: ddf57b7532389122ab973e1d6269545f20153141a48edf98a84b88981f2bf3750a1c862ec6bcc73fa0e4a386ca32076dca2dc9156ee89f8148f1908cdb369145
6
+ metadata.gz: c16766a54c0d03486eaba195ee8d8b8107c9a3b7a7498db7b5c936cafb449d8fcf50d4e3b4dc7feecd68a6b78afd49bec125ffe69bdf6dc4c61700add8c29d70
7
+ data.tar.gz: 353f04a1c4bed25bf0856ce3f487a657e3e4d2dbabcf15d3754d733b9571162beda7f90a5a1167cf983253d81e15eba3a289bc59cb12bf412b899bf8af3efb94
@@ -2,79 +2,128 @@ module Lita
2
2
  module Handlers
3
3
  class GithubPinger < Handler
4
4
 
5
+ ####
6
+ # ENGINEER NOTIFICATION PREFERENCES
7
+ ####
8
+
9
+ # example entry: {
10
+ # :slack => "taylor"
11
+ # :github => "taylorlapeyre"
12
+ # :frequency => "only_mentions"
13
+ # :ping_location => "dm"
14
+ #}
15
+ #
16
+ # :ping_location can be...
17
+ # - "dm"
18
+ # - "eng-pr" (pings you in #eng-pr)
19
+ # default: "dm"
20
+ #
21
+ # :frequency can be
22
+ # - "all_discussion" (pings you about any comments on your PRs and @mentions)
23
+ # - "only_mentions" (will only ping you when you are explicitly @mentioned)
24
+ # - "off"
25
+ # default: "all_discussion"
5
26
  config :engineers, type: Array, required: true
6
27
 
7
28
  http.post("/ghping", :ghping)
8
29
 
9
30
  def ghping(request, response)
10
31
  puts "########## New GH PR Event! ##########"
11
-
12
32
  body = MultiJson.load(request.body)
33
+
13
34
  if body["comment"]
14
- puts "Detected a comment. Extracting data... "
35
+ act_on_comment(body, response)
36
+ end
15
37
 
16
- comment_url = body["comment"]["html_url"]
17
- comment = body["comment"]["body"]
18
- context = body["pull_request"] || body["issue"]
38
+ if body["action"] && body["action"] == "assigned"
39
+ act_on_assign(body, response)
40
+ end
41
+ end
19
42
 
20
- commenter = find_engineer(github: body["comment"]["user"]["login"])
21
- pr_owner = find_engineer(github: context["user"]["login"])
43
+ def act_on_assign(body, response)
44
+ puts "Detected that someone got assigned to a pull request."
45
+ assignee = find_engineer(github: body["pull_request"]["assignee"])
46
+ assigner = find_engineer(github: body["pull_request"]["user"]["login"])
22
47
 
23
- puts "Reacting to PR comment #{comment_url}"
24
- puts "Found commenter #{commenter}"
25
- puts "Found pr owner #{pr_owner}"
48
+ puts "#{assignee} determined as the assignee."
49
+ puts "#{assigner} determined as assigner."
26
50
 
27
- engineers_to_ping = []
28
- # automatically include the creator of the PR, unless he's
29
- # commenting on his own PR
51
+ pr_url = body["pull_request"]["html_url"]
52
+ message = "*Heads up!* #{pr_owner[:slack]} has assigned you to review their pull request:\n#{pr_url}"
30
53
 
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
54
+ puts "Sending DM to #{assignee}..."
55
+ send_dm(assignee[:slack], message)
36
56
 
37
- # Is anyone mentioned in this comment?
38
- if comment.include?("@")
39
- puts "Found @mentions in the body of the comment! Extracting usernames... "
57
+ response
58
+ end
40
59
 
41
- # get each @mentioned engineer in the comment
42
- mentions = comment.split("@")[1..-1].map { |snip| snip.split(" ").first }
60
+ def act_on_comment(request, response)
61
+ puts "Detected a comment. Extracting data... "
43
62
 
44
- puts "Done. Got #{mentions}"
45
- puts "Converting usernames to engineers..."
63
+ comment_url = body["comment"]["html_url"]
64
+ comment = body["comment"]["body"]
65
+ context = body["pull_request"] || body["issue"]
46
66
 
47
- mentioned_engineers = mentions.map { |username| find_engineer(github: username) }
67
+ commenter = find_engineer(github: body["comment"]["user"]["login"])
68
+ pr_owner = find_engineer(github: context["user"]["login"])
48
69
 
49
- puts "Done. Got #{mentioned_engineers}"
70
+ puts "Reacting to PR comment #{comment_url}"
71
+ puts "Found commenter #{commenter}"
72
+ puts "Found pr owner #{pr_owner}"
50
73
 
51
- # add them to the list of usernames to ping
52
- engineers_to_ping = engineers_to_ping.concat(mentioned_engineers).uniq.compact
53
- end
74
+ # Sanity Checks - might be a new engineer around that hasn't set up
75
+ # their config.
54
76
 
55
- puts "New list of engineers to ping: #{engineers_to_ping}."
56
- puts "Starting pinging process for each engineer..."
57
- engineers_to_ping.each do |engineer|
58
- puts "looking at #{engineer}'s preferences..'"
59
- next if engineer[:frequency] == "off"
60
-
61
- case engineer[:ping_location]
62
- when "dm", nil
63
- puts "Preference was either 'dm' or nil, so sending 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)
67
- when "eng-pr", "eng_pr"
68
- puts "Preference was either 'eng-pr' or 'eng_pr', so alerting #eng-pr."
69
- public_message = "@#{engineer[:slack]}, new PR mention: "
70
- public_message += "#{comment_url}\n#{comment}"
71
- alert_eng_pr(public_message)
72
- end
73
- end
77
+ engineers_to_ping = []
78
+ # automatically include the creator of the PR, unless he's
79
+ # commenting on his own PR
74
80
 
75
- puts "GitHub Hook successfully processed."
81
+ if commenter != pr_owner && ["all_discussion", nil].include?(pr_owner[:frequency])
82
+ puts "PR owner was not the commenter, and has a :frequency of 'all_discussion' or nil"
83
+ puts "Therefore, adding the PR owner to list of engineers to ping."
84
+ engineers_to_ping << pr_owner
76
85
  end
77
86
 
87
+ # Is anyone mentioned in this comment?
88
+ if comment.include?("@")
89
+ puts "Found @mentions in the body of the comment! Extracting usernames... "
90
+
91
+ # get each @mentioned engineer in the comment
92
+ mentions = comment.split("@")[1..-1].map { |snip| snip.split(" ").first }
93
+
94
+ puts "Done. Got #{mentions}"
95
+ puts "Converting usernames to engineers..."
96
+
97
+ mentioned_engineers = mentions.map { |username| find_engineer(github: username) }
98
+
99
+ puts "Done. Got #{mentioned_engineers}"
100
+
101
+ # add them to the list of usernames to ping
102
+ engineers_to_ping = engineers_to_ping.concat(mentioned_engineers).uniq.compact
103
+ end
104
+
105
+ puts "New list of engineers to ping: #{engineers_to_ping}."
106
+ puts "Starting pinging process for each engineer..."
107
+ engineers_to_ping.each do |engineer|
108
+ puts "looking at #{engineer}'s preferences..'"
109
+ next if engineer[:frequency] == "off"
110
+
111
+ case engineer[:ping_location]
112
+ when "dm", nil
113
+ puts "Preference was either 'dm' or nil, so sending DM."
114
+ private_message = "New PR comment from @#{commenter[:slack]}:\n"
115
+ private_message += "#{comment_url}\n#{comment}"
116
+ send_dm(engineer[:slack], private_message)
117
+ when "eng-pr", "eng_pr"
118
+ puts "Preference was either 'eng-pr' or 'eng_pr', so alerting #eng-pr."
119
+ public_message = "@#{engineer[:slack]}, new PR mention: "
120
+ public_message += "#{comment_url}\n#{comment}"
121
+ alert_eng_pr(public_message)
122
+ end
123
+ end
124
+
125
+ puts "GitHub Hook successfully processed."
126
+
78
127
  response
79
128
  end
80
129
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-github-pinger"
3
- spec.version = "0.4.7"
3
+ spec.version = "0.4.8"
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.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Lapeyre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita