<commit_before>require 'sinatra'
require 'json'
require 'faraday'

set :lifx_access_token, ENV['LIFX_ACCESS_TOKEN'] || raise("no LIFX_ACCESS_TOKEN set")
set :bulb_selector,     ENV['BULB_SELECTOR']     || raise("no BULB_SELECTOR set")
set :project_name,      ENV['PROJECT_NAME']      || raise("no PROJECT_NAME set")
set :branch_name,       ENV['BRANCH_NAME']       || raise("no BRANCH_NAME set")
set :secret,            ENV['SECRET']            || raise("no SECRET set")
set :lifx_api_host,     ENV['LIFX_ENDPOINT']     || 'api.lifx.com'

helpers do
  def lifx_api
    Faraday.new(url: "https://#{settings.lifx_api_host}") do |c|
      c.authorization :Bearer, settings.lifx_access_token
      c.use Faraday::Response::RaiseError
    end
  end
end

post "/" do
  halt(401, 'Looks like you forgot to add ?secret=the-secret') if params[:secret].nil?
  halt(401, 'Secret is incorrect') if params[:secret] != settings.secret

  event = JSON.parse(request.body.read)

  if request["X-Buildkite-Event"] == "build"
    case event['build']['state']
    when 'running'
      lifx_api.post "/lights/#{settings.bulb_selector}/effects/breathe.json",
        power_on:   false,
        color:      "yellow brightness:5%",
        from_color: "yellow brightness:35%",
        period:     5,
        cycles:     9999,
        persist:    true
    when 'passed'<commit_msg>Fix HTTP header check<commit_after>require 'sinatra'
require 'json'
require 'faraday'

set :lifx_access_token, ENV['LIFX_ACCESS_TOKEN'] || raise("no LIFX_ACCESS_TOKEN set")
set :bulb_selector,     ENV['BULB_SELECTOR']     || raise("no BULB_SELECTOR set")
set :project_name,      ENV['PROJECT_NAME']      || raise("no PROJECT_NAME set")
set :branch_name,       ENV['BRANCH_NAME']       || raise("no BRANCH_NAME set")
set :secret,            ENV['SECRET']            || raise("no SECRET set")
set :lifx_api_host,     ENV['LIFX_ENDPOINT']     || 'api.lifx.com'

helpers do
  def lifx_api
    Faraday.new(url: "https://#{settings.lifx_api_host}") do |c|
      c.authorization :Bearer, settings.lifx_access_token
      c.use Faraday::Response::RaiseError
    end
  end
end

post "/" do
  halt(401, 'Looks like you forgot to add ?secret=the-secret') if params[:secret].nil?
  halt(401, 'Secret is incorrect') if params[:secret] != settings.secret

  event = JSON.parse(request.body.read)

  if headers["X-Buildkite-Event"] == "build"
    case event['build']['state']
    when 'running'
      lifx_api.post "/lights/#{settings.bulb_selector}/effects/breathe.json",
        power_on:   false,
        color:      "yellow brightness:5%",
        from_color: "yellow brightness:35%",
        period:     5,
        cycles:     9999,
        persist:    true
    when 'passed'
{'fraction_non_alphanumeric': 0.14107274063188832, 'fraction_numerical': 0.010286554004408524, 'mean_word_length': 3.268025078369906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1380746', 'n_tokens_mistral': 974, 'n_tokens_neox': 931, 'n_words': 206}