lita-travis-announcer 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f7791db49ad0004ef4a23e9297afd0b163f34ea
4
- data.tar.gz: 32f2326e4e94e837d03be5df53b1f516918f3d0d
3
+ metadata.gz: 77e99afa00451234dde29ea2ba935c10e06d26f0
4
+ data.tar.gz: 16bb4ef73a5d71c7331d0a3f8c2258cd41198f23
5
5
  SHA512:
6
- metadata.gz: 190d7489f9d58f94e25660fb6e49e3c21cca241c81f9153c68f804860ff9557f344d1ab5b5eea56ed0142aa6250c363e29bd9ecf8277d306daef6c9268eb35f5
7
- data.tar.gz: 5fb1c98e19cd41b75da80925a968cf8e59fb9a262fb9a77521f3fa856436b040079efb6d529f7d1370f364aed22e34634a49ad1a4540069d6df8f798ec67cc6e
6
+ metadata.gz: 488f162643a7549e1ac46486e1d190cd907e47e07e92a2a7c18ed045f3454f98f6f0cf8a87721d4386ef8a9c1d33ed5ce761648970dbb83abd04c48ecb52ed10
7
+ data.tar.gz: 65f174d020b601d30f674b7bedc48f96545f0948501fc34c8adf714a3ac917f5b5a9027e9e9a4294003bd902c20e0028081d5199b0c707034c32326ec65e8a31
@@ -6,19 +6,18 @@ module Lita
6
6
 
7
7
  config :travis_room, default: 'shell'
8
8
 
9
- http.post '/travis-announcer/travis', :travis_webhook
9
+ http.post '/travis-announcer/travis', :parse_travis_webhook
10
10
 
11
- route /talk_travis/, :talk_travis
12
-
13
- def travis_webhook(request, response)
11
+ def parse_travis_webhook(request, response)
14
12
  raw_json = request.params.fetch('payload')
15
- travis_hook = Lita::TravisWebhook.new(raw_json)
16
- handle_travis_build(travis_hook)
13
+ travis_hook = Lita::TravisWebhook.from_string(raw_json)
14
+ response.write handle_travis_build(travis_hook)
17
15
  end
18
16
 
19
17
  def handle_travis_build(hook)
20
18
  announce '*Broken build!*' if hook.broken?
21
19
  announce hook.notification_string
20
+ hook.notification_string
22
21
  end
23
22
 
24
23
  def announce(message)
@@ -3,14 +3,18 @@ require 'pry'
3
3
  require 'ostruct'
4
4
 
5
5
  module Lita
6
- class TravisWebhook
7
- def initialize(plaintext)
8
- @raw_json = plaintext
9
- @parsed = JSON.load plaintext
10
- @ostruct = OpenStruct.new parsed
6
+ class TravisWebhook < OpenStruct
7
+ def initialize(parsed_json)
8
+ @parsed_json = parsed_json
9
+ @ostruct = super
11
10
  end
12
11
 
13
- attr_reader :raw_json, :parsed, :ostruct
12
+ attr_reader :parsed_json, :ostruct
13
+
14
+ def self.from_string(raw_json)
15
+ parsed = JSON.parse(raw_json)
16
+ new parsed
17
+ end
14
18
 
15
19
  def description
16
20
  status_message
@@ -33,19 +37,7 @@ module Lita
33
37
  end
34
38
 
35
39
  def keys
36
- parsed.keys
37
- end
38
-
39
- def method_missing(m, *args, &block)
40
- if ostruct.respond_to? m
41
- ostruct.send m, *args, &block
42
- else
43
- super
44
- end
45
- end
46
-
47
- def respond_to_missing?(*_args)
48
- true
40
+ parsed_json.keys
49
41
  end
50
42
  end
51
43
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-travis-announcer'
3
- spec.version = '1.0.0'
3
+ spec.version = '1.1.0'
4
4
  spec.authors = ['Daniel J. Pritchett']
5
5
  spec.email = ['dpritchett@gmail.com']
6
6
  spec.description = 'Chatops tools for announcing and deploying successful software builds'
