<commit_before>require "sinatra"
require "json"
require "pony"

configure do
  # A string describing the odds of a code review (e.g. "1:10").
  set :odds, ENV["ODDS"]

  # A list of strings describing e-mail addresses a code review may be addressed to.
  set :reviewers, ENV["REVIEWERS"].split(",")
end

Pony.options = {
  via: :smtp,
  via_options: {
    address: ENV["SMTP_HOST"],
    port: ENV["SMTP_PORT"],
    domain: ENV["SMTP_DOMAIN"],
    user_name: ENV['SMTP_USERNAME'],
    password: ENV['SMTP_PASSWORD'],
    authentication: :plain,
    enable_starttls_auto: true
  }
}

post "/" do
  data = JSON.parse request.body.read

  chance = Odds.parse settings.odds

  data["commits"].each do |commit|
    if rand(100) <= chance

      reviewers = settings.reviewers.reject do |reviewer|
        reviewer == commit["author"]["email"]
      end

      reviewer = reviewers.sample

      if reviewer

        Pony.mail({
          to: reviewer,
          from: "Hyper <<EMAIL>>",
          subject: "You've been selected to review #{commit["author"]["name"]}'s commit",
          body: erb(:reviewer_email, locals: {
            reviewee: commit["author"]["name"],
            url: commit["url"]
          })
        })

        Pony.mail({
          to: commit["author"]["email"],
          from: "Hyper <<EMAIL>>",
          subject: "Your commit has been selected for review",
          body: erb(:reviewee_email, locals: {
            reviewer: reviewer,
            url: commit["url"]
          })
        })

      end
    end
  end

  ""
end<commit_msg>Use committer's e-mail instead of author's<commit_after>require "sinatra"
require "json"
require "pony"

configure do
  # A string describing the odds of a code review (e.g. "1:10").
  set :odds, ENV["ODDS"]

  # A list of strings describing e-mail addresses a code review may be addressed to.
  set :reviewers, ENV["REVIEWERS"].split(",")
end

Pony.options = {
  via: :smtp,
  via_options: {
    address: ENV["SMTP_HOST"],
    port: ENV["SMTP_PORT"],
    domain: ENV["SMTP_DOMAIN"],
    user_name: ENV['SMTP_USERNAME'],
    password: ENV['<PASSWORD>'],
    authentication: :plain,
    enable_starttls_auto: true
  }
}

post "/" do
  data = JSON.parse request.body.read

  chance = Odds.parse settings.odds

  data["commits"].each do |commit|
    if rand(100) <= chance

      reviewers = settings.reviewers.reject do |reviewer|
        reviewer == commit["committer"]["email"]
      end

      reviewer = reviewers.sample

      if reviewer

        Pony.mail({
          to: reviewer,
          from: "Hyper <<EMAIL>>",
          subject: "You've been selected to review #{commit["author"]["name"]}'s commit",
          body: erb(:reviewer_email, locals: {
            reviewee: commit["author"]["name"],
            url: commit["url"]
          })
        })

        Pony.mail({
          to: commit["committer"]["email"],
          from: "Hyper <<EMAIL>>",
          subject: "Your commit has been selected for review",
          body: erb(:reviewee_email, locals: {
            reviewer: reviewer,
            url: commit["url"]
          })
        })

      end
    end
  end

  ""
end
{'fraction_non_alphanumeric': 0.14109067850348764, 'fraction_numerical': 0.003804692454026633, 'mean_word_length': 2.4108108108108106, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, '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': '1502726', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1001, 'n_words': 262}