front_end_builds 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20481cc2b843d67d5fa16c51f35827c1e4700f9c
4
+ data.tar.gz: e0be7cf579d0783f1c50439708d99a4cac240d1b
5
+ SHA512:
6
+ metadata.gz: 0e2c9ec15f9628b4e05715244efeb6e14839e6ecd1a807613f6ae30dc504bbadc0b9ce873b8471485cb667c8e5e6cfe5457c1bff35e10d02d00837bd7ed410ef
7
+ data.tar.gz: a386fabf124d546256a923ad0d50737aafbaf4b293ae87a1364ff735f55bd490f9a068f0c987763ab336a74653fb87ff6d10366ab16a0695c50193e93b98f7b5
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'FrontEndBuilds'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module FrontEndBuilds
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,60 @@
1
+ require_dependency "front_end_builds/application_controller"
2
+
3
+ module FrontEndBuilds
4
+ class BuildsController < ApplicationController
5
+
6
+ def index
7
+ front_end = FrontEndBuilds::Build.find_best(build_search_params)
8
+
9
+ if front_end
10
+ render text: front_end.with_head_tag(csrf_tag)
11
+ else
12
+ render text: "not found", status: 404
13
+ end
14
+ end
15
+
16
+ def create
17
+ app = find_app
18
+
19
+ if app
20
+ build = app.builds.create(build_create_params)
21
+ end
22
+
23
+ if app && build
24
+ build.fetch!
25
+ build.activate!
26
+ head :ok
27
+ else
28
+ head :unprocessable_entity
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def csrf_tag
35
+ [
36
+ "<meta name='csrf-param' content='#{request_forgery_protection_token}' />",
37
+ "<meta name='csrf-token' content='#{form_authenticity_token}' />"
38
+ ].join('').to_s
39
+ end
40
+
41
+ def build_search_params
42
+ params.permit(:app_name, :branch, :sha, :job)
43
+ end
44
+
45
+ def build_create_params
46
+ params.permit(
47
+ :branch,
48
+ :sha,
49
+ :job
50
+ )
51
+ end
52
+
53
+ def find_app
54
+ FrontEndBuilds::App.find_by(
55
+ name: params[:app_name],
56
+ api_key: params[:api_key]
57
+ )
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,4 @@
1
+ module FrontEndBuilds
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module FrontEndBuilds
2
+ class App < ActiveRecord::Base
3
+ has_many :builds, class_name: 'FrontEndBuilds::Build'
4
+
5
+ validates :name, presence: true
6
+ validates :api_key, presence: true
7
+
8
+ before_validation :ensure_api_key!
9
+
10
+ def ensure_api_key!
11
+ self.api_key = SecureRandom.uuid if api_key.blank?
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,86 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module FrontEndBuilds
5
+ class Build < ActiveRecord::Base
6
+ belongs_to :app, class_name: "FrontEndBuilds::App"
7
+
8
+ validates :app, presence: true
9
+ validates :sha, presence: true
10
+ validates :job, presence: true
11
+ validates :branch, presence: true
12
+
13
+ def self.find_best(params = {})
14
+ scope = self
15
+
16
+ query = {
17
+ fetched: true
18
+ }
19
+
20
+ if params[:app]
21
+ query[:app] = params[:app]
22
+ end
23
+
24
+ if params[:app_name]
25
+ scope = scope
26
+ .joins(:app)
27
+ .where(
28
+ front_end_builds_apps: { name: params[:app_name] }
29
+ )
30
+ end
31
+
32
+ if params[:sha]
33
+ query[:sha] = params[:sha]
34
+
35
+ elsif params[:job]
36
+ query[:job] = params[:job]
37
+
38
+ elsif params[:branch]
39
+ # only force activeness on branch based searched. Anyone who
40
+ # is searching by sha or build# is probably debugging/testing,
41
+ # so they would want non active builds
42
+ query[:branch] = params[:branch]
43
+ query[:active] = true
44
+
45
+ end
46
+
47
+ scope
48
+ .where(query)
49
+ .limit(1)
50
+ .order('created_at desc')
51
+ .first
52
+ end
53
+
54
+ def fetch!
55
+ return if fetched?
56
+
57
+ # Store endpoint in app
58
+ endpoint = "http://ted.conferences.#{app.name}.s3-website-us-east-1.amazonaws.com/dist-#{job}-#{sha}/index.html"
59
+ html = Net::HTTP.get(URI.parse(endpoint))
60
+
61
+ update_attributes(
62
+ html: html,
63
+ fetched: true
64
+ )
65
+ end
66
+
67
+ def activate!
68
+ update_attributes(active: true)
69
+ end
70
+
71
+ def with_head_tag(tag)
72
+ html.clone.insert(head_pos, tag)
73
+ end
74
+
75
+ private
76
+
77
+ def head_pos
78
+ head_open = html.index("<head")
79
+ if head_open
80
+ html.index(">", head_open) + 1
81
+ else
82
+ 0
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>FrontEndBuilds</title>
5
+ <%= stylesheet_link_tag "front_end_builds/application", media: "all" %>
6
+ <%= javascript_include_tag "front_end_builds/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ FrontEndBuilds::Engine.routes.draw do
2
+ end
@@ -0,0 +1,22 @@
1
+ class CreateFrontEndBuildsBuilds < ActiveRecord::Migration
2
+ def change
3
+ create_table :front_end_builds_builds do |t|
4
+ t.references :app
5
+ t.string :sha
6
+ t.string :job
7
+ t.string :branch
8
+ t.text :html
9
+ t.boolean :fetched, default: false
10
+ t.boolean :active, default: false
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ add_index :front_end_builds_builds, :fetched
16
+ add_index :front_end_builds_builds, :active
17
+ add_index :front_end_builds_builds, :created_at
18
+ add_index :front_end_builds_builds, [:app_id, :branch]
19
+ add_index :front_end_builds_builds, [:app_id, :sha]
20
+ add_index :front_end_builds_builds, [:app_id, :job]
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ class CreateFrontEndBuildsApps < ActiveRecord::Migration
2
+ def change
3
+ create_table :front_end_builds_apps do |t|
4
+ t.string :name
5
+ t.string :api_key
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :front_end_builds_apps, :name
11
+ add_index :front_end_builds_apps, :api_key
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module FrontEndBuilds
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace FrontEndBuilds
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, fixture: false
7
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
8
+ g.assets false
9
+ g.helper false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+
4
+ # Create a front end in your rails router.
5
+ def front_end(name, path = name, options = {})
6
+
7
+ # Generic routes that have nothing to do with the app
8
+ # name. Use this for testing or providing a non
9
+ # app api endpoint.
10
+ namespace :front_end_builds do
11
+ resources :builds, only: [:index, :create]
12
+ end
13
+
14
+ # Create a new build for this app.
15
+ post(
16
+ "#{path}" => "front_end_builds/builds#create",
17
+ defaults: {
18
+ app_name: name
19
+ }
20
+ )
21
+
22
+ # Fetch a build for this app.
23
+ get(
24
+ "/#{path}/(*path)" => "front_end_builds/builds#index",
25
+ defaults: {
26
+ branch: :master,
27
+ app_name: name
28
+ }.merge(options)
29
+ )
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module FrontEndBuilds
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "front_end_builds/engine"
2
+ require "front_end_builds/ext/routes"
3
+
4
+ module FrontEndBuilds
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :front_end_builds do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: front_end_builds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - 'Ryan Toronto '
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl_rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.4.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.4.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-stack_explorer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: shoulda-matchers
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.7.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.19.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.19.0
125
+ description: Description of FrontEndBuilds.
126
+ email:
127
+ - rt@ted.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - MIT-LICENSE
133
+ - Rakefile
134
+ - app/assets/javascripts/front_end_builds/application.js
135
+ - app/assets/stylesheets/front_end_builds/application.css
136
+ - app/controllers/front_end_builds/application_controller.rb
137
+ - app/controllers/front_end_builds/builds_controller.rb
138
+ - app/helpers/front_end_builds/application_helper.rb
139
+ - app/models/front_end_builds/app.rb
140
+ - app/models/front_end_builds/build.rb
141
+ - app/views/layouts/front_end_builds/application.html.erb
142
+ - config/routes.rb
143
+ - db/migrate/20141010162405_create_front_end_builds_builds.rb
144
+ - db/migrate/20141010165726_create_front_end_builds_apps.rb
145
+ - lib/front_end_builds.rb
146
+ - lib/front_end_builds/engine.rb
147
+ - lib/front_end_builds/ext/routes.rb
148
+ - lib/front_end_builds/version.rb
149
+ - lib/tasks/front_end_builds_tasks.rake
150
+ homepage: http://github.com/tedconf/front_end_builds
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.2.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Summary of FrontEndBuilds.
174
+ test_files: []