@@ -0,0 +1,49 @@
1
+ {
2
+ "id": 375009707,
3
+ "number": "55",
4
+ "config": {
5
+ "os": "linux",
6
+ "rvm": [
7
+ "2.3.3"
8
+ ],
9
+ "dist": "trusty",
10
+ "group": "stable",
11
+ ".result": "configured",
12
+ "language": "ruby",
13
+ "services": [
14
+ "redis-server"
15
+ ],
16
+ "notifications": {
17
+ "webhooks": [
18
+ "http:\/\/bookbot.pritchettbots.com\/travis-announcer\/travis",
19
+ "http:\/\/7c7e83e9.ngrok.io\/travis-announcer\/travis"
20
+ ]
21
+ }
22
+ },
23
+ "type": "push",
24
+ "state": "passed",
25
+ "status": 0,
26
+ "result": 0,
27
+ "status_message": "Passed",
28
+ "result_message": "Passed",
29
+ "started_at": "2018-05-04T18:12:31Z",
30
+ "finished_at": "2018-05-04T18:14:52Z",
31
+ "duration": 141,
32
+ "build_url": "https:\/\/travis-ci.org\/dpritchett\/ruby-bookbot\/builds\/375009707",
33
+ "commit_id": 112084793,
34
+ "commit": "7379b6e92f7dc9328953d03d207732852c6e9401",
35
+ "base_commit": "7379b6e92f7dc9328953d03d207732852c6e9401",
36
+ "head_commit": null,
37
+ "branch": "master",
38
+ "message": "Trying out some travis magic",
39
+ "compare_url": "https:\/\/github.com\/dpritchett\/ruby-bookbot\/compare\/632250aff63e...7379b6e92f7d",
40
+ "committed_at": "2018-05-04T18:12:21Z",
41
+ "author_name": "Daniel J. Pritchett",
42
+ "author_email": "dpritchett@gmail.com",
43
+ "committer_name": "Daniel J. Pritchett",
44
+ "committer_email": "dpritchett@gmail.com",
45
+ "pull_request": false,
46
+ "pull_request_number": null,
47
+ "pull_request_title": null,
48
+ "tag": null,
49
+ "repository": {
@@ -5,34 +5,46 @@ require 'json'
5
5
  describe Lita::Handlers::TravisAnnouncer, lita_handler: true do
6
6
  let(:robot) { Lita::Robot.new(registry) }
7
7
 
8
- def load_fixture(name)
9
- path = File.join('spec', 'fixtures', "#{name}.json")
10
- as_text = open(path).readlines.join("\n")
11
-
12
- result = Lita::TravisWebhook.new(as_text)
13
- end
14
-
15
- describe 'routes' do
8
+ describe 'http routes' do
16
9
  it {
17
10
  is_expected.to route_http(:post, '/travis-announcer/travis')
18
- .to(:travis_webhook)
11
+ .to(:parse_travis_webhook)
19
12
  }
20
-
21
- #it {
22
- #is_expected.to(route('Lita play url http://zombo.com')
23
- #.to(:handle_sonos_play_url))
24
- #}
25
13
  end
26
14
 
27
- describe 'travis webhooks' do
28
- it 'should deal with the incoming json payload' do
29
- result = load_fixture('travis_success')
15
+ context 'dummy post request' do
16
+ let(:request) { double 'post request' }
17
+ let(:response) { double 'post response' }
18
+ let(:payload) { load_fixture 'travis_success' }
19
+
20
+ before do
21
+ request.stub_chain(:params, :fetch) { payload }
22
+ response.stub :write
30
23
  end
31
- end
32
24
 
33
- describe 'announcing build results' do
34
- it 'should work idk' do
35
- subject.announce 'hi there'
25
+ it 'replies to the POSTer with the parsed notification text' do
26
+ expect(response).to receive(:write).with(/ruby-bookbot/)
27
+ subject.parse_travis_webhook(request, response)
28
+ end
29
+
30
+ it 'calls :handle_travis_build' do
31
+ expect(subject).to receive(:handle_travis_build)
32
+ subject.parse_travis_webhook(request, response)
33
+ end
34
+
35
+ it 'lets shares the build info in chat' do
36
+ expect(subject).to receive(:announce)
37
+ .with(/ruby-bookbot.+some Travis magic/i)
38
+ subject.parse_travis_webhook(request, response)
39
+ end
40
+
41
+ context 'the dummy post is a failed build' do
42
+ let(:payload) { load_fixture 'travis_failure' }
43
+
44
+ it 'lets folks know about the failure in chat before pasting the link' do
45
+ expect(subject).to receive(:announce).exactly(2).times
46
+ subject.parse_travis_webhook(request, response)
47
+ end
36
48
  end
37
49
  end
38
50
  end
@@ -1,9 +1,11 @@
1
1
  require 'spec_helper'
2
- require 'pry'
2
+ require 'json'
3
3
 
4
4
  describe Lita::TravisWebhook do
5
5
  let(:input_path) { 'travis_success' }
6
- let(:json_input) { load_fixture input_path }
6
+ let(:raw_input) { load_fixture input_path }
7
+ let(:json_input) { JSON.parse raw_input }
8
+
7
9
  subject { Lita::TravisWebhook.new json_input }
8
10
 
9
11
  it 'should parse a known good response' do
@@ -15,7 +17,7 @@ describe Lita::TravisWebhook do
15
17
  expect(subject.working?).to be_truthy
16
18
  expect(subject.broken?).to be_falsey
17
19
  end
18
-
20
+
19
21
  context 'a failed build' do
20
22
  let(:input_path) { 'travis_failure' }
21
23
 
@@ -24,4 +26,37 @@ describe Lita::TravisWebhook do
24
26
  expect(subject.broken?).to be_truthy
25
27
  end
26
28
  end
29
+
30
+ describe ':notification_string' do
31
+ let(:result) { subject.notification_string }
32
+
33
+ it 'should include the build status' do
34
+ subject.stub(:description) { 'hi mom' }
35
+ expect(result).to include 'hi mom'
36
+ end
37
+
38
+ it 'should include the repo name' do
39
+ expect(result).to include 'ruby-bookbot'
40
+ end
41
+
42
+ it 'should include the compare URL for the commit' do
43
+ expect(result).to include 'https://github.com/dpritchett/ruby-bookbot/compare/632250aff63e...7379b6e92f7d'
44
+ end
45
+
46
+ context 'a bad build' do
47
+ let(:input_path) { 'travis_failure' }
48
+
49
+ it 'should include the compare URL for the commit' do
50
+ expect(result).to include 'https://github.com/dpritchett/ruby-bookbot/commit/64794d01af72'
51
+ end
52
+ end
53
+
54
+ context 'malformed input' do
55
+ let(:input_path) { 'travis_malformed' }
56
+
57
+ it 'throws an error when parsing' do
58
+ expect { subject.description }.to raise_error JSON::ParserError
59
+ end
60
+ end
61
+ end
27
62
  end
@@ -8,5 +8,5 @@ Lita.version_3_compatibility_mode = false
8
8
  # load a webhook fixture from a JSON file
9
9
  def load_fixture(name)
10
10
  path = File.join('spec', 'fixtures', "#{name}.json")
11
- open(path).readlines.join("\n")
11
+ open(path).readlines.join("\n")
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-travis-announcer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Pritchett
@@ -113,6 +113,7 @@ files:
113
113
  - lita-travis-announcer.gemspec
114
114
  - locales/en.yml
115
115
  - spec/fixtures/travis_failure.json
116
+ - spec/fixtures/travis_malformed.json
116
117
  - spec/fixtures/travis_success.json
117
118
  - spec/lita/handlers/travis_announcer_spec.rb
118
119
  - spec/lita/travis_webhook_spec.rb
@@ -146,6 +147,7 @@ specification_version: 4
146
147
  summary: Chatops tools for announcing and deploying successful software builds
147
148
  test_files:
148
149
  - spec/fixtures/travis_failure.json
150
+ - spec/fixtures/travis_malformed.json
149
151
  - spec/fixtures/travis_success.json
150
152
  - spec/lita/handlers/travis_announcer_spec.rb
151
153
  - spec/lita/travis_webhook_spec.rb