Sha256: 3d6aaa713150f6accba7179d36bfe9b7c966d55b9ded573a2fe5f0d72e999c32

Contents?: true

Size: 1.92 KB

Versions: 82

Compression:

Stored size: 1.92 KB

Contents

# encoding: utf-8
require 'travis/client'
require 'travis/tools/safe_string'

module Travis
  module Client
    class Artifact < Entity
      CHUNKED = "application/json; chunked=true; version=2, application/json; version=2"

      # @!parse attr_reader :job_id, :type, :body
      attributes :job_id, :type, :body

      # @!parse attr_reader :job
      has :job

      def encoded_body
        Tools::SafeString.encoded(body)
      end

      def colorized_body
        attributes['colorized_body'] ||= Tools::SafeString.colorized(body)
      end

      def clean_body
        attributes['clean_body'] ||= Tools::SafeString.clean(body)
      end

      def current_body
        attributes['current_body'] ||= begin
          body = load_attribute('body')
          body.to_s.empty? ? session.get_raw("jobs/#{job_id}/log") : body
        end
      end

      def body(stream = block_given?)
        return current_body unless block_given? or stream
        return yield(current_body) unless stream and job.pending?
        number = 0

        session.listen(self) do |listener|
          listener.on 'job:log' do |event|
            next unless event.payload['number'] > number
            number = event.payload['number']
            yield event.payload['_log']
            listener.disconnect if event.payload['final']
          end

          listener.on 'job:finished' do |event|
            listener.disconnect
          end

          listener.on_connect do
            data = session.get_raw("/logs/#{id}", nil, "Accept" => CHUNKED)['log']
            if data['parts']
              data['parts'].each { |p| yield p['content'] }
              number = data['parts'].last['number'] if data['parts'].any?
            else
              yield data['body']
              listener.disconnect
            end
          end
        end
      end

      def pusher_entity
        job
      end

      one :log
      many :logs
      aka :artifact
    end
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
travis-1.6.7.travis.431.6 lib/travis/client/artifact.rb
travis-1.6.7.travis.428.9 lib/travis/client/artifact.rb
travis-1.6.7.travis.427.9 lib/travis/client/artifact.rb
travis-1.6.7.travis.426.8 lib/travis/client/artifact.rb
travis-1.6.7.travis.425.8 lib/travis/client/artifact.rb
travis-1.6.7.travis.422.4 lib/travis/client/artifact.rb
travis-1.6.7.travis.420.4 lib/travis/client/artifact.rb
travis-1.6.6 lib/travis/client/artifact.rb
travis-1.6.6.travis.419.4 lib/travis/client/artifact.rb
travis-1.6.6.travis.417.4 lib/travis/client/artifact.rb
travis-1.6.5 lib/travis/client/artifact.rb
travis-1.6.4.travis.414.4 lib/travis/client/artifact.rb
travis-1.6.4.travis.413.4 lib/travis/client/artifact.rb
travis-1.6.4.travis.410.4 lib/travis/client/artifact.rb
travis-1.6.4.travis.411.4 lib/travis/client/artifact.rb
travis-1.6.4.travis.406.4 lib/travis/client/artifact.rb
travis-1.6.4.travis.405.4 lib/travis/client/artifact.rb
travis-1.6.4.travis.395.4 lib/travis/client/artifact.rb
travis-1.6.3 lib/travis/client/artifact.rb
travis-1.6.3.travis.394.4 lib/travis/client/artifact.rb