Sha256: c0a9d73c2a23b59dc934dd4b2aeed3e2c9455f32696a7768e9083a1a95630c0c

Contents?: true

Size: 1.51 KB

Versions: 8

Compression:

Stored size: 1.51 KB

Contents

require_dependency "front_end_builds/application_controller"

module FrontEndBuilds
  class BuildsController < ApplicationController
    before_filter :set_app!, only: :create

    def index
      front_end = FrontEndBuilds::Build.find_best(build_search_params)

      if front_end
        render text: front_end.with_head_tag(csrf_tag)
      else
        render text: "not found", status: 404
      end
    end

    def create
      build = @app.builds.new(build_create_params)

      if build.save
        build.fetch!
        build.activate!
        head :ok

      else
        render(
          text: 'Could not create the build: ' + build.errors.full_messages.to_s,
          status: :unprocessable_entity
        )
      end
    end

    private

    def set_app!
      @app = find_app
      if @app.nil?
        render(
          text: 'That app name/API combination was not found.',
          status: :unprocessable_entity
        )
      end
    end

    def csrf_tag
      [
        "<meta name='csrf-param' content='#{request_forgery_protection_token}' />",
        "<meta name='csrf-token' content='#{form_authenticity_token}' />"
      ].join('').to_s
    end

    def build_search_params
      params.permit(:app_name, :branch, :sha, :job)
    end

    def build_create_params
      params.permit(
        :branch,
        :sha,
        :job,
        :endpoint
      )
    end

    def find_app
      FrontEndBuilds::App.where(
        name: params[:app_name],
        api_key: params[:api_key]
      ).limit(1).first
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
front_end_builds-0.0.13 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.12 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.11 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.10 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.9 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.8 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.7 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.6 app/controllers/front_end_builds/builds_controller.rb