Mercurial > prosody-modules
comparison mod_pubsub_github/mod_pubsub_github.lua @ 3530:552d4944d1ca
mod_pubsub_github: Rearrange code to make it easier to handle other event types
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 31 Mar 2019 19:08:43 +0200 |
| parents | 6ac98c4dbbd3 |
| children | 3bece2db869c |
comparison
equal
deleted
inserted
replaced
| 3529:6ac98c4dbbd3 | 3530:552d4944d1ca |
|---|---|
| 57 if node_mapping then | 57 if node_mapping then |
| 58 node = node_prefix .. data.repository[node_mapping]; | 58 node = node_prefix .. data.repository[node_mapping]; |
| 59 end | 59 end |
| 60 | 60 |
| 61 local github_event = request.headers.x_github_event or data.object_kind; | 61 local github_event = request.headers.x_github_event or data.object_kind; |
| 62 module:log("debug", "Handling '%s' event: \n%s\n", github_event, tostring(request.body)); | |
| 63 | |
| 62 if github_event == "push" then | 64 if github_event == "push" then |
| 63 module:log("debug", "Handling 'push' event: \n%s\n", tostring(request.body)); | 65 |
| 66 for _, commit in ipairs(data.commits) do | |
| 67 local ok, err = pubsub_service:publish(node, github_actor, commit.id, | |
| 68 st.stanza("item", { id = commit.id, xmlns = "http://jabber.org/protocol/pubsub" }) | |
| 69 :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" }) | |
| 70 :tag("id"):text(commit.id):up() | |
| 71 :tag("title"):text(commit.message:match("^[^\r\n]*")):up() | |
| 72 :tag("summary"):text(("Commit to %s by %s: %s"):format(data.repository.name, commit.author.name, commit.message:match("^[^\r\n]*"))):up() | |
| 73 :tag("content"):text(commit.message):up() | |
| 74 :tag("link", { rel = "alternate", href = commit.url }):up() | |
| 75 :tag("published"):text(commit.author.date):up() | |
| 76 :tag("author") | |
| 77 :tag("name"):text(commit.author.name):up() | |
| 78 :tag("email"):text(commit.author.email):up() | |
| 79 :up() | |
| 80 ); | |
| 81 if not ok then | |
| 82 return error_mapping[err] or 500; | |
| 83 end | |
| 84 end | |
| 85 | |
| 64 elseif github_event then | 86 elseif github_event then |
| 65 module:log("debug", "Unsupported Github event %q", github_event); | 87 module:log("debug", "Unsupported Github event %q", github_event); |
| 66 return 501; | 88 return 501; |
| 67 end -- else .. is this even github? | |
| 68 | |
| 69 for _, commit in ipairs(data.commits) do | |
| 70 local ok, err = pubsub_service:publish(node, github_actor, commit.id, | |
| 71 st.stanza("item", { id = commit.id, xmlns = "http://jabber.org/protocol/pubsub" }) | |
| 72 :tag("entry", { xmlns = "http://www.w3.org/2005/Atom" }) | |
| 73 :tag("id"):text(commit.id):up() | |
| 74 :tag("title"):text(commit.message:match("^[^\r\n]*")):up() | |
| 75 :tag("summary"):text(("Commit to %s by %s: %s"):format(data.repository.name, commit.author.name, commit.message:match("^[^\r\n]*"))):up() | |
| 76 :tag("content"):text(commit.message):up() | |
| 77 :tag("link", { rel = "alternate", href = commit.url }):up() | |
| 78 :tag("published"):text(commit.author.date):up() | |
| 79 :tag("author") | |
| 80 :tag("name"):text(commit.author.name):up() | |
| 81 :tag("email"):text(commit.author.email):up() | |
| 82 :up() | |
| 83 ); | |
| 84 if not ok then | |
| 85 return error_mapping[err] or 500; | |
| 86 end | |
| 87 end | 89 end |
| 88 | 90 |
| 89 response.status_code = 202; | 91 response.status_code = 202; |
| 90 return "Thank you Github!"; | 92 return "Thank you Github!"; |
| 91 end | 93 end |
