<commit_before># 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 delete_body(reason = {})
        reason = { reason: reason } unless reason.is_a? Hash
        session.patch_raw("jobs/#{job_id}/log", reason)
        reload
      end

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

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

      def clean_body<commit_msg>handle log being already gone<commit_after># 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 delete_body(reason = {})
        reason = { reason: reason } unless reason.is_a? Hash
        session.patch_raw("jobs/#{job_id}/log", reason)
        reload
      rescue Travis::Client::Error => error
        raise unless error.message == '409'
        self
      end

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

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

      def clean_body
{'fraction_non_alphanumeric': 0.10617876424715057, 'fraction_numerical': 0.005398920215956809, 'mean_word_length': 2.7567567567567566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6485716', 'n_tokens_mistral': 518, 'n_tokens_neox': 505, 'n_words': 125}