lita-gitlab-ci-hipchat 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/lib/lita-gitlab-ci-hipchat.rb +11 -0
- data/lib/lita/gitlab_ci/author.rb +15 -0
- data/lib/lita/gitlab_ci/build_message.rb +50 -0
- data/lib/lita/gitlab_ci/commit.rb +35 -0
- data/lib/lita/handlers/gitlab_ci_hipchat.rb +28 -0
- data/lita-gitlab-ci-hipchat.gemspec +26 -0
- data/locales/en.yml +4 -0
- data/spec/fabricators/gitlabci_data_fabricator.rb +77 -0
- data/spec/lita/gitlab_ci/author_spec.rb +15 -0
- data/spec/lita/gitlab_ci/build_message_spec.rb +110 -0
- data/spec/lita/gitlab_ci/commit_spec.rb +61 -0
- data/spec/lita/handlers/gitlab_ci_hipchat_spec.rb +37 -0
- data/spec/spec_helper.rb +11 -0
- metadata +184 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68771e4b40167dc8b7215cb195191e7c3e48c3d0
|
4
|
+
data.tar.gz: f647c80d7522bfdabd6914a76bedaaac66c717ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27b821eb606b90cf73648f855629374362e922f01ab51c0342276c04403df45d979a0f9c07709c75e4bf30f5d11b9ec034bbc016e33bb1e119b8deaa25b95c23
|
7
|
+
data.tar.gz: e2cc04c68c106b3bdd8f58ea3606173d9c3b5518c3fb1a007de02569e0dfc99b7d360099eab172e4ad751824c0d7cf047c548a6b84d30ddfc196a34ad953c52d
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Loïc Guitaut
|
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,34 @@
|
|
1
|
+
# lita-gitlab-ci-hipchat
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/Flink/lita-gitlab-ci-hipchat.svg?branch=develop)](https://travis-ci.org/Flink/lita-gitlab-ci-hipchat) [![Coverage Status](https://coveralls.io/repos/Flink/lita-gitlab-ci-hipchat/badge.png?branch=develop)](https://coveralls.io/r/Flink/lita-gitlab-ci-hipchat?branch=develop) [![Code Climate](https://codeclimate.com/github/Flink/lita-gitlab-ci-hipchat/badges/gpa.svg)](https://codeclimate.com/github/Flink/lita-gitlab-ci-hipchat)
|
4
|
+
|
5
|
+
Receive and display nicely web hooks from GitLab CI in HipChat.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add lita-gitlab-ci-hipchat to your Lita instance's Gemfile:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem 'lita-gitlab-ci-hipchat'
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Lita.configure do |config|
|
20
|
+
# The API token for your bot’s user
|
21
|
+
config.handlers.gitlab_ci_hipchat.api_token = 'token'
|
22
|
+
# The room to be notified (HipChat name, not JID)
|
23
|
+
config.handlers.gitlab_ci_hipchat.room = 'my_room'
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
This handler add a HTTP route at `/gitlab-ci`. So you have to add a web
|
30
|
+
hook pointing to that URL (http://lita-bot.tld/gitlab-ci).
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require 'hipchat'
|
8
|
+
require 'lita/gitlab_ci/author'
|
9
|
+
require 'lita/gitlab_ci/commit'
|
10
|
+
require 'lita/gitlab_ci/build_message'
|
11
|
+
require "lita/handlers/gitlab_ci_hipchat"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Lita
|
2
|
+
module GitlabCi
|
3
|
+
class BuildMessage
|
4
|
+
attr_reader :hipchat, :data
|
5
|
+
|
6
|
+
def initialize(hipchat, data)
|
7
|
+
@hipchat = hipchat
|
8
|
+
@data = OpenStruct.new(data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def color
|
12
|
+
data.build_status == 'success' ? 'green' : 'red'
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
[build_header, build_commits].join
|
17
|
+
end
|
18
|
+
|
19
|
+
def send_to_hipchat!
|
20
|
+
hipchat.send('lita', to_s, color: color)
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_header
|
24
|
+
"<p>Build for #{ project_infos } #{ project_branch }: #{ project_status }</p>"
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_commits
|
28
|
+
commits.map do |commit|
|
29
|
+
Commit.new(commit)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def commits
|
34
|
+
data.push_data['commits'].reverse
|
35
|
+
end
|
36
|
+
|
37
|
+
def project_infos
|
38
|
+
"<a href=\"#{ data.gitlab_url }\">#{ data.project_name }</a>"
|
39
|
+
end
|
40
|
+
|
41
|
+
def project_branch
|
42
|
+
"(#{ data.ref })"
|
43
|
+
end
|
44
|
+
|
45
|
+
def project_status
|
46
|
+
"<strong>#{ data.build_status }</strong>!"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Lita
|
2
|
+
module GitlabCi
|
3
|
+
class Commit
|
4
|
+
attr_reader :commit
|
5
|
+
|
6
|
+
def initialize(commit)
|
7
|
+
@commit = OpenStruct.new(commit)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"<pre> #{ sha_link } — #{ title } (#{ date }) #{ author }</pre>"
|
12
|
+
end
|
13
|
+
|
14
|
+
def sha_link
|
15
|
+
"<a href=\"#{ commit.url }\">#{ sha }</a>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def sha
|
19
|
+
commit.id[0..6]
|
20
|
+
end
|
21
|
+
|
22
|
+
def title
|
23
|
+
commit.message.split("\n").first
|
24
|
+
end
|
25
|
+
|
26
|
+
def date
|
27
|
+
Time.parse(commit.timestamp).utc.strftime('%Y-%m-%d %H:%M')
|
28
|
+
end
|
29
|
+
|
30
|
+
def author
|
31
|
+
@author ||= Author.new(commit.author)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class GitlabCiHipchat < Handler
|
4
|
+
http.post '/gitlab-ci', :receive
|
5
|
+
|
6
|
+
def self.default_config(config)
|
7
|
+
end
|
8
|
+
|
9
|
+
def receive(request, response)
|
10
|
+
json_data = JSON.parse(request.body.read)
|
11
|
+
message = Lita::GitlabCi::BuildMessage.new(hipchat, json_data)
|
12
|
+
message.send_to_hipchat!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def hipchat
|
18
|
+
@hipchat ||= hipchat_client[config.room]
|
19
|
+
end
|
20
|
+
|
21
|
+
def hipchat_client
|
22
|
+
@hipchat_client ||= HipChat::Client.new(config.api_token, api_version: 'v2')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Lita.register_handler(GitlabCiHipchat)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-gitlab-ci-hipchat"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["Loïc Guitaut"]
|
5
|
+
spec.email = ["flink@belfalas.eu"]
|
6
|
+
spec.description = %q{Receive and display nicely web hooks from GitLab CI in HipChat.}
|
7
|
+
spec.summary = %q{A Lita handler to receive GitLab CI web hooks}
|
8
|
+
spec.homepage = "https://github.com/Flink/lita-gitlab-ci-hipchat"
|
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.3"
|
18
|
+
spec.add_runtime_dependency "hipchat", "~> 1.3.0"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
23
|
+
spec.add_development_dependency "simplecov"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
spec.add_development_dependency "fabrication"
|
26
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
Fabricator(:gitlabci_data, class_name: 'Hash') do
|
2
|
+
initialize_with do
|
3
|
+
{
|
4
|
+
"build_id" => 2,
|
5
|
+
"build_status" => "failed",
|
6
|
+
"build_started_at" => "2014-05-05T18:01:02.563Z",
|
7
|
+
"build_finished_at" => "2014-05-05T18:01:07.611Z",
|
8
|
+
"project_id" => 1,
|
9
|
+
"project_name" => "Brightbox / Brightbox Cli",
|
10
|
+
"gitlab_url" => "http://localhost:3000/brightbox/brightbox-cli",
|
11
|
+
"ref" => "master",
|
12
|
+
"sha" => "a26cf5de9ed9827746d4970872376b10d9325f40",
|
13
|
+
"before_sha" => "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
|
14
|
+
"push_data" => {
|
15
|
+
"before" => "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
|
16
|
+
"after" => "a26cf5de9ed9827746d4970872376b10d9325f40",
|
17
|
+
"ref" => "refs/heads/master",
|
18
|
+
"user_id" => 1,
|
19
|
+
"user_name" => "Administrator",
|
20
|
+
"project_id" => 5,
|
21
|
+
"repository" => {
|
22
|
+
"name" => "Brightbox Cli",
|
23
|
+
"url" => "dzaporozhets@localhost:brightbox/brightbox-cli.git",
|
24
|
+
"description" => "Voluptatibus quae error consectetur voluptas dolores vel excepturi possimus.",
|
25
|
+
"homepage" => "http://localhost:3000/brightbox/brightbox-cli"
|
26
|
+
},
|
27
|
+
"commits" => [
|
28
|
+
{
|
29
|
+
"id" => "a26cf5de9ed9827746d4970872376b10d9325f40",
|
30
|
+
"message" => "Release v1.2.2",
|
31
|
+
"timestamp" => "2014-04-22T16:46:42+03:00",
|
32
|
+
"url" => "http://localhost:3000/brightbox/brightbox-cli/commit/a26cf5de9ed9827746d4970872376b10d9325f40",
|
33
|
+
"author" => {
|
34
|
+
"name" => "Paul Thornthwaite",
|
35
|
+
"email" => "tokengeek@gmail.com"
|
36
|
+
}
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"id" => "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
|
40
|
+
"message" => "Fix server user data update\n\nIncorrect condition was being used so Base64 encoding option was having\nopposite effect from desired.",
|
41
|
+
"timestamp" => "2014-04-11T18:17:26+03:00",
|
42
|
+
"url" => "http://localhost:3000/brightbox/brightbox-cli/commit/34f57f6ba3ed0c21c5e361bbb041c3591411176c",
|
43
|
+
"author" => {
|
44
|
+
"name" => "Paul Thornthwaite",
|
45
|
+
"email" => "tokengeek@gmail.com"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
],
|
49
|
+
"total_commits_count" => 2,
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Fabricator(:gitlabci_author_data, class_name: 'Hash') do
|
56
|
+
initialize_with do
|
57
|
+
{
|
58
|
+
"name" => "Paul Thornthwaite",
|
59
|
+
"email" => "tokengeek@gmail.com"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Fabricator(:gitlabci_commit_data, class_name: 'Hash') do
|
65
|
+
initialize_with do
|
66
|
+
{
|
67
|
+
"id" => "34f57f6ba3ed0c21c5e361bbb041c3591411176c",
|
68
|
+
"message" => "Fix server user data update\n\nIncorrect condition was being used so Base64 encoding option was having\nopposite effect from desired.",
|
69
|
+
"timestamp" => "2014-04-11T18:17:26+03:00",
|
70
|
+
"url" => "http://localhost:3000/brightbox/brightbox-cli/commit/34f57f6ba3ed0c21c5e361bbb041c3591411176c",
|
71
|
+
"author" => {
|
72
|
+
"name" => "Paul Thornthwaite",
|
73
|
+
"email" => "tokengeek@gmail.com"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::GitlabCi::Author do
|
4
|
+
let(:data) { Fabricate(:gitlabci_author_data) }
|
5
|
+
let(:author) { described_class.new(data) }
|
6
|
+
|
7
|
+
describe '#to_s' do
|
8
|
+
let(:formatted_author) { "<<a href=\"mailto:tokengeek@gmail.com\">Paul Thornthwaite</a>>" }
|
9
|
+
let(:author_string) { author.to_s }
|
10
|
+
|
11
|
+
it 'returns the Author as a string' do
|
12
|
+
expect(author_string).to eq formatted_author
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::GitlabCi::BuildMessage do
|
4
|
+
let(:hipchat) { double(HipChat) }
|
5
|
+
let(:data) { Fabricate(:gitlabci_data) }
|
6
|
+
let(:message) { described_class.new(hipchat, data) }
|
7
|
+
|
8
|
+
describe '#color' do
|
9
|
+
let(:color) { message.color }
|
10
|
+
|
11
|
+
context 'when build status is "success"' do
|
12
|
+
before do
|
13
|
+
data['build_status'] = 'success'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns "green"' do
|
17
|
+
expect(color).to eq 'green'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when build status is "failed"' do
|
22
|
+
before do
|
23
|
+
data['build_status'] = 'failed'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns "red"' do
|
27
|
+
expect(color).to eq 'red'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#send_to_hipchat!' do
|
33
|
+
let(:message_str) { '' }
|
34
|
+
let(:send_to_hipchat) { message.send_to_hipchat! }
|
35
|
+
let(:color) { 'red' }
|
36
|
+
|
37
|
+
before do
|
38
|
+
allow(message).to receive(:to_s).and_return message_str
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'sends the message to the hipchat object' do
|
42
|
+
expect(hipchat).to receive(:send).with('lita', message_str, color: color)
|
43
|
+
send_to_hipchat
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#project_status' do
|
48
|
+
let(:formatted_status) { '<strong>failed</strong>!' }
|
49
|
+
let(:project_status) { message.project_status }
|
50
|
+
|
51
|
+
it 'returns the build status formatted' do
|
52
|
+
expect(project_status).to eq formatted_status
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#project_branch' do
|
57
|
+
let(:formatted_branch) { '(master)' }
|
58
|
+
let(:project_branch) { message.project_branch }
|
59
|
+
|
60
|
+
it 'returns the branch formatted' do
|
61
|
+
expect(project_branch).to eq formatted_branch
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#project_infos' do
|
66
|
+
let(:formatted_infos) { '<a href="http://localhost:3000/brightbox/brightbox-cli">Brightbox / Brightbox Cli</a>' }
|
67
|
+
let(:project_infos) { message.project_infos }
|
68
|
+
|
69
|
+
it 'returns the project name formatted' do
|
70
|
+
expect(project_infos).to eq formatted_infos
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#commits' do
|
75
|
+
let(:expected_commits) { data['push_data']['commits'].reverse }
|
76
|
+
let(:commits) { message.commits }
|
77
|
+
|
78
|
+
it 'returns the available commits in the reverse order' do
|
79
|
+
expect(commits).to eq expected_commits
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#build_commits' do
|
84
|
+
let(:commits) { message.commits }
|
85
|
+
let(:build_commits) { message.build_commits }
|
86
|
+
|
87
|
+
it 'returns new Commit object for each commit' do
|
88
|
+
expect(Lita::GitlabCi::Commit).to receive(:new).exactly(commits.size).times
|
89
|
+
build_commits
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#build_header' do
|
94
|
+
let(:formatted_header) { '<p>Build for <a href="http://localhost:3000/brightbox/brightbox-cli">Brightbox / Brightbox Cli</a> (master): <strong>failed</strong>!</p>' }
|
95
|
+
let(:build_header) { message.build_header }
|
96
|
+
|
97
|
+
it 'returns formatted header for current build' do
|
98
|
+
expect(build_header).to eq formatted_header
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#to_s' do
|
103
|
+
let(:formatted_message) { [message.build_header, message.build_commits].join }
|
104
|
+
let(:message_string) { message.to_s }
|
105
|
+
|
106
|
+
it 'returns the build message as a string' do
|
107
|
+
expect(message_string).to eq formatted_message
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::GitlabCi::Commit do
|
4
|
+
let(:data) { Fabricate(:gitlabci_commit_data) }
|
5
|
+
let(:commit) { described_class.new(data) }
|
6
|
+
|
7
|
+
describe '#sha' do
|
8
|
+
let(:expected_sha) { '34f57f6' }
|
9
|
+
let(:sha) { commit.sha }
|
10
|
+
|
11
|
+
it 'returns a short SHA (7 chars) from commit' do
|
12
|
+
expect(sha).to eq expected_sha
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#sha_link' do
|
17
|
+
let(:formatted_sha) { "<a href=\"http://localhost:3000/brightbox/brightbox-cli/commit/34f57f6ba3ed0c21c5e361bbb041c3591411176c\">34f57f6</a>" }
|
18
|
+
let(:sha_link) { commit.sha_link }
|
19
|
+
|
20
|
+
it 'returns the SHA formatted' do
|
21
|
+
expect(sha_link).to eq formatted_sha
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#title' do
|
26
|
+
let(:first_line) { 'Fix server user data update' }
|
27
|
+
let(:title) { commit.title }
|
28
|
+
|
29
|
+
it 'returns the first line of the commit' do
|
30
|
+
expect(title).to eq first_line
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#date' do
|
35
|
+
let(:formatted_date) { '2014-04-11 15:17' }
|
36
|
+
let(:date) { commit.date }
|
37
|
+
|
38
|
+
it 'returns the date formatted' do
|
39
|
+
expect(date).to eq formatted_date
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#author' do
|
44
|
+
let(:author_data) { commit.commit.author }
|
45
|
+
let(:author) { commit.author }
|
46
|
+
|
47
|
+
it 'returns a new Author object' do
|
48
|
+
expect(Lita::GitlabCi::Author).to receive(:new).with(author_data)
|
49
|
+
author
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#to_s' do
|
54
|
+
let(:formatted_commit) { "<pre> <a href=\"http://localhost:3000/brightbox/brightbox-cli/commit/34f57f6ba3ed0c21c5e361bbb041c3591411176c\">34f57f6</a> — Fix server user data update (2014-04-11 15:17) <<a href=\"mailto:tokengeek@gmail.com\">Paul Thornthwaite</a>></pre>" }
|
55
|
+
let(:commit_string) { commit.to_s }
|
56
|
+
|
57
|
+
it 'returns the Commit as a string' do
|
58
|
+
expect(commit_string).to eq formatted_commit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::GitlabCiHipchat, lita_handler: true do
|
4
|
+
it { routes_http(:post, '/gitlab-ci').to(:receive) }
|
5
|
+
|
6
|
+
describe '#receive(request, response)' do
|
7
|
+
let(:request) { double(Rack::Request) }
|
8
|
+
let(:response) { double(Rack::Response) }
|
9
|
+
let(:body) { StringIO.new(json) }
|
10
|
+
let(:hipchat) { double(HipChat).as_null_object }
|
11
|
+
let(:json) { "{ \"build_status\": \"success\", \"push_data\": { \"commits\": [] } }" }
|
12
|
+
let(:json_parsed) { JSON.parse(json) }
|
13
|
+
let(:message) { double(Lita::GitlabCi::BuildMessage).as_null_object }
|
14
|
+
let(:gitlab_ci_receive) { subject.receive(request, response) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(request).to receive(:body).and_return(body)
|
18
|
+
allow(subject).to receive(:hipchat).and_return(hipchat)
|
19
|
+
allow(Lita::GitlabCi::BuildMessage).to receive(:new).and_return(message)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'parses body to JSON' do
|
23
|
+
expect(JSON).to receive(:parse).and_return(json_parsed)
|
24
|
+
gitlab_ci_receive
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'creates a new BuildMessage' do
|
28
|
+
expect(Lita::GitlabCi::BuildMessage).to receive(:new).with(hipchat, json_parsed).and_return(message)
|
29
|
+
gitlab_ci_receive
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sends the message to HipChat' do
|
33
|
+
expect(message).to receive(:send_to_hipchat!)
|
34
|
+
gitlab_ci_receive
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
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 'fabrication'
|
10
|
+
require "lita-gitlab-ci-hipchat"
|
11
|
+
require "lita/rspec"
|
metadata
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-gitlab-ci-hipchat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Loïc Guitaut
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-01 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.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hipchat
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
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: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fabrication
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Receive and display nicely web hooks from GitLab CI in HipChat.
|
126
|
+
email:
|
127
|
+
- flink@belfalas.eu
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".ruby-version"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- lib/lita-gitlab-ci-hipchat.rb
|
141
|
+
- lib/lita/gitlab_ci/author.rb
|
142
|
+
- lib/lita/gitlab_ci/build_message.rb
|
143
|
+
- lib/lita/gitlab_ci/commit.rb
|
144
|
+
- lib/lita/handlers/gitlab_ci_hipchat.rb
|
145
|
+
- lita-gitlab-ci-hipchat.gemspec
|
146
|
+
- locales/en.yml
|
147
|
+
- spec/fabricators/gitlabci_data_fabricator.rb
|
148
|
+
- spec/lita/gitlab_ci/author_spec.rb
|
149
|
+
- spec/lita/gitlab_ci/build_message_spec.rb
|
150
|
+
- spec/lita/gitlab_ci/commit_spec.rb
|
151
|
+
- spec/lita/handlers/gitlab_ci_hipchat_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
homepage: https://github.com/Flink/lita-gitlab-ci-hipchat
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata:
|
157
|
+
lita_plugin_type: handler
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 2.2.2
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: A Lita handler to receive GitLab CI web hooks
|
178
|
+
test_files:
|
179
|
+
- spec/fabricators/gitlabci_data_fabricator.rb
|
180
|
+
- spec/lita/gitlab_ci/author_spec.rb
|
181
|
+
- spec/lita/gitlab_ci/build_message_spec.rb
|
182
|
+
- spec/lita/gitlab_ci/commit_spec.rb
|
183
|
+
- spec/lita/handlers/gitlab_ci_hipchat_spec.rb
|
184
|
+
- spec/spec_helper.rb
|