lita-bitbucket-wehbhook 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +4 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +19 -0
- data/Rakefile +6 -0
- data/lib/lita-bitbucket-wehbhook.rb +1 -0
- data/lib/lita/handlers/bitbucket_wehbhook.rb +51 -0
- data/lita-bitbucket-wehbhook.gemspec +24 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/bitbucket_wehbhook_spec.rb +115 -0
- data/spec/spec_helper.rb +10 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 178c2f98ae87e4406d3c4081c88048e662f06cd0
|
4
|
+
data.tar.gz: 9c27efb584fce64d8aea9ad285a434052034ad8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbb199b4ca9552b435e7b83095be779a7fcb029970fca4b9b0b12555584824054e6138c1d0caa880652d52231bb8bbf7131650cce95f2a5ab9ff88221ff7fd3b
|
7
|
+
data.tar.gz: 84ecd15e33aff4bb0cd61300046d2268a057d3f66c978c2baafb003d8a84e003c58ef61c238745bd48f1a8b71d443b572bfb8d27f4a3cfe1bee95ea57d9300f0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Shuky Dvir
|
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,19 @@
|
|
1
|
+
# lita-bitbucket-wehbhook
|
2
|
+
|
3
|
+
A Lita handler to send Bitbucket.org commit messages to the chat.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add lita-bitbucket-wehbhook to your Lita instance's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "lita-bitbucket-wehbhook"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
TODO: Describe any configuration attributes the plugin exposes.
|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "lita/handlers/bitbucket_wehbhook"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
module Handlers
|
5
|
+
class BitbucketWehbhook < Handler
|
6
|
+
|
7
|
+
http.post "/bitbucket-webhook", :receive
|
8
|
+
|
9
|
+
def receive(request, response)
|
10
|
+
json_data = parse_json(request.params['payload']) or return
|
11
|
+
message = format_message(json_data)
|
12
|
+
rooms = Lita.config.adapter.rooms
|
13
|
+
rooms.each do |room|
|
14
|
+
target = Source.new(room: room)
|
15
|
+
robot.send_message(target, message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def parse_json(json)
|
22
|
+
MultiJson.load(json)
|
23
|
+
rescue MultiJson::LoadError => e
|
24
|
+
Lita.logger.error("Could not parse JSON from Bitbucket: #{e.message}")
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
def format_message(json)
|
29
|
+
branches = Hash.new
|
30
|
+
|
31
|
+
json['commits'].each do |c|
|
32
|
+
branches[c['branch']] = "On branch '#{c['branch']}' \n" if branches[c['branch']].nil?
|
33
|
+
branches[c['branch']] << "- #{c['message']} (#{json['canon_url'] + json['repository']['absolute_url'] + 'commits/' + c['node']})}\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
message = "[Bitbucket] #{json['commits'].first['author']} committed to #{branches.size} branches at #{json['canon_url'] + json['repository']['absolute_url']}\n"
|
37
|
+
branches.each { |b| message += b[1] }
|
38
|
+
message
|
39
|
+
rescue
|
40
|
+
Lita.logger.warn "Error formatting message. JSON: #{json}"
|
41
|
+
return
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Lita.register_handler(BitbucketWehbhook)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Lita.load_locales Dir[File.expand_path(
|
50
|
+
File.join("..", "..", "..", "..", "locales", "*.yml"), __FILE__
|
51
|
+
)]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-bitbucket-wehbhook"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Josh Dvir"]
|
5
|
+
spec.email = ["shuky.dvir@gmail.com"]
|
6
|
+
spec.description = %q{A Lita handler to send Bitbucket.org commit messages to the chat.}
|
7
|
+
spec.summary = %q{A Lita handler to send Bitbucket.org commit messages to the chat.}
|
8
|
+
spec.homepage = ""
|
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", ">= 3.0"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
|
22
|
+
spec.add_development_dependency "simplecov"
|
23
|
+
spec.add_development_dependency "coveralls"
|
24
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::BitbucketWehbhook, lita_handler: true do
|
4
|
+
it { routes_http(:post, "/bitbucket-webhook").to(:receive) }
|
5
|
+
|
6
|
+
describe "#receive" do
|
7
|
+
let(:request) do
|
8
|
+
request = double("Rack::Request")
|
9
|
+
allow(request).to receive(:params).and_return(params)
|
10
|
+
request
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:response) { Rack::Response.new }
|
14
|
+
|
15
|
+
let(:params) { }
|
16
|
+
|
17
|
+
let(:json) do
|
18
|
+
<<-JSON.chomp
|
19
|
+
{
|
20
|
+
"canon_url": "https://bitbucket.org",
|
21
|
+
"commits": [
|
22
|
+
{
|
23
|
+
"author": "josh",
|
24
|
+
"branch": "master",
|
25
|
+
"files": [
|
26
|
+
{
|
27
|
+
"file": "foo.py",
|
28
|
+
"type": "modified"
|
29
|
+
}
|
30
|
+
],
|
31
|
+
"message": "Added some more things to foo1.py",
|
32
|
+
"node": "620ade18607a",
|
33
|
+
"parents": [
|
34
|
+
"702c70160afc"
|
35
|
+
],
|
36
|
+
"raw_author": "Josh Bertrand <josh@somedomain.com>",
|
37
|
+
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
|
38
|
+
"revision": null,
|
39
|
+
"size": -1,
|
40
|
+
"timestamp": "2012-05-30 05:58:56",
|
41
|
+
"utctimestamp": "2012-05-30 03:58:56+00:00"
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"author": "josh",
|
45
|
+
"branch": "develop",
|
46
|
+
"files": [
|
47
|
+
{
|
48
|
+
"file": "somefile.py",
|
49
|
+
"type": "modified"
|
50
|
+
}
|
51
|
+
],
|
52
|
+
"message": "Added some more things to somefile.py",
|
53
|
+
"node": "620ade18607a",
|
54
|
+
"parents": [
|
55
|
+
"702c70160afc"
|
56
|
+
],
|
57
|
+
"raw_author": "Josh Bertrand <josh@somedomain.com>",
|
58
|
+
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
|
59
|
+
"revision": null,
|
60
|
+
"size": -1,
|
61
|
+
"timestamp": "2012-05-30 05:58:56",
|
62
|
+
"utctimestamp": "2012-05-30 03:58:56+00:00"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"author": "josh",
|
66
|
+
"branch": "master",
|
67
|
+
"files": [
|
68
|
+
{
|
69
|
+
"file": "bar.py",
|
70
|
+
"type": "modified"
|
71
|
+
}
|
72
|
+
],
|
73
|
+
"message": "Added some more things to bar2.py",
|
74
|
+
"node": "620ade18607a",
|
75
|
+
"parents": [
|
76
|
+
"702c70160afc"
|
77
|
+
],
|
78
|
+
"raw_author": "Josh Bertrand <josh@somedomain.com>",
|
79
|
+
"raw_node": "620ade18607ac42d872b568bb92acaa9a28620e9",
|
80
|
+
"revision": null,
|
81
|
+
"size": -1,
|
82
|
+
"timestamp": "2012-05-30 05:58:56",
|
83
|
+
"utctimestamp": "2012-05-30 03:58:56+00:00"
|
84
|
+
}
|
85
|
+
],
|
86
|
+
"repository": {
|
87
|
+
"absolute_url": "/josh/project-x/",
|
88
|
+
"fork": false,
|
89
|
+
"is_private": true,
|
90
|
+
"name": "Project X",
|
91
|
+
"owner": "josh",
|
92
|
+
"scm": "git",
|
93
|
+
"slug": "project-x",
|
94
|
+
"website": "https://bitbucket.org/"
|
95
|
+
},
|
96
|
+
"user": "josh"
|
97
|
+
}
|
98
|
+
JSON
|
99
|
+
end
|
100
|
+
|
101
|
+
context "bad json" do
|
102
|
+
before do
|
103
|
+
allow_message_expectations_on_nil
|
104
|
+
allow(params).to receive(:[]).with("payload").and_return("yaaaaaaiiii")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "sends a notification message to the chat of a broken json" do
|
108
|
+
expect(Lita.logger).to receive(:error) do |error|
|
109
|
+
expect(error).to include("Could not parse JSON from Bitbucket")
|
110
|
+
end
|
111
|
+
subject.receive(request, response)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -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-bitbucket-wehbhook"
|
10
|
+
require "lita/rspec"
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-bitbucket-wehbhook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Dvir
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-28 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: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
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: 3.0.0.beta2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0.beta2
|
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 to send Bitbucket.org commit messages to the chat.
|
98
|
+
email:
|
99
|
+
- shuky.dvir@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/lita-bitbucket-wehbhook.rb
|
112
|
+
- lib/lita/handlers/bitbucket_wehbhook.rb
|
113
|
+
- lita-bitbucket-wehbhook.gemspec
|
114
|
+
- locales/en.yml
|
115
|
+
- spec/lita/handlers/bitbucket_wehbhook_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
homepage: ''
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
lita_plugin_type: handler
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.1.10
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: A Lita handler to send Bitbucket.org commit messages to the chat.
|
142
|
+
test_files:
|
143
|
+
- spec/lita/handlers/bitbucket_wehbhook_spec.rb
|
144
|
+
- spec/spec_helper.rb
|