liquid_feedback_frontend
view env/lf4rcs/commit.lua @ 1219:30523f31b186
Added lf4rcs module and example configuration
| author | bsw | 
|---|---|
| date | Mon Nov 30 19:40:38 2015 +0100 (2015-11-30) | 
| parents | |
| children | af42478acf74 | 
 line source
     1 function lf4rcs.commit(issue)
     2   local repository, path, url = lf4rcs.get_config(issue.area.unit)
     3   if not (config.lf4rcs[repository] and config.lf4rcs[repository].commit) then
     4     error("Unsupported repository type")
     5   end
     6   local initiatives = Initiative:new_selector()
     7     :add_where{ "issue_id = ?", issue.id }
     8     :exec()
     9   for i, initiative in ipairs(initiatives) do
    10     local function exec(...)
    11       local command, output, err_message, exit_code = lf4rcs.exec(...)
    12       local log = "Executed: " .. command .. "\n"
    13       if output then
    14         log = log .. output .. "\n"
    15       end
    16       if err_message and #err_message > 0 then
    17         log = log .. "ERROR: " .. err_message .. "\n"
    18       end
    19       if exit_code and exit_code ~= 0 then
    20         log = log .. "Exit code: " .. tostring(exit_code) .. "\n"
    21       end
    22       issue.admin_notice = (issue.admin_notice or "") .. log
    23       issue:save()
    24     end
    25     local close_message, merge_message
    26     if initiative.winner then
    27       close_message = "Initiative i" .. initiative.id
    28                       .. " accepted as winner. Closing branch."
    29       merge_message = "Initiative i" .. initiative.id 
    30                       .. " accepted as winner. Applying branch changesets to upstream."
    31     else
    32       close_message = "Initiative i" .. initiative.id .. " rejected. Closing branch."
    33     end
    34     local target_node_id = initiative.current_draft.external_reference
    35     if target_node_id then
    36       local branch = "i" .. initiative.id
    37       lf4rcs[repository].commit(path, exec, branch, target_node_id, close_message, merge_message)
    38     end
    39   end
    40 end
