Skip to content

Instantly share code, notes, and snippets.

@fwuensche
Last active February 13, 2023 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fwuensche/f907ff0d98b06955b26090406805dfc6 to your computer and use it in GitHub Desktop.
Save fwuensche/f907ff0d98b06955b26090406805dfc6 to your computer and use it in GitHub Desktop.
Cherry Push Integrations: simplecov
# 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