Alexander Gladysh wrote: > Couldn't RSS feed script work with a branch name? The branch is already a parameter. But I should filter out the merge messages. The problem is where to place the feed.xml file. > Is there a source for it somewhere? Attached. Not the most beautiful code I ever wrote. --Mike
-- git2rss.lua gitname feedurl [branch] -- Written by Mike Pall. Public domain. local tagfmt = "luajit.org,2009" -- Change this! local sub, match, format = string.sub, string.match, string.format local write = io.write local xml_escape = { ["<"] = "<", [">"] = ">", ["&"] = "&", } local function esc(s) return string.gsub(s, "[<>&]", xml_escape) end local gitname = arg and arg[1] or "?" local feedurl = arg and arg[2] or "?" local branch = arg and arg[3] or "master" local curdate = os.date("!%Y-%m-%dT%H:%M:%SZ") local fp = assert(io.popen("git log --pretty=medium --date=iso --max-count=10 "..branch)) write(format([[ <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom";> <title>Recent commits to %s</title> <link rel="self" type="application/atom+xml" href="%s"/> <id>%s</id> <updated>%s</updated> ]], gitname, feedurl, feedurl, curdate)) local desc = "" local title = false for line in fp:lines() do local text = match(line, "^%s+(.*)$") if text then test = match(text, "(.-)%s*$") if text ~= "" then if title then desc = desc..text.."\n" else write("<title>", esc(text), "</title>\n") title = true end end else if title then if desc ~= "" then write("<content type=\"html\"><pre>\n", esc(esc(desc)), "</pre></content>\n") end write("</entry>\n") title = false desc = "" end local tag, text = match(line, "^([%w:]+)%s*(.*)$") if tag == "commit" then write("<entry>\n") write("<id>tag:", tagfmt, ":git:commit:", gitname, ":", text, "</id>\n") elseif tag == "Date:" then local ymd, hms, t1, t2 = match(text, "^(%S+)%s(%S+)%s(%S%S%S)(%S%S)$") write(format("<updated>%sT%s%s:%s</updated>\n", ymd, hms, t1, t2)) end end end if title then if desc ~= "" then write("<content type=\"html\"><pre>\n", esc(esc(desc)), "</pre></content>\n") end write("</entry>\n") end write("</feed>\n")