<commit_before>class DeploymentsController < ApplicationController
  before_filter :require_user
  before_filter :load_deployments, :only => [:index, :show]
  before_filter :load_deployment, :only => [:edit, :update]

  viewstate :show do |default|
    default.merge!({
      :view => 'pretty',
    })
  end

  def index
    save_breadcrumb(deployments_path(:viewstate => viewstate_id))
    respond_to do |format|
      format.js { render :partial => 'list' }
      format.html
      format.json { render :json => @deployments }
    end
  end

  # It is expected that params[:pool_id] will be set on requests into this method
  def launch_new
    @pool = Pool.find(params[:pool_id]) or raise "Invalid pool"
    require_privilege(Privilege::CREATE, Deployment, @pool)
    unless @pool.enabled
      flash[:warning] = t 'deployments.disabled_pool'
      redirect_to pool_path(@pool) and return
    end

    @deployment = Deployment.new(:pool_id => @pool.id)
    @suggested_deployables = SuggestedDeployable.list_for_user(current_user, Privilege::USE)
    init_new_deployment_attrs
    respond_to do |format|
      format.js { render :partial => 'launch_new' }
      format.html
      format.json { render :json => @deployment }
    end
  end

  # launch_new will post here, but you can use this RESTfully as well
  def new
    @deployment = Deployment.new(params[:deployment])
    @pool = @deployment.pool
    @suggested_deployables = SuggestedDeployable.list_for_user(current_user, Privilege::USE)
    require_privilege(Privilege::CREATE, Deployment, @pool)
    url = get_deployable_url
    respond_to do |format|
      if @deployment.accessible_and_valid_deployable_xml?(url)
        errors = @deployment.check_assemblies_matches(current_user)
        unless errors.empty?
          flash[:error] = {
            :summary => "Some assemblies will not be launched:",
            :failures => errors
          }
        end
        format.js { render :partial => 'new' }
        format.html
        format.json { render :json => @deployment }
      else
        init_new_deployment_attrs
        format.js { render :partial => 'launch_new' }
        format.html { render :launch_new }
        format.json { render :json => @deployment.errors, :status => :unprocessable_entity }
      end
    end
  end

  def create
    @deployment = Deployment.new(params[:deployment])
    require_privilege(Privilege::CREATE, Deployment, @deployment.pool)
    @deployment.owner = current_user
    respond_to do |format|
      if @deployment.save
        status = @deployment.launch(current_user)
        if status[:errors].empty?
          flash[:notice] = "Deployment launched"
        else
          flash[:error] = {
            :summary  => "Failed to launch following assemblies:",
            :failures => status[:errors],
            :successes => status[:successes]
          }
        end
        format.js do
          @deployment_properties = @deployment.properties<commit_msg>allow deployments to be specified by url on launch<commit_after>class DeploymentsController < ApplicationController
  before_filter :require_user
  before_filter :load_deployments, :only => [:index, :show]
  before_filter :load_deployment, :only => [:edit, :update]

  viewstate :show do |default|
    default.merge!({
      :view => 'pretty',
    })
  end

  def index
    save_breadcrumb(deployments_path(:viewstate => viewstate_id))
    respond_to do |format|
      format.js { render :partial => 'list' }
      format.html
      format.json { render :json => @deployments }
    end
  end

  # It is expected that params[:pool_id] will be set on requests into this method
  def launch_new
    @pool = Pool.find(params[:pool_id]) or raise "Invalid pool"
    require_privilege(Privilege::CREATE, Deployment, @pool)
    unless @pool.enabled
      flash[:warning] = t 'deployments.disabled_pool'
      redirect_to pool_path(@pool) and return
    end

    @deployment = Deployment.new(:pool_id => @pool.id)
    @suggested_deployables = SuggestedDeployable.list_for_user(current_user, Privilege::USE)
    init_new_deployment_attrs
    respond_to do |format|
      format.js { render :partial => 'launch_new' }
      format.html
      format.json { render :json => @deployment }
    end
  end

  # launch_new will post here, but you can use this RESTfully as well
  def new
    @deployment = Deployment.new(params[:deployment])
    @pool = @deployment.pool
    @suggested_deployables = SuggestedDeployable.list_for_user(current_user, Privilege::USE)
    require_privilege(Privilege::CREATE, Deployment, @pool)
    url = get_deployable_url
    respond_to do |format|
      if @deployment.accessible_and_valid_deployable_xml?(url)
        errors = @deployment.check_assemblies_matches(current_user)
        unless errors.empty?
          flash[:error] = {
            :summary => "Some assemblies will not be launched:",
            :failures => errors
          }
        end
        format.js { render :partial => 'new' }
        format.html
        format.json { render :json => @deployment }
      else
        init_new_deployment_attrs
        format.js { render :partial => 'launch_new' }
        format.html { render :launch_new }
        format.json { render :json => @deployment.errors, :status => :unprocessable_entity }
      end
    end
  end

  def create
    @deployment = Deployment.new(params[:deployment])
    require_privilege(Privilege::CREATE, Deployment, @deployment.pool)
    @deployment.owner = current_user
    @deployment.accessible_and_valid_deployable_xml?(get_deployable_url)
    respond_to do |format|
      if @deployment.save
        status = @deployment.launch(current_user)
        if status[:errors].empty?
          flash[:notice] = "Deployment launched"
        else
          flash[:error] = {
            :summary  => "Failed to launch following assemblies:",
            :failures => status[:errors],
            :successes => status[:successes]
          }
        end
        format.js do
          @deployment_properties = @deployment.properties
{'fraction_non_alphanumeric': 0.10161929940515532, 'fraction_numerical': 0.0, 'mean_word_length': 2.974392646093237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '2485376', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1788, 'n_words': 422}