-
Notifications
You must be signed in to change notification settings - Fork 0
/
codebuild_frontend.rb
42 lines (35 loc) · 1.17 KB
/
codebuild_frontend.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'sinatra'
require 'sinatra/content_for'
require 'aws-sdk-dynamodb'
require 'hashie'
if development?
require 'better_errors'
use BetterErrors::Middleware
BetterErrors.application_root = __dir__
end
set :root, File.dirname(__FILE__)
set :views, File.expand_path('./app/views/')
set :erb, layout_options: { views: 'app/layouts' }
set :dynamo_table, ENV['CODEBUILD_HISTORY_DYNAMO_TABLE'] || 'codebuild-history'
set :region, ENV['CODEBUILD_HISTORY_AWS_REGION'] || 'us-east-1'
set :dynamo_client, Aws::DynamoDB::Client.new(region: settings.region)
Dir.glob('./app/models/*.rb') { |model_file| require model_file }
get '/' do
@repos = Repo.all
@header = { tag: 'CodeBuild Project Repositories' }
erb :index
end
get '/repos/:repo_id/projects/:code' do
@project = Repo.find(params[:repo_id]).project(params[:code])
@header = { tag: "Branches for project #{@project.code}" }
erb :project
end
get '/projects/:code/sources/:id' do
@source = Source.find(params.to_h.symbolize_keys)
@header = {
tag: "Builds for #{@source.source_title}",
html: %(Builds for <a href="#{@source.git_url}" target="_blank">) \
"#{@source.source_title}</a>"
}
erb :source
end