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 +4 -4
- data/README.md +13 -4
- data/Rakefile +3 -0
- data/lib/simplecov_badger.rb +1 -0
- data/lib/simplecov_badger/configuration.rb +7 -2
- data/lib/simplecov_badger/formatter.rb +5 -3
- data/lib/simplecov_badger/install.rake +32 -0
- data/lib/simplecov_badger/railtie.rb +11 -0
- data/lib/simplecov_badger/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84d9ec588ba94fb06e29b3f68da95d741e77214d4e9d2260e6e9f2f9a404263a
|
4
|
+
data.tar.gz: c9490fb028566d38262d8f1d31268f99b8fb3f0e59faa68d14818c12c1cba2c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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
data/lib/simplecov_badger.rb
CHANGED
@@ -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.
|
13
|
-
config.
|
14
|
-
{ percentage: result.source_files.covered_percent.round(2),
|
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
|
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.
|
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-
|
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
|