<commit_before>class ReceivePullRequestEvent
  include Sidekiq::Worker

  def perform(payload)
    @payload = payload

    case @payload["action"]
    when "opened"
      self.on_opened(@payload["pull_request"])
    when "synchronize"
      self.on_synchronize
    end
  end

  def on_opened(pull_request_json)
    check_box_pairs = pull_request_json["body"].scan(/- \[([ x])\] @(\w+)/)

    pr_sha = pull_request_json["head"]["sha"]

    minimum_reviewers_required = Setting.lookup("minimum_reviewers_required")
    if minimum_reviewers_required.present? && check_box_pairs.count < minimum_reviewers_required
      github = Octokit::Client.new(access_token: ENV["CODY_GITHUB_ACCESS_TOKEN"])
      github.create_status(
        @payload["repository"]["full_name"],
        pr_sha,
        "failure",
        context: "code-review/cody",
        description: "APRICOT: Too few reviewers are listed",
        target_url: ENV["CODY_GITHUB_STATUS_TARGET_URL"]
      )

      return
    end

    pending_reviews = []
    completed_reviews = []

    check_box_pairs.each do |pair|
      if pair[0] == "x"
        completed_reviews << pair[1].strip
      else
        pending_reviews << pair[1].strip
      end<commit_msg>if the author does not put a body then github sends JSON nil in the payload<commit_after>class ReceivePullRequestEvent
  include Sidekiq::Worker

  def perform(payload)
    @payload = payload

    case @payload["action"]
    when "opened"
      self.on_opened(@payload["pull_request"])
    when "synchronize"
      self.on_synchronize
    end
  end

  def on_opened(pull_request_json)
    pull_request_json["body"] ||= ""
    check_box_pairs = pull_request_json["body"].scan(/- \[([ x])\] @(\w+)/)

    pr_sha = pull_request_json["head"]["sha"]

    minimum_reviewers_required = Setting.lookup("minimum_reviewers_required")
    if minimum_reviewers_required.present? && check_box_pairs.count < minimum_reviewers_required
      github = Octokit::Client.new(access_token: ENV["CODY_GITHUB_ACCESS_TOKEN"])
      github.create_status(
        @payload["repository"]["full_name"],
        pr_sha,
        "failure",
        context: "code-review/cody",
        description: "APRICOT: Too few reviewers are listed",
        target_url: ENV["CODY_GITHUB_STATUS_TARGET_URL"]
      )

      return
    end

    pending_reviews = []
    completed_reviews = []

    check_box_pairs.each do |pair|
      if pair[0] == "x"
        completed_reviews << pair[1].strip
      else
        pending_reviews << pair[1].strip
      end
{'fraction_non_alphanumeric': 0.1166468960063266, 'fraction_numerical': 0.002372479240806643, 'mean_word_length': 3.2521008403361344, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '2755555', 'n_tokens_mistral': 836, 'n_tokens_neox': 806, 'n_words': 147}