<commit_before>require 'active_record'
require 'travis/scheduler/models/commit'
require 'travis/scheduler/models/organization'
require 'travis/scheduler/models/repository'
require 'travis/scheduler/models/user'

class Request < ActiveRecord::Base
  belongs_to :commit
  belongs_to :repository
  belongs_to :owner, polymorphic: true

  def pull_request?
    event_type == 'pull_request'
  end

  def pull_request_title
    payload && payload['pull_request'] && payload['pull_request']['title'] if pull_request?
  end

  # TODO duplicated in Commit
  def pull_request_number
    payload && payload['pull_request'] && payload['pull_request']['number'] if pull_request?
  end

  def branch_name
    payload && payload['ref'] && payload['ref'].scan(%r{refs/heads/(.*?)$}).flatten.first
  end

  def tag_name
    payload && payload['ref'] && payload['ref'].scan(%r{refs/tags/(.*?)$}).flatten.first
  end

  def same_repo_pull_request?
    payload = Hashr.new(self.payload)
    head_repo = payload.try(:pull_request).try(:head).try(:repo).try(:full_name)
    base_repo = payload.try(:pull_request).try(:base).try(:repo).try(:full_name)
    !!(head_repo && base_repo && head_repo == base_repo)
  rescue => e
    Travis.config.error "[request:#{id}] Couldn't determine whether pull request is from the same repository: #{e.message}"
    false
  end
end
<commit_msg>deserialize request.payload, use Travis.logger for fox' sake<commit_after>require 'active_record'
require 'travis/scheduler/models/commit'
require 'travis/scheduler/models/organization'
require 'travis/scheduler/models/repository'
require 'travis/scheduler/models/user'

class Request < ActiveRecord::Base
  belongs_to :commit
  belongs_to :repository
  belongs_to :owner, polymorphic: true

  serialize :payload

  def pull_request?
    event_type == 'pull_request'
  end

  def pull_request_title
    payload && payload['pull_request'] && payload['pull_request']['title'] if pull_request?
  end

  # TODO duplicated in Commit
  def pull_request_number
    payload && payload['pull_request'] && payload['pull_request']['number'] if pull_request?
  end

  def branch_name
    payload && payload['ref'] && payload['ref'].scan(%r{refs/heads/(.*?)$}).flatten.first
  end

  def tag_name
    payload && payload['ref'] && payload['ref'].scan(%r{refs/tags/(.*?)$}).flatten.first
  end

  def same_repo_pull_request?
    payload = Hashr.new(self.payload)
    head_repo = payload.try(:pull_request).try(:head).try(:repo).try(:full_name)
    base_repo = payload.try(:pull_request).try(:base).try(:repo).try(:full_name)
    !!(head_repo && base_repo && head_repo == base_repo)
  rescue => e
    Travis::Scheduler.logger.error "[request:#{id}] Couldn't determine whether pull request is from the same repository: #{e.message}"
    false
  end
end

{'fraction_non_alphanumeric': 0.14362464183381088, 'fraction_numerical': 0.0, 'mean_word_length': 4.9425531914893615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5700009', 'n_tokens_mistral': 893, 'n_tokens_neox': 879, 'n_words': 184}