simplecov-shields-badge 0.1.0

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: ec4d6437f0c063c2a9f3ef8e70d250ced0e43a81
4
+ data.tar.gz: dc1bc6c5c9ab60be49c05603dc5f8900be94f005
5
+ SHA512:
6
+ metadata.gz: 651751b119030417bf7164302e7db8ecd7e04e9953845446b6b5859b98e3f8cc9342c4007c6bc31751aa7f4691d901f5b487a20488442688d3a5563a4b0ff156
7
+ data.tar.gz: 1c7b5bf514e231f107fb648bf1d78ec0c8fbaa83bb25faa624466f7c81dcb25398137f7520943e031f9c3cf78562b9bbb4ce62ff5c98ce0c58448029dde4e8d1
@@ -0,0 +1,58 @@
1
+ module SimpleCov
2
+ module Formatter
3
+ class ShieldsBadge
4
+ VERSION = "0.1.0"
5
+
6
+ def format(result)
7
+ coverage = result.covered_percent
8
+ generate_badge(coverage)
9
+ upload_to_gh_pages
10
+ end
11
+
12
+ private
13
+
14
+ def generate_badge(coverage)
15
+ %x(curl #{badge_url(coverage)} > badge.svg)
16
+ end
17
+
18
+ def badge_url(coverage)
19
+ color = coverage_color(coverage)
20
+ "https://img.shields.io/badge/coverage-#{coverage.round(2)}%25-#{color}.svg"
21
+ end
22
+
23
+ def coverage_color(coverage)
24
+ case coverage
25
+ when 0..20 then :red
26
+ when 20..40 then :orange
27
+ when 40..60 then :yellow
28
+ when 60..80 then :yellowgreen
29
+ when 80..90 then :green
30
+ else :brightgreen
31
+ end
32
+ end
33
+
34
+ def upload_to_gh_pages
35
+ github_user = ENV["GITHUB_USER"]
36
+ github_mail = ENV["GITHUB_MAIL"]
37
+ github_org = ENV["GITHUB_ORG"]
38
+ github_repo = ENV["GITHUB_REPO"]
39
+ github_token = ENV["GITHUB_ACCESS_TOKEN"]
40
+
41
+ return unless (github_user and github_mail and github_org and github_repo and github_token)
42
+
43
+ %x(mv badge.svg ../)
44
+ %x(git remote remove upstream)
45
+ %x(git remote add upstream 'https://#{github_token}@github.com/#{github_org}/#{github_repo}.git' > /dev/null 2> /dev/null)
46
+ %x(git config --global user.name #{github_user})
47
+ %x(git config --global user.email #{github_mail})
48
+ %x(git fetch upstream)
49
+ %x(git checkout gh-pages -f)
50
+ %x(git reset -- .)
51
+ %x(mv ../badge.svg .)
52
+ %x(git add badge.svg)
53
+ %x(git commit -a -m 'CI: Coverage for $COMMIT_ID')
54
+ %x(git push upstream gh-pages:gh-pages)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,44 @@
1
+ require 'helper'
2
+
3
+ class TestShieldsBadge < Minitest::Test
4
+ def test_defined
5
+ assert defined?(SimpleCov::Formatter::ShieldsBadge)
6
+ assert defined?(SimpleCov::Formatter::ShieldsBadge::VERSION)
7
+ end
8
+
9
+ def stub_file(filename, coverage)
10
+ lines = coverage.each_with_index.map do |cov, i|
11
+ skipped = false
12
+ if cov == :skipped
13
+ skipped = true
14
+ cov = 0
15
+ end
16
+ stub('SimpleCov::SourceFile::Line', skipped?: skipped, line_number: i+1, coverage: cov)
17
+ end
18
+ stub('SimpleCov::SourceFile', filename: filename, lines: lines)
19
+ end
20
+
21
+ def test_badge_svg_is_generated
22
+ formatter = SimpleCov::Formatter::ShieldsBadge.new
23
+
24
+ result = stub('SimpleCov::Result', covered_percent: 0)
25
+ formatter.format(result)
26
+ assert_equal(true, File.exist?('badge.svg'))
27
+ end
28
+
29
+ def test_right_badge_color
30
+ formatter = SimpleCov::Formatter::ShieldsBadge.new
31
+ assert_equal(:red, formatter.send(:coverage_color, 0))
32
+ assert_equal(:red, formatter.send(:coverage_color, 20))
33
+ assert_equal(:orange, formatter.send(:coverage_color, 21))
34
+ assert_equal(:orange, formatter.send(:coverage_color, 40))
35
+ assert_equal(:yellow, formatter.send(:coverage_color, 41))
36
+ assert_equal(:yellow, formatter.send(:coverage_color, 60))
37
+ assert_equal(:yellowgreen, formatter.send(:coverage_color, 61))
38
+ assert_equal(:yellowgreen, formatter.send(:coverage_color, 80))
39
+ assert_equal(:green, formatter.send(:coverage_color, 81))
40
+ assert_equal(:green, formatter.send(:coverage_color, 90))
41
+ assert_equal(:brightgreen, formatter.send(:coverage_color, 91))
42
+ assert_equal(:brightgreen, formatter.send(:coverage_color, 100))
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-shields-badge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nilton Vasques
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-13 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.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.1'
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.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.10'
69
+ description: Shields Badget Simplecov Formatter
70
+ email:
71
+ - nilton.vasques@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/shields_badge.rb
77
+ - test/test_shields_badge.rb
78
+ homepage: https://github.com/niltonvasques/simplecov-shields-badge
79
+ licenses:
80
+ - mit
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A gem to generate a badge from simplecov coverage result, using shields.io
102
+ platform and publish the badge to gh-pages
103
+ test_files:
104
+ - test/test_shields_badge.rb