Sha256: c1cfb9b508a58d73ebbb05f092a7e3821d0bba0655daf39dbf102697ffb4ba58

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

module Slather
  module CoverageService
    module Coveralls

      def coverage_file_class
        Slather::CoverallsCoverageFile
      end
      private :coverage_file_class

      def travis_job_id
        ENV['TRAVIS_JOB_ID']
      end
      private :travis_job_id

      def coveralls_coverage_data
        if ci_service == :travis_ci || ci_service == :travis_pro
          if travis_job_id
            if ci_service == :travis_ci
              {
                :service_job_id => travis_job_id,
                :service_name => "travis-ci",
                :source_files => coverage_files.map(&:as_json)
              }.to_json
            elsif ci_service == :travis_pro
              {
                :service_job_id => travis_job_id,
                :service_name => "travis-pro",
                :repo_token => ci_access_token,
                :source_files => coverage_files.map(&:as_json)
              }.to_json
            end
          else
            raise StandardError, "Environment variable `TRAVIS_JOB_ID` not set. Is this running on a travis build?"
          end
        else
          raise StandardError, "No support for ci named #{ci_service}"
        end
      end
      private :coveralls_coverage_data

      def post
        f = File.open('coveralls_json_file', 'w+')
        begin
          f.write(coveralls_coverage_data)
          f.close
          `curl -s --form json_file=@#{f.path} #{coveralls_api_jobs_path}`
        rescue StandardError => e
          FileUtils.rm(f)
          raise e
        end
        FileUtils.rm(f)
      end

      def coveralls_api_jobs_path
        "https://coveralls.io/api/v1/jobs"
      end
      private :coveralls_api_jobs_path

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slather-1.5.5 lib/slather/coverage_service/coveralls.rb
slather-1.5.4 lib/slather/coverage_service/coveralls.rb
slather-1.5.3 lib/slather/coverage_service/coveralls.rb
slather-1.5.2 lib/slather/coverage_service/coveralls.rb
slather-1.2.0 lib/slather/coverage_service/coveralls.rb