Class: Covered::Coveralls
- Inherits:
-
Object
- Object
- Covered::Coveralls
- Defined in:
- lib/covered/coveralls.rb
Defined Under Namespace
Classes: Wrapper
Constant Summary collapse
- URL =
"https://coveralls.io/api/v1/jobs"
Instance Method Summary collapse
- #call(wrapper, output = $stderr) ⇒ Object
- #detect_service ⇒ Object
-
#initialize(token: nil, service: nil, job_id: nil) ⇒ Coveralls
constructor
A new instance of Coveralls.
Constructor Details
#initialize(token: nil, service: nil, job_id: nil) ⇒ Coveralls
Returns a new instance of Coveralls.
50 51 52 53 54 |
# 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 |
Instance Method Details
#call(wrapper, output = $stderr) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# 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 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |