simplecov-coverboard 0.1.0

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: 224f42ae9118e409f76d5d08a94973ee13539fc1
4
+ data.tar.gz: 2863fc83126ab91a54c3987762043a8c3d46ed9d
5
+ SHA512:
6
+ metadata.gz: 3f7b4f9d3ccc983582a21fe17a8f41efb47334212ebbe99071b6fdadde88f20367a24b64795a43db6b2062323d3642b6e547ac9e8c850310a9faf4dbf277bdcf
7
+ data.tar.gz: 9f37b11d4db73b9a0aa729c8a180eba2f515d0d584ba1fc421643feee96bc938effe1b8949c1f6e19ba2a5b59f3c8fec264df72e9a05e237c9242f296b4e5ebf
data/.coverboard.yml ADDED
@@ -0,0 +1,3 @@
1
+ coverboard:
2
+ uid: 'qwerty123456'
3
+ verbose: false
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,27 @@
1
+ .rvmrc
2
+ .bundle
3
+ Gemfile.lock
4
+
5
+ ## MAC OS
6
+ .DS_Store
7
+
8
+ ## TEXTMATE
9
+ *.tmproj
10
+ tmtags
11
+
12
+ ## EMACS
13
+ *~
14
+ \#*
15
+ .\#*
16
+
17
+ ## VIM
18
+ *.swp
19
+
20
+ ## RUBYMINE
21
+ .idea
22
+
23
+ ## PROJECT::GENERAL
24
+ coverage
25
+ rdoc
26
+ pkg
27
+ .sass-cache
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ Metrics/BlockNesting:
2
+ Max: 2
3
+
4
+ Metrics/LineLength:
5
+ AllowURI: true
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ CountComments: false
10
+ Max: 10
11
+
12
+ Metrics/ParameterLists:
13
+ Max: 4
14
+ CountKeywordArgs: true
15
+
16
+ Style/AccessModifierIndentation:
17
+ EnforcedStyle: outdent
18
+
19
+ Style/CollectionMethods:
20
+ PreferredMethods:
21
+ map: 'collect'
22
+ reduce: 'inject'
23
+ find: 'detect'
24
+ find_all: 'select'
25
+
26
+ Style/Documentation:
27
+ Enabled: false
28
+
29
+ Style/DoubleNegation:
30
+ Enabled: false
31
+
32
+ Style/FileName:
33
+ Exclude:
34
+ - 'lib/simplecov-coverboard.rb'
35
+ - 'test/test_simple_cov-html.rb'
36
+
37
+ Style/HashSyntax:
38
+ EnforcedStyle: hash_rockets
39
+
40
+ Style/RegexpLiteral:
41
+ Enabled: false
42
+
43
+ Style/SpaceInsideHashLiteralBraces:
44
+ EnforcedStyle: no_space
45
+
46
+ Style/StringLiterals:
47
+ EnforcedStyle: double_quotes
48
+
49
+ Style/TrailingComma:
50
+ EnforcedStyleForMultiline: 'comma'
data/.travis.yml ADDED
@@ -0,0 +1,27 @@
1
+ language: ruby
2
+
3
+ before_install:
4
+ - gem install bundler
5
+
6
+ bundler_args: --without development --jobs=3 --retry=3
7
+
8
+ cache: bundler
9
+
10
+ sudo: false
11
+
12
+ rvm:
13
+ - 1.8.7
14
+ - 1.9.3
15
+ - 2.0.0
16
+ - 2.1
17
+ - 2.2
18
+ - ruby-head
19
+ - jruby
20
+ - rbx-2
21
+
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
25
+ - rvm: jruby
26
+ - rvm: rbx-2
27
+ fast_finish: true
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+
7
+ # Use local copy of simplecov in development when checked out, fetch from git otherwise
8
+ if File.directory?(File.dirname(__FILE__) + "/../simplecov")
9
+ gem "simplecov", :path => File.dirname(__FILE__) + "/../simplecov"
10
+ else
11
+ gem "simplecov", :git => "https://github.com/colszowka/simplecov"
12
+ end
13
+
14
+ group :test do
15
+ gem "test-unit"
16
+ end
17
+
18
+ group :development do
19
+ gem "rubocop"
20
+ gem "sass"
21
+ gem "sprockets"
22
+ end
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard "bundler" do
5
+ watch("Gemfile")
6
+ # Uncomment next line if Gemfile contain `gemspec' command
7
+ # watch(/^.+\.gemspec/)
8
+ end
9
+
10
+ guard "rake", :task => "assets:compile" do
11
+ watch(%r{^assets\/})
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2013 Christoph Olszowka
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ simplecov-coverboard
2
+ =====================
3
+ Helpling Hackathon project
4
+ :beer: :pizza: :banana: :monkey:
5
+
6
+ [![Build Status](https://travis-ci.org/Coverboard/simplecov-coverboard.svg)](https://travis-ci.org/Coverboard/simplecov-coverboard)
7
+
8
+ ## What?
9
+ *simplecov-coverboard* is a SimpleCov::Formatter which sends your code coverage metrics.
10
+ You can see the metrics on the CoverBoard project dashboard.
11
+
12
+ ## How to install
13
+ ### Add required gems to your Gemfile
14
+ ```
15
+ gem 'simplecov'
16
+ gem 'simplecov-coverboard', git: https://github.com/coverboard/simplecov-coverboard
17
+ ```
18
+ ### Configure your project
19
+ Create a file which will contain the uid of your project: .coverboard.yml
20
+
21
+ ```
22
+ coverboard:
23
+ uid: 'demo'
24
+ ```
25
+
26
+ Set the default SimpleCov formatter
27
+
28
+ ```
29
+ SimpleCov.formatter = SimpleCov::Formatter::CoverBoardFormatter
30
+ ```
31
+
32
+ ### Check the charts
33
+ After running your tests check the charts https://aqueous-forest-2696.herokuapp.com/?project=demo
34
+
35
+ ## Contribution
36
+ - fork the repository
37
+ - create a PR
38
+
39
+ ## About the author
40
+ * [Lautaro](https://www.github.com/lautaro-mazzitelli-helpling)
41
+ * [Michał](https://www.github.com/mfranczakhelpling)
42
+ * [Yair](https://github.com/yair-helpling)
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # See https://github.com/colszowka/simplecov/issues/171
5
+ desc "Set permissions on all files so they are compatible with both user-local and system-wide installs"
6
+ task :fix_permissions do
7
+ system 'bash -c "find . -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \;"'
8
+ end
9
+ # Enforce proper permissions on each build
10
+ Rake::Task[:build].prerequisites.unshift :fix_permissions
11
+
12
+ require "rake/testtask"
13
+ Rake::TestTask.new(:test) do |test|
14
+ test.libs << "lib" << "test"
15
+ test.pattern = "test/**/test_*.rb"
16
+ test.verbose = true
17
+ end
18
+
19
+ begin
20
+ require "rubocop/rake_task"
21
+ RuboCop::RakeTask.new
22
+ rescue LoadError
23
+ task :rubocop do
24
+ $stderr.puts "Rubocop is disabled"
25
+ end
26
+ end
27
+
28
+ task :default => [:test, :rubocop]
@@ -0,0 +1,13 @@
1
+ require 'json'
2
+
3
+ class ApplicationMessage
4
+ attr_accessor :metrics, :uid, :ts
5
+
6
+ def to_json
7
+ msg = Hash.new
8
+ msg[:uid] = @uid
9
+ msg[:metrics] = @metrics
10
+ msg[:ts] = Time.now.strftime('%s')
11
+ msg.to_json
12
+ end
13
+ end
data/lib/api/config.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+
3
+ module CoverBoard
4
+ class Config
5
+ DOT_FILE = '.coverboard.yml'
6
+
7
+ @@config = nil
8
+
9
+ HTTPS = true
10
+ HOST = 'aqueous-forest-2696.herokuapp.com'
11
+ PORT = 80
12
+ ENDPOINT = '/api/metrics'
13
+
14
+ def self.uid
15
+ from_yml 'uid'
16
+ end
17
+
18
+ def self.user
19
+ from_yml 'user'
20
+ end
21
+
22
+ def self.password
23
+ from_yml 'password'
24
+ end
25
+
26
+ def self.host
27
+ from_yml 'host', HOST
28
+ end
29
+
30
+ def self.port
31
+ from_yml 'port', PORT
32
+ end
33
+
34
+ def self.endpoint
35
+ from_yml 'endpoint', ENDPOINT
36
+ end
37
+
38
+ def self.verbose
39
+ from_yml 'verbose', false
40
+ end
41
+
42
+ def self.https
43
+ from_yml 'https', HTTPS
44
+ end
45
+
46
+ private
47
+ def self.from_yml(key, default='')
48
+ if @@config.nil?
49
+ path = "#{Dir.pwd}/#{DOT_FILE}"
50
+ if File.exists? path
51
+ @@config = YAML.load(File.read(path))
52
+ end
53
+ end
54
+ return default if @@config.nil? || @@config['coverboard'][key].nil?
55
+ @@config['coverboard'][key]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,36 @@
1
+ require 'net/http'
2
+
3
+ class Connector
4
+ def post(payload)
5
+ uri = build_uri
6
+ req = Net::HTTP::Post.new(uri)
7
+ req.content_type = 'application/json'
8
+ req.body = payload
9
+
10
+ if CoverBoard::Config.user && CoverBoard::Config.password
11
+ req.basic_auth CoverBoard::Config.user, CoverBoard::Config.password
12
+ end
13
+
14
+ if CoverBoard::Config.verbose
15
+ puts "Pushing to #{uri}"
16
+ puts "Application id #{CoverBoard::Config.uid}"
17
+ puts "Payload #{payload}"
18
+ end
19
+
20
+ response = Net::HTTP.new(uri.hostname, uri.port).start {|http| http.request(req) }
21
+
22
+ if CoverBoard::Config.verbose
23
+ puts "Response #{response.code} #{response.message}: #{response.body}"
24
+ end
25
+
26
+ response
27
+ end
28
+
29
+ private
30
+ def build_uri
31
+ uri = 'http'
32
+ uri += 's' if CoverBoard::Config.https
33
+
34
+ URI("#{uri}://#{CoverBoard::Config.host}:#{CoverBoard::Config.port}#{CoverBoard::Config.endpoint}")
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class CoverBoardFormatter
4
+ VERSION = "0.1.0"
5
+
6
+ def VERSION.to_a
7
+ split(".").map(&:to_i)
8
+ end
9
+
10
+ def VERSION.major
11
+ to_a[0]
12
+ end
13
+
14
+ def VERSION.minor
15
+ to_a[1]
16
+ end
17
+
18
+ def VERSION.patch
19
+ to_a[2]
20
+ end
21
+
22
+ def VERSION.pre
23
+ to_a[3]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,71 @@
1
+ require "erb"
2
+ require "cgi"
3
+ require "fileutils"
4
+ require "digest/sha1"
5
+ require "time"
6
+
7
+ # Ensure we are using a compatible version of SimpleCov
8
+ major, minor, patch = SimpleCov::VERSION.scan(/\d+/).first(3).map(&:to_i)
9
+ if major < 0 || minor < 9 || patch < 0
10
+ fail "The version of SimpleCov you are using is too old. "\
11
+ "Please update with `gem install simplecov` or `bundle update simplecov`"
12
+ end
13
+
14
+ module SimpleCov
15
+ module Formatter
16
+ class CoverBoardFormatter
17
+ DOT_FILE = '.coverboard.yml'
18
+
19
+ def initialize
20
+ @uid = load_from_config
21
+ end
22
+
23
+ def format(result)
24
+ send_to_api(create_message(metrics(result)))
25
+ end
26
+
27
+ private
28
+ # michal says: LATERRRRR
29
+ PRECISSION = 2
30
+ TIMESTAMP = Time.now.getutc
31
+
32
+ def metrics(numbers)
33
+ prefix = 'coverage-'
34
+
35
+ metrics = Hash.new
36
+ numbers.groups.each do |key, value|
37
+ key = prefix + key.gsub(' ','-').downcase
38
+ metrics[key] = value.covered_percent.round(PRECISSION)
39
+ end
40
+ metrics[prefix.gsub('-','')] = numbers.source_files.covered_percent.round(PRECISSION)
41
+ metrics
42
+ end
43
+
44
+ def create_message metrics
45
+ app_message = ApplicationMessage.new
46
+ app_message.uid = @uid
47
+ app_message.ts = TIMESTAMP
48
+ app_message.metrics = metrics
49
+ return app_message.to_json
50
+ end
51
+
52
+ def send_to_api msg
53
+ connector = Connector.new
54
+ puts connector.post msg
55
+ end
56
+
57
+ private
58
+ def load_from_config
59
+ config = YAML.load(File.read("#{Dir.pwd}/#{DOT_FILE}"))
60
+ @uid = config['coverboard']['uid']
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
67
+ require "simplecov-coverboard/version"
68
+
69
+ require "api/config"
70
+ require "api/application_message"
71
+ require "api/connector"
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ require "simplecov-coverboard/version"
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "simplecov-coverboard"
6
+ gem.version = SimpleCov::Formatter::CoverBoardFormatter::VERSION
7
+ gem.platform = Gem::Platform::RUBY
8
+ gem.authors = ["Michal Franczak", "Lautaro Mazzitelli"]
9
+ gem.homepage = "https://github.com/lautaro-mazzitelli-helpling/simplecov-coverboard"
10
+ gem.description = %(Simplecov formatter which sends metrics to CoverBoard)
11
+ gem.summary = gem.description
12
+ gem.license = "MIT"
13
+
14
+ gem.required_ruby_version = ">= 1.8.7"
15
+ gem.add_development_dependency "bundler", "~> 1.9"
16
+ gem.add_runtime_dependency "simplecov"
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ gem.require_paths = ["lib"]
22
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/setup"
2
+ require "simplecov"
3
+ require "simplecov-coverboard"
4
+ require "test/unit"
@@ -0,0 +1,8 @@
1
+ require "helper"
2
+
3
+ class TestSimpleCovCoverBoard < Test::Unit::TestCase
4
+ def test_defined
5
+ assert defined?(SimpleCov::Formatter::CoverBoardFormatter)
6
+ assert defined?(SimpleCov::Formatter::CoverBoardFormatter::VERSION)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-coverboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michal Franczak
8
+ - Lautaro Mazzitelli
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.9'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.9'
28
+ - !ruby/object:Gem::Dependency
29
+ name: simplecov
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Simplecov formatter which sends metrics to CoverBoard
43
+ email:
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .coverboard.yml
49
+ - .document
50
+ - .gitignore
51
+ - .rubocop.yml
52
+ - .travis.yml
53
+ - Gemfile
54
+ - Guardfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/api/application_message.rb
59
+ - lib/api/config.rb
60
+ - lib/api/connector.rb
61
+ - lib/simplecov-coverboard.rb
62
+ - lib/simplecov-coverboard/version.rb
63
+ - simplecov-coverboard.gemspec
64
+ - test/helper.rb
65
+ - test/test_simple_cov-html.rb
66
+ homepage: https://github.com/lautaro-mazzitelli-helpling/simplecov-coverboard
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.8.7
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Simplecov formatter which sends metrics to CoverBoard
90
+ test_files:
91
+ - test/helper.rb
92
+ - test/test_simple_cov-html.rb