coverage-badge 0.1.0 → 0.1.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 +4 -4
- data/lib/coverage/badge.rb +4 -0
- data/lib/coverage/badge/formatter.rb +58 -0
- data/lib/coverage/badge/template/flat.svg +21 -0
- data/lib/coverage/badge/version.rb +7 -0
- metadata +3 -13
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -2
- data/.ruby-version +0 -1
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -60
- data/Makefile +0 -5
- data/README.md +0 -48
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/coverage-badge.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41b6fd5fc9fb5888a6d87619db6d1c789e9b927006a0b721322a982487fb0837
|
4
|
+
data.tar.gz: 26ca2e7f32290e215e87e2c823270ec12e61d150c7722bb11ef03394c5f9a230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76f9666be30f157ef781da9efe7c4ca7fef969c91e344fe6931cc1931f4c16494aa6513551f85d0e66edbe6a3b773e35759bab1cd2e93d7dff242a28b108c9cb
|
7
|
+
data.tar.gz: bae69e44f88ae2acb63b3f128eeec22762fe6387de3696fe204bae229fa145641a5d49ae8a1642847df141264627e58ad8657ab04d0408794f5324f0ef910bfc
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coverage
|
4
|
+
module Badge
|
5
|
+
class Formatter
|
6
|
+
DEFAULT_COLOR = '#e05d44'
|
7
|
+
|
8
|
+
COLORS = {
|
9
|
+
(91..100) => '#4c1',
|
10
|
+
(76..90) => '#97CA00',
|
11
|
+
(61..75) => '#a4a61d',
|
12
|
+
(41..60) => '#dfb317',
|
13
|
+
(1..40) => '#fe7d37'
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
def format(result)
|
17
|
+
coverage = result&.source_files&.covered_percent&.round(0)
|
18
|
+
raise ArgumentError, 'Please configure Simplecov' unless coverage
|
19
|
+
|
20
|
+
badge = template(coverage)
|
21
|
+
export_to_file('/coverage/badge.svg', badge)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def template(coverage)
|
27
|
+
template = File.read(resource_dir + '/template/flat.svg')
|
28
|
+
|
29
|
+
template.gsub!('{{ total }}', coverage.to_s)
|
30
|
+
template.gsub!('{{ color }}', color(coverage))
|
31
|
+
|
32
|
+
template
|
33
|
+
end
|
34
|
+
|
35
|
+
def export_to_file(path, content)
|
36
|
+
fh = File.open(current_dir + path, 'w')
|
37
|
+
fh.write(content)
|
38
|
+
fh.close
|
39
|
+
end
|
40
|
+
|
41
|
+
def color(coverage)
|
42
|
+
COLORS.each do |range, value|
|
43
|
+
return value if range.member?(coverage)
|
44
|
+
end
|
45
|
+
|
46
|
+
DEFAULT_COLOR
|
47
|
+
end
|
48
|
+
|
49
|
+
def resource_dir
|
50
|
+
File.expand_path(__dir__)
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_dir
|
54
|
+
Dir.pwd
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20">
|
3
|
+
<linearGradient id="b" x2="0" y2="100%">
|
4
|
+
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
5
|
+
<stop offset="1" stop-opacity=".1"/>
|
6
|
+
</linearGradient>
|
7
|
+
<mask id="a">
|
8
|
+
<rect width="99" height="20" rx="3" fill="#fff"/>
|
9
|
+
</mask>
|
10
|
+
<g mask="url(#a)">
|
11
|
+
<path fill="#555" d="M0 0h63v20H0z"/>
|
12
|
+
<path fill="{{ color }}" d="M63 0h36v20H63z"/>
|
13
|
+
<path fill="url(#b)" d="M0 0h99v20H0z"/>
|
14
|
+
</g>
|
15
|
+
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
16
|
+
<text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
|
17
|
+
<text x="31.5" y="14">coverage</text>
|
18
|
+
<text x="80" y="15" fill="#010101" fill-opacity=".3">{{ total }}%</text>
|
19
|
+
<text x="80" y="14">{{ total }}%</text>
|
20
|
+
</g>
|
21
|
+
</svg>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coverage-badge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Orsoev
|
@@ -101,19 +101,9 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
|
-
- ".rubocop.yml"
|
107
|
-
- ".ruby-version"
|
108
|
-
- Gemfile
|
109
|
-
- Gemfile.lock
|
110
|
-
- Makefile
|
111
|
-
- README.md
|
112
|
-
- Rakefile
|
113
|
-
- bin/console
|
114
|
-
- bin/setup
|
115
|
-
- coverage-badge.gemspec
|
116
104
|
- lib/coverage/badge.rb
|
105
|
+
- lib/coverage/badge/formatter.rb
|
106
|
+
- lib/coverage/badge/template/flat.svg
|
117
107
|
- lib/coverage/badge/version.rb
|
118
108
|
homepage: https://rubygems.org/gems/coverage-badge
|
119
109
|
licenses: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.6.3
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
coverage-badge (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.0)
|
10
|
-
diff-lcs (1.3)
|
11
|
-
docile (1.3.2)
|
12
|
-
jaro_winkler (1.5.3)
|
13
|
-
json (2.2.0)
|
14
|
-
parallel (1.17.0)
|
15
|
-
parser (2.6.3.0)
|
16
|
-
ast (~> 2.4.0)
|
17
|
-
rainbow (3.0.0)
|
18
|
-
rake (10.5.0)
|
19
|
-
rspec (3.8.0)
|
20
|
-
rspec-core (~> 3.8.0)
|
21
|
-
rspec-expectations (~> 3.8.0)
|
22
|
-
rspec-mocks (~> 3.8.0)
|
23
|
-
rspec-core (3.8.0)
|
24
|
-
rspec-support (~> 3.8.0)
|
25
|
-
rspec-expectations (3.8.3)
|
26
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
-
rspec-support (~> 3.8.0)
|
28
|
-
rspec-mocks (3.8.0)
|
29
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
-
rspec-support (~> 3.8.0)
|
31
|
-
rspec-support (3.8.0)
|
32
|
-
rubocop (0.74.0)
|
33
|
-
jaro_winkler (~> 1.5.1)
|
34
|
-
parallel (~> 1.10)
|
35
|
-
parser (>= 2.6)
|
36
|
-
rainbow (>= 2.2.2, < 4.0)
|
37
|
-
ruby-progressbar (~> 1.7)
|
38
|
-
unicode-display_width (>= 1.4.0, < 1.7)
|
39
|
-
ruby-progressbar (1.10.1)
|
40
|
-
simplecov (0.17.0)
|
41
|
-
docile (~> 1.1)
|
42
|
-
json (>= 1.8, < 3)
|
43
|
-
simplecov-html (~> 0.10.0)
|
44
|
-
simplecov-html (0.10.2)
|
45
|
-
unicode-display_width (1.6.0)
|
46
|
-
|
47
|
-
PLATFORMS
|
48
|
-
ruby
|
49
|
-
|
50
|
-
DEPENDENCIES
|
51
|
-
bundler (~> 1.17)
|
52
|
-
coverage-badge!
|
53
|
-
rake (~> 10.0)
|
54
|
-
rspec (~> 3.8.0)
|
55
|
-
rspec-core (~> 3.8.0)
|
56
|
-
rubocop (~> 0.74.0)
|
57
|
-
simplecov (~> 0.17.0)
|
58
|
-
|
59
|
-
BUNDLED WITH
|
60
|
-
1.17.3
|
data/Makefile
DELETED
data/README.md
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# Coverage::Badge
|
2
|
-
|
3
|
-
Generate a SVG badge for code coverage in your project
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'coverage-badge', '~> 0.1.0 '
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install coverage-badge
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
if ENV['CI'] == 'true'
|
25
|
-
require 'simplecov'
|
26
|
-
|
27
|
-
SimpleCov.start 'rails' do
|
28
|
-
require 'coverage-badge'
|
29
|
-
|
30
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
31
|
-
[
|
32
|
-
SimpleCov::Formatter::HTMLFormatter,
|
33
|
-
Coverage::Badge::Formatter
|
34
|
-
]
|
35
|
-
)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
```
|
39
|
-
|
40
|
-
## Development
|
41
|
-
|
42
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
-
|
44
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
-
|
46
|
-
## Contributing
|
47
|
-
|
48
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/andreyors/coverage-badge.
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'coverage/badge'
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/coverage-badge.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'coverage/badge/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'coverage-badge'
|
9
|
-
spec.version = Coverage::Badge::VERSION
|
10
|
-
spec.authors = ['Andrey Orsoev']
|
11
|
-
spec.email = ['andrey.orsoev@gmail.com']
|
12
|
-
|
13
|
-
spec.summary = 'Generate a SVG badge with coverage data'
|
14
|
-
spec.description = 'Provide a coverage information for your codebase'
|
15
|
-
spec.homepage = 'https://rubygems.org/gems/coverage-badge'
|
16
|
-
|
17
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
19
|
-
end
|
20
|
-
spec.require_paths = ['lib']
|
21
|
-
|
22
|
-
spec.add_development_dependency 'bundler', '~> 1.17'
|
23
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
25
|
-
spec.add_development_dependency 'rspec-core', '~> 3.8.0'
|
26
|
-
spec.add_development_dependency 'rubocop', '~> 0.74.0'
|
27
|
-
spec.add_development_dependency 'simplecov', '~> 0.17.0'
|
28
|
-
end
|