bsw@1656: -- Configuration of lf4rcs bsw@1656: -- ------------------------------------------------------------------------ bsw@1656: config.lf4rcs = {} bsw@1656: bsw@1656: -- Example configuration for controlling a Git repository bsw@1656: bsw@1656: config.lf4rcs.git = { bsw@1656: bsw@1656: render_draft_reference = function(url, draft) bsw@1656: if not draft.external_reference then return end bsw@1656: ui.tag{ content = _"Changeset:" } bsw@1656: slot.put(" ") bsw@1656: ui.link{ bsw@1656: text = draft.external_reference, bsw@1656: external = url .. ";a=commit;h=" .. draft.external_reference bsw@1656: } bsw@1656: end, bsw@1656: bsw@1656: get_remote_user = function() bsw@1656: return os.getenv("REMOTE_USER") bsw@1656: end, bsw@1656: bsw@1656: get_branches = function(path, exec) bsw@1656: local branches = {} bsw@1656: for line in io.lines() do bsw@1656: local oldrev, newrev, branch = string.match(line, "([^ ]+) ([^ ]+) refs/heads/(.+)") bsw@1656: if not branch then bsw@1656: return nil, "unexpected format from git hook environment" bsw@1656: end bsw@1656: branches[branch] = { newrev } bsw@1656: end bsw@1656: return branches bsw@1656: end, bsw@1656: bsw@1656: commit = function(path, exec, branch, target_node_id, close_message, merge_message) bsw@1656: if merge_message then bsw@1656: exec("git", "-C", path, "checkout", "-f", "master") bsw@1656: exec("git", "-C", path, "merge", target_node_id, "-m", merge_message) bsw@1656: exec("git", "-C", path, "push", "origin", "master") bsw@1656: end bsw@1656: end bsw@1656: bsw@1656: } bsw@1656: bsw@1656: -- Example configuration for controlling a Mercurial repository bsw@1656: config.lf4rcs.hg = { bsw@1656: bsw@1656: working_branch_name = "work", bsw@1656: bsw@1656: render_draft_reference = function(url, draft) bsw@1656: if not draft.external_reference then return end bsw@1656: ui.tag{ content = _"Changeset graph:" } bsw@1656: slot.put(" ") bsw@1656: ui.link{ bsw@1656: text = draft.external_reference, bsw@1656: external = url .. "/graph/" .. draft.external_reference bsw@1656: } bsw@1656: end, bsw@1656: bsw@1656: get_remote_user = function() bsw@1656: return os.getenv("REMOTE_USER") bsw@1656: end, bsw@1656: bsw@1656: get_branches = function(path, exec) bsw@1656: local first_node_id = os.getenv("HG_NODE") bsw@1656: if not first_node_id then bsw@1656: return nil, "internal error, no first node ID available" bsw@1656: end bsw@1656: local hg_log = exec( bsw@1656: "hg", "log", "-R", path, "-r", first_node_id .. ":", "--template", "{branches}\n" bsw@1656: ) bsw@1656: local branches = {} bsw@1656: for branch in hg_log:gmatch("(.-)\n") do bsw@1656: if branch == "" then branch = "default" end bsw@1656: if not branches[branch] then bsw@1656: branches[branch] = {} bsw@1656: local head_lines = exec( bsw@1656: "hg", "heads", "-R", path, "--template", "{node}\n", branch bsw@1656: ) bsw@1656: for node_id in string.gmatch(head_lines, "[^\n]+") do bsw@1656: table.insert(branches[branch], node_id) bsw@1656: end bsw@1656: end bsw@1656: end bsw@1656: return branches bsw@1656: end, bsw@1656: bsw@1656: extra_checks = function(path, exec) bsw@1656: local result = exec("hg", "heads", "-t", "-c") bsw@1656: for branch in string.gmatch(result, "[^\n]+") do bsw@1656: if branch == lf4rcs.config.hg.working_branch_name then bsw@1656: return nil, "open head found for branch " .. lf4rcs.config.hg.working_branch_name bsw@1656: end bsw@1656: end bsw@1656: return true bsw@1656: end, bsw@1656: bsw@1656: commit = function(path, exec, branch, target_node_id, close_message, merge_message) bsw@1656: exec("hg", "up", "-R", path, "-C", "-r", target_node_id) bsw@1656: exec("hg", "commit", "-R", path, "--close-branch", "-m", close_message) bsw@1656: if merge_message then bsw@1656: exec("hg", "up", "-R", path, "-C", "-r", "default") bsw@1656: exec("hg", "merge", "-R", path, "-r", "tip") bsw@1656: exec("hg", "commit", "-R", path, "-m", merge_message) bsw@1656: end bsw@1656: end bsw@1656: bsw@1656: } bsw@1656: bsw@1656: -- Grace period after creating an initiative for pushing changes during verification phase bsw@1656: -- disabled by default (nil), use PostgreSQL interval notation bsw@1656: -- config.lf4rcs.push_grace_period = nil bsw@1656: bsw@1656: lf4rcs.init() bsw@1656: