# HG changeset patch # User Kim Alvefur # Date 1554052123 -7200 # Node ID 552d4944d1ca4848073a43768e4fa7d816f1b885 # Parent 6ac98c4dbbd3440f716d522c88de1746120a2617 mod_pubsub_github: Rearrange code to make it easier to handle other event types diff -r 6ac98c4dbbd3 -r 552d4944d1ca mod_pubsub_github/mod_pubsub_github.lua --- a/mod_pubsub_github/mod_pubsub_github.lua Sun Mar 31 19:07:22 2019 +0200 +++ b/mod_pubsub_github/mod_pubsub_github.lua Sun Mar 31 19:08:43 2019 +0200 @@ -59,31 +59,33 @@ end local github_event = request.headers.x_github_event or data.object_kind; + module:log("debug", "Handling '%s' event: \n%s\n", github_event, tostring(request.body)); + if github_event == "push" then - module:log("debug", "Handling 'push' event: \n%s\n", tostring(request.body)); + + for _, commit in ipairs(data.commits) do + local ok, err = pubsub_service:publish(node, github_actor, commit.id, + st.stanza("item", { id = commit.id, xmlns = "http://jabber.org/protocol/pubsub" }) + :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" }) + :tag("id"):text(commit.id):up() + :tag("title"):text(commit.message:match("^[^\r\n]*")):up() + :tag("summary"):text(("Commit to %s by %s: %s"):format(data.repository.name, commit.author.name, commit.message:match("^[^\r\n]*"))):up() + :tag("content"):text(commit.message):up() + :tag("link", { rel = "alternate", href = commit.url }):up() + :tag("published"):text(commit.author.date):up() + :tag("author") + :tag("name"):text(commit.author.name):up() + :tag("email"):text(commit.author.email):up() + :up() + ); + if not ok then + return error_mapping[err] or 500; + end + end + elseif github_event then module:log("debug", "Unsupported Github event %q", github_event); return 501; - end -- else .. is this even github? - - for _, commit in ipairs(data.commits) do - local ok, err = pubsub_service:publish(node, github_actor, commit.id, - st.stanza("item", { id = commit.id, xmlns = "http://jabber.org/protocol/pubsub" }) - :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" }) - :tag("id"):text(commit.id):up() - :tag("title"):text(commit.message:match("^[^\r\n]*")):up() - :tag("summary"):text(("Commit to %s by %s: %s"):format(data.repository.name, commit.author.name, commit.message:match("^[^\r\n]*"))):up() - :tag("content"):text(commit.message):up() - :tag("link", { rel = "alternate", href = commit.url }):up() - :tag("published"):text(commit.author.date):up() - :tag("author") - :tag("name"):text(commit.author.name):up() - :tag("email"):text(commit.author.email):up() - :up() - ); - if not ok then - return error_mapping[err] or 500; - end end response.status_code = 202;