Module: Slather::CoverageService::Coveralls

Defined in:
lib/slather/coverage_service/coveralls.rb

Instance Method Summary collapse

Instance Method Details

#buildkite_build_urlObject



153
154
155
# File 'lib/slather/coverage_service/coveralls.rb', line 153

def buildkite_build_url
  "https://buildkite.com/" + ENV['BUILDKITE_PROJECT_SLUG'] + "/builds/" + ENV['BUILDKITE_BUILD_NUMBER'] + "#"
end

#buildkite_git_infoObject



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/slather/coverage_service/coveralls.rb', line 141

def buildkite_git_info
  {
    :head => {
      :id => ENV['BUILDKITE_COMMIT'],
      :author_name => (`git log --format=%an -n 1 HEAD`.chomp || ""),
      :author_email => (`git log --format=%ae -n 1 HEAD`.chomp || ""),
      :message => (`git log --format=%s -n 1 HEAD`.chomp || "")
    },
    :branch => ENV['BUILDKITE_BRANCH']
  }
end

#postObject



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/slather/coverage_service/coveralls.rb', line 327

def post
  f = File.open('coveralls_json_file', 'w+')
  begin
    f.write(coveralls_coverage_data)
    f.close

    curl_result = `curl -s --form json_file=@#{f.path} #{coveralls_api_jobs_path}`

    if curl_result.is_a? String 
      curl_result_json = JSON.parse(curl_result)          

      if curl_result_json["error"]
        error_message = curl_result_json["message"]
        raise StandardError, "Error while uploading coverage data to Coveralls. CI Service: #{ci_service} Message: #{error_message}"
      end
    end

  rescue StandardError => e
    FileUtils.rm(f)
    raise e
  end
  FileUtils.rm(f)
end