]> Untitled Git - godot-builder.git/blob - hook/make-build-request.lua
Squashed commit of the following:
[godot-builder.git] / hook / make-build-request.lua
1 require "apache2"
2
3 --[[
4 If a snapshot link is given, then push it onto the builder redis queue
5
6 Example snapshot link:
7 https://git.purplebirdman.com/wolf-seeking-sheep.git/snapshot/127ef0ef17ec1067f77bb7097e84a537a4a01ec7.tar.gz
8 ]]--
9
10 function lpush_onto_job_queue(s)
11     local cmd = ("redis-cli -h redis LPUSH snapshots %s"):format(s)
12     local handle = io.popen(cmd)
13     local output = handle:read('*a')
14     handle:close()
15
16     return output
17 end
18
19 function dump_file(s)
20     local handle = io.open(s)
21     local output = handle:read('*a')
22     handle:close()
23
24     return output;
25 end
26
27 function handle(r)
28     r.content_type = "text/html"
29
30     local args = r:parseargs()
31     local snapshot_uri = args.snapshot_uri
32
33     if snapshot_uri then
34         -- filename might have spaces that apache replaces with '+'
35         snapshot_uri = string.gsub(snapshot_uri, '+', ' ')
36         snapshot_uri = string.gsub(snapshot_uri, '%%2F', '/')
37
38         local out = lpush_onto_job_queue(snapshot_uri)
39         r:puts( out )
40         return apache2.OK
41     else
42         r:puts( dump_file(r.document_root .. '/build-request.html') )
43         return apache2.OK
44     end
45 end