-- Command-line arguments
local config_file, server, node, branch, base_link = unpack(arg, 1, 5);
local config = assert(io.open(config_file));
local jid = assert(config:read("*l"), "no JID in config")
local password = assert(config:read("*l"), "no password in config")
local verse = require "verse";
require "verse.client";
local xmppstream = require "util.xmppstream";
local hgstream_handlers = {
stream_ns = "";
stream_tag = "log";
streamopened = function (sess) sess.notopen = nil; end;
streamclosed = function () end;
};
function hgstream_handlers.handlestanza(sess, commit)
local atom = verse.stanza("entry", { xmlns = "http://www.w3.org/2005/Atom" });
local id = commit.attr.node;
atom:tag("id"):text(id):up();
local author = commit:get_child("author");
atom:tag("author")
:tag("name"):text(author:get_text()):up()
:tag("email"):text(author.attr.email):up()
:up();
atom:tag("published"):text(commit:get_child("date"):get_text()):up();
atom:tag("title"):text(commit:get_child("msg"):get_text()):up();
atom:tag("link", { rel = "alternate", href = base_link..id:sub(1,12) }):up();
sess.conn.pubsub:publish(server, node, branch, atom);
end
local conn = verse.new();
conn:add_plugin("disco");
conn:add_plugin("pubsub");
conn:hook("stanza", print, 1000);
conn:hook("stanza-out", print, 1000);
conn:hook("ready", function ()
local hgstream = xmppstream.new({ notopen = true, conn = conn }, hgstream_handlers);
for line in io.lines() do
hgstream:feed(line);
end
conn:close();
end);
local function exit() os.exit(); end
conn:hook("authentication-failure", exit);
conn:hook("disconnected", exit);
conn:connect_client(jid, password);
verse.loop();