<commit_before>class Projects::Clusters::ApplicationsController < Projects::ApplicationController
  before_action :cluster
  before_action :application_class, only: [:create]
  before_action :authorize_read_cluster!
  before_action :authorize_create_cluster!, only: [:create]

  def create
    application = @application_class.find_or_initialize_by(cluster: @cluster)

    if has_attribute?(:hostname)
      application.hostname = params[:hostname]
    end

    if application.respond_to?(:oauth_application)
      application.oauth_application = create_oauth_application(application)
    end

    application.save!

    Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application)

    head :no_content
  rescue StandardError
    head :bad_request<commit_msg>Fix exception in clusters/applications_controller.rb<commit_after>class Projects::Clusters::ApplicationsController < Projects::ApplicationController
  before_action :cluster
  before_action :application_class, only: [:create]
  before_action :authorize_read_cluster!
  before_action :authorize_create_cluster!, only: [:create]

  def create
    application = @application_class.find_or_initialize_by(cluster: @cluster)

    if application.has_attribute?(:hostname)
      application.hostname = params[:hostname]
    end

    if application.respond_to?(:oauth_application)
      application.oauth_application = create_oauth_application(application)
    end

    application.save!

    Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application)

    head :no_content
  rescue StandardError
    head :bad_request
{'fraction_non_alphanumeric': 0.0818677986658581, 'fraction_numerical': 0.0, 'mean_word_length': 5.962025316455696, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4890840', 'n_tokens_mistral': 455, 'n_tokens_neox': 440, 'n_words': 80}