simplecov_badger 0.0.3 → 0.0.4

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: 84d9ec588ba94fb06e29b3f68da95d741e77214d4e9d2260e6e9f2f9a404263a
4
+ data.tar.gz: c9490fb028566d38262d8f1d31268f99b8fb3f0e59faa68d14818c12c1cba2c5
5
5
  SHA512:
6
- metadata.gz: 6d82cf9b5d6ec555bab27369ad83e7711e7d3a6056820067d4f4bf1990b293fac1c70f49604ea4d5628e9090e3645f26cf0f897478352cfac30a8a0abdc5b14f
7
- data.tar.gz: '05832ea232b03c07c7d82666665af8f3c6c6fb6bab36c8e8080afa0916693959894b7ac99095761a9fdd8a9751334fdca64f9fd811b1374dd709227237cc6df7'
6
+ metadata.gz: 7010a07eb9a9720e8cfa9b8b827da9323b1853f696f74f6b691afbef68774622500cc79c5c497582bb2e8174d64882811573e58f0bb0eb1eabda0d11ab3d2cde
7
+ data.tar.gz: ee1912d15e97cbe3506ac1d596be31a4878fcc8894cecfa8f8d07869ad8a2d637e872e2ff990d448606c8e8ecf99e62520a88b01dae3fcffb4f3d756aa416016
data/README.md CHANGED
@@ -1,6 +1,5 @@
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
5
4
 
6
5
  ## Installation
@@ -19,6 +18,9 @@ Or install it yourself as:
19
18
 
20
19
  $ gem install simplecov_badger
21
20
 
21
+ Then run
22
+ $ bundle exec rake simplecov_badger:install
23
+
22
24
  ## Usage
23
25
 
24
26
  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`:
@@ -34,22 +36,29 @@ SimpleCov.start do
34
36
  end
35
37
  ```
36
38
 
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)]
39
+ And then setting the token you received from the install rake task in an env somewhere:
40
+ ```ruby
41
+ ENV["SIMPLECOV_BADGER_TOKEN"] = "Example_Token"
42
+ ````
43
+
44
+ After running your test suite on your master branch, a url for your badge will be printed in the console.
38
45
  Subsequent runs will update the badge on the same url.
39
46
 
40
- The gem comes with a standard configuration. If you want to override any of these (three) settings, it can be done like this:
47
+ The gem comes with a standard configuration. If you want to override any of these settings, it can be done like this:
41
48
 
42
49
  ```ruby
43
50
  # this is the standard configuration
44
51
  SimpleCov::Badger.configure do |config|
45
52
  config.post_url = "coverage.traels.it/badges",
46
- config.repo_url = `git config --get remote.origin.url`,
53
+ config.repo_url = `git config --get remote.origin.url`.strip,
47
54
  config.run_if = -> { `git rev-parse --abbrev-ref HEAD` == "master\n" }
55
+ config.token = ENV["SIMPLECOV_BADGER_TOKEN"]
48
56
  end
49
57
  ```
50
58
  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
59
  The `repo_url` defaults to the git repo's origin url.
52
60
  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.
61
+ `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.
53
62
 
54
63
  ## Development
55
64
 
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,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
@@ -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.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolai Bach Woller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -86,6 +86,8 @@ files:
86
86
  - lib/simplecov_badger.rb
87
87
  - lib/simplecov_badger/configuration.rb
88
88
  - lib/simplecov_badger/formatter.rb
89
+ - lib/simplecov_badger/install.rake
90
+ - lib/simplecov_badger/railtie.rb
89
91
  - lib/simplecov_badger/version.rb
90
92
  - simplecov_badger.gemspec
91
93
  homepage: https://github.com/traels-it/simplecov_badger