simplecov-formatter-shield 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0d9af30c1ea9d6f6a09b5032fc48eeb1cb576205
4
+ data.tar.gz: 870f33e6bd8bf7d9c8da56d7ab8439d41ad6b3a9
5
+ SHA512:
6
+ metadata.gz: 7f541abcf220aa0509196efd70bf32094238309cf4df7f4951155d22317d256bdf229fe92cab3aabe1aafe936baef6481c1208d0462d4a991fa3ebb389c23e1f
7
+ data.tar.gz: 933f2243883dcbb09bdd97f77855d53419def70cfce19b09977ff35e8d0eaa07bbef1b9c32ef4c5a3d3f3794dd842ec4da773ae2439aa8829cb8413e8fc4ff65
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,66 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 200
9
+
10
+ Metrics/MethodLength:
11
+ Max: 40
12
+
13
+ Metrics/ModuleLength:
14
+ Max: 500
15
+
16
+ Metrics/AbcSize:
17
+ Max: 50
18
+
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 12
21
+
22
+ Metrics/PerceivedComplexity:
23
+ Max: 13
24
+
25
+ Style/RedundantReturn:
26
+ Enabled: false
27
+
28
+ Style/GuardClause:
29
+ Enabled: false
30
+
31
+ Style/IndentHash:
32
+ EnforcedStyle: consistent
33
+
34
+ Metrics/ClassLength:
35
+ Max: 200
36
+
37
+ Style/RedundantSelf:
38
+ Enabled: false
39
+
40
+ Style/NegatedIf:
41
+ Enabled: false
42
+
43
+ Style/DefWithParentheses:
44
+ Enabled: false
45
+
46
+ Style/MultilineMethodCallIndentation:
47
+ EnforcedStyle: indented
48
+
49
+ Style/AlignParameters:
50
+ EnforcedStyle: with_fixed_indentation
51
+
52
+ Style/SingleLineBlockParams:
53
+ Enabled: false
54
+
55
+ Style/FrozenStringLiteralComment:
56
+ Enabled: false
57
+
58
+ Lint/EndAlignment:
59
+ AlignWith: variable
60
+
61
+ CaseIndentation:
62
+ IndentWhenRelativeTo: end
63
+ IndentOneStep: false
64
+
65
+ Style/FrozenStringLiteralComment:
66
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simplecov-formatter-shield.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nicolas Pepin-Perreault
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # SimpleCov::Formatter::ShieldFormatter
2
+
3
+ SimpleCov formatter to generate status shields for your reports. Although one already existed, the idea was to create one with as little dependencies as possible, and eventually more than one backend (i.e. not strictly dependent on shields.io).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'simplecov-formatter-shield'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simplecov-formatter-shield
20
+
21
+ ## Usage
22
+
23
+ When initializing SimpleCov, simply add the formatter to your list of formatters.
24
+
25
+ ```ruby
26
+ SimpleCov.formatter = [..., SimpleCov::Formatter::ShieldFormatter.new]
27
+ ```
28
+
29
+ ## Development
30
+
31
+ Use rubocop for linting, default options until a .rubocop.yml is provided.
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/npepinpe/simplecov-formatter-shield.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'simplecov-formatter-shield'
5
+ require 'irb'
6
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class ShieldFormatter
4
+ module Generators
5
+ class Error < StandardError
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ require 'net/http' # I know this is terrible, but it avoids additional dependencies
2
+
3
+ module SimpleCov
4
+ module Formatter
5
+ class ShieldFormatter
6
+ module Generators
7
+ # TODO: Make configurable
8
+ class ShieldsIO < StandardError
9
+ HOST = 'img.shields.io'.freeze
10
+ PATH = 'badge'.freeze
11
+ EXTENSION = 'png'.freeze
12
+ STYLE = 'flat'.freeze
13
+
14
+ def initialize(options)
15
+ @options = options
16
+ @image = nil
17
+ end
18
+
19
+ def generate
20
+ return @image ||= begin
21
+ generate!
22
+ end
23
+ end
24
+
25
+ def generate!
26
+ uri = build_uri
27
+ response = Net::HTTP.get_response(uri)
28
+ raise(Generators::Error, "Could not fetch image at #{uri} => #{response.msg} (#{response.code})") unless (200..399).cover?(response.code.to_i)
29
+
30
+ return response.body
31
+ end
32
+ private :generate!
33
+
34
+ def build_uri
35
+ parts = [@options.text, @options.status, @options.color].map { |part| CGI.encode(part.to_s) }
36
+ path = "/#{PATH}/#{parts.join('-')}.#{EXTENSION}"
37
+ return URI::HTTPS.build(host: HOST, path: path, query: "style=#{STYLE}")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ require 'simplecov-formatter-shield/generators/error'
2
+ require 'simplecov-formatter-shield/generators/shields_io'
3
+
4
+ module SimpleCov
5
+ module Formatter
6
+ class ShieldFormatter
7
+ module Generators
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class ShieldFormatter
4
+ VERSION = '0.0.2'.freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ require 'simplecov-formatter-shield/generators'
2
+
3
+ module SimpleCov
4
+ module Formatter
5
+ class ShieldFormatter
6
+ TEXT = 'coverage'.freeze
7
+ Options = Struct.new(:text, :color, :status)
8
+
9
+ def format(result)
10
+ percentage = result.covered_percent.to_f.round(2)
11
+ options = Options.new(TEXT, color(percentage), status(percentage))
12
+ puts "Created shield at #{output_path}" if write(image(options))
13
+ rescue Generators::Error => error
14
+ puts "Could not create shield: #{output_path} => #{error.message}"
15
+ rescue IOError => error
16
+ puts "Could not write file at #{output_path} => #{error.message}"
17
+ end
18
+
19
+ # Private API
20
+ def write(bytes)
21
+ File.open(output_path, 'wb') do |file|
22
+ file << bytes
23
+ end
24
+ end
25
+ private :write
26
+
27
+ def output_path
28
+ return File.join(SimpleCov.coverage_path, 'shield.png')
29
+ end
30
+ private :output_path
31
+
32
+ def color(percentage)
33
+ case percentage
34
+ when 95..100
35
+ :brightgreen
36
+ when 80..95
37
+ :green
38
+ when 70..80
39
+ :yellowgreen
40
+ when 60..70
41
+ :yellow
42
+ when 40..60
43
+ :orange
44
+ else
45
+ :red
46
+ end
47
+ end
48
+ private :color
49
+
50
+ def status(percentage)
51
+ return "#{percentage}%"
52
+ end
53
+ private :status
54
+
55
+ def image(options)
56
+ generator = Generators::ShieldsIO.new(options)
57
+ return generator.generate
58
+ end
59
+ private :image
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'simplecov-formatter-shield/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'simplecov-formatter-shield'
7
+ spec.version = SimpleCov::Formatter::ShieldFormatter::VERSION
8
+ spec.authors = ['Nicolas Pepin-Perreault']
9
+ spec.email = ['n.pepinpe@gmail.com']
10
+
11
+ spec.summary = %(SimpleCov formatter to generate TravisCI like shields.)
12
+ spec.description = %(SimpleCov formatter to generate TravisCI like shields with as little dependencies as possible.)
13
+ spec.homepage = 'https://github.com/npepinpe/simplecov-formatter-shield'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'simplecov', '~> 0.11'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.11'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'minitest', '~> 5.0'
26
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-formatter-shield
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Pepin-Perreault
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simplecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
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.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: SimpleCov formatter to generate TravisCI like shields with as little
70
+ dependencies as possible.
71
+ email:
72
+ - n.pepinpe@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/simplecov-formatter-shield.rb
87
+ - lib/simplecov-formatter-shield/generators.rb
88
+ - lib/simplecov-formatter-shield/generators/error.rb
89
+ - lib/simplecov-formatter-shield/generators/shields_io.rb
90
+ - lib/simplecov-formatter-shield/version.rb
91
+ - simplecov-formatter-shield.gemspec
92
+ homepage: https://github.com/npepinpe/simplecov-formatter-shield
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: SimpleCov formatter to generate TravisCI like shields.
116
+ test_files: []
117
+ has_rdoc: