foca / integrity

Don't mind this, go to http://github.com/integrity/integrity

This URL has Read+Write access

integrity / app.rb
100644 138 lines (107 sloc) 2.914 kb
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require File.dirname(__FILE__) + "/lib/integrity"
require "sinatra"
require "helpers"
 
set :root, Integrity.root
set :public, Integrity.root / "public"
set :views, Integrity.root / "views"
 
enable :sessions
 
include Integrity
 
configure :development do
  config = Integrity.root / "config" / "config.yml"
  Integrity.config = config if File.exists? config
end
 
configure do
  Integrity.new
end
 
not_found do
  status 404
  show :not_found, :title => "lost, are we?"
end
 
error do
  @error = request.env['sinatra.error']
  status 500
  show :error, :title => "something has gone terribly wrong"
end
 
before do
  # The browser only sends http auth data for requests that are explicitly
  # required to do so. This way we get the real values of +#logged_in?+ and
  # +#current_user+
  login_required if session[:user]
end
 
get "/" do
  @projects = Project.only_public_unless(authorized?)
  show :home, :title => "projects"
end
 
get "/login" do
  login_required
  session[:user] = current_user
  redirect root_url
end
 
get "/new" do
  login_required
 
  @project = Project.new
  show :new, :title => ["projects", "new project"]
end
 
post "/" do
  login_required
 
  @project = Project.new(params[:project_data])
  if @project.save
    @project.enable_notifiers(params["enabled_notifiers[]"], params["notifiers"])
    redirect project_url(@project)
  else
    show :new, :title => ["projects", "new project"]
  end
end
 
get "/:project" do
  login_required unless current_project.public?
  show :project, :title => ["projects", current_project.name]
end
 
get "/:project.atom" do
  login_required unless current_project.public?
  response["Content-Type"] = "application/rss+xml; charset=utf-8"
  builder :project
end
 
put "/:project" do
  login_required
 
  if current_project.update_attributes(params[:project_data])
    current_project.enable_notifiers(params["enabled_notifiers"], params["notifiers"])
    redirect project_url(current_project)
  else
    show :new, :title => ["projects", current_project.permalink, "edit"]
  end
end
 
delete "/:project" do
  login_required
 
  current_project.destroy
  redirect root_url
end
 
get "/:project/edit" do
  login_required
 
  show :new, :title => ["projects", current_project.permalink, "edit"]
end
 
post "/:project/push" do
  login_required
 
  content_type "text/plain"
 
  begin
    current_project.push(params[:payload])
    "Thanks, build started."
  rescue JSON::ParserError => exception
    throw :halt, [422, exception.to_s]
  end
end
 
post "/:project/builds" do
  login_required
 
  current_project.build
  redirect project_url(@project)
end
 
get "/:project/builds/:build" do
  login_required unless current_project.public?
  show :build, :title => ["projects", current_project.permalink, current_build.short_commit_identifier]
end
 
get "/integrity.css" do
  response["Content-Type"] = "text/css; charset=utf-8"
  sass :integrity
end
 
helpers do
  include Helpers
end