simplecov_badger 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fa869a8744a6c7f94d5564afc859c6888cc42a3cf8a91bfba008ed12aaba7dc
4
- data.tar.gz: 9d103c4beff16789532b79cd24f1a5f24ed2097ba8eb9cd3815be038579aab41
3
+ metadata.gz: 479b075da95d9e0caa5cbab73f912960d382942c62e4cc82ce379b2d12d552a7
4
+ data.tar.gz: fe331af0e9bbe7aabc3959bfdfee40d317bdca65195673b10822bb791d272c64
5
5
  SHA512:
6
- metadata.gz: 6d82cf9b5d6ec555bab27369ad83e7711e7d3a6056820067d4f4bf1990b293fac1c70f49604ea4d5628e9090e3645f26cf0f897478352cfac30a8a0abdc5b14f
7
- data.tar.gz: '05832ea232b03c07c7d82666665af8f3c6c6fb6bab36c8e8080afa0916693959894b7ac99095761a9fdd8a9751334fdca64f9fd811b1374dd709227237cc6df7'
6
+ metadata.gz: d0f3b631ae5eaf2fd85dfbf16cef1f5a56304048112467f6fdd4aad7c1858c8b955fbec07c0cb1310438176eff0b2578e3f119d318341118b7cce50f673cbc79
7
+ data.tar.gz: 62c4ff8422f7f36549ae2e18d4299f98d862d55ae748f03525cf6b747e3f5c7387926c9a353e396bf99845322080aadd9aa4f9003b767f57396660dd20929707
@@ -0,0 +1,45 @@
1
+ version: v1.0
2
+ name: build
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu1804
7
+ auto_cancel:
8
+ running:
9
+ when: 'true'
10
+ blocks:
11
+ - name: Tests
12
+ task:
13
+ jobs:
14
+ - name: Ruby 2.7
15
+ commands:
16
+ - checkout
17
+ - sem-version ruby 2.7
18
+ - cache restore
19
+ - bundle install --path vendor/bundle
20
+ - cache store
21
+ - bundle exec rake test
22
+ - name: Ruby 3.0
23
+ commands:
24
+ - checkout
25
+ - sem-version ruby 3.0
26
+ - cache restore
27
+ - bundle install --path vendor/bundle
28
+ - cache store
29
+ - bundle exec rake test
30
+ - name: Ruby 3.1
31
+ commands:
32
+ - checkout
33
+ - sem-version ruby 3.1
34
+ - cache restore
35
+ - bundle install --path vendor/bundle
36
+ - cache store
37
+ - bundle exec rake test
38
+ - name: Ruby 3.2
39
+ commands:
40
+ - checkout
41
+ - sem-version ruby 3.2
42
+ - cache restore
43
+ - bundle install --path vendor/bundle
44
+ - cache store
45
+ - bundle exec rake test
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
8
-
7
+ gem "minitest", "~> 5.18.0"
8
+ gem "debug"
data/Gemfile.lock CHANGED
@@ -1,49 +1,60 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simplecov_badger (0.0.3)
4
+ simplecov_badger (0.0.4)
5
5
  rest-client (~> 2.1.0)
