codeclimate_ci 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee4a00ffa704653de7b1d23ceb5ccec2decc0139
4
+ data.tar.gz: 86709e7f8f42b75b45668ccf6ce850605af2b644
5
+ SHA512:
6
+ metadata.gz: 79ff48cf5ea167945e37430cedc4998e36a7cc251053214ccae397177e74853f1af2f9b66aea6310b2fcc053456f72c9dd26deae32a6552c5b19786977dc7b40
7
+ data.tar.gz: 1b17c55c143981c362445ab6a7d6f187f3c291e4463310ab61259d67a709b355e6f669b88c4b9913ef3954190e33cec7c1fa7bd273236bf8c3448230dd09a7cf
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ RunRailsCops: false
3
+ Excludes:
4
+ - bin/**
5
+ - codeclimate_ci.gemspec
6
+
7
+ Documentation:
8
+ Description: 'Document classes and non-namespace modules.'
9
+ Enabled: false
10
+
11
+ SymbolArray:
12
+ Description: 'Use %i or %I for arrays of symbols.'
13
+ Enabled: true
14
+
15
+ AlignParameters:
16
+ Enabled: false
17
+
18
+ LineLength:
19
+ Description: 'Limit lines to 120 characters.'
20
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in code_climate_check.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ildarsafin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Code Climate CI
2
+
3
+ [<img src="https://semaphoreapp.com/api/v1/projects/67b7f0f3-e224-43a2-afd9-b24c5176e6dd/214701/shields_badge.png">](https://semaphoreapp.com/fs/codeclimate_ci)
4
+ [![Code Climate](https://codeclimate.com/github/fs/codeclimate_ci.png)](https://codeclimate.com/github/fs/codeclimate_ci)
5
+ [![Test Coverage](https://codeclimate.com/github/fs/codeclimate_ci/badges/coverage.svg)](https://codeclimate.com/github/fs/codeclimate_ci)
6
+
7
+ The main idea of the Code Climate CI gem is that you can implement it to your [CI script](https://github.com/fs/rails-base/blob/master/bin/ci).
8
+
9
+ Gem will compare code quality in current branch with master branch through [CodeClimate API](https://codeclimate.com/docs/api) and if code in your branch become worse then ci script will be interrupted.
10
+
11
+ You can also compare code quality in your branch using this gem right from your console.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```bash
18
+ gem 'codeclimate_ci'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```bash
24
+ bundle
25
+ ```
26
+
27
+ Or install it yourself as:
28
+
29
+ ```bash
30
+ gem install codeclimate_ci
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Just type in your console:
36
+
37
+ ```shell
38
+ codeclimate_ci --codeclimate-api-token CODECLIMATE_API_TOKEN --repo-id REPOSITORY_ID --branch_name BRANCH
39
+ ```
40
+
41
+ * For codeclimate api token you need to go to codeclimate account settings in `Integrations` tab and there you can see `API Token`.
42
+ * For repo id you need to go to your private repo and then you'll see it in you address string.
43
+
44
+ ## Response examples
45
+
46
+ ### If you entered wrong api-token or repo-id response will be:
47
+
48
+ ```shell
49
+ Invalid credentials given. Please check your codeclimate_api_token and repo_id.
50
+ ```
51
+
52
+ ### If GPA in your branch became worse than in master response will be:
53
+
54
+ ```shell
55
+ Code in your branch became worse on %diff_point% points
56
+ ```
57
+ ### If GPA in your branch became better than in master response will be:
58
+
59
+ ```shell
60
+ Gpa score has improved to %diff_point% points. Go on...
61
+ ```
62
+
63
+ ## Quality tools
64
+
65
+ * `bin/quality` based on [RuboCop](https://github.com/bbatsov/rubocop)
66
+ * `.rubocop.yml` describes active checks
67
+
68
+ ## Development
69
+
70
+ * `bin/bootstrap` install gems
71
+ * `bin/build` check your specs and runs quality tools
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it ( https://github.com/[my-github-username]/codeclimate_ci/fork )
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create a new Pull Request
80
+
81
+ ## Credits
82
+
83
+ Code Climate CI is maintained by [Ildar Safin](http://github.com/ildarsafin).
84
+ It was written by [Flatstack](http://www.flatstack.com) with the help of our
85
+ [contributors](http://github.com/fs/codeclimate_ci/contributors).
86
+
87
+
88
+ [![Flatstack](http://www.flatstack.com/assets/images/logo.png)](http://www.flatstack.com)
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Bundler.setup
5
+
6
+ require 'rake'
7
+ require 'rspec'
8
+ require 'rspec/core/rake_task'
9
+
10
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
11
+ require 'codeclimate_ci/version'
12
+
13
+ # Default directory to look in is `/specs`
14
+ # Run with `rake spec`
15
+ RSpec::Core::RakeTask.new(:spec) do |spec|
16
+ spec.pattern = 'spec/**/*_spec.rb'
17
+ end
18
+
19
+ task default: :spec
20
+ task test: :spec
data/bin/bootstrap ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+ # Make sure local dependencies are met.
3
+
4
+ cd "$(dirname $0)"/..
5
+
6
+ rm -f .bundle/config
7
+
8
+ bundle check --path .bundle > /dev/null 2>&1 ||
9
+ bundle install --path=.bundle
data/bin/build ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -e
4
+
5
+ bin/rspec
6
+ bin/quality
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'codeclimate_ci'
5
+
6
+ CodeclimateCi::CLI.start(ARGV)
data/bin/quality ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -e
4
+
5
+ bin/rubocop
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rubocop', 'rubocop')
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/codeclimate_ci/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'codeclimate_ci'
6
+ spec.version = CodeclimateCi::VERSION
7
+ spec.authors = ['FlatStack team']
8
+ spec.summary = %q{Simple gem for checking your code with CodeClimate}
9
+ spec.description = %q{ Gem that allows You to check your code quality with CodeClimate and integrate it with your CI scripts }
10
+ spec.license = 'MIT'
11
+ spec.homepage = 'https://github.com/fs/codeclimate_ci'
12
+ spec.email = 'fs-admin@flatstack.com'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = ['codeclimate_ci']
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.6'
20
+ spec.add_development_dependency 'rake', '~> 10.3'
21
+ spec.add_development_dependency 'rspec', '~> 3.0'
22
+ spec.add_development_dependency 'pry', '~> 0.10'
23
+ spec.add_development_dependency 'rubocop', '~> 0.25'
24
+ spec.add_development_dependency 'webmock', '~> 1.18'
25
+
26
+ spec.add_dependency 'thor', '~> 0.19'
27
+ spec.add_dependency 'httparty', '~> 0.13'
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'codeclimate_ci/version'
2
+ require 'codeclimate_ci/cli'
3
+ require 'codeclimate_ci/configuration'
4
+ require 'codeclimate_ci/get_gpa'
5
+ require 'codeclimate_ci/compare_gpa'
6
+ require 'codeclimate_ci/api_requester'
7
+ require 'codeclimate_ci/report'
8
+
9
+ module CodeclimateCi
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'httparty'
2
+
3
+ module CodeclimateCi
4
+ class ApiRequester
5
+ include HTTParty
6
+ CODECLIMATE_URI = 'https://codeclimate.com/api/repos'
7
+
8
+ def initialize(token, repo_id)
9
+ self.class.base_uri "#{CODECLIMATE_URI}/#{repo_id}"
10
+ self.class.default_params api_token: token
11
+ end
12
+
13
+ def branch_info(branch)
14
+ self.class.get("/branches/#{branch}")
15
+ end
16
+
17
+ def connection_established?
18
+ @connection_established ||= self.class.get('/').code == 200
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,63 @@
1
+ require 'thor'
2
+
3
+ module CodeclimateCi
4
+ class CLI < Thor
5
+ method_option :codeclimate_api_token, required: true
6
+ method_option :repo_id, required: true
7
+ method_option :branch_name, required: true
8
+ method_option :retry_count
9
+ method_option :sleep_time
10
+
11
+ desc('check', 'Check code quality with CodeClimate')
12
+
13
+ def check
14
+ CodeclimateCi.configuration.load_from_options(options)
15
+
16
+ exit_invalid_credentials! unless api_requester.connection_established?
17
+
18
+ if compare_gpa.worse?(branch_name)
19
+ exit_worse_code!
20
+ else
21
+ exit_good_code!
22
+ end
23
+ end
24
+
25
+ default_task :check
26
+
27
+ private
28
+
29
+ def compare_gpa
30
+ @compare_gpa ||= CompareGpa.new(api_requester)
31
+ end
32
+
33
+ def api_requester
34
+ @api_requester ||= ApiRequester.new(
35
+ CodeclimateCi.configuration.codeclimate_api_token,
36
+ CodeclimateCi.configuration.repo_id
37
+ )
38
+ end
39
+
40
+ def diff
41
+ compare_gpa.diff(branch_name)
42
+ end
43
+
44
+ def branch_name
45
+ CodeclimateCi.configuration.branch_name
46
+ end
47
+
48
+ def exit_worse_code!
49
+ Report.worse_code(diff)
50
+ exit(1)
51
+ end
52
+
53
+ def exit_good_code!
54
+ Report.good_code(diff)
55
+ exit(0)
56
+ end
57
+
58
+ def exit_invalid_credentials!
59
+ Report.invalid_credentials
60
+ exit(1)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,29 @@
1
+ module CodeclimateCi
2
+ class CompareGpa
3
+ def initialize(api_requester)
4
+ @api_requester = api_requester
5
+ end
6
+
7
+ def worse?(branch_name)
8
+ diff(branch_name) < 0
9
+ end
10
+
11
+ def diff(branch_name)
12
+ branch_gpa(branch_name) - master_gpa
13
+ end
14
+
15
+ private
16
+
17
+ def master_gpa
18
+ @master_gpa ||= gpa('master').gpa
19
+ end
20
+
21
+ def branch_gpa(branch_name)
22
+ @branch_gpa ||= gpa(branch_name).gpa
23
+ end
24
+
25
+ def gpa(branch_name)
26
+ GetGpa.new(@api_requester, branch_name)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module CodeclimateCi
2
+ class Configuration
3
+ OPTIONS = %i(codeclimate_api_token repo_id branch_name retry_count sleep_time)
4
+ DEFAULTS = {
5
+ 'retry_count' => '3',
6
+ 'sleep_time' => '5'
7
+ }
8
+
9
+ attr_accessor(*OPTIONS)
10
+
11
+ def load_from_options(options)
12
+ OPTIONS.each do |option|
13
+ send("#{option}=", value_or_default(options, option))
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def value_or_default(options, option)
20
+ options[option.to_s] || DEFAULTS[option.to_s]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,57 @@
1
+ module CodeclimateCi
2
+ class GetGpa
3
+ NULL_VALUE = 0
4
+
5
+ def initialize(api_requester, branch)
6
+ @api_requester, @branch = api_requester, branch
7
+ end
8
+
9
+ def gpa
10
+ retry_count.times do
11
+ return last_snapshot_gpa if analyzed?
12
+ wait_and_refresh!
13
+ end
14
+
15
+ NULL_VALUE
16
+ end
17
+
18
+ private
19
+
20
+ def wait_and_refresh!
21
+ Report.result_not_ready(@retry_counter, @branch)
22
+
23
+ increment_retry_counter
24
+ sleep(sleep_time)
25
+ refresh!
26
+ end
27
+
28
+ def increment_retry_counter
29
+ @retry_counter ||= 0
30
+ @retry_counter += 1
31
+ end
32
+
33
+ def retry_count
34
+ CodeclimateCi.configuration.retry_count.to_i
35
+ end
36
+
37
+ def sleep_time
38
+ CodeclimateCi.configuration.sleep_time.to_i
39
+ end
40
+
41
+ def last_snapshot_gpa
42
+ branch_info['last_snapshot']['gpa'].to_f
43
+ end
44
+
45
+ def analyzed?
46
+ branch_info.include?('last_snapshot')
47
+ end
48
+
49
+ def branch_info
50
+ @branch_info ||= @api_requester.branch_info(@branch)
51
+ end
52
+
53
+ def refresh!
54
+ @branch_info = nil
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,25 @@
1
+ module CodeclimateCi
2
+ module Report
3
+ module_function
4
+
5
+ def result_not_ready(retry_count, branch)
6
+ puts "Retry #{retry_count}. #{branch} branch analyze is not ready or branch does not exist"
7
+ end
8
+
9
+ def worse_code(gpa_diff)
10
+ puts "Code in your branch became worse on #{rounded_diff_value(gpa_diff)} points"
11
+ end
12
+
13
+ def good_code(gpa_diff)
14
+ puts "Gpa score has improved to #{rounded_diff_value(gpa_diff)} points. Go on..."
15
+ end
16
+
17
+ def invalid_credentials
18
+ puts 'Invalid credentials given. Please check your codeclimate_api_token and repo_id.'
19
+ end
20
+
21
+ def rounded_diff_value(gpa_diff)
22
+ gpa_diff.abs.round(2)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module CodeclimateCi
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe CodeclimateCi::ApiRequester do
4
+ let(:token) { 'token' }
5
+ let(:repo_id) { 'repo-id' }
6
+ let(:api_requester) { CodeclimateCi::ApiRequester.new(token, repo_id) }
7
+
8
+ describe '#branch_info' do
9
+ let(:branch) { 'master' }
10
+
11
+ let(:endpoint) do
12
+ "https://codeclimate.com/api/repos/#{repo_id}/branches/#{branch}?api_token=#{token}"
13
+ end
14
+
15
+ before do
16
+ stub_request(:get, endpoint)
17
+ end
18
+
19
+ it 'requests correct API endpoint' do
20
+ api_requester.branch_info(branch)
21
+ expect(WebMock).to have_requested(:get, endpoint)
22
+ end
23
+ end
24
+
25
+ describe '#connection_established?' do
26
+ let(:endpoint) do
27
+ "https://codeclimate.com/api/repos/#{repo_id}/?api_token=#{token}"
28
+ end
29
+
30
+ before do
31
+ stub_request(:get, endpoint).to_return(status: 404)
32
+ end
33
+
34
+ it 'requests correct API endpoint' do
35
+ api_requester.connection_established?
36
+ expect(WebMock).to have_requested(:get, endpoint)
37
+ end
38
+
39
+ it 'returns false' do
40
+ expect(api_requester.connection_established?).to be_falsey
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe CodeclimateCi::CLI do
4
+ let(:args) { ['--branch_name', 'master'] }
5
+
6
+ let(:cli) { CodeclimateCi::CLI.new(args) }
7
+ let(:api_requester) { double(CodeclimateCi::ApiRequester) }
8
+ let(:compare_gpa) { double(CodeclimateCi::CompareGpa, diff: 0) }
9
+
10
+ def do_check
11
+ cli.check
12
+ rescue SystemExit => e
13
+ @exit = e.status
14
+ end
15
+
16
+ before do
17
+ allow(CodeclimateCi::ApiRequester).to receive(:new) { api_requester }
18
+ allow(CodeclimateCi::CompareGpa).to receive(:new) { compare_gpa }
19
+ end
20
+
21
+ context 'when connection is not established' do
22
+ before do
23
+ allow(api_requester).to receive(:connection_established?) { false }
24
+ end
25
+
26
+ it 'reports invalid credentials' do
27
+ expect(CodeclimateCi::Report).to receive(:invalid_credentials)
28
+ do_check
29
+ end
30
+
31
+ it 'exits with 1' do
32
+ do_check
33
+ expect(@exit).to eql(1)
34
+ end
35
+ end
36
+
37
+ context 'when connection is established' do
38
+ before do
39
+ allow(api_requester).to receive(:connection_established?) { true }
40
+ end
41
+
42
+ context 'when code is worse' do
43
+ before do
44
+ allow(compare_gpa).to receive(:worse?) { true }
45
+ end
46
+
47
+ it 'reports worse code' do
48
+ expect(CodeclimateCi::Report).to receive(:worse_code)
49
+ do_check
50
+ end
51
+
52
+ it 'exits with 1' do
53
+ do_check
54
+ expect(@exit).to eql(1)
55
+ end
56
+ end
57
+
58
+ context 'when code is better' do
59
+ before do
60
+ allow(compare_gpa).to receive(:worse?) { false }
61
+ end
62
+
63
+ it 'reports good code' do
64
+ expect(CodeclimateCi::Report).to receive(:good_code)
65
+ do_check
66
+ end
67
+
68
+ it 'exits with 0' do
69
+ do_check
70
+ expect(@exit).to eql(0)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe CodeclimateCi::CompareGpa do
4
+ let(:api_requester) { double(CodeclimateCi::ApiRequester) }
5
+
6
+ let(:codeclimate_ci) { CodeclimateCi::CompareGpa.new(api_requester) }
7
+ let(:configuration) { double(CodeclimateCi::Configuration, retry_count: '2', sleep_time: '1') }
8
+
9
+ let(:good_branch_info) { { 'last_snapshot' => { 'gpa' => '4' } } }
10
+ let(:bad_branch_info) { { 'last_snapshot' => { 'gpa' => '1' } } }
11
+
12
+ before do
13
+ allow(CodeclimateCi).to receive(:configuration) { configuration }
14
+
15
+ allow(api_requester).to receive(:branch_info).with('master') { good_branch_info }
16
+ allow(api_requester).to receive(:branch_info).with('another_branch') { bad_branch_info }
17
+ end
18
+
19
+ it 'properly defines branch with worse code quality' do
20
+ expect(codeclimate_ci.worse?('another_branch')).to be_truthy
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe CodeclimateCi::Configuration do
4
+ let(:options) do
5
+ {
6
+ 'codeclimate_api_token' => '12345678',
7
+ 'repo_id' => '124356',
8
+ 'branch_name' => 'new-feature'
9
+ }
10
+ end
11
+
12
+ let(:configuration) { CodeclimateCi::Configuration.new }
13
+
14
+ describe '#load_from_options(options)' do
15
+ before do
16
+ configuration.load_from_options(options)
17
+ end
18
+
19
+ it 'properly setups options' do
20
+ expect(configuration.codeclimate_api_token).to eq('12345678')
21
+ expect(configuration.repo_id).to eq('124356')
22
+ expect(configuration.branch_name).to eq('new-feature')
23
+ expect(configuration.retry_count).to eq('3')
24
+ expect(configuration.sleep_time).to eq('5')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe CodeclimateCi::GetGpa do
4
+ let(:codeclimate_ci) { CodeclimateCi::GetGpa.new(api_requester, 'repo1') }
5
+ let(:api_requester) { double(CodeclimateCi::ApiRequester) }
6
+ let(:configuration) { double(CodeclimateCi::Configuration, retry_count: '3', sleep_time: '5') }
7
+ let(:analyzed_branch_info) { { 'last_snapshot' => { 'gpa' => 3 } } }
8
+ let(:empty_branch_info) { '' }
9
+
10
+ before { allow(CodeclimateCi).to receive(:configuration) { configuration } }
11
+
12
+ context 'when task is analyzed' do
13
+ before do
14
+ allow(api_requester).to receive(:branch_info) { analyzed_branch_info }
15
+ end
16
+
17
+ it 'returns correct gpa value' do
18
+ expect(codeclimate_ci.gpa).to eq 3
19
+ end
20
+ end
21
+
22
+ context 'when task is not analyzed' do
23
+ let(:configuration) do
24
+ double(CodeclimateCi::Configuration, retry_count: '2', sleep_time: '0')
25
+ end
26
+
27
+ before do
28
+ allow(api_requester).to receive(:branch_info) { empty_branch_info }
29
+ end
30
+
31
+ it 'returns correct gpa value' do
32
+ expect(codeclimate_ci.gpa).to eq 0
33
+ end
34
+ end
35
+
36
+ context 'when task analyzed after retry' do
37
+ let(:configuration) do
38
+ double(CodeclimateCi::Configuration, retry_count: '2', sleep_time: '0')
39
+ end
40
+
41
+ before do
42
+ allow(api_requester).to receive(:branch_info).and_return(empty_branch_info, analyzed_branch_info)
43
+ end
44
+
45
+ it 'returns correct gpa value after retry' do
46
+ expect(api_requester).to receive(:branch_info).twice
47
+ expect(codeclimate_ci.gpa).to eq 3
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ # Run codeclimate-test-reporter only in CI
2
+ if ENV['CI']
3
+ require 'codeclimate-test-reporter'
4
+ CodeClimate::TestReporter.start
5
+ end
6
+
7
+ require 'rspec'
8
+ require 'codeclimate_ci'
9
+ require 'webmock/rspec'
10
+
11
+ RSpec.configure do |config|
12
+ config.filter_run focus: true
13
+ config.run_all_when_everything_filtered = true
14
+
15
+ config.after(:all) do
16
+ WebMock.allow_net_connect!
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeclimate_ci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - FlatStack team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.25'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.25'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.18'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.18'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.19'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.19'
111
+ - !ruby/object:Gem::Dependency
112
+ name: httparty
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.13'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.13'
125
+ description: " Gem that allows You to check your code quality with CodeClimate and
126
+ integrate it with your CI scripts "
127
+ email: fs-admin@flatstack.com
128
+ executables:
129
+ - codeclimate_ci
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/bootstrap
141
+ - bin/build
142
+ - bin/codeclimate_ci
143
+ - bin/quality
144
+ - bin/rspec
145
+ - bin/rubocop
146
+ - codeclimate_ci.gemspec
147
+ - lib/codeclimate_ci.rb
148
+ - lib/codeclimate_ci/api_requester.rb
149
+ - lib/codeclimate_ci/cli.rb
150
+ - lib/codeclimate_ci/compare_gpa.rb
151
+ - lib/codeclimate_ci/configuration.rb
152
+ - lib/codeclimate_ci/get_gpa.rb
153
+ - lib/codeclimate_ci/report.rb
154
+ - lib/codeclimate_ci/version.rb
155
+ - spec/codeclimate_ci/api_requester_spec.rb
156
+ - spec/codeclimate_ci/cli_spec.rb
157
+ - spec/codeclimate_ci/compare_gpa_spec.rb
158
+ - spec/codeclimate_ci/configuration_spec.rb
159
+ - spec/codeclimate_ci/get_gpa_spec.rb
160
+ - spec/spec_helper.rb
161
+ homepage: https://github.com/fs/codeclimate_ci
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.2.2
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: Simple gem for checking your code with CodeClimate
185
+ test_files:
186
+ - spec/codeclimate_ci/api_requester_spec.rb
187
+ - spec/codeclimate_ci/cli_spec.rb
188
+ - spec/codeclimate_ci/compare_gpa_spec.rb
189
+ - spec/codeclimate_ci/configuration_spec.rb
190
+ - spec/codeclimate_ci/get_gpa_spec.rb
191
+ - spec/spec_helper.rb