comparison mod_pubsub_github/mod_pubsub_github.lua @ 3513:9556e92b2ec4

mod_pubsub_github: Abort on unknown github events
author Kim Alvefur <zash@zash.se>
date Sun, 31 Mar 2019 17:47:45 +0200
parents f09423c29f31
children 8811b7dbe6e2
comparison
equal deleted inserted replaced
3512:5fb14ae57b4c 3513:9556e92b2ec4
24 if not data then 24 if not data then
25 response.status_code = 400; 25 response.status_code = 400;
26 return "Invalid JSON. From you of all people..."; 26 return "Invalid JSON. From you of all people...";
27 end 27 end
28 28
29 module:log("debug", "Handling POST: \n%s\n", tostring(request.body)); 29 local github_event = request.headers.x_github_event
30 if github_event == "push" then
31 module:log("debug", "Handling 'push' event: \n%s\n", tostring(request.body));
32 elseif github_event then
33 module:log("debug", "Unsupported Github event %q", github_event);
34 return 501;
35 end -- else .. is this even github?
30 36
31 for _, commit in ipairs(data.commits) do 37 for _, commit in ipairs(data.commits) do
32 local ok, err = pubsub_service:publish(node, true, data.repository.name, 38 local ok, err = pubsub_service:publish(node, true, data.repository.name,
33 st.stanza("item", { id = data.repository.name, xmlns = "http://jabber.org/protocol/pubsub" }) 39 st.stanza("item", { id = data.repository.name, xmlns = "http://jabber.org/protocol/pubsub" })
34 :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" }) 40 :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" })