Last active
February 13, 2023 17:45
-
-
Save fwuensche/f907ff0d98b06955b26090406805dfc6 to your computer and use it in GitHub Desktop.
Cherry Push Integrations: simplecov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'json' | |
require 'httparty' | |
PROJECT_NAME = 'rsv-ink/majestic_monolith' | |
file = File.read('./simplecov.json') | |
json = JSON.parse(file) | |
occurrences = [] | |
json['RSpec']['coverage'].each do |file_path, values| | |
values['lines'].each_with_index do |value, index| | |
next if value.nil? || value.positive? | |
occurrences << { | |
name: "#{file_path}:#{index + 1}", | |
url: "https://github.com/#{PROJECT_NAME}/blob/master/#{file_path}#L#{index + 1}", | |
} | |
end | |
end | |
payload = { | |
api_key: ENV.fetch('CHERRY_PUSH_API_KEY'), | |
project_name: PROJECT_NAME, | |
date: Time.now, | |
metrics: [{ name: 'Missing Test Coverage', occurrences: occurrences }], | |
} | |
res = | |
HTTParty.post( | |
'https://www.cherrypush.com/api/push', | |
body: payload.to_json, | |
headers: { | |
'Content-Type' => 'application/json', | |
}, | |
) | |
if res.code == 200 | |
puts 'Report available at https://www.cherrypush.com/projects' | |
else | |
puts res.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment