-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-webhook.reb
63 lines (52 loc) · 1.46 KB
/
github-webhook.reb
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
Rebol [
Title: "Github webhook handler"
Author: onetom@hackerspace.sg
Date: 2013-08-31
Purpose: {
Handle github post receive hooks as described at
https://help.github.com/articles/post-receive-hooks
Note that the JSON data is sent as URL encoded form data
in a POST request, so the mime type is not application/json,
but application/x-www-form-urlencoded
Here is a similar solution in Ruby:
https://github.com/SmartReceipt/webhook/blob/master/lib/webhook/app.rb
}
Description: {
Configure by changing the 'port variable and the 'handle function.
Remove [print data] from the 'log function to make the script silent.
}
]
port: 6175
handle: funct [json[string!]] [
log json
]
log: funct [data] [
print data
write/append %github-webhook.log rejoin [now " -- " data newline]
data
]
listen-port: open/lines join tcp://: port
log ["Listening on port" port "..."]
forever [
http-port: first wait listen-port
http-port/timeout: 5
attempt [
request-line: first http-port
headers: collect [
while [not empty? line: first http-port][
parse line [
copy header to ":" skip (keep header)
copy value to end (keep any [ attempt [load value] value ])
]
]
]
body: make string! len: select headers "Content-Length"
until [
read-io http-port tail body (len - length? body)
len = length? body
]
handle find/tail dehex body "payload="
insert http-port rejoin ["HTTP/1.0 204 No Content" crlf crlf]
]
close http-port
]