<commit_before>require 'active_support/all'
require 'active_model_serializers'
require 'state_machines-activerecord'
require 'validate_url'
require 'responders'
require 'explicit-parameters'
require 'attr_encrypted'

require 'sass-rails'
require 'coffee-rails'
require 'jquery-rails'
require 'rails-timeago'
require 'lodash-rails'
require 'ansi_stream'
require 'autoprefixer-rails'
require 'rails_autolink'
require 'gemoji'

require 'omniauth-github'

require 'pubsubstub'
require 'safe_yaml/load'
require 'securecompare'

require 'redis-objects'
require 'redis-namespace'

require 'octokit'
require 'faraday-http-cache'

require 'shipit/version'

require 'shipit/octokit_check_runs'
require 'shipit/flock'
require 'shipit/github_app'
require 'shipit/paginator'
require 'shipit/null_serializer'
require 'shipit/csv_serializer'
require 'shipit/octokit_iterator'
require 'shipit/first_parent_commits_iterator'
require 'shipit/simple_message_verifier'
require 'shipit/command'
require 'shipit/commands'
require 'shipit/stack_commands'
require 'shipit/task_commands'
require 'shipit/deploy_commands'
require 'shipit/rollback_commands'
require 'shipit/environment_variables'
require 'shipit/stat'
require 'shipit/strip_cache_control'

SafeYAML::OPTIONS[:default_mode] = :safe
SafeYAML::OPTIONS[:deserialize_symbols] = false

module Shipit
  extend self

  delegate :table_name_prefix, to: :secrets

  attr_accessor :disable_api_authentication, :timeout_exit_codes
  attr_writer :internal_hook_receivers

  self.timeout_exit_codes = [].freeze

  def authentication_disabled?
    ENV['SHIPIT_DISABLE_AUTH'].present?
  end

  def app_name
    @app_name ||= secrets.app_name || Rails.application.class.name.split(':').first || 'Shipit'
  end

  def redis_url
    secrets.redis_url.present? ? URI(secrets.redis_url) : nil
  end

  def redis(namespace = nil)
    @redis ||= Redis.new(url: redis_url.to_s.presence, logger: Rails.logger)
    return @redis unless namespace
    Redis::Namespace.new(namespace, redis: @redis)
  end

  def github
    @github ||= GitHubApp.new(secrets.github)
  end

  def legacy_github_api
    if secrets&.github_api.present?<commit_msg>Increase number of connection retries<commit_after>require 'active_support/all'
require 'active_model_serializers'
require 'state_machines-activerecord'
require 'validate_url'
require 'responders'
require 'explicit-parameters'
require 'attr_encrypted'

require 'sass-rails'
require 'coffee-rails'
require 'jquery-rails'
require 'rails-timeago'
require 'lodash-rails'
require 'ansi_stream'
require 'autoprefixer-rails'
require 'rails_autolink'
require 'gemoji'

require 'omniauth-github'

require 'pubsubstub'
require 'safe_yaml/load'
require 'securecompare'

require 'redis-objects'
require 'redis-namespace'

require 'octokit'
require 'faraday-http-cache'

require 'shipit/version'

require 'shipit/octokit_check_runs'
require 'shipit/flock'
require 'shipit/github_app'
require 'shipit/paginator'
require 'shipit/null_serializer'
require 'shipit/csv_serializer'
require 'shipit/octokit_iterator'
require 'shipit/first_parent_commits_iterator'
require 'shipit/simple_message_verifier'
require 'shipit/command'
require 'shipit/commands'
require 'shipit/stack_commands'
require 'shipit/task_commands'
require 'shipit/deploy_commands'
require 'shipit/rollback_commands'
require 'shipit/environment_variables'
require 'shipit/stat'
require 'shipit/strip_cache_control'

SafeYAML::OPTIONS[:default_mode] = :safe
SafeYAML::OPTIONS[:deserialize_symbols] = false

module Shipit
  extend self

  delegate :table_name_prefix, to: :secrets

  attr_accessor :disable_api_authentication, :timeout_exit_codes
  attr_writer :internal_hook_receivers

  self.timeout_exit_codes = [].freeze

  def authentication_disabled?
    ENV['SHIPIT_DISABLE_AUTH'].present?
  end

  def app_name
    @app_name ||= secrets.app_name || Rails.application.class.name.split(':').first || 'Shipit'
  end

  def redis_url
    secrets.redis_url.present? ? URI(secrets.redis_url) : nil
  end

  def redis(namespace = nil)
    @redis ||= Redis.new(
      url: redis_url.to_s.presence,
      logger: Rails.logger,
      reconnect_attempts: 3,
      reconnect_delay: 0.5,
      reconnect_delay_max: 1,
    )
    return @redis unless namespace
    Redis::Namespace.new(namespace, redis: @redis)
  end

  def github
    @github ||= GitHubApp.new(secrets.github)
  end

  def legacy_github_api
    if secrets&.github_api.present?
{'fraction_non_alphanumeric': 0.1018018018018018, 'fraction_numerical': 0.0009009009009009009, 'mean_word_length': 5.982704402515723, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4350348', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1505, 'n_words': 304}