liquid_feedback_frontend

annotate env/lf4rcs/update_references.lua @ 1235:7f818548b7b8

Added push grace period for verification phase to lf4rcs
author bsw
date Fri Dec 04 14:25:43 2015 +0100 (2015-12-04)
parents 30523f31b186
children 4204e1185f66
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@1235 72 if initiative.issue.state == "verification" then
bsw@1235 73 if config.lf4rcs.push_grace_period
bsw@1235 74 local in_push_grace_period = Initiative:new_selector()
bsw@1235 75 :reset_fields()
bsw@1235 76 :add_field({ "now() - initiative.created_at <= ?", config.lf4rcs.push_grace_period }, "in_push_grace_period")
bsw@1235 77 :add_where{ "id = ?", initiative.id }
bsw@1235 78 :single_object_mode()
bsw@1235 79 :exec()).in_push_grace_period
bsw@1235 80 if not in_push_period then
bsw@1235 81 abort("issue is already frozen and the push grace period is expired")
bsw@1235 82 end
bsw@1235 83 else
bsw@1235 84 abort("issue is already frozen")
bsw@1235 85 end
bsw@1235 86 else
bsw@1235 87 abort("issue is already closed (" .. initiative.issue.state .. ")")
bsw@1235 88 end
bsw@1219 89 end
bsw@1219 90 if initiative.revoked then
bsw@1219 91 abort("initiative has been revoked")
bsw@1219 92 end
bsw@1219 93 local initiator = Initiator:by_pk(initiative.id, member.id)
bsw@1219 94 if not initiator then
bsw@1219 95 abort("member is not initiator of initiative i" .. initiative_id)
bsw@1219 96 end
bsw@1219 97 if not initiator.accepted then
bsw@1219 98 abort(
bsw@1219 99 "member has not accepted invitation to become initiator of initiative i"
bsw@1219 100 .. initiative_id
bsw@1219 101 )
bsw@1219 102 end
bsw@1219 103 local node_id = head_node_ids[1] or false
bsw@1219 104 if node_id then
bsw@1219 105 log("adding node " .. node_id .. " to initiative i" .. initiative_id)
bsw@1219 106 else
bsw@1219 107 log("removing node reference from initiative i" .. initiative_id)
bsw@1219 108 end
bsw@1219 109 Draft:update_content(member.id, initiative_id, nil, nil, node_id)
bsw@1219 110 end
bsw@1219 111 end
bsw@1219 112 log("changes cleared. continue committing.")
bsw@1219 113 db:query("COMMIT")
bsw@1219 114 os.exit(0)
bsw@1219 115 end
bsw@1219 116

Impressum / About Us