lita-github-commits 0.0.2 → 0.0.3

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: db21716b69044be4479bcd4828a7d8fad5171e52
4
- data.tar.gz: bbcdc2cc6c93ade267e0ffa571af9163384b32dc
3
+ metadata.gz: 7aa1facf7a84b6537381b3ef78694d97c65508de
4
+ data.tar.gz: 3822f5ff206ca183233670c018b9bc20fd3fa20c
5
5
  SHA512:
6
- metadata.gz: 1c8c4e7e5f795389b025c654248bd592eb3fcf40475657f46ada0d44e62aba1b4cbcfadedebb2dc6786ca08246e1d1e94dbedaa1f882872bf0bbb8c5b8a02771
7
- data.tar.gz: cf296f96de3b45aa94b0a0704afa5738bb94213b7dbafdc8c133dca4165958b98198c608802d5fcc019327f778e3e39d969b13e6008aece89679cb10233379c0
6
+ metadata.gz: 3d3668c149f36b55f0bd9b5f108f96d832c53e402604eb5b4223110cb2f9e2dd4291c8ee0fde5eda9316392321f89bdb549478dc46b68939edd7a54a04c27ab4
7
+ data.tar.gz: d808c5f2ad8bf7d4dfd173b85f725c1bdd81301f59d0ae820b031bef5d14ca0f0f23ddb164f7b0048be1f28430013cef2eeaab33cf6b07166ba582c70947f6ca
@@ -11,9 +11,17 @@ module Lita
11
11
  http.post "/github-commits", :receive
12
12
 
13
13
  def receive(request, response)
14
- payload = parse_payload(request.params['payload']) or return
15
- repo = get_repo(payload)
16
- notify_rooms(repo, payload)
14
+ event_type = request.env['HTTP_X_GITHUB_EVENT'] || 'unknown'
15
+ if event_type == "push"
16
+ payload = parse_payload(request.params['payload']) or return
17
+ repo = get_repo(payload)
18
+ notify_rooms(repo, payload)
19
+ elsif event_type == "ping"
20
+ response.status = 200
21
+ response.write "Working!"
22
+ else
23
+ response.status = 404
24
+ end
17
25
  end
18
26
 
19
27
  private
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-github-commits"
3
- spec.version = "0.0.2"
3
+ spec.version = "0.0.3"
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}
@@ -7,6 +7,7 @@ describe Lita::Handlers::GithubCommits, lita_handler: true do
7
7
 
8
8
  let(:request) do
9
9
  request = double("Rack::Request")
10
+ allow(request).to receive(:env).and_return({"HTTP_X_GITHUB_EVENT" => "push"})
10
11
  allow(request).to receive(:params).and_return(params)
11
12
  request
12
13
  end
@@ -307,6 +308,15 @@ describe Lita::Handlers::GithubCommits, lita_handler: true do
307
308
  JSON
308
309
  end
309
310
 
311
+ let(:ping_payload) do
312
+ <<-JSON.chomp
313
+ {
314
+ "zen":"Non-blocking is better than blocking",
315
+ "hook_id":12345
316
+ }
317
+ JSON
318
+ end
319
+
310
320
 
311
321
  context "request with commits" do
312
322
  before do
@@ -372,6 +382,35 @@ describe Lita::Handlers::GithubCommits, lita_handler: true do
372
382
  end
373
383
 
374
384
 
385
+ context "ping event" do
386
+ before do
387
+ Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
388
+ allow(params).to receive(:[]).with("payload").and_return(ping_payload)
389
+ allow(request).to receive(:env).and_return({"HTTP_X_GITHUB_EVENT" => "ping"})
390
+ end
391
+
392
+ it "handles the ping event" do
393
+ expect(Lita.logger).to_not receive(:error)
394
+ expect(response).to receive(:write).with("Working!")
395
+ subject.receive(request, response)
396
+ end
397
+ end
398
+
399
+ context "unknown event" do
400
+ before do
401
+ Lita.config.handlers.github_commits.repos["octokitty/testing"] = "#baz"
402
+ allow(params).to receive(:[]).with("payload").and_return(ping_payload)
403
+ allow(request).to receive(:env).and_return({"HTTP_X_GITHUB_EVENT" => "fakefake"})
404
+ end
405
+
406
+ it "handles the ping event" do
407
+ expect(Lita.logger).to_not receive(:error)
408
+ expect(response).to_not receive(:write)
409
+ subject.receive(request, response)
410
+ end
411
+ end
412
+
413
+
375
414
  context "improper config" do
376
415
  before do
377
416
  allow(params).to receive(:[]).with("payload").and_return(deleted_payload)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github-commits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch Dempsey