lita-github-commits 0.0.3 → 0.1.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +2 -0
- data/lib/lita/handlers/github_commits.rb +20 -3
- data/lita-github-commits.gemspec +2 -2
- data/spec/lita/handlers/github_commits_spec.rb +105 -371
- data/spec/lita/handlers/payload.rb +320 -0
- data/spec/spec_helper.rb +2 -0
- metadata +27 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12e8b4542b71a4926a65325bd81f31a69dceacf4
|
4
|
+
data.tar.gz: acc6306f84b6d82b40743428b14d004a2bfbdf74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd51f0c3ea78a96592479c754131f625b848975e5689d3ece758b7ba7ccba1ddd16bb21972b276b3482d714fdfbb2927ed5bdec7236bf4317bf79e683563626b
|
7
|
+
data.tar.gz: e84a2d04d86673822b265c083d567712c47b4ee5edbd472206c64c98bca8b6ba2a3699cd986ce9e47f94bdcc0343593da4db143f1d6f254ebbc58553ea18f256
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -31,6 +31,8 @@ Lita.configure do |config|
|
|
31
31
|
end
|
32
32
|
```
|
33
33
|
|
34
|
+
**Note**: For HipChat, the room should be the JID of the HipChat room (eg. `123_development@conf.hipchat.com`)
|
35
|
+
|
34
36
|
## Usage
|
35
37
|
|
36
38
|
You will need to add a GitHub Webhook url that points to: `http://address.of.lita/github-commits`
|
@@ -44,18 +44,35 @@ module Lita
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def format_message(payload)
|
47
|
-
|
48
|
-
|
47
|
+
commits = payload['commits']
|
48
|
+
branch = branch_from_ref(payload['ref'])
|
49
|
+
if commits.size > 0
|
50
|
+
author = committer_and_author(commits.first)
|
51
|
+
commit_pluralization = commits.size > 1 ? 'commits' : 'commit'
|
52
|
+
"[GitHub] Got #{commits.size} new #{commit_pluralization} #{author} on #{payload['repository']['owner']['name']}/#{payload['repository']['name']} on the #{branch} branch"
|
49
53
|
elsif payload['created']
|
50
54
|
"[GitHub] #{payload['pusher']['name']} created: #{payload['ref']}: #{payload['base_ref']}"
|
51
55
|
elsif payload['deleted']
|
52
56
|
"[GitHub] #{payload['pusher']['name']} deleted: #{payload['ref']}"
|
53
57
|
end
|
54
58
|
rescue
|
55
|
-
Lita.logger.warn "Error formatting message for
|
59
|
+
Lita.logger.warn "Error formatting message for payload: #{payload}"
|
56
60
|
return
|
57
61
|
end
|
58
62
|
|
63
|
+
def branch_from_ref(ref)
|
64
|
+
ref.split('/').last
|
65
|
+
end
|
66
|
+
|
67
|
+
def committer_and_author(commit)
|
68
|
+
if commit['author']['username'] != commit['committer']['username']
|
69
|
+
"authored by #{commit['author']['name']} and committed by " +
|
70
|
+
"#{commit['committer']['name']}"
|
71
|
+
else
|
72
|
+
"from #{commit['author']['name']}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
59
76
|
def rooms_for_repo(repo)
|
60
77
|
rooms = Lita.config.handlers.github_commits.repos[repo]
|
61
78
|
|
data/lita-github-commits.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-github-commits"
|
3
|
-
spec.version = "0.0
|
3
|
+
spec.version = "0.1.0"
|
4
4
|
spec.authors = ["Mitch Dempsey"]
|
5
5
|
spec.email = ["mrdempsey@gmail.com"]
|
6
6
|
spec.description = %q{A Lita handler that will display GitHub commit messages in the channel}
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
14
|
spec.require_paths = ["lib"]
|
15
15
|
|
16
|
-
spec.add_runtime_dependency "lita", ">= 2.3"
|
16
|
+
spec.add_runtime_dependency "lita", ">= 2.3", "< 5.0"
|
17
17
|
|
18
18
|
spec.add_development_dependency "bundler", "~> 1.3"
|
19
19
|
spec.add_development_dependency "rake"
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require_relative "payload"
|
2
3
|
|
3
4
|
describe Lita::Handlers::GithubCommits, lita_handler: true do
|
5
|
+
|
6
|
+
include Payload
|
7
|
+
|
4
8
|
it { routes_http(:post, "/github-commits").to(:receive) }
|
5
9
|
|
6
10
|
describe "#receive" do
|
@@ -16,415 +20,145 @@ describe Lita::Handlers::GithubCommits, lita_handler: true do
|
|
16
20
|
|
17
21
|
let(:params) { double("Hash") }
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
|
24
|
-
"commits":[
|
25
|
-
{
|
26
|
-
"added":[
|
27
|
-
|
28
|
-
],
|
29
|
-
"author":{
|
30
|
-
"email":"lolwut@noway.biz",
|
31
|
-
"name":"Garen Torikian",
|
32
|
-
"username":"octokitty"
|
33
|
-
},
|
34
|
-
"committer":{
|
35
|
-
"email":"lolwut@noway.biz",
|
36
|
-
"name":"Garen Torikian",
|
37
|
-
"username":"octokitty"
|
38
|
-
},
|
39
|
-
"distinct":true,
|
40
|
-
"id":"c441029cf673f84c8b7db52d0a5944ee5c52ff89",
|
41
|
-
"message":"Test",
|
42
|
-
"modified":[
|
43
|
-
"README.md"
|
44
|
-
],
|
45
|
-
"removed":[
|
46
|
-
|
47
|
-
],
|
48
|
-
"timestamp":"2013-02-22T13:50:07-08:00",
|
49
|
-
"url":"https://github.com/octokitty/testing/commit/c441029cf673f84c8b7db52d0a5944ee5c52ff89"
|
50
|
-
},
|
51
|
-
{
|
52
|
-
"added":[
|
53
|
-
|
54
|
-
],
|
55
|
-
"author":{
|
56
|
-
"email":"lolwut@noway.biz",
|
57
|
-
"name":"Garen Torikian",
|
58
|
-
"username":"octokitty"
|
59
|
-
},
|
60
|
-
"committer":{
|
61
|
-
"email":"lolwut@noway.biz",
|
62
|
-
"name":"Garen Torikian",
|
63
|
-
"username":"octokitty"
|
64
|
-
},
|
65
|
-
"distinct":true,
|
66
|
-
"id":"36c5f2243ed24de58284a96f2a643bed8c028658",
|
67
|
-
"message":"This is me testing the windows client.",
|
68
|
-
"modified":[
|
69
|
-
"README.md"
|
70
|
-
],
|
71
|
-
"removed":[
|
72
|
-
|
73
|
-
],
|
74
|
-
"timestamp":"2013-02-22T14:07:13-08:00",
|
75
|
-
"url":"https://github.com/octokitty/testing/commit/36c5f2243ed24de58284a96f2a643bed8c028658"
|
76
|
-
},
|
77
|
-
{
|
78
|
-
"added":[
|
79
|
-
"words/madame-bovary.txt"
|
80
|
-
],
|
81
|
-
"author":{
|
82
|
-
"email":"lolwut@noway.biz",
|
83
|
-
"name":"Garen Torikian",
|
84
|
-
"username":"octokitty"
|
85
|
-
},
|
86
|
-
"committer":{
|
87
|
-
"email":"lolwut@noway.biz",
|
88
|
-
"name":"Garen Torikian",
|
89
|
-
"username":"octokitty"
|
90
|
-
},
|
91
|
-
"distinct":true,
|
92
|
-
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
93
|
-
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
94
|
-
"modified":[
|
95
|
-
|
96
|
-
],
|
97
|
-
"removed":[
|
98
|
-
"madame-bovary.txt"
|
99
|
-
],
|
100
|
-
"timestamp":"2013-03-12T08:14:29-07:00",
|
101
|
-
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
102
|
-
}
|
103
|
-
],
|
104
|
-
"compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
|
105
|
-
"created":false,
|
106
|
-
"deleted":false,
|
107
|
-
"forced":false,
|
108
|
-
"head_commit":{
|
109
|
-
"added":[
|
110
|
-
"words/madame-bovary.txt"
|
111
|
-
],
|
112
|
-
"author":{
|
113
|
-
"email":"lolwut@noway.biz",
|
114
|
-
"name":"Garen Torikian",
|
115
|
-
"username":"octokitty"
|
116
|
-
},
|
117
|
-
"committer":{
|
118
|
-
"email":"lolwut@noway.biz",
|
119
|
-
"name":"Garen Torikian",
|
120
|
-
"username":"octokitty"
|
121
|
-
},
|
122
|
-
"distinct":true,
|
123
|
-
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
124
|
-
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
125
|
-
"modified":[
|
126
|
-
|
127
|
-
],
|
128
|
-
"removed":[
|
129
|
-
"madame-bovary.txt"
|
130
|
-
],
|
131
|
-
"timestamp":"2013-03-12T08:14:29-07:00",
|
132
|
-
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
133
|
-
},
|
134
|
-
"pusher":{
|
135
|
-
"email":"lolwut@noway.biz",
|
136
|
-
"name":"Garen Torikian"
|
137
|
-
},
|
138
|
-
"ref":"refs/heads/master",
|
139
|
-
"repository":{
|
140
|
-
"created_at":1332977768,
|
141
|
-
"description":"",
|
142
|
-
"fork":false,
|
143
|
-
"forks":0,
|
144
|
-
"has_downloads":true,
|
145
|
-
"has_issues":true,
|
146
|
-
"has_wiki":true,
|
147
|
-
"homepage":"",
|
148
|
-
"id":3860742,
|
149
|
-
"language":"Ruby",
|
150
|
-
"master_branch":"master",
|
151
|
-
"name":"testing",
|
152
|
-
"open_issues":2,
|
153
|
-
"owner":{
|
154
|
-
"email":"lolwut@noway.biz",
|
155
|
-
"name":"octokitty"
|
156
|
-
},
|
157
|
-
"private":false,
|
158
|
-
"pushed_at":1363295520,
|
159
|
-
"size":2156,
|
160
|
-
"stargazers":1,
|
161
|
-
"url":"https://github.com/octokitty/testing",
|
162
|
-
"watchers":1
|
163
|
-
}
|
164
|
-
}
|
165
|
-
JSON
|
23
|
+
context "request with commits" do
|
24
|
+
before do
|
25
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
26
|
+
allow(params).to receive(:[]).with("payload").and_return(valid_payload)
|
166
27
|
end
|
167
28
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
"commits":[],
|
176
|
-
"compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
|
177
|
-
"created":true,
|
178
|
-
"deleted":false,
|
179
|
-
"forced":false,
|
180
|
-
"head_commit":{
|
181
|
-
"added":[
|
182
|
-
"words/madame-bovary.txt"
|
183
|
-
],
|
184
|
-
"author":{
|
185
|
-
"email":"lolwut@noway.biz",
|
186
|
-
"name":"Garen Torikian",
|
187
|
-
"username":"octokitty"
|
188
|
-
},
|
189
|
-
"committer":{
|
190
|
-
"email":"lolwut@noway.biz",
|
191
|
-
"name":"Garen Torikian",
|
192
|
-
"username":"octokitty"
|
193
|
-
},
|
194
|
-
"distinct":true,
|
195
|
-
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
196
|
-
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
197
|
-
"modified":[
|
198
|
-
|
199
|
-
],
|
200
|
-
"removed":[
|
201
|
-
"madame-bovary.txt"
|
202
|
-
],
|
203
|
-
"timestamp":"2013-03-12T08:14:29-07:00",
|
204
|
-
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
205
|
-
},
|
206
|
-
"pusher":{
|
207
|
-
"email":"lolwut@noway.biz",
|
208
|
-
"name":"Garen Torikian"
|
209
|
-
},
|
210
|
-
"ref":"refs/heads/master",
|
211
|
-
"repository":{
|
212
|
-
"created_at":1332977768,
|
213
|
-
"description":"",
|
214
|
-
"fork":false,
|
215
|
-
"forks":0,
|
216
|
-
"has_downloads":true,
|
217
|
-
"has_issues":true,
|
218
|
-
"has_wiki":true,
|
219
|
-
"homepage":"",
|
220
|
-
"id":3860742,
|
221
|
-
"language":"Ruby",
|
222
|
-
"master_branch":"master",
|
223
|
-
"name":"testing",
|
224
|
-
"open_issues":2,
|
225
|
-
"owner":{
|
226
|
-
"email":"lolwut@noway.biz",
|
227
|
-
"name":"octokitty"
|
228
|
-
},
|
229
|
-
"private":false,
|
230
|
-
"pushed_at":1363295520,
|
231
|
-
"size":2156,
|
232
|
-
"stargazers":1,
|
233
|
-
"url":"https://github.com/octokitty/testing",
|
234
|
-
"watchers":1
|
235
|
-
}
|
236
|
-
}
|
237
|
-
JSON
|
29
|
+
it "sends a notification message to the applicable rooms" do
|
30
|
+
expect(robot).to receive(:send_message) do |target, message|
|
31
|
+
expect(target.room).to eq("#baz")
|
32
|
+
expect(message).to eq(
|
33
|
+
"[GitHub] Got 3 new commits from Garen Torikian on octokitty/testing on the master branch")
|
34
|
+
end
|
35
|
+
subject.receive(request, response)
|
238
36
|
end
|
37
|
+
end
|
239
38
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
"before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
|
246
|
-
"commits":[],
|
247
|
-
"compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
|
248
|
-
"created":false,
|
249
|
-
"deleted":true,
|
250
|
-
"forced":false,
|
251
|
-
"head_commit":{
|
252
|
-
"added":[
|
253
|
-
"words/madame-bovary.txt"
|
254
|
-
],
|
255
|
-
"author":{
|
256
|
-
"email":"lolwut@noway.biz",
|
257
|
-
"name":"Garen Torikian",
|
258
|
-
"username":"octokitty"
|
259
|
-
},
|
260
|
-
"committer":{
|
261
|
-
"email":"lolwut@noway.biz",
|
262
|
-
"name":"Garen Torikian",
|
263
|
-
"username":"octokitty"
|
264
|
-
},
|
265
|
-
"distinct":true,
|
266
|
-
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
267
|
-
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
268
|
-
"modified":[
|
269
|
-
|
270
|
-
],
|
271
|
-
"removed":[
|
272
|
-
"madame-bovary.txt"
|
273
|
-
],
|
274
|
-
"timestamp":"2013-03-12T08:14:29-07:00",
|
275
|
-
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
276
|
-
},
|
277
|
-
"pusher":{
|
278
|
-
"email":"lolwut@noway.biz",
|
279
|
-
"name":"Garen Torikian"
|
280
|
-
},
|
281
|
-
"ref":"refs/heads/master",
|
282
|
-
"repository":{
|
283
|
-
"created_at":1332977768,
|
284
|
-
"description":"",
|
285
|
-
"fork":false,
|
286
|
-
"forks":0,
|
287
|
-
"has_downloads":true,
|
288
|
-
"has_issues":true,
|
289
|
-
"has_wiki":true,
|
290
|
-
"homepage":"",
|
291
|
-
"id":3860742,
|
292
|
-
"language":"Ruby",
|
293
|
-
"master_branch":"master",
|
294
|
-
"name":"testing",
|
295
|
-
"open_issues":2,
|
296
|
-
"owner":{
|
297
|
-
"email":"lolwut@noway.biz",
|
298
|
-
"name":"octokitty"
|
299
|
-
},
|
300
|
-
"private":false,
|
301
|
-
"pushed_at":1363295520,
|
302
|
-
"size":2156,
|
303
|
-
"stargazers":1,
|
304
|
-
"url":"https://github.com/octokitty/testing",
|
305
|
-
"watchers":1
|
306
|
-
}
|
307
|
-
}
|
308
|
-
JSON
|
39
|
+
context "request with one commit" do
|
40
|
+
before do
|
41
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
42
|
+
allow(params).to receive(:[]).with("payload").and_return(
|
43
|
+
valid_payload_one_commit)
|
309
44
|
end
|
310
45
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
46
|
+
it "sends a singular commit notification message to the applicable rooms" do
|
47
|
+
expect(robot).to receive(:send_message) do |target, message|
|
48
|
+
expect(target.room).to eq("#baz")
|
49
|
+
expect(message).to eq(
|
50
|
+
"[GitHub] Got 1 new commit from Garen Torikian on octokitty/testing on the master branch")
|
51
|
+
end
|
52
|
+
subject.receive(request, response)
|
318
53
|
end
|
54
|
+
end
|
319
55
|
|
56
|
+
context "request with commits" do
|
57
|
+
before do
|
58
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
59
|
+
allow(params).to receive(:[]).with("payload").and_return(valid_payload_diff_committer)
|
60
|
+
end
|
320
61
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
it "sends a notification message to the applicable rooms" do
|
328
|
-
expect(robot).to receive(:send_message) do |target, message|
|
329
|
-
expect(target.room).to eq("#baz")
|
330
|
-
expect(message).to include("[GitHub] Got")
|
331
|
-
end
|
332
|
-
subject.receive(request, response)
|
62
|
+
it "sends a notification message to the applicable rooms" do
|
63
|
+
expect(robot).to receive(:send_message) do |target, message|
|
64
|
+
expect(message).to eq(
|
65
|
+
"[GitHub] Got 3 new commits authored by Garen Torikian and " +
|
66
|
+
"committed by Repository Owner on octokitty/testing on the master branch")
|
333
67
|
end
|
68
|
+
subject.receive(request, response)
|
334
69
|
end
|
70
|
+
end
|
335
71
|
|
336
72
|
|
73
|
+
context "create payload" do
|
74
|
+
before do
|
75
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
76
|
+
allow(params).to receive(:[]).with("payload").and_return(created_payload)
|
77
|
+
end
|
337
78
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
end
|
343
|
-
|
344
|
-
it "sends a notification message to the applicable rooms" do
|
345
|
-
expect(robot).to receive(:send_message) do |target, message|
|
346
|
-
expect(target.room).to eq("#baz")
|
347
|
-
expect(message).to include("[GitHub] Garen Torikian created")
|
348
|
-
end
|
349
|
-
subject.receive(request, response)
|
79
|
+
it "sends a notification message to the applicable rooms" do
|
80
|
+
expect(robot).to receive(:send_message) do |target, message|
|
81
|
+
expect(target.room).to eq("#baz")
|
82
|
+
expect(message).to include("[GitHub] Garen Torikian created")
|
350
83
|
end
|
84
|
+
subject.receive(request, response)
|
351
85
|
end
|
86
|
+
end
|
352
87
|
|
353
88
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
89
|
+
context "delete payload" do
|
90
|
+
before do
|
91
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
92
|
+
allow(params).to receive(:[]).with("payload").and_return(deleted_payload)
|
93
|
+
end
|
359
94
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
end
|
365
|
-
subject.receive(request, response)
|
95
|
+
it "sends a notification message to the applicable rooms" do
|
96
|
+
expect(robot).to receive(:send_message) do |target, message|
|
97
|
+
expect(target.room).to eq("#baz")
|
98
|
+
expect(message).to include("[GitHub] Garen Torikian deleted")
|
366
99
|
end
|
100
|
+
subject.receive(request, response)
|
367
101
|
end
|
102
|
+
end
|
368
103
|
|
369
104
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
105
|
+
context "bad payload" do
|
106
|
+
before do
|
107
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
108
|
+
allow(params).to receive(:[]).with("payload").and_return("yaryary")
|
109
|
+
end
|
375
110
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
end
|
380
|
-
subject.receive(request, response)
|
111
|
+
it "sends a notification message to the applicable rooms" do
|
112
|
+
expect(Lita.logger).to receive(:error) do |error|
|
113
|
+
expect(error).to include("Could not parse JSON payload from Github")
|
381
114
|
end
|
115
|
+
subject.receive(request, response)
|
382
116
|
end
|
117
|
+
end
|
383
118
|
|
384
119
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
120
|
+
context "ping event" do
|
121
|
+
before do
|
122
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
123
|
+
allow(params).to receive(:[]).with("payload").and_return(ping_payload)
|
124
|
+
allow(request).to receive(:env).and_return({"HTTP_X_GITHUB_EVENT" => "ping"})
|
125
|
+
end
|
391
126
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
end
|
127
|
+
it "handles the ping event" do
|
128
|
+
expect(Lita.logger).to_not receive(:error)
|
129
|
+
expect(response).to receive(:write).with("Working!")
|
130
|
+
subject.receive(request, response)
|
397
131
|
end
|
132
|
+
end
|
398
133
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
134
|
+
context "unknown event" do
|
135
|
+
before do
|
136
|
+
Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
|
137
|
+
allow(params).to receive(:[]).with("payload").and_return(ping_payload)
|
138
|
+
allow(request).to receive(:env).and_return({"HTTP_X_GITHUB_EVENT" => "fakefake"})
|
139
|
+
end
|
405
140
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
end
|
141
|
+
it "handles the ping event" do
|
142
|
+
expect(Lita.logger).to_not receive(:error)
|
143
|
+
expect(response).to_not receive(:write)
|
144
|
+
subject.receive(request, response)
|
411
145
|
end
|
146
|
+
end
|
412
147
|
|
413
148
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
149
|
+
context "improper config" do
|
150
|
+
before do
|
151
|
+
allow(params).to receive(:[]).with("payload").and_return(deleted_payload)
|
152
|
+
end
|
418
153
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
end
|
423
|
-
subject.receive(request, response)
|
154
|
+
it "sends a notification message to the applicable rooms" do
|
155
|
+
expect(Lita.logger).to receive(:warn) do |warning|
|
156
|
+
expect(warning).to include("Notification from GitHub Commits for unconfigured project")
|
424
157
|
end
|
158
|
+
subject.receive(request, response)
|
425
159
|
end
|
426
|
-
|
427
|
-
|
428
160
|
end
|
429
161
|
|
162
|
+
end
|
163
|
+
|
430
164
|
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
module Payload
|
2
|
+
|
3
|
+
def valid_payload_one_commit
|
4
|
+
payload = MultiJson.load(valid_payload, symbolize_keys: true)
|
5
|
+
payload[:commits] = [payload[:commits].first]
|
6
|
+
payload.to_json
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid_payload_diff_committer
|
10
|
+
payload = MultiJson.load(valid_payload, symbolize_keys: true)
|
11
|
+
payload[:commits] = payload[:commits].map do |commit|
|
12
|
+
commit[:committer] = {
|
13
|
+
email: "committer@noway.biz",
|
14
|
+
name: "Repository Owner",
|
15
|
+
username: "owner"
|
16
|
+
}
|
17
|
+
commit
|
18
|
+
end
|
19
|
+
payload.to_json
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_payload
|
23
|
+
<<-JSON.chomp
|
24
|
+
{
|
25
|
+
"after":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
26
|
+
"before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
|
27
|
+
"commits":[
|
28
|
+
{
|
29
|
+
"added":[
|
30
|
+
|
31
|
+
],
|
32
|
+
"author":{
|
33
|
+
"email":"lolwut@noway.biz",
|
34
|
+
"name":"Garen Torikian",
|
35
|
+
"username":"octokitty"
|
36
|
+
},
|
37
|
+
"committer":{
|
38
|
+
"email":"lolwut@noway.biz",
|
39
|
+
"name":"Garen Torikian",
|
40
|
+
"username":"octokitty"
|
41
|
+
},
|
42
|
+
"distinct":true,
|
43
|
+
"id":"c441029cf673f84c8b7db52d0a5944ee5c52ff89",
|
44
|
+
"message":"Test",
|
45
|
+
"modified":[
|
46
|
+
"README.md"
|
47
|
+
],
|
48
|
+
"removed":[
|
49
|
+
|
50
|
+
],
|
51
|
+
"timestamp":"2013-02-22T13:50:07-08:00",
|
52
|
+
"url":"https://github.com/octokitty/testing/commit/c441029cf673f84c8b7db52d0a5944ee5c52ff89"
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"added":[
|
56
|
+
|
57
|
+
],
|
58
|
+
"author":{
|
59
|
+
"email":"lolwut@noway.biz",
|
60
|
+
"name":"Garen Torikian",
|
61
|
+
"username":"octokitty"
|
62
|
+
},
|
63
|
+
"committer":{
|
64
|
+
"email":"lolwut@noway.biz",
|
65
|
+
"name":"Garen Torikian",
|
66
|
+
"username":"octokitty"
|
67
|
+
},
|
68
|
+
"distinct":true,
|
69
|
+
"id":"36c5f2243ed24de58284a96f2a643bed8c028658",
|
70
|
+
"message":"This is me testing the windows client.",
|
71
|
+
"modified":[
|
72
|
+
"README.md"
|
73
|
+
],
|
74
|
+
"removed":[
|
75
|
+
|
76
|
+
],
|
77
|
+
"timestamp":"2013-02-22T14:07:13-08:00",
|
78
|
+
"url":"https://github.com/octokitty/testing/commit/36c5f2243ed24de58284a96f2a643bed8c028658"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"added":[
|
82
|
+
"words/madame-bovary.txt"
|
83
|
+
],
|
84
|
+
"author":{
|
85
|
+
"email":"lolwut@noway.biz",
|
86
|
+
"name":"Garen Torikian",
|
87
|
+
"username":"octokitty"
|
88
|
+
},
|
89
|
+
"committer":{
|
90
|
+
"email":"lolwut@noway.biz",
|
91
|
+
"name":"Garen Torikian",
|
92
|
+
"username":"octokitty"
|
93
|
+
},
|
94
|
+
"distinct":true,
|
95
|
+
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
96
|
+
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
97
|
+
"modified":[
|
98
|
+
|
99
|
+
],
|
100
|
+
"removed":[
|
101
|
+
"madame-bovary.txt"
|
102
|
+
],
|
103
|
+
"timestamp":"2013-03-12T08:14:29-07:00",
|
104
|
+
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
105
|
+
}
|
106
|
+
],
|
107
|
+
"compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
|
108
|
+
"created":false,
|
109
|
+
"deleted":false,
|
110
|
+
"forced":false,
|
111
|
+
"head_commit":{
|
112
|
+
"added":[
|
113
|
+
"words/madame-bovary.txt"
|
114
|
+
],
|
115
|
+
"author":{
|
116
|
+
"email":"lolwut@noway.biz",
|
117
|
+
"name":"Garen Torikian",
|
118
|
+
"username":"octokitty"
|
119
|
+
},
|
120
|
+
"committer":{
|
121
|
+
"email":"lolwut@noway.biz",
|
122
|
+
"name":"Garen Torikian",
|
123
|
+
"username":"octokitty"
|
124
|
+
},
|
125
|
+
"distinct":true,
|
126
|
+
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
127
|
+
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
128
|
+
"modified":[
|
129
|
+
|
130
|
+
],
|
131
|
+
"removed":[
|
132
|
+
"madame-bovary.txt"
|
133
|
+
],
|
134
|
+
"timestamp":"2013-03-12T08:14:29-07:00",
|
135
|
+
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
136
|
+
},
|
137
|
+
"pusher":{
|
138
|
+
"email":"lolwut@noway.biz",
|
139
|
+
"name":"Garen Torikian"
|
140
|
+
},
|
141
|
+
"ref":"refs/heads/master",
|
142
|
+
"repository":{
|
143
|
+
"created_at":1332977768,
|
144
|
+
"description":"",
|
145
|
+
"fork":false,
|
146
|
+
"forks":0,
|
147
|
+
"has_downloads":true,
|
148
|
+
"has_issues":true,
|
149
|
+
"has_wiki":true,
|
150
|
+
"homepage":"",
|
151
|
+
"id":3860742,
|
152
|
+
"language":"Ruby",
|
153
|
+
"master_branch":"master",
|
154
|
+
"name":"testing",
|
155
|
+
"open_issues":2,
|
156
|
+
"owner":{
|
157
|
+
"email":"lolwut@noway.biz",
|
158
|
+
"name":"octokitty"
|
159
|
+
},
|
160
|
+
"private":false,
|
161
|
+
"pushed_at":1363295520,
|
162
|
+
"size":2156,
|
163
|
+
"stargazers":1,
|
164
|
+
"url":"https://github.com/octokitty/testing",
|
165
|
+
"watchers":1
|
166
|
+
}
|
167
|
+
}
|
168
|
+
JSON
|
169
|
+
end
|
170
|
+
|
171
|
+
def created_payload
|
172
|
+
<<-JSON.chomp
|
173
|
+
{
|
174
|
+
"after":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
175
|
+
"before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
|
176
|
+
"commits":[],
|
177
|
+
"compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
|
178
|
+
"created":true,
|
179
|
+
"deleted":false,
|
180
|
+
"forced":false,
|
181
|
+
"head_commit":{
|
182
|
+
"added":[
|
183
|
+
"words/madame-bovary.txt"
|
184
|
+
],
|
185
|
+
"author":{
|
186
|
+
"email":"lolwut@noway.biz",
|
187
|
+
"name":"Garen Torikian",
|
188
|
+
"username":"octokitty"
|
189
|
+
},
|
190
|
+
"committer":{
|
191
|
+
"email":"lolwut@noway.biz",
|
192
|
+
"name":"Garen Torikian",
|
193
|
+
"username":"octokitty"
|
194
|
+
},
|
195
|
+
"distinct":true,
|
196
|
+
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
197
|
+
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
198
|
+
"modified":[
|
199
|
+
|
200
|
+
],
|
201
|
+
"removed":[
|
202
|
+
"madame-bovary.txt"
|
203
|
+
],
|
204
|
+
"timestamp":"2013-03-12T08:14:29-07:00",
|
205
|
+
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
206
|
+
},
|
207
|
+
"pusher":{
|
208
|
+
"email":"lolwut@noway.biz",
|
209
|
+
"name":"Garen Torikian"
|
210
|
+
},
|
211
|
+
"ref":"refs/heads/master",
|
212
|
+
"repository":{
|
213
|
+
"created_at":1332977768,
|
214
|
+
"description":"",
|
215
|
+
"fork":false,
|
216
|
+
"forks":0,
|
217
|
+
"has_downloads":true,
|
218
|
+
"has_issues":true,
|
219
|
+
"has_wiki":true,
|
220
|
+
"homepage":"",
|
221
|
+
"id":3860742,
|
222
|
+
"language":"Ruby",
|
223
|
+
"master_branch":"master",
|
224
|
+
"name":"testing",
|
225
|
+
"open_issues":2,
|
226
|
+
"owner":{
|
227
|
+
"email":"lolwut@noway.biz",
|
228
|
+
"name":"octokitty"
|
229
|
+
},
|
230
|
+
"private":false,
|
231
|
+
"pushed_at":1363295520,
|
232
|
+
"size":2156,
|
233
|
+
"stargazers":1,
|
234
|
+
"url":"https://github.com/octokitty/testing",
|
235
|
+
"watchers":1
|
236
|
+
}
|
237
|
+
}
|
238
|
+
JSON
|
239
|
+
end
|
240
|
+
|
241
|
+
def deleted_payload
|
242
|
+
<<-JSON.chomp
|
243
|
+
{
|
244
|
+
"after":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
245
|
+
"before":"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a",
|
246
|
+
"commits":[],
|
247
|
+
"compare":"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a",
|
248
|
+
"created":false,
|
249
|
+
"deleted":true,
|
250
|
+
"forced":false,
|
251
|
+
"head_commit":{
|
252
|
+
"added":[
|
253
|
+
"words/madame-bovary.txt"
|
254
|
+
],
|
255
|
+
"author":{
|
256
|
+
"email":"lolwut@noway.biz",
|
257
|
+
"name":"Garen Torikian",
|
258
|
+
"username":"octokitty"
|
259
|
+
},
|
260
|
+
"committer":{
|
261
|
+
"email":"lolwut@noway.biz",
|
262
|
+
"name":"Garen Torikian",
|
263
|
+
"username":"octokitty"
|
264
|
+
},
|
265
|
+
"distinct":true,
|
266
|
+
"id":"1481a2de7b2a7d02428ad93446ab166be7793fbb",
|
267
|
+
"message":"Rename madame-bovary.txt to words/madame-bovary.txt",
|
268
|
+
"modified":[
|
269
|
+
|
270
|
+
],
|
271
|
+
"removed":[
|
272
|
+
"madame-bovary.txt"
|
273
|
+
],
|
274
|
+
"timestamp":"2013-03-12T08:14:29-07:00",
|
275
|
+
"url":"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb"
|
276
|
+
},
|
277
|
+
"pusher":{
|
278
|
+
"email":"lolwut@noway.biz",
|
279
|
+
"name":"Garen Torikian"
|
280
|
+
},
|
281
|
+
"ref":"refs/heads/master",
|
282
|
+
"repository":{
|
283
|
+
"created_at":1332977768,
|
284
|
+
"description":"",
|
285
|
+
"fork":false,
|
286
|
+
"forks":0,
|
287
|
+
"has_downloads":true,
|
288
|
+
"has_issues":true,
|
289
|
+
"has_wiki":true,
|
290
|
+
"homepage":"",
|
291
|
+
"id":3860742,
|
292
|
+
"language":"Ruby",
|
293
|
+
"master_branch":"master",
|
294
|
+
"name":"testing",
|
295
|
+
"open_issues":2,
|
296
|
+
"owner":{
|
297
|
+
"email":"lolwut@noway.biz",
|
298
|
+
"name":"octokitty"
|
299
|
+
},
|
300
|
+
"private":false,
|
301
|
+
"pushed_at":1363295520,
|
302
|
+
"size":2156,
|
303
|
+
"stargazers":1,
|
304
|
+
"url":"https://github.com/octokitty/testing",
|
305
|
+
"watchers":1
|
306
|
+
}
|
307
|
+
}
|
308
|
+
JSON
|
309
|
+
end
|
310
|
+
|
311
|
+
def ping_payload
|
312
|
+
<<-JSON.chomp
|
313
|
+
{
|
314
|
+
"zen":"Non-blocking is better than blocking",
|
315
|
+
"hook_id":12345
|
316
|
+
}
|
317
|
+
JSON
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,97 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-github-commits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitch Dempsey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.3'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '2.3'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - ~>
|
37
|
+
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: '1.3'
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- - ~>
|
44
|
+
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '1.3'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rake
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rspec
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- -
|
65
|
+
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: 3.0.0.beta2
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- -
|
72
|
+
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: 3.0.0.beta2
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: simplecov
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- -
|
79
|
+
- - ">="
|
74
80
|
- !ruby/object:Gem::Version
|
75
81
|
version: '0'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- -
|
86
|
+
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '0'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: coveralls
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- -
|
93
|
+
- - ">="
|
88
94
|
- !ruby/object:Gem::Version
|
89
95
|
version: '0'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- -
|
100
|
+
- - ">="
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: '0'
|
97
103
|
description: A Lita handler that will display GitHub commit messages in the channel
|
@@ -101,8 +107,8 @@ executables: []
|
|
101
107
|
extensions: []
|
102
108
|
extra_rdoc_files: []
|
103
109
|
files:
|
104
|
-
- .gitignore
|
105
|
-
- .travis.yml
|
110
|
+
- ".gitignore"
|
111
|
+
- ".travis.yml"
|
106
112
|
- Gemfile
|
107
113
|
- LICENSE
|
108
114
|
- README.md
|
@@ -111,6 +117,7 @@ files:
|
|
111
117
|
- lib/lita/handlers/github_commits.rb
|
112
118
|
- lita-github-commits.gemspec
|
113
119
|
- spec/lita/handlers/github_commits_spec.rb
|
120
|
+
- spec/lita/handlers/payload.rb
|
114
121
|
- spec/spec_helper.rb
|
115
122
|
homepage: https://github.com/webdestroya/lita-github-commits
|
116
123
|
licenses:
|
@@ -123,20 +130,21 @@ require_paths:
|
|
123
130
|
- lib
|
124
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
132
|
requirements:
|
126
|
-
- -
|
133
|
+
- - ">="
|
127
134
|
- !ruby/object:Gem::Version
|
128
135
|
version: '0'
|
129
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
137
|
requirements:
|
131
|
-
- -
|
138
|
+
- - ">="
|
132
139
|
- !ruby/object:Gem::Version
|
133
140
|
version: '0'
|
134
141
|
requirements: []
|
135
142
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.2.2
|
137
144
|
signing_key:
|
138
145
|
specification_version: 4
|
139
146
|
summary: A Lita handler that will display GitHub commit messages in the channel
|
140
147
|
test_files:
|
141
148
|
- spec/lita/handlers/github_commits_spec.rb
|
149
|
+
- spec/lita/handlers/payload.rb
|
142
150
|
- spec/spec_helper.rb
|