6
- simplecov (~> 0.18.5)
6
+ simplecov (>= 0.18.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- docile (1.3.2)
11
+ debug (1.7.2)
12
+ irb (>= 1.5.0)
13
+ reline (>= 0.3.1)
14
+ docile (1.4.0)
12
15
  domain_name (0.5.20190701)
13
16
  unf (>= 0.0.5, < 1.0.0)
14
17
  http-accept (1.7.0)
15
- http-cookie (1.0.3)
18
+ http-cookie (1.0.5)
16
19
  domain_name (~> 0.5)
20
+ io-console (0.6.0)
21
+ irb (1.6.4)
22
+ reline (>= 0.3.0)
17
23
  m (1.5.1)
18
24
  method_source (>= 0.6.7)
19
25
  rake (>= 0.9.2.2)
20
26
  method_source (1.0.0)
21
- mime-types (3.3.1)
27
+ mime-types (3.4.1)
22
28
  mime-types-data (~> 3.2015)
23
- mime-types-data (3.2019.1009)
24
- minitest (5.14.0)
29
+ mime-types-data (3.2023.0218.1)
30
+ minitest (5.18.0)
25
31
  mocha (1.11.2)
26
32
  netrc (0.11.0)
27
33
  rake (12.3.3)
34
+ reline (0.3.3)
35
+ io-console (~> 0.5)
28
36
  rest-client (2.1.0)
29
37
  http-accept (>= 1.7.0, < 2.0)
30
38
  http-cookie (>= 1.0.2, < 2.0)
31
39
  mime-types (>= 1.16, < 4.0)
32
40
  netrc (~> 0.8)
33
- simplecov (0.18.5)
41
+ simplecov (0.22.0)
34
42
  docile (~> 1.1)
35
43
  simplecov-html (~> 0.11)
36
- simplecov-html (0.12.2)
44
+ simplecov_json_formatter (~> 0.1)
45
+ simplecov-html (0.12.3)
46
+ simplecov_json_formatter (0.1.4)
37
47
  unf (0.1.4)
38
48
  unf_ext
39
- unf_ext (0.0.7.7)
49
+ unf_ext (0.0.8.2)
40
50
 
41
51
  PLATFORMS
42
52
  ruby
43
53
 
44
54
  DEPENDENCIES
55
+ debug
45
56
  m (~> 1.5.1)
46
- minitest (~> 5.0)
57
+ minitest (~> 5.18.0)
47
58
  mocha (~> 1.11.2)
48
59
  rake (~> 12.0)
49
60
  simplecov_badger!
data/README.md CHANGED
@@ -1,14 +1,16 @@
1
1
  # SimpleCov::Badger
2
2
  This gem is a formatter for SimpleCov. It sends the total test coverage from SimpleCov to a url via a post request.
3
- It is heavily inspired by the formatter in MarcGrimme's simplecov-small-badge: https://github.com/MarcGrimme/simplecov-small-badge
4
3
  The gem is connected with our simplecov badge service for rendering badge .svgs. See more at: https://coverage.traels.it
4
+ The badge can then be used in your readme.
5
5
 
6
6
  ## Installation
7
7
 
8
- Add this line to your application's Gemfile:
8
+ Add this line to your application's Gemfile in the test, development group:
9
9
 
10
10
  ```ruby
11
- gem 'simplecov_badger'
11
+ group :development, :test do
12
+ gem 'simplecov_badger'
13
+ end
12
14
  ```
13
15
 
14
16
  And then execute:
@@ -19,11 +21,18 @@ Or install it yourself as:
19
21
 
20
22
  $ gem install simplecov_badger
21
23
 
24
+ Then run
25
+
26
+ $ bundle exec rake simplecov_badger:install
27
+
22
28
  ## Usage
23
29
 
24
30
  There are very few things to do, before you can use the gem. The only necessary setup is to add the `SimpleCov::Badger::Formatter` to `SimpleCov`'s formatters in the same place you start `SimpleCov`:
25
31
 
26
32
  ```ruby
33
+ require "simplecov"
34
+ require "simplecov_badger"
35
+
27
36
  SimpleCov.start do
28
37
  SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
29
38
  [
@@ -34,22 +43,46 @@ SimpleCov.start do
34
43
  end
35
44
  ```
36
45
 
37
- After running your test suite on your master branch, you can find a badge on the url https://coverage.traels.it/badges/[Base64.urlsafe_encode64(your_repo_url)]
46
+ And then setting the token you received from the install rake task in an env somewhere, for example by using the [dotenv](https://rubygems.org/gems/dotenv) gem:
47
+
48
+ If you use rails we recommend setting the token in the [credentials](https://guides.rubyonrails.org/security.html#custom-credentials) instead and conf.
49
+ ```ruby
50
+ # in config/initializers/simplecov_badger.rb
51
+ if Module.const_defined? "SimpleCov"
52
+ SimpleCov::Badger.configure do |config|
53
+ config.token = Rails.application.credentials.simplecov_badger[:token]
54
+ end
55
+ end
56
+ ```
57
+
58
+ After running your test suite on your master branch, a url for your badge will be printed in the console.
38
59
  Subsequent runs will update the badge on the same url.
39
60
 
40
- The gem comes with a standard configuration. If you want to override any of these (three) settings, it can be done like this:
61
+ The gem comes with a standard configuration. If you want to override any of these settings, it can be done like this:
41
62
 
42
63
  ```ruby
43
64
  # this is the standard configuration
44
65
  SimpleCov::Badger.configure do |config|
45
66
  config.post_url = "coverage.traels.it/badges",
46
- config.repo_url = `git config --get remote.origin.url`,
67
+ config.repo_url = `git config --get remote.origin.url`.strip,
47
68
  config.run_if = -> { `git rev-parse --abbrev-ref HEAD` == "master\n" }
69
+ config.token = ENV["SIMPLECOV_BADGER_TOKEN"]
48
70
  end
49
71
  ```
50
72
  Changing the `post_url` changes where the gem posts the coverage to and as a result you will have to make a service for drawing badges yourself.
51
73
  The `repo_url` defaults to the git repo's origin url.
52
74
  The `run_if` defaults to a lambda, that returns true if your current branch is master. This means the badge is only updated, when the test suite is run on the master branch. If replaced, it should be with another lambda that returns true whenever you want the badge updated.
75
+ `token` is used when updating your badge with a new coverage. It defaults to reading from an env variable. When running the install rake task, a token is saved at your projects root in a file called `.simplecov_badger_auth_token`. It is recommended to set this token as an env variable, when not running Rails. If you do use Rails, set the token in your test credentials and configure to read from there instead. Should you lose your token, there is currently no recovery process, but you can configure your repo_url to something else and run the install task again to get a new token.
76
+
77
+ Now every time your test suites is run on your master branch, a new badge is generated. A link to this badge can be found in the test output
78
+ ```shell
79
+ SimpleCov::Badger: Your badge can be found at: https://coverage.traels.it/badges/some_base_64_encoded_string
80
+ ```
81
+ Using markdown, the badge can be inserted like this:
82
+ ```markdown
83
+ ![SimpleCov coverage](https://coverage.traels.it/badges/some_base_64_encoded_string)
84
+ ```
85
+
53
86
 
54
87
  ## Development
55
88
 
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
+ path = File.expand_path(__dir__)
5
+ Dir.glob("#{path}/lib/simplecov_badger/*.rake").each { |f| import f }
6
+
4
7
  Rake::TestTask.new(:test) do |t|
5
8
  t.libs << "test"
6
9
  t.libs << "lib"
@@ -3,8 +3,9 @@ module SimpleCov::Badger
3
3
  def self.options
4
4
  {
5
5
  post_url: "https://coverage.traels.it/badges",
6
- repo_url: `git config --get remote.origin.url`,
7
- run_if: -> { `git rev-parse --abbrev-ref HEAD` == "master\n" }
6
+ repo_url: `git config --get remote.origin.url`.strip,
7
+ run_if: -> { `git rev-parse --abbrev-ref HEAD` == "master\n" },
8
+ token: ENV["SIMPLECOV_BADGER_TOKEN"]
8
9
  }
9
10
  end
10
11
 
@@ -17,5 +18,9 @@ module SimpleCov::Badger
17
18
 
18
19
  Base64.urlsafe_encode64(repo_url)
19
20
  end
21
+
22
+ def badge_url
23
+ "#{post_url}/#{encoded_repo_url}"
24
+ end
20
25
  end
21
26
  end
@@ -9,10 +9,12 @@ module SimpleCov::Badger
9
9
 
10
10
  def format(result)
11
11
  if config.run_if.call
12
- RestClient.post(
13
- config.post_url,
14
- { percentage: result.source_files.covered_percent.round(2), repo_url: config.encoded_repo_url }
12
+ RestClient.patch(
13
+ config.badge_url,
14
+ { percentage: result.source_files.covered_percent.round(2), token: config.token }
15
15
  )
16
+
17
+ puts "SimpleCov::Badger: Your badge can be found at: #{config.badge_url}"
16
18
  end
17
19
  end
18
20
  end
@@ -0,0 +1,32 @@
1
+ desc "Create the initial badge and save an authentication token in a file"
2
+ namespace :simplecov_badger do
3
+ task install: :environment do
4
+ require "simplecov_badger"
5
+ require "json"
6
+
7
+ config = SimpleCov::Badger.configuration
8
+
9
+ begin
10
+ response = RestClient.post(
11
+ config.post_url,
12
+ { repo_url: config.encoded_repo_url }
13
+ )
14
+ File.write("#{project_root}/.simplecov_badger_auth_token", JSON.parse(response.body)["token"])
15
+ rescue => exception
16
+ puts exception.response
17
+ puts exception.response.body
18
+ end
19
+ end
20
+
21
+ def project_root
22
+ if defined?(Rails)
23
+ return Rails.root
24
+ end
25
+
26
+ if defined?(Bundler)
27
+ return Bundler.root
28
+ end
29
+
30
+ Dir.pwd
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ require "rails"
2
+ require "simplecov_badger"
3
+ require "pathname"
4
+
5
+ class SimpleCov::Badger::Railtie < Rails::Railtie
6
+ railtie_name :simplecov_badger
7
+
8
+ rake_tasks do
9
+ load Pathname.new(__dir__).join("install.rake")
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module SimpleCov
2
2
  module Badger
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require "simplecov_badger/formatter"
3
3
  require "simplecov_badger/configuration"
4
4
  require "base64"
5
5
  require "rest-client"
6
+ require "simplecov_badger/railtie" if defined?(Rails)
6
7
 
7
8
  module SimpleCov
8
9
  module Badger
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ["lib"]
26
26
 
27
27
  # dependencies
28
- spec.add_dependency "simplecov", "~> 0.18.5"
28
+ spec.add_dependency "simplecov", ">= 0.18.5"
29
29
  spec.add_dependency "rest-client", "~> 2.1.0"
30
30
 
31
31
  spec.add_development_dependency "m", "~> 1.5.1"
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov_badger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolai Bach Woller
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2023-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.18.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.18.5
27
27
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".semaphore/semaphore.yml"
78
79
  - ".travis.yml"
79
80
  - Gemfile
80
81
  - Gemfile.lock
@@ -86,6 +87,8 @@ files:
86
87
  - lib/simplecov_badger.rb
87
88
  - lib/simplecov_badger/configuration.rb
88
89
  - lib/simplecov_badger/formatter.rb
90
+ - lib/simplecov_badger/install.rake
91
+ - lib/simplecov_badger/railtie.rb
89
92
  - lib/simplecov_badger/version.rb
90
93
  - simplecov_badger.gemspec
91
94
  homepage: https://github.com/traels-it/simplecov_badger
@@ -94,7 +97,7 @@ licenses:
94
97
  metadata:
95
98
  homepage_uri: https://github.com/traels-it/simplecov_badger
96
99
  source_code_uri: https://github.com/traels-it/simplecov_badger
97
- post_install_message:
100
+ post_install_message:
98
101
  rdoc_options: []
99
102
  require_paths:
100
103
  - lib
@@ -109,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  - !ruby/object:Gem::Version
110
113
  version: '0'
111
114
  requirements: []
112
- rubygems_version: 3.1.2
113
- signing_key:
115
+ rubygems_version: 3.3.7
116
+ signing_key:
114
117
  specification_version: 4
115
118
  summary: A small gem that posts simplecovs test coverage to a web service.
116
119
  test_files: []