class Covered::Coveralls

Constants

URL

Public Class Methods

new(token: nil, service: nil, job_id: nil) click to toggle source
# File lib/covered/coveralls.rb, line 50
def initialize(token: nil, service: nil, job_id: nil)
        @token = token
        @service = service
        @job_id = job_id
end

Public Instance Methods

call(wrapper, output = $stderr) click to toggle source
# File lib/covered/coveralls.rb, line 72
def call(wrapper, output = $stderr)
        if body = detect_service
                output.puts "Submitting data using #{body.inspect}..."
                
                source_files = []
                
                wrapper.each do |coverage|
                        path = wrapper.relative_path(coverage.path)
                        
                        source_files << {
                                name: path,
                                source_digest: Digest::MD5.hexdigest(coverage.read),
                                coverage: coverage.to_a,
                        }
                end
                
                body[:source_files] = source_files
                
                Async do
                        representation = Async::REST::Representation.new(
                                Async::REST::Resource.for(URL),
                                wrapper: Wrapper.new
                        )
                        
                        begin
                                response = representation.post(body)
                                
                                output.puts "Got response: #{response.read}"
                                
                        ensure
                                representation.close
                        end
                end
        end
end
detect_service() click to toggle source
# File lib/covered/coveralls.rb, line 56
def detect_service
        if token = ENV.fetch('COVERALLS_REPO_TOKEN', @token)
                return {"repo_token" => token}
        elsif @service && @job_id
                return {"service_name" => @service, "service_job_id" => @job_id}
        elsif job_id = ENV['TRAVIS_JOB_ID']
                return {"service_name" => "travis-ci", "service_job_id" => job_id}
        elsif token = ENV['GITHUB_TOKEN']
                return {"service_name" => "github", "repo_token" => token}
        else
                warn "#{self.class} can't detect service! Please specify COVERALLS_REPO_TOKEN."
        end
        
        return nil
end