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
|
# File 'lib/cargo/cargo_server.rb', line 12
def call(env)
if env['REQUEST_METHOD'] == 'OPTIONS'
[200, {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET, OPTIONS',
'Access-Control-Allow-Headers' => 'X-Prototype-Version, X-Requested-With, Accept',
'Access-Control-Max-Age' => '1728000',
'Access-Control' => 'allow <*>'
}, '']
else
req = Rack::Request.new(env)
puts req.path_info
case req.path_info
when '/start'
puts Cargo::Commands::Hack.new(req['name'], req['id'])
notify("Starting Story", "Starting story '#{req['name']}' [#{req['id']}]", 0)
[200, { 'Content-Type' => 'application/json; charset=utf-8'},
"{success: 'starting story'}"]
when '/finish'
branch = git_branch
story_id = branch.split('-').last
if story_id == req['id']
puts Cargo::Commands::Ship.new
notify("Finishing Story", "Finishing story '#{req['name']}' [#{req['id']}]", 0)
else
notify("Story id doesn't match current branch", "Story id doesn't match current branch '#{branch}' [#{req['id']}]", 1)
end
[200, {'Content-Type' => 'application/json; charset=utf-8'},
"{success: 'finishing story'}"]
when '/cargo.user.js'
[200, {'Content-Type' => 'text/javascript'},
File.read("#{File.dirname(__FILE__)}/../../files/cargo.user.js")]
else
[404, {'Content-Type' => 'text/html'}, '404 Not Found']
end
end
end
|