<commit_before>class Service::Twitter < Service
  string  :token, :secret
  boolean :digest

  def receive_push
    return unless payload['commits']

    statuses   = []
    repository = payload['repository']['name']

    if data['digest'] == '1'
      commit = payload['commits'][-1]
      author = commit['author'] || {}
      tiny_url = shorten_url("#{payload['repository']['url']}/commits/#{ref_name}")
      status = "[#{repository}] #{tiny_url} #{author['name']} - #{payload['commits'].length} commits"
      status.length >= 140 ? statuses << status[0..136] + '...' : statuses << status
    else
      payload['commits'].each do |commit|
        author = commit['author'] || {}
        tiny_url = shorten_url(commit['url'])
        status = "[#{repository}] #{tiny_url} #{author['name']} - #{commit['message']}"
        status.length >= 140 ? statuses << status[0..136] + '...' : statuses << status
      end
    end

    statuses.each do |status|
      post(status)
    end
  end

  def post(status)
    params = { 'status' => status, 'source' => 'github' }

    access_token = ::OAuth::AccessToken.new(consumer, data['token'], data['secret'])
    consumer.request(:post, "/1/statuses/update.json",
                     access_token, { :scheme => :query_string }, params)
  end

  def consumer_key
    secrets['twitter']['key']
  end

  def consumer_secret
    secrets['twitter']['secret']
  end

  def consumer
    @consumer ||= ::OAuth::Consumer.new(consumer_key, consumer_secret,
                                        {:site => "http://api.twitter.com"})
  end
end<commit_msg>raise twitter errors<commit_after>class Service::Twitter < Service
  string  :token, :secret
  boolean :digest

  def receive_push
    return unless payload['commits']

    statuses   = []
    repository = payload['repository']['name']

    if data['digest'] == '1'
      commit = payload['commits'][-1]
      author = commit['author'] || {}
      tiny_url = shorten_url("#{payload['repository']['url']}/commits/#{ref_name}")
      status = "[#{repository}] #{tiny_url} #{author['name']} - #{payload['commits'].length} commits"
      status.length >= 140 ? statuses << status[0..136] + '...' : statuses << status
    else
      payload['commits'].each do |commit|
        author = commit['author'] || {}
        tiny_url = shorten_url(commit['url'])
        status = "[#{repository}] #{tiny_url} #{author['name']} - #{commit['message']}"
        status.length >= 140 ? statuses << status[0..136] + '...' : statuses << status
      end
    end

    statuses.each do |status|
      post(status)
    end
  end

  def post(status)
    params = { 'status' => status, 'source' => 'github' }

    access_token = ::OAuth::AccessToken.new(consumer, data['token'], data['secret'])
    res = consumer.request(:post, "/1/statuses/update.json",
      access_token, { :scheme => :query_string }, params)
    if res.code !~ /^2\d\d/
      raise_response_error(res)
    end
  end

  def raise_response_error(res)
    error = "Received HTTP #{res.code}"
    if msg = response_error_message(res)
      error << ": "
      error << msg
    end

    raise_config_error(error)
  end

  def response_error_message(res)
    JSON.parse(res.body)
  rescue
  end

  def consumer_key
    secrets['twitter']['key']
  end

  def consumer_secret
    secrets['twitter']['secret']
  end

  def consumer
    @consumer ||= ::OAuth::Consumer.new(consumer_key, consumer_secret,
                                        {:site => "http://api.twitter.com"})
  end
end
{'fraction_non_alphanumeric': 0.17344327551890815, 'fraction_numerical': 0.00995166334944555, 'mean_word_length': 2.9132369299221357, 'pattern_counts': {'":': 1, '<': 25, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4898827', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1052, 'n_words': 225}