liquid_feedback_frontend

diff config/example.lua @ 1219:30523f31b186

Added lf4rcs module and example configuration
author bsw
date Mon Nov 30 19:40:38 2015 +0100 (2015-11-30)
parents fede09736f2b
children e80c8790a1ca
line diff
     1.1 --- a/config/example.lua	Mon Jul 27 23:33:26 2015 +0200
     1.2 +++ b/config/example.lua	Mon Nov 30 19:40:38 2015 +0100
     1.3 @@ -255,6 +255,118 @@
     1.4  }
     1.5  
     1.6  
     1.7 +-- Configuration of lf4rcs
     1.8 +-- ------------------------------------------------------------------------
     1.9 +config.lf4rc = {}
    1.10 +
    1.11 +-- Example configuration for controlling a Git repository
    1.12 +config.lf4rcs.git = {
    1.13 +  
    1.14 +  render_draft_reference = function(url, draft)
    1.15 +    if not draft.external_reference then return end
    1.16 +    ui.tag{ content = _"Changeset:" }
    1.17 +    slot.put(" ")
    1.18 +    ui.link{
    1.19 +      text = draft.external_reference,
    1.20 +      external = url .. ";a=commit;h=" .. draft.external_reference
    1.21 +    }
    1.22 +  end,
    1.23 +  
    1.24 +  get_remote_user = function()
    1.25 +    return os.getenv("REMOTE_USER")
    1.26 +  end,
    1.27 +  
    1.28 +  get_branches = function(path, exec)
    1.29 +    local branches = {}
    1.30 +    for line in io.lines() do
    1.31 +      local oldrev, newrev, branch = string.match(line, "([^ ]+) ([^ ]+) refs/heads/(.+)")
    1.32 +      if not branch then
    1.33 +        return nil, "unexpected format from git hook environment"
    1.34 +      end
    1.35 +      branches[branch] = { newrev }
    1.36 +    end
    1.37 +    return branches
    1.38 +  end,
    1.39 +  
    1.40 +  commit = function(path, exec, branch, target_node_id, close_message, merge_message)
    1.41 +    if merge_message then
    1.42 +      -- TODO reset on error
    1.43 +      exec("git", "-C", path, "checkout", "master")
    1.44 +      exec("git", "-C", path, "merge", target_node_id, "-m", merge_message)
    1.45 +      exec("git", "-C", path, "push", "origin", "master")
    1.46 +    end
    1.47 +  end
    1.48 +
    1.49 +}
    1.50 +
    1.51 +-- Example configuration for controlling a Mercurial repository
    1.52 +config.lf4rcs.hg = {
    1.53 +
    1.54 +  working_branch_name = "work",
    1.55 +
    1.56 +  render_draft_reference = function(url, draft)
    1.57 +    if not draft.external_reference then return end
    1.58 +    ui.tag{ content = _"Changeset graph:" }
    1.59 +    slot.put(" ")
    1.60 +    ui.link{
    1.61 +      text = draft.external_reference,
    1.62 +      external = url .. "/graph/" .. draft.external_reference
    1.63 +    }
    1.64 +  end,
    1.65 +  
    1.66 +  get_remote_user = function()
    1.67 +    return os.getenv("REMOTE_USER")
    1.68 +  end,
    1.69 +  
    1.70 +  get_branches = function(path, exec)
    1.71 +    local first_node_id = os.getenv("HG_NODE")
    1.72 +    if not first_node_id then
    1.73 +      return nil, "internal error, no first node ID available"
    1.74 +    end
    1.75 +    local hg_log = exec(
    1.76 +      "hg", "log", "-R", path, "-r", first_node_id .. ":", "--template", "{branches}\n"
    1.77 +    )
    1.78 +    local branches = {}
    1.79 +    for branch in hg_log:gmatch("(.-)\n") do
    1.80 +      if branch == "" then branch = "default" end
    1.81 +      if not branches[branch] then
    1.82 +        branches[branch] = {}
    1.83 +        local head_lines = exec(
    1.84 +          "hg", "heads", "-R", path, "--template", "{node}\n", branch
    1.85 +        )
    1.86 +        for node_id in string.gmatch(head_lines, "[^\n]+") do
    1.87 +          table.insert(branches[branch], node_id)
    1.88 +        end
    1.89 +      end
    1.90 +    end
    1.91 +    return branches
    1.92 +  end,
    1.93 +
    1.94 +  extra_checks = function(path, exec)
    1.95 +    local result = exec("hg", "heads", "-t", "-c")
    1.96 +    for branch in string.gmatch(result, "[^\n]+") do
    1.97 +      if branch == lf4rcs.config.hg.working_branch_name then
    1.98 +        return nil, "open head found for branch " .. lf4rcs.config.hg.working_branch_name
    1.99 +      end
   1.100 +    end
   1.101 +    return true
   1.102 +  end,
   1.103 +
   1.104 +  commit = function(path, exec, branch, target_node_id, close_message, merge_message)
   1.105 +    exec("hg", "up", "-R", path, "-C", "-r", target_node_id)
   1.106 +    exec("hg", "commit", "-R", path, "--close-branch", "-m", close_message)
   1.107 +    if merge_message then
   1.108 +      exec("hg", "up", "-R", path, "-C", "-r", "default")
   1.109 +      exec("hg", "merge", "-R", path, "-r", "tip")
   1.110 +      exec("hg", "commit", "-R", path, "-m", merge_message)
   1.111 +    end
   1.112 +  end
   1.113 +  
   1.114 +}
   1.115 +
   1.116 +lf4rcs.init()
   1.117 +
   1.118 +
   1.119  -- External references
   1.120  -- ------------------------------------------------------------------------
   1.121  -- Rendering of external references

Impressum / About Us