-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubhook.lua
More file actions
64 lines (54 loc) · 1.39 KB
/
githubhook.lua
File metadata and controls
64 lines (54 loc) · 1.39 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
require "JSON"
pushes = {}
function handle_room_config(config)
end
function handle_room_message(message)
end
function handle_room_presence(presence)
end
function handle_new_connection(info)
pushes[info['client']] = ""
return true
end
function handle_connection_data(info)
pushes[info['client']] = pushes[info['client']] .. info['data']
end
function handle_closed_connection(info)
local obj = JSON.Decode(pushes[info['client']])
pushes[info['client']] = nil
if type(obj['commits']) ~= 'table' then
return
end
local commits = obj['commits']
local msg = string.format("%d new commit(s) on %s:", #commits, obj['repository']['name'])
for i, com in ipairs(commits) do
local added = com['added']
local removed = com['removed']
local modified = com['modified']
msg = msg .. string.format("\n%s: \"%s\" (modified: %d, added: %d, deleted: %d)",
com['author']['username'],
com['message'],
#modified,
#added,
#removed)
end
send_room_message(msg)
end
port = nil
if os.getenv('HOOK_PORT') ~= nil then
local p = tonumber(os.getenv('HOOK_PORT'))
if p ~= nil then
if p > 1024 and p < 65536 then
port = p
end
end
end
if port == nil then
dout("You forgot to specify the port to listen on");
os.exit(1)
end
ok, err = server_listen('test', port)
if (not ok) then
dout(string.format("server_listen() failed: %s", err))
os.exit(1)
end