lita-travis-announcer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb372bd9f0898488d345c0f611ad1296517ca2d1
4
+ data.tar.gz: d1c57584eec5ef890da5ec7d84b03edf7518c612
5
+ SHA512:
6
+ metadata.gz: 49476b3f734945f92513f67728502cd974f2a27d5de86fdbdc20946fb02134c6a270c190487a90e9964381b15c02896e2d8baf1519bbf0e6325a5e8a2da488b1
7
+ data.tar.gz: 16454255fb69e3c3815a7fa86ea8490360a9179fda9d92f0a2fc0982afadd7180a9a226ad8775af68073b6b779c906cf13e9a352e84dc68010e3513e8846af9e
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # vimmitude
20
+ *.swp
21
+ *.swo
22
+ *~
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # lita-travis-announcer
2
+
3
+ [![Build Status](https://travis-ci.org/dpritchett/lita-travis-announcer.png?branch=master)](https://travis-ci.org/dpritchett/lita-travis-announcer)
4
+
5
+ TODO: Add a description of the plugin.
6
+
7
+ ## Installation
8
+
9
+ Add lita-travis-announcer to your Lita instance's Gemfile:
10
+
11
+ ``` ruby
12
+ gem "lita-travis-announcer"
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ TODO: Describe any configuration attributes the plugin exposes.
18
+
19
+ ## Usage
20
+
21
+ TODO: Describe the plugin's features and how to use them.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,13 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/travis_announcer"
8
+ require "lita/travis_webhook"
9
+
10
+ Lita::Handlers::TravisAnnouncer.template_root File.expand_path(
11
+ File.join("..", "..", "templates"),
12
+ __FILE__
13
+ )
Binary file
@@ -0,0 +1,36 @@
1
+ require 'pry'
2
+
3
+ module Lita
4
+ module Handlers
5
+ class TravisAnnouncer < Handler
6
+
7
+ config :travis_room, default: '#general'
8
+
9
+ http.post '/travis-announcer/travis', :travis_webhook
10
+
11
+ route /talk_travis/, :talk_travis
12
+
13
+ def travis_webhook(request, response)
14
+ raw_json = request.params.fetch('payload')
15
+ travis_hook = Lita::TravisWebhook.new(raw_json)
16
+ handle_travis_build(travis_hook)
17
+ end
18
+
19
+ def handle_travis_build(hook)
20
+ if hook.working?
21
+ announce "we did it, twitch!"
22
+ else
23
+ announce "it was a bad build."
24
+ end
25
+ end
26
+
27
+ def announce(message)
28
+ msg = "Received announcement: #{message}"
29
+ puts msg
30
+ robot.send_message Source.new(room: '#general'), msg
31
+ end
32
+
33
+ Lita.register_handler(self)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+ require 'pry'
3
+ require 'ostruct'
4
+
5
+ module Lita
6
+ class TravisWebhook
7
+ def initialize(plaintext)
8
+ @raw_json = plaintext
9
+ @parsed = JSON.load plaintext
10
+ @ostruct = OpenStruct.new parsed
11
+ end
12
+
13
+ attr_reader :raw_json, :parsed, :ostruct
14
+
15
+ def description
16
+ status_message
17
+ end
18
+
19
+ def working?
20
+ %w[Pending Passed Fixed].include? status_message
21
+ end
22
+
23
+ def broken?
24
+ !working?
25
+ end
26
+
27
+ def keys
28
+ parsed.keys
29
+ end
30
+
31
+ def method_missing(m, *args, &block)
32
+ if ostruct.respond_to? m
33
+ ostruct.send m, *args, &block
34
+ else
35
+ super
36
+ end
37
+ end
38
+
39
+ def respond_to_missing?(*_args)
40
+ true
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'lita-travis-announcer'
3
+ spec.version = '0.1.0'
4
+ spec.authors = ['Daniel J. Pritchett']
5
+ spec.email = ['dpritchett@gmail.com']
6
+ spec.description = 'Chatops tools for announcing and deploying successful software builds'
7
+ spec.summary = 'Chatops tools for announcing and deploying successful software builds'
8
+ spec.homepage = 'https://github.com/dpritchett/lita-travis-announcer'
9
+ spec.license = 'MIT'
10
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_runtime_dependency 'lita', '>= 4.7'
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.3'
20
+ spec.add_development_dependency 'pry-byebug'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rack-test'
23
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
24
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ travis-announcer:
@@ -0,0 +1,95 @@
1
+ {
2
+ "id": 375024421,
3
+ "number": "56",
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": "failed",
25
+ "status": 1,
26
+ "result": 1,
27
+ "status_message": "Failed",
28
+ "result_message": "Failed",
29
+ "started_at": "2018-05-04T18:47:46Z",
30
+ "finished_at": "2018-05-04T18:49:41Z",
31
+ "duration": 115,
32
+ "build_url": "https:\/\/travis-ci.org\/dpritchett\/ruby-bookbot\/builds\/375024421",
33
+ "commit_id": 112089127,
34
+ "commit": "64794d01af723add0f895383c1fa67cdfb865da3",
35
+ "base_commit": "64794d01af723add0f895383c1fa67cdfb865da3",
36
+ "head_commit": null,
37
+ "branch": "djp\/broken-build-for-travis",
38
+ "message": "purposefully breaking the build for a travis fixture generation",
39
+ "compare_url": "https:\/\/github.com\/dpritchett\/ruby-bookbot\/commit\/64794d01af72",
40
+ "committed_at": "2018-05-04T18:47:26Z",
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": {
50
+ "id": 12787622,
51
+ "name": "ruby-bookbot",
52
+ "owner_name": "dpritchett",
53
+ "url": null
54
+ },
55
+ "matrix": [
56
+ {
57
+ "id": 375024422,
58
+ "repository_id": 12787622,
59
+ "parent_id": 375024421,
60
+ "number": "56.1",
61
+ "state": "failed",
62
+ "config": {
63
+ "os": "linux",
64
+ "rvm": "2.3.3",
65
+ "dist": "trusty",
66
+ "group": "stable",
67
+ ".result": "configured",
68
+ "language": "ruby",
69
+ "services": [
70
+ "redis-server"
71
+ ],
72
+ "notifications": {
73
+ "webhooks": [
74
+ "http:\/\/bookbot.pritchettbots.com\/travis-announcer\/travis",
75
+ "http:\/\/7c7e83e9.ngrok.io\/travis-announcer\/travis"
76
+ ]
77
+ }
78
+ },
79
+ "status": 1,
80
+ "result": 1,
81
+ "commit": "64794d01af723add0f895383c1fa67cdfb865da3",
82
+ "branch": "djp\/broken-build-for-travis",
83
+ "message": "purposefully breaking the build for a travis fixture generation",
84
+ "compare_url": "https:\/\/github.com\/dpritchett\/ruby-bookbot\/commit\/64794d01af72",
85
+ "started_at": null,
86
+ "finished_at": null,
87
+ "committed_at": "2018-05-04T18:47:26Z",
88
+ "author_name": "Daniel J. Pritchett",
89
+ "author_email": "dpritchett@gmail.com",
90
+ "committer_name": "Daniel J. Pritchett",
91
+ "committer_email": "dpritchett@gmail.com",
92
+ "allow_failure": false
93
+ }
94
+ ]
95
+ }
@@ -0,0 +1,95 @@
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": {
50
+ "id": 12787622,
51
+ "name": "ruby-bookbot",
52
+ "owner_name": "dpritchett",
53
+ "url": null
54
+ },
55
+ "matrix": [
56
+ {
57
+ "id": 375009708,
58
+ "repository_id": 12787622,
59
+ "parent_id": 375009707,
60
+ "number": "55.1",
61
+ "state": "passed",
62
+ "config": {
63
+ "os": "linux",
64
+ "rvm": "2.3.3",
65
+ "dist": "trusty",
66
+ "group": "stable",
67
+ ".result": "configured",
68
+ "language": "ruby",
69
+ "services": [
70
+ "redis-server"
71
+ ],
72
+ "notifications": {
73
+ "webhooks": [
74
+ "http:\/\/bookbot.pritchettbots.com\/travis-announcer\/travis",
75
+ "http:\/\/7c7e83e9.ngrok.io\/travis-announcer\/travis"
76
+ ]
77
+ }
78
+ },
79
+ "status": 0,
80
+ "result": 0,
81
+ "commit": "7379b6e92f7dc9328953d03d207732852c6e9401",
82
+ "branch": "master",
83
+ "message": "Trying out some travis magic",
84
+ "compare_url": "https:\/\/github.com\/dpritchett\/ruby-bookbot\/compare\/632250aff63e...7379b6e92f7d",
85
+ "started_at": null,
86
+ "finished_at": null,
87
+ "committed_at": "2018-05-04T18:12:21Z",
88
+ "author_name": "Daniel J. Pritchett",
89
+ "author_email": "dpritchett@gmail.com",
90
+ "committer_name": "Daniel J. Pritchett",
91
+ "committer_email": "dpritchett@gmail.com",
92
+ "allow_failure": false
93
+ }
94
+ ]
95
+ }
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+ require 'json'
4
+
5
+ describe Lita::Handlers::TravisAnnouncer, lita_handler: true do
6
+ let(:robot) { Lita::Robot.new(registry) }
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
16
+ it {
17
+ is_expected.to route_http(:post, '/travis-announcer/travis')
18
+ .to(:travis_webhook)
19
+ }
20
+
21
+ #it {
22
+ #is_expected.to(route('Lita play url http://zombo.com')
23
+ #.to(:handle_sonos_play_url))
24
+ #}
25
+ end
26
+
27
+ describe 'travis webhooks' do
28
+ it 'should deal with the incoming json payload' do
29
+ result = load_fixture('travis_success')
30
+ end
31
+ end
32
+
33
+ describe 'announcing build results' do
34
+ it 'should work idk' do
35
+ subject.announce 'hi there'
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe Lita::TravisWebhook do
5
+ let(:input_path) { 'travis_success' }
6
+ let(:json_input) { load_fixture input_path }
7
+ subject { Lita::TravisWebhook.new json_input }
8
+
9
+ it 'should parse a known good response' do
10
+ result = subject.author_name
11
+ expect(result).to match(/Daniel.+Pritchett/i)
12
+ end
13
+
14
+ it 'should acknowledge when the build was successful' do
15
+ expect(subject.working?).to be_truthy
16
+ expect(subject.broken?).to be_falsey
17
+ end
18
+
19
+ context 'a failed build' do
20
+ let(:input_path) { 'travis_failure' }
21
+
22
+ it 'should acknowledge when the build failed' do
23
+ expect(subject.working?).to be_falsey
24
+ expect(subject.broken?).to be_truthy
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ require "lita-travis-announcer"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
7
+
8
+ # load a webhook fixture from a JSON file
9
+ def load_fixture(name)
10
+ path = File.join('spec', 'fixtures', "#{name}.json")
11
+ open(path).readlines.join("\n")
12
+ end
File without changes
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-travis-announcer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel J. Pritchett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ description: Chatops tools for announcing and deploying successful software builds
98
+ email:
99
+ - dpritchett@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - lib/lita-travis-announcer.rb
110
+ - lib/lita/.travis_webhook.rb.swp
111
+ - lib/lita/handlers/travis_announcer.rb
112
+ - lib/lita/travis_webhook.rb
113
+ - lita-travis-announcer.gemspec
114
+ - locales/en.yml
115
+ - spec/fixtures/travis_failure.json
116
+ - spec/fixtures/travis_success.json
117
+ - spec/lita/handlers/travis_announcer_spec.rb
118
+ - spec/lita/travis_webhook_spec.rb
119
+ - spec/spec_helper.rb
120
+ - templates/.gitkeep
121
+ homepage: https://github.com/dpritchett/lita-travis-announcer
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ lita_plugin_type: handler
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Chatops tools for announcing and deploying successful software builds
146
+ test_files:
147
+ - spec/fixtures/travis_failure.json
148
+ - spec/fixtures/travis_success.json
149
+ - spec/lita/handlers/travis_announcer_spec.rb
150
+ - spec/lita/travis_webhook_spec.rb
151
+ - spec/spec_helper.rb