lita-travis 0.0.1

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: f56859d671f1c39ce38af13a79a5b49c8613db23
4
+ data.tar.gz: 9546917a0eb4da13531af82ddfea9b07720cf8e8
5
+ SHA512:
6
+ metadata.gz: 51d47d32dcfc097c68f1268a902713f60b65bd164cc0166b36623d0258e96ac78928b262e94a73b9e2f057339c465e885f5811a9c471a173a6b3d021a38bb250
7
+ data.tar.gz: 5ac1d6bac9da631860f8e2940f9fb622449b0ed4e377d4ad4495d6779a9e8dfdb29083da55b85d12293276691e0b2834180a087330b880d1cb22a02068712621
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ notifications:
8
+ webhooks:
9
+ urls:
10
+ - https://lita-freenode.herokuapp.com/travis
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Jimmy Cuadra
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # lita-travis
2
+
3
+ [![Build Status](https://travis-ci.org/jimmycuadra/lita-travis.png?branch=master)](https://travis-ci.org/jimmycuadra/lita-travis)
4
+ [![Code Climate](https://codeclimate.com/github/jimmycuadra/lita-travis.png)](https://codeclimate.com/github/jimmycuadra/lita-travis)
5
+ [![Coverage Status](https://coveralls.io/repos/jimmycuadra/lita-travis/badge.png)](https://coveralls.io/r/jimmycuadra/lita-travis)
6
+
7
+ **lita-travis** is a [Lita](https://github.com/jimmycuadra/lita) handler for receiving notifications from [Travis CI](https://travis-ci.org/). When Travis is configured to post notifications to your Lita instance, Lita will announce the results of project builds in chat rooms of your choice.
8
+
9
+ ## Installation
10
+
11
+ Add lita-travis to your Lita instance's Gemfile:
12
+
13
+ ``` ruby
14
+ gem "lita-travis"
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ ### Required attributes
20
+
21
+ * `token` (String) - Your Travis CI secret token, found on your profile page on the Travis website. Default: `nil`.
22
+
23
+ ### Optional attributes
24
+
25
+ * `repos` (Hash) - A map of repositories to allow notifications for and the chat rooms to post them in. The keys should be strings in the format "github_username/repository_name" and the values should be either a string room name or an array of string room names. Default: `{}`.
26
+
27
+ ### Example
28
+
29
+ ``` ruby
30
+ Lita.configure do |config|
31
+ config.handlers.travis.token = "abcdefg123"
32
+ config.handlers.travis.repos = {
33
+ "username/repo1" => "#someroom",
34
+ "username/repo2" => ["#someroom", "#someotherroom"]
35
+ }
36
+ end
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ Set the configuration attributes as described in the section above, and add the following to the `.travis.yml` file for each project you want to get build notifications for:
42
+
43
+ ``` yml
44
+ notifications:
45
+ webhooks:
46
+ urls:
47
+ - http://example.com/travis
48
+ ```
49
+
50
+ Replace "example.com" with the hostname where your instance of Lita is running.
51
+
52
+ See Travis CI's [documentation on notifications](http://about.travis-ci.org/docs/user/notifications/) for additional options.
53
+
54
+ ## License
55
+
56
+ [MIT](http://opensource.org/licenses/MIT)
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 @@
1
+ require "lita/handlers/travis"
@@ -0,0 +1,90 @@
1
+ require "digest"
2
+
3
+ require "lita"
4
+
5
+ module Lita
6
+ module Handlers
7
+ # Provides Travis CI webhooks for Lita.
8
+ class Travis < Handler
9
+ def self.default_config(config)
10
+ config.token = nil
11
+ config.repos = {}
12
+ end
13
+
14
+ http.post "/travis", :receive
15
+
16
+ def receive(request, response)
17
+ data = parse_payload(request.params["payload"]) or return
18
+ repo = get_repo(data)
19
+ validate_repo(repo, request.env["HTTP_AUTHORIZATION"]) or return
20
+ notify_rooms(repo, data)
21
+ end
22
+
23
+ private
24
+
25
+ def parse_payload(json)
26
+ begin
27
+ MultiJson.load(json)
28
+ rescue MultiJson::LoadError => e
29
+ Lita.logger.error(
30
+ "Could not parse JSON payload from Travis CI: #{e.message}"
31
+ )
32
+ return
33
+ end
34
+ end
35
+
36
+ def get_repo(pl)
37
+ "#{pl["repository"]["owner_name"]}/#{pl["repository"]["name"]}"
38
+ end
39
+
40
+ def notify_rooms(repo, data)
41
+ rooms = rooms_for_repo(repo) or return
42
+ message = <<-MSG.chomp
43
+ [Travis CI] #{repo}: #{data["status_message"]} at #{data["commit"]} \
44
+ - #{data["compare_url"]}
45
+ MSG
46
+
47
+ rooms.each do |room|
48
+ target = Source.new(nil, room)
49
+ robot.send_message(target, message)
50
+ end
51
+ end
52
+
53
+ def rooms_for_repo(repo)
54
+ rooms = Lita.config.handlers.travis.repos[repo]
55
+
56
+ if rooms
57
+ Array(rooms)
58
+ else
59
+ Lita.logger.warn <<-WARNING.chomp
60
+ Notification from Travis CI for unconfigured project: #{repo}
61
+ WARNING
62
+ return
63
+ end
64
+ end
65
+
66
+ def validate_repo(repo, auth_hash)
67
+ token = Lita.config.handlers.travis.token
68
+
69
+ unless token
70
+ Lita.logger.warn <<-WARNING.chomp
71
+ Notification from Travis CI could not be validated because \
72
+ Lita.config.handlers.token is not set.
73
+ WARNING
74
+ return
75
+ end
76
+
77
+ unless Digest::SHA2.hexdigest("#{repo}#{token}") == auth_hash
78
+ Lita.logger.warn <<-WARNING.chomp
79
+ Notification from Travis CI did not pass authentication.
80
+ WARNING
81
+ return
82
+ end
83
+
84
+ true
85
+ end
86
+ end
87
+
88
+ Lita.register_handler(Travis)
89
+ end
90
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-travis"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Jimmy Cuadra"]
5
+ spec.email = ["jimmy@jimmycuadra.com"]
6
+ spec.description = %q{A Lita handler for receiving notifications from Travis CI.}
7
+ spec.summary = %q{A Lita handler for receiving notifications from Travis CI.}
8
+ spec.homepage = "https://github.com/jimmycuadra/lita-travis"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.3"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rspec", ">= 2.14"
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "coveralls"
23
+ end
@@ -0,0 +1,124 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Travis, lita_handler: true do
4
+ it { routes_http(:post, "/travis").to(:receive) }
5
+
6
+ describe ".default_config" do
7
+ it "sets token to nil" do
8
+ expect(Lita.config.handlers.travis.token).to be_nil
9
+ end
10
+
11
+ it "sets repos to an empty hash" do
12
+ expect(Lita.config.handlers.travis.repos).to eq({})
13
+ end
14
+ end
15
+
16
+ describe "#receive" do
17
+ let(:request) do
18
+ request = double("Rack::Request")
19
+ allow(request).to receive(:params).and_return(params)
20
+ request
21
+ end
22
+
23
+ let(:response) { Rack::Response.new }
24
+
25
+ let(:params) { double("Hash") }
26
+
27
+ let(:valid_env) do
28
+ env = double("Hash")
29
+ allow(env).to receive(:[]).with("HTTP_AUTHORIZATION").and_return(
30
+ Digest::SHA2.hexdigest("foo/barabc123")
31
+ )
32
+ env
33
+ end
34
+
35
+ let(:invalid_env) do
36
+ env = double("Hash")
37
+ allow(env).to receive(:[]).with("HTTP_AUTHORIZATION").and_return("foo")
38
+ env
39
+ end
40
+
41
+ let(:valid_payload) do
42
+ <<-JSON.chomp
43
+ {
44
+ "status_message": "Passed",
45
+ "commit": "abcdefg",
46
+ "compare_url": "https://example.com/",
47
+ "repository": {
48
+ "name": "bar",
49
+ "owner_name": "foo"
50
+ }
51
+ }
52
+ JSON
53
+ end
54
+
55
+ context "happy path" do
56
+ before do
57
+ Lita.config.handlers.travis.token = "abc123"
58
+ Lita.config.handlers.travis.repos["foo/bar"] = "#baz"
59
+ allow(request).to receive(:env).and_return(valid_env)
60
+ allow(params).to receive(:[]).with("payload").and_return(valid_payload)
61
+ end
62
+
63
+ it "sends a notification message to the applicable rooms" do
64
+ expect(robot).to receive(:send_message) do |target, message|
65
+ expect(target.room).to eq("#baz")
66
+ expect(message).to include("[Travis CI]")
67
+ end
68
+ subject.receive(request, response)
69
+ end
70
+ end
71
+
72
+ context "with a missing token" do
73
+ before do
74
+ Lita.config.handlers.travis.repos["foo/bar"] = "#baz"
75
+ allow(request).to receive(:env).and_return(valid_env)
76
+ allow(params).to receive(:[]).with("payload").and_return(valid_payload)
77
+ end
78
+
79
+ it "logs a warning that the token is not set" do
80
+ expect(Lita.logger).to receive(:warn) do |warning|
81
+ expect(warning).to include("token is not set")
82
+ end
83
+ subject.receive(request, response)
84
+ end
85
+ end
86
+
87
+ context "with an invalid authorization header" do
88
+ before do
89
+ Lita.config.handlers.travis.token = "abc123"
90
+ Lita.config.handlers.travis.repos["foo/bar"] = "#baz"
91
+ allow(request).to receive(:env).and_return(invalid_env)
92
+ allow(params).to receive(:[]).with("payload").and_return(valid_payload)
93
+ end
94
+
95
+ it "logs a warning that the request was invalid" do
96
+ expect(Lita.logger).to receive(:warn) do |warning|
97
+ expect(warning).to include("did not pass authentication")
98
+ end
99
+ subject.receive(request, response)
100
+ end
101
+ end
102
+
103
+ context "without setting a value for the repo in config.repos" do
104
+ before do
105
+ Lita.config.handlers.travis.token = "abc123"
106
+ allow(request).to receive(:env).and_return(valid_env)
107
+ allow(params).to receive(:[]).with("payload").and_return(valid_payload)
108
+ end
109
+
110
+ it "logs a warning that the request was invalid" do
111
+ expect(Lita.logger).to receive(:warn) do |warning|
112
+ expect(warning).to include("unconfigured project")
113
+ end
114
+ subject.receive(request, response)
115
+ end
116
+ end
117
+
118
+ it "logs an error if the payload cannot be parsed" do
119
+ allow(params).to receive(:[]).with("payload").and_return("not json")
120
+ expect(Lita.logger).to receive(:error)
121
+ subject.receive(request, response)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,10 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-travis"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-travis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jimmy Cuadra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-26 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: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
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: rake
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
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: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Lita handler for receiving notifications from Travis CI.
98
+ email:
99
+ - jimmy@jimmycuadra.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - lib/lita-travis.rb
111
+ - lib/lita/handlers/travis.rb
112
+ - lita-travis.gemspec
113
+ - spec/lita/handlers/travis_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: https://github.com/jimmycuadra/lita-travis
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: A Lita handler for receiving notifications from Travis CI.
139
+ test_files:
140
+ - spec/lita/handlers/travis_spec.rb
141
+ - spec/spec_helper.rb
142
+ has_rdoc: