lita-snap-ci 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # lita-snap-ci
2
2
 
3
- Reports from [snap-ci]('https://snap-ci.com/'). [![Build Status](https://snap-ci.com/groteck/lita-snap-ci/branch/master/build_image)](https://snap-ci.com/groteck/lita-snap-ci/branch/master)
3
+ Lita handler, to display the snap-ci pipelines of a project.
4
+
5
+ | Services |
6
+ |--- |
7
+ | [![Build Status](https://snap-ci.com/groteck/lita-snap-ci/branch/master/build_image)](https://snap-ci.com/groteck/lita-snap-ci/branch/master) |
8
+ |--- |
9
+ | [![Code Climate](https://codeclimate.com/github/groteck/lita-snap-ci/badges/gpa.svg)](https://codeclimate.com/github/groteck/lita-snap-ci) |
10
+ |--- |
11
+ | [![Test Coverage](https://codeclimate.com/github/groteck/lita-snap-ci/badges/coverage.svg)](https://codeclimate.com/github/groteck/lita-snap-ci/coverage) |
4
12
 
5
13
  ## Installation
6
14
 
@@ -1,9 +1,17 @@
1
1
  require 'multi_json'
2
+ require_relative 'translations'
2
3
 
3
4
  module SnapCi
4
5
  class Parser
6
+ include Translations
7
+
8
+ ERROR_PARAMETERS = {
9
+ 'result' => t('parser.error', { locale: :en }),
10
+ 'stages' => nil
11
+ }
12
+
5
13
  def initialize(response)
6
- @pipeline = MultiJson.load(response.body)['_embedded']['pipelines'].last
14
+ set_pipeline(MultiJson.load(response.body))
7
15
  end
8
16
 
9
17
  def to_parameters
@@ -12,5 +20,15 @@ module SnapCi
12
20
  steps: @pipeline['stages']
13
21
  }
14
22
  end
23
+
24
+ private
25
+
26
+ def set_pipeline(body)
27
+ @pipeline = if !body.has_value? 'Resource not found!'
28
+ body['_embedded']['pipelines'].last
29
+ else
30
+ ERROR_PARAMETERS
31
+ end
32
+ end
15
33
  end
16
34
  end
@@ -44,11 +44,22 @@ module SnapCi
44
44
  end
45
45
 
46
46
  def pipeline_to_s(branch, parameters)
47
- " #{branch}: #{parameters[:status]} (#{steps_to_s(parameters[:steps])})"
47
+ status_to_s(branch, parameters[:status]) + steps_to_s(parameters[:steps])
48
+ end
49
+
50
+ def status_to_s(branch, status)
51
+ " #{branch}: #{status}"
48
52
  end
49
53
 
50
54
  def steps_to_s(steps)
51
- steps.map { |step| "#{step["name"]}: #{step["result"]}" }.join(", ")
55
+ if !steps.nil?
56
+ " (#{steps
57
+ .map { |step| "#{step["name"]}: #{step["result"]}" }
58
+ .join(", ")
59
+ })"
60
+ else
61
+ ''
62
+ end
52
63
  end
53
64
 
54
65
  def uris
@@ -0,0 +1,24 @@
1
+ require 'i18n'
2
+
3
+ module SnapCi
4
+ module Translations
5
+ module ClassMethods
6
+ def t(key, hash = {})
7
+ I18n.t("lita.handlers.snap_ci.#{key}", hash)
8
+ end
9
+ end
10
+
11
+ module InstanceMethods
12
+ private
13
+
14
+ def t(key, hash = {})
15
+ self.class.t(key, hash)
16
+ end
17
+ end
18
+
19
+ def self.included(receiver)
20
+ receiver.extend ClassMethods
21
+ receiver.send :include, InstanceMethods
22
+ end
23
+ end
24
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-snap-ci"
3
- spec.version = "1.0.0"
3
+ spec.version = "1.1.0"
4
4
  spec.authors = ["Juan Fraire"]
5
5
  spec.email = ["groteck@gmail.com"]
6
6
  spec.description = "Snap-ci integration with lita"
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
20
  spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "codeclimate-test-reporter"
21
22
  spec.add_development_dependency "rake"
22
23
  spec.add_development_dependency "rack-test"
23
24
  spec.add_development_dependency "webmock"
@@ -8,3 +8,5 @@ en:
8
8
  project:
9
9
  command: snap-ci status <owner>/<repo> or <repo>
10
10
  desc: display a single project report with all the branches and status
11
+ parser:
12
+ error: Untracked branch in snap-ci
@@ -0,0 +1,3 @@
1
+ {
2
+ "message": "Resource not found!"
3
+ }
@@ -0,0 +1,2 @@
1
+ Project: wrong_org/wrong_project:
2
+ wrong_branch: Untracked branch in snap-ci
@@ -1,37 +1,76 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Handlers::SnapCi, lita_handler: true do
4
- before do
5
- load_config
6
- end
4
+ context 'with valid projects' do
5
+ before do
6
+ load_config
7
+ end
7
8
 
8
- describe 'command `snap-ci report`:' do
9
- it 'display a general report' do
10
- send_message("snap-ci report")
9
+ describe 'command `snap-ci report`:' do
10
+ it 'display a general report' do
11
+ send_message("snap-ci report")
11
12
 
12
- load_message_fixture('snap-ci_report').each_line do |line|
13
- expect(replies.last).to include(line.delete("\n"))
13
+ load_message_fixture('snap-ci_report').each_line do |line|
14
+ expect(replies.last).to include(line.delete("\n"))
15
+ end
16
+ end
17
+ end
18
+
19
+ describe 'command `snap-ci project`:' do
20
+ context 'with only repo format' do
21
+ it 'displays the project status' do
22
+ send_message("snap-ci project api")
23
+
24
+ load_message_fixture('snap-ci_status').each_line do |line|
25
+ expect(replies.last).to include(line.delete("\n"))
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'with owner/repo format' do
31
+ it 'displays the project status' do
32
+ send_message("snap-ci project oneorg/api")
33
+
34
+ load_message_fixture('snap-ci_status').each_line do |line|
35
+ expect(replies.last).to include(line.delete("\n"))
36
+ end
37
+ end
14
38
  end
15
39
  end
16
40
  end
41
+ context 'with invalid projects' do
42
+ before do
43
+ load_wrong_config
44
+ end
17
45
 
18
- describe 'command `snap-ci project`' do
19
- context 'with repo format' do
20
- it 'displays the project status' do
21
- send_message("snap-ci project api")
46
+ describe 'command `snap-ci report`:' do
47
+ it 'display a general report with the failure message' do
48
+ send_message("snap-ci report")
22
49
 
23
- load_message_fixture('snap-ci_status').each_line do |line|
50
+ load_message_fixture('error').each_line do |line|
24
51
  expect(replies.last).to include(line.delete("\n"))
25
52
  end
26
53
  end
27
54
  end
28
55
 
29
- context 'with owner/repo format' do
30
- it 'displays the project status' do
31
- send_message("snap-ci project oneorg/api")
56
+ describe 'command `snap-ci project`:' do
57
+ context 'with only repo format' do
58
+ it 'displays the project status with the failure message' do
59
+ send_message("snap-ci project wrong_project")
32
60
 
33
- load_message_fixture('snap-ci_status').each_line do |line|
34
- expect(replies.last).to include(line.delete("\n"))
61
+ load_message_fixture('error').each_line do |line|
62
+ expect(replies.last).to include(line.delete("\n"))
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'with owner/repo format' do
68
+ it 'displays the project status with the failure message' do
69
+ send_message("snap-ci project wrong_org/wrong_project")
70
+
71
+ load_message_fixture('error').each_line do |line|
72
+ expect(replies.last).to include(line.delete("\n"))
73
+ end
35
74
  end
36
75
  end
37
76
  end
@@ -1,6 +1,7 @@
1
1
  require "lita-snap-ci"
2
2
  require "lita/rspec"
3
3
  require 'webmock/rspec'
4
+ require "codeclimate-test-reporter"
4
5
 
5
6
  # Load helpers
6
7
  require_relative 'support/fixture'
@@ -10,6 +11,8 @@ require_relative 'support/config'
10
11
  # was generated with Lita 4, the compatibility mode should be left disabled.
11
12
  Lita.version_3_compatibility_mode = false
12
13
 
14
+ CodeClimate::TestReporter.start
15
+
13
16
  RSpec.configure do |c|
14
17
  c.include Fixture
15
18
  c.include Config
@@ -18,4 +18,16 @@ module Config
18
18
  }
19
19
  ]
20
20
  end
21
+
22
+ def load_wrong_config
23
+ registry.config.handlers.snap_ci.user = "snapUser"
24
+ registry.config.handlers.snap_ci.token = "Snap-ci-api-key"
25
+ registry.config.handlers.snap_ci.projects = [
26
+ {
27
+ owner: 'wrong_org',
28
+ repository: 'wrong_project',
29
+ branches: ['wrong_branch']
30
+ }
31
+ ]
32
+ end
21
33
  end
@@ -33,5 +33,8 @@ module Fixture
33
33
  to_return(status: 200, body: load_json_fixture('websites_develop'))
34
34
  stub_request(:get, "#{URL}otherorg/websites/branch/master/pipelines").
35
35
  to_return(status: 200, body: load_json_fixture('websites_master'))
36
+ # wrong_project example
37
+ stub_request(:get, "#{URL}wrong_org/wrong_project/branch/wrong_branch/pipelines").
38
+ to_return(status: 404, body: load_json_fixture('error'))
36
39
  end
37
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-snap-ci
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
  - Juan Fraire
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-11 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
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'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +129,9 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
132
+ - ".codeclimate.yml"
118
133
  - ".gitignore"
134
+ - ".rubocop.yml"
119
135
  - Gemfile
120
136
  - README.md
121
137
  - Rakefile
@@ -126,11 +142,14 @@ files:
126
142
  - lib/snap_ci/parser.rb
127
143
  - lib/snap_ci/project.rb
128
144
  - lib/snap_ci/project_list.rb
145
+ - lib/snap_ci/translations.rb
129
146
  - lita-snap-ci.gemspec
130
147
  - locales/en.yml
131
148
  - spec/fixtures/api_development.json
132
149
  - spec/fixtures/api_master.json
133
150
  - spec/fixtures/api_staging.json
151
+ - spec/fixtures/error.json
152
+ - spec/fixtures/error.message
134
153
  - spec/fixtures/front_master.json
135
154
  - spec/fixtures/front_staging.json
136
155
  - spec/fixtures/pipelines.json
@@ -172,6 +191,8 @@ test_files:
172
191
  - spec/fixtures/api_development.json
173
192
  - spec/fixtures/api_master.json
174
193
  - spec/fixtures/api_staging.json
194
+ - spec/fixtures/error.json
195
+ - spec/fixtures/error.message
175
196
  - spec/fixtures/front_master.json
176
197
  - spec/fixtures/front_staging.json
177
198
  - spec/fixtures/pipelines.json