liquid_feedback_frontend

annotate env/lf4rcs/update_references.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 7f818548b7b8
rev   line source
bsw@1219 1 function lf4rcs.update_references(repository, path, unit_id)
bsw@1219 2 local function log(message)
bsw@1219 3 print(lf4rcs.log_prefix .. message)
bsw@1219 4 end
bsw@1219 5 if not config.lf4rcs[repository]
bsw@1219 6 or not config.lf4rcs[repository].get_remote_user
bsw@1219 7 or not config.lf4rcs[repository].get_branches
bsw@1219 8 then
bsw@1219 9 log("Unsupported repository type")
bsw@1219 10 os.exit(1)
bsw@1219 11 end
bsw@1219 12 log("inspecting changesets")
bsw@1219 13 local remote_user = config.lf4rcs[repository].get_remote_user()
bsw@1219 14 local function abort(message)
bsw@1219 15 log("TEST FAILED: " .. message)
bsw@1219 16 log("ABORTING and ROLLBACK due to failed test.")
bsw@1219 17 db:query("ROLLBACK")
bsw@1219 18 os.exit(1)
bsw@1219 19 end
bsw@1219 20 db:query("BEGIN")
bsw@1219 21 local member = Member:new_selector()
bsw@1219 22 :add_where{ "login = ?", remote_user }
bsw@1219 23 :optional_object_mode()
bsw@1219 24 :exec()
bsw@1219 25 if not member then
bsw@1219 26 abort(
bsw@1219 27 "internal error, member '"
bsw@1219 28 .. remote_user .. "' not found in database"
bsw@1219 29 )
bsw@1219 30 end
bsw@1219 31 local function exec(...)
bsw@1219 32 local command, output, err_message, exit_code = lf4rcs.exec(...)
bsw@1219 33 if not output then
bsw@1219 34 log("Could not execute: " .. command)
bsw@1219 35 abort(err_message)
bsw@1219 36 end
bsw@1219 37 if exit_code ~= 0 then
bsw@1219 38 log("Could not execute: " .. command)
bsw@1219 39 abort("Exit code: " .. tostring(exit_code))
bsw@1219 40 end
bsw@1219 41 return output
bsw@1219 42 end
bsw@1219 43 if config.lf4rcs[repository].extra_checks then
bsw@1219 44 local success, err_message = config.lf4rcs[repository].extra_checks(path, exec)
bsw@1219 45 if not success then
bsw@1219 46 abort(err_message)
bsw@1219 47 end
bsw@1219 48 end
bsw@1219 49 local branches, err = config.lf4rcs[repository].get_branches(path, exec)
bsw@1219 50 if not branches then abort(err) end
bsw@1219 51 for branch, head_node_ids in pairs(branches) do
bsw@1219 52 log('checking branch ' .. branch)
bsw@1219 53 if branch ~= config.lf4rcs[repository].working_branch_name then
bsw@1219 54 local initiative_id = string.match(branch, "^i([0-9]+)$")
bsw@1219 55 if not initiative_id
bsw@1219 56 or initiative_id ~= tostring(tonumber(initiative_id))
bsw@1219 57 then
bsw@1219 58 abort("this branch name is not allowed")
bsw@1219 59 end
bsw@1219 60 initiative_id = tonumber(initiative_id)
bsw@1219 61 if #head_node_ids > 1 then
bsw@1219 62 abort("number of heads found for branch is greater than 1: " .. #head_node_ids)
bsw@1219 63 end
bsw@1219 64 local initiative = Initiative:by_id(initiative_id)
bsw@1219 65 if not initiative then
bsw@1219 66 abort("initiative i" .. initiative_id .. " not found" )
bsw@1219 67 end
bsw@1219 68 if initiative.issue.area.unit_id ~= tonumber(unit_id) then
bsw@1219 69 abort("initiative belongs to another unit (unit ID " .. initiative.issue.area.unit_id .. ")")
bsw@1219 70 end
bsw@1219 71 if initiative.issue.state ~= "admission" and initiative.issue.state ~= "discussion" then
bsw@1219 72 abort("issue is already frozen or closed (" .. initiative.issue.state .. ")")
bsw@1219 73 end
bsw@1219 74 if initiative.revoked then
bsw@1219 75 abort("initiative has been revoked")
bsw@1219 76 end
bsw@1219 77 local initiator = Initiator:by_pk(initiative.id, member.id)
bsw@1219 78 if not initiator then
bsw@1219 79 abort("member is not initiator of initiative i" .. initiative_id)
bsw@1219 80 end
bsw@1219 81 if not initiator.accepted then
bsw@1219 82 abort(
bsw@1219 83 "member has not accepted invitation to become initiator of initiative i"
bsw@1219 84 .. initiative_id
bsw@1219 85 )
bsw@1219 86 end
bsw@1219 87 local node_id = head_node_ids[1] or false
bsw@1219 88 if node_id then
bsw@1219 89 log("adding node " .. node_id .. " to initiative i" .. initiative_id)
bsw@1219 90 else
bsw@1219 91 log("removing node reference from initiative i" .. initiative_id)
bsw@1219 92 end
bsw@1219 93 Draft:update_content(member.id, initiative_id, nil, nil, node_id)
bsw@1219 94 end
bsw@1219 95 end
bsw@1219 96 log("changes cleared. continue committing.")
bsw@1219 97 db:query("COMMIT")
bsw@1219 98 os.exit(0)
bsw@1219 99 end
bsw@1219 100

Impressum / About Us