<commit_before># A user from the Slack API
class User < ApplicationRecord
  include TokenManagement
  include GitHubTokenManagement
  include HerokuTokenManagement

  has_many :commands, dependent: :destroy
  has_many :actions,  dependent: :destroy

  def self.omniauth_user_data(omniauth_info)
    token = omniauth_info[:credentials][:token]
    response = slack_client.get("/api/users.identity?token=#{token}")

    JSON.parse(response.body)
  end

  def self.from_omniauth(omniauth_info)
    body = omniauth_user_data(omniauth_info)

    user = find_or_initialize_by(
      slack_user_id: body["user"]["id"]
    )
    user.slack_team_id   = body["team"]["id"]
    user.slack_user_name = body["user"]["name"]
    user.save
    user
  end

  def self.slack_client
    Faraday.new(url: "https://slack.com") do |connection|
      connection.headers["Content-Type"] = "application/json"
      connection.adapter Faraday.default_adapter
    end
  end

  def heroku_api
    @heroku_api ||= HerokuApi.new(heroku_token)
  end

  def heroku_user_information
    return nil unless heroku_configured?
    heroku_api.user_information
  end

  def create_command_for(params)
    command = commands.create(
      channel_id: params[:channel_id],
      channel_name: params[:channel_name],
      command: params[:command],
      command_text: params[:text],
      response_url: params[:response_url],
      team_id: params[:team_id],
      team_domain: params[:team_domain]
    )
    CommandExecutorJob.perform_later(command_id: command.id)
    YubikeyExpireJob.set(wait: 10.seconds).perform_later(command_id: command.id)
    command
  end

  def create_action_for(params)
    actions.create(
      action_ts: params[:action_ts],
      callback_id: params[:callback_id],
      channel_id: params[:channel][:id],
      channel_name: params[:channel][:name],
      message_ts: params[:message_ts],
      response_url: params[:response_url],
      team_domain: params[:team][:domain],
      team_id: params[:team][:id],
      value: params[:actions][0][:value]
    )
  end
end<commit_msg>Fix complexity in hashes in create_action_for<commit_after># A user from the Slack API
class User < ApplicationRecord
  include TokenManagement
  include GitHubTokenManagement
  include HerokuTokenManagement

  has_many :commands, dependent: :destroy
  has_many :actions,  dependent: :destroy

  def self.omniauth_user_data(omniauth_info)
    token = omniauth_info[:credentials][:token]
    response = slack_client.get("/api/users.identity?token=#{token}")

    JSON.parse(response.body)
  end

  def self.from_omniauth(omniauth_info)
    body = omniauth_user_data(omniauth_info)

    user = find_or_initialize_by(
      slack_user_id: body["user"]["id"]
    )
    user.slack_team_id   = body["team"]["id"]
    user.slack_user_name = body["user"]["name"]
    user.save
    user
  end

  def self.slack_client
    Faraday.new(url: "https://slack.com") do |connection|
      connection.headers["Content-Type"] = "application/json"
      connection.adapter Faraday.default_adapter
    end
  end

  def heroku_api
    @heroku_api ||= HerokuApi.new(heroku_token)
  end

  def heroku_user_information
    return nil unless heroku_configured?
    heroku_api.user_information
  end

  def create_command_for(params)
    command = commands.create(
      channel_id: params[:channel_id],
      channel_name: params[:channel_name],
      command: params[:command],
      command_text: params[:text],
      response_url: params[:response_url],
      team_id: params[:team_id],
      team_domain: params[:team_domain]
    )
    CommandExecutorJob.perform_later(command_id: command.id)
    YubikeyExpireJob.set(wait: 10.seconds).perform_later(command_id: command.id)
    command
  end

  def create_action_for(params)
    channel = params[:channel]
    team = params[:team]
    button_clicked = params[:actions][0]
    actions.create(
      action_ts: params[:action_ts],
      callback_id: params[:callback_id],
      channel_id: channel[:id],
      channel_name: channel[:name],
      message_ts: params[:message_ts],
      response_url: params[:response_url],
      team_domain: team[:domain],
      team_id: team[:id],
      value: button_clicked[:value]
    )
  end
end
{'fraction_non_alphanumeric': 0.11034971644612476, 'fraction_numerical': 0.0014177693761814746, 'mean_word_length': 3.9278230500582074, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1156053', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1355, 'n_words': 250}