| rev | 
   line source | 
| 
bsw@1656
 | 
     1 -- Configuration of lf4rcs
 | 
| 
bsw@1656
 | 
     2 -- ------------------------------------------------------------------------
 | 
| 
bsw@1656
 | 
     3 config.lf4rcs = {}
 | 
| 
bsw@1656
 | 
     4 
 | 
| 
bsw@1656
 | 
     5 -- Example configuration for controlling a Git repository
 | 
| 
bsw@1656
 | 
     6 
 | 
| 
bsw@1656
 | 
     7 config.lf4rcs.git = {
 | 
| 
bsw@1656
 | 
     8   
 | 
| 
bsw@1656
 | 
     9   render_draft_reference = function(url, draft)
 | 
| 
bsw@1656
 | 
    10     if not draft.external_reference then return end
 | 
| 
bsw@1656
 | 
    11     ui.tag{ content = _"Changeset:" }
 | 
| 
bsw@1656
 | 
    12     slot.put(" ")
 | 
| 
bsw@1656
 | 
    13     ui.link{
 | 
| 
bsw@1656
 | 
    14       text = draft.external_reference,
 | 
| 
bsw@1656
 | 
    15       external = url .. ";a=commit;h=" .. draft.external_reference
 | 
| 
bsw@1656
 | 
    16     }
 | 
| 
bsw@1656
 | 
    17   end,
 | 
| 
bsw@1656
 | 
    18   
 | 
| 
bsw@1656
 | 
    19   get_remote_user = function()
 | 
| 
bsw@1656
 | 
    20     return os.getenv("REMOTE_USER")
 | 
| 
bsw@1656
 | 
    21   end,
 | 
| 
bsw@1656
 | 
    22   
 | 
| 
bsw@1656
 | 
    23   get_branches = function(path, exec)
 | 
| 
bsw@1656
 | 
    24     local branches = {}
 | 
| 
bsw@1656
 | 
    25     for line in io.lines() do
 | 
| 
bsw@1656
 | 
    26       local oldrev, newrev, branch = string.match(line, "([^ ]+) ([^ ]+) refs/heads/(.+)")
 | 
| 
bsw@1656
 | 
    27       if not branch then
 | 
| 
bsw@1656
 | 
    28         return nil, "unexpected format from git hook environment"
 | 
| 
bsw@1656
 | 
    29       end
 | 
| 
bsw@1656
 | 
    30       branches[branch] = { newrev }
 | 
| 
bsw@1656
 | 
    31     end
 | 
| 
bsw@1656
 | 
    32     return branches
 | 
| 
bsw@1656
 | 
    33   end,
 | 
| 
bsw@1656
 | 
    34   
 | 
| 
bsw@1656
 | 
    35   commit = function(path, exec, branch, target_node_id, close_message, merge_message)
 | 
| 
bsw@1656
 | 
    36     if merge_message then
 | 
| 
bsw@1656
 | 
    37       exec("git", "-C", path, "checkout", "-f", "master")
 | 
| 
bsw@1656
 | 
    38       exec("git", "-C", path, "merge", target_node_id, "-m", merge_message)
 | 
| 
bsw@1656
 | 
    39       exec("git", "-C", path, "push", "origin", "master")
 | 
| 
bsw@1656
 | 
    40     end
 | 
| 
bsw@1656
 | 
    41   end
 | 
| 
bsw@1656
 | 
    42 
 | 
| 
bsw@1656
 | 
    43 }
 | 
| 
bsw@1656
 | 
    44 
 | 
| 
bsw@1656
 | 
    45 -- Example configuration for controlling a Mercurial repository
 | 
