Sha256: 008b8031240161b407b30467e64f7cc1db561519ade110e5877cffceeb41e10c

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

require_dependency "front_end_builds/application_controller"

module FrontEndBuilds
  class BuildsController < ApplicationController

    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
      app = find_app

      if app
        build = app.builds.create(build_create_params)
      end

      if app && build
        build.fetch!
        build.activate!
        head :ok
      else
        head :unprocessable_entity
      end
    end

    private

    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
      )
    end

    def find_app
      FrontEndBuilds::App.find_by(
        name: params[:app_name],
        api_key: params[:api_key]
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
front_end_builds-0.0.4 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.3 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.2 app/controllers/front_end_builds/builds_controller.rb
front_end_builds-0.0.1 app/controllers/front_end_builds/builds_controller.rb