# frozen_string_literal: true # Service to upload SourceMap files to Honeybadger during Heroku deployment # process, once the bin/webpack step is completed. module NeetoCommonsBackend class SourceMapPublishService def process! upload_all_js_source_maps end private def upload_all_js_source_maps file = File.open("public/packs/manifest.json") data = JSON.parse(file.read) file.close data.entries .filter { |file_name, _file_url| file_name.end_with?(".js") } .map { |_file_name, file_url| file_url } .each(&method(:upload_source_map)) end def upload_source_map(file_url) relative_path = "public#{URI.parse(file_url).path}" minified_url = "https://*#{file_url}" Rails.logger.debug( revision: ENV["HEROKU_SLUG_COMMIT"], minified_url:, source_map: "#{relative_path}.map", minified_file: relative_path ) begin Rails.logger.debug ` curl https://api.honeybadger.io/v1/source_maps \ -F api_key=#{ENV["HONEYBADGER_JS_API_KEY"] || ENV["HONEYBADGER_API_KEY"]} \ -F revision=#{ENV["HEROKU_SLUG_COMMIT"]} \ -F minified_url=#{minified_url} \ -F source_map=@#{relative_path}.map \ -F minified_file=@#{relative_path} ` rescue RestClient::ExceptionWithResponse => e Rails.logger.debug e.response end end end end