| 
bsw@1656
 | 
    46 config.lf4rcs.hg = {
 | 
| 
bsw@1656
 | 
    47 
 | 
| 
bsw@1656
 | 
    48   working_branch_name = "work",
 | 
| 
bsw@1656
 | 
    49 
 | 
| 
bsw@1656
 | 
    50   render_draft_reference = function(url, draft)
 | 
| 
bsw@1656
 | 
    51     if not draft.external_reference then return end
 | 
| 
bsw@1656
 | 
    52     ui.tag{ content = _"Changeset graph:" }
 | 
| 
bsw@1656
 | 
    53     slot.put(" ")
 | 
| 
bsw@1656
 | 
    54     ui.link{
 | 
| 
bsw@1656
 | 
    55       text = draft.external_reference,
 | 
| 
bsw@1656
 | 
    56       external = url .. "/graph/" .. draft.external_reference
 | 
| 
bsw@1656
 | 
    57     }
 | 
| 
bsw@1656
 | 
    58   end,
 | 
| 
bsw@1656
 | 
    59   
 | 
| 
bsw@1656
 | 
    60   get_remote_user = function()
 | 
| 
bsw@1656
 | 
    61     return os.getenv("REMOTE_USER")
 | 
| 
bsw@1656
 | 
    62   end,
 | 
| 
bsw@1656
 | 
    63   
 | 
| 
bsw@1656
 | 
    64   get_branches = function(path, exec)
 | 
| 
bsw@1656
 | 
    65     local first_node_id = os.getenv("HG_NODE")
 | 
| 
bsw@1656
 | 
    66     if not first_node_id then
 | 
| 
bsw@1656
 | 
    67       return nil, "internal error, no first node ID available"
 | 
| 
bsw@1656
 | 
    68     end
 | 
| 
bsw@1656
 | 
    69     local hg_log = exec(
 | 
| 
bsw@1656
 | 
    70       "hg", "log", "-R", path, "-r", first_node_id .. ":", "--template", "{branches}\n"
 | 
| 
bsw@1656
 | 
    71     )
 | 
| 
bsw@1656
 | 
    72     local branches = {}
 | 
| 
bsw@1656
 | 
    73     for branch in hg_log:gmatch("(.-)\n") do
 | 
| 
bsw@1656
 | 
    74       if branch == "" then branch = "default" end
 | 
| 
bsw@1656
 | 
    75       if not branches[branch] then
 | 
| 
bsw@1656
 | 
    76         branches[branch] = {}
 | 
| 
bsw@1656
 | 
    77         local head_lines = exec(
 | 
| 
bsw@1656
 | 
    78           "hg", "heads", "-R", path, "--template", "{node}\n", branch
 | 
| 
bsw@1656
 | 
    79         )
 | 
| 
bsw@1656
 | 
    80         for node_id in string.gmatch(head_lines, "[^\n]+") do
 | 
| 
bsw@1656
 | 
    81           table.insert(branches[branch], node_id)
 | 
| 
bsw@1656
 | 
    82         end
 | 
| 
bsw@1656
 | 
    83       end
 | 
| 
bsw@1656
 | 
    84     end
 | 
| 
bsw@1656
 | 
    85     return branches
 | 
| 
bsw@1656
 | 
    86   end,
 | 
| 
bsw@1656
 | 
    87 
 | 
| 
bsw@1656
 | 
    88   extra_checks = function(path, exec)
 | 
| 
bsw@1656
 | 
    89     local result = exec("hg", "heads", "-t", "-c")
 | 
| 
bsw@1656
 | 
    90     for branch in string.gmatch(result, "[^\n]+") do
 | 
| 
bsw@1656
 | 
    91       if branch == lf4rcs.config.hg.working_branch_name then
 | 
| 
bsw@1656
 | 
    92         return nil, "open head found for branch " .. lf4rcs.config.hg.working_branch_name
 | 
| 
bsw@1656
 | 
    93       end
 | 
| 
bsw@1656
 | 
    94     end
 | 
| 
bsw@1656
 | 
    95     return true
 | 
| 
bsw@1656
 | 
    96   end,
 | 
| 
bsw@1656
 | 
    97 
 | 
| 
bsw@1656
 | 
    98   commit = function(path, exec, branch, target_node_id, close_message, merge_message)
 | 
| 
bsw@1656
 | 
    99     exec("hg", "up", "-R", path, "-C", "-r", target_node_id)
 | 
| 
bsw@1656
 | 
   100     exec("hg", "commit", "-R", path, "--close-branch", "-m", close_message)
 | 
| 
bsw@1656
 | 
   101     if merge_message then
 | 
| 
bsw@1656
 | 
   102       exec("hg", "up", "-R", path, "-C", "-r", "default")
 | 
| 
bsw@1656
 | 
   103       exec("hg", "merge", "-R", path, "-r", "tip")
 | 
| 
bsw@1656
 | 
   104       exec("hg", "commit", "-R", path, "-m", merge_message)
 | 
| 
bsw@1656
 | 
   105     end
 | 
| 
bsw@1656
 | 
   106   end
 | 
| 
bsw@1656
 | 
   107   
 | 
| 
bsw@1656
 | 
   108 }
 | 
| 
bsw@1656
 | 
   109 
 | 
| 
bsw@1656
 | 
   110 -- Grace period after creating an initiative for pushing changes during verification phase
 | 
| 
bsw@1656
 | 
   111 -- disabled by default (nil), use PostgreSQL interval notation
 | 
| 
bsw@1656
 | 
   112 -- config.lf4rcs.push_grace_period = nil
 | 
| 
bsw@1656
 | 
   113 
 | 
| 
bsw@1656
 | 
   114 lf4rcs.init()
 | 
| 
bsw@1656
 | 
   115 
 |