Software /
code /
prosody-modules
Changeset
3517:ea1edd7cfb01
mod_pubsub_github: Add support for publishing to multiple node based on repository
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 31 Mar 2019 18:10:12 +0200 |
parents | 3516:d94875c3ddda |
children | 3518:95c1c3e057cf |
files | mod_pubsub_github/README.markdown mod_pubsub_github/mod_pubsub_github.lua |
diffstat | 2 files changed, 33 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_pubsub_github/README.markdown Sun Mar 31 18:08:50 2019 +0200 +++ b/mod_pubsub_github/README.markdown Sun Mar 31 18:10:12 2019 +0200 @@ -20,18 +20,31 @@ Component "pubsub.example.com" "pubsub" modules_enabled = { "pubsub_github" } +The URL for Github to post to would be either: + +- `http://pubsub.example.com:5280/pubsub_github` +- `https://pubsub.example.com:5281/pubsub_github` + The module also takes the following config options: Name Default Description ----------------------- ------------------- ------------------------------------------------------------ `github_node` `"github"`{.lua} The pubsub node to publish commits on. `github_secret` **Required** Shared secret used to sign HTTP requests. + `github_node_prefix` `"github/"`{.lua} + `github_node_mapping` *not set* Field in repository object to use as node instead of `github_node` `github_actor` *superuser* Which actor to do the publish as (used for access control) -The URL for Github to post to would be either: +More advanced example -- http://pubsub.example.com:5280/pubsub\_github -- https://pubsub.example.com:5281/pubsub\_github +``` {.lua} +Component "pubsub.example.com" "pubsub" + modules_enabled = { "pubsub_github" } + github_actor = "github.com" + github_node_mapping = "name" --> github_node_prefix .. "repo" + -- github_node_mapping = "full_name" --> github_node_prefix .. "owner/repo" + github_secret = "sekr1t" +``` If your HTTP host doesn't match the pubsub component's address, you will need to inform Prosody. For more info see Prosody's [HTTP server
--- a/mod_pubsub_github/mod_pubsub_github.lua Sun Mar 31 18:08:50 2019 +0200 +++ b/mod_pubsub_github/mod_pubsub_github.lua Sun Mar 31 18:10:12 2019 +0200 @@ -5,7 +5,9 @@ local hmac_sha1 = require "util.hashes".hmac_sha1; local pubsub_service = module:depends("pubsub").service; -local node = module:get_option("github_node", "github"); +local default_node = module:get_option("github_node", "github"); +local node_prefix = module:get_option_string("github_node_prefix", "github/"); +local node_mapping = module:get_option_string("github_node_mapping"); local github_actor = module:get_option_string("github_actor") or true; local secret = module:get_option("github_secret"); @@ -37,6 +39,11 @@ return 501; end -- else .. is this even github? + local node = default_node; + if node_mapping then + node = node_prefix .. data.repository[node_mapping]; + end + 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" }) @@ -65,13 +72,15 @@ }; }); -function module.load() - if not pubsub_service.nodes[node] then - local ok, err = pubsub_service:create(node, true); - if not ok then - module:log("error", "Error creating node: %s", err); - else - module:log("debug", "Node %q created", node); +if not node_mapping then + function module.load() + if not pubsub_service.nodes[default_node] then + local ok, err = pubsub_service:create(default_node, true); + if not ok then + module:log("error", "Error creating node: %s", err); + else + module:log("debug", "Node %q created", default_node); + end end end end