-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
48 lines (39 loc) · 1.11 KB
/
app.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
43
44
45
46
47
48
require 'rubygems'
require 'sinatra'
require 'erb'
require 'grit'
require 'project'
get '/' do
redirect '/projects'
end
get '/projects' do
@title = "All Projects"
@projects = Project.all
erb :index
end
get '/projects/:project_slug' do
@project = Project.find(params[:project_slug]) or raise Sinatra::NotFound
@title = "Project: #{@project.name}"
erb :show
end
post '/projects/:project_slug/checkout' do
@project = Project.find(params[:project_slug]) or raise Sinatra::NotFound
@project.checkout!
redirect "/projects/#{@project.slug}"
end
post '/projects/:project_slug/commits' do
@project = Project.find(params[:project_slug]) or raise Sinatra::NotFound
commit_message = params[:message]
if commit_message && commit_message != ''
@project.add_and_commit_all!(commit_message)
@project.push!
redirect "/projects/#{@project.slug}"
else
@title = "Project: #{@project.name}"
@error_message = "You must enter a message to commit."
erb :show
end
end
error Project::CommitError do
'Something bad happened while attempting to commit: ' + request.env['sinatra.error'].message
end