liquid_feedback_frontend

view env/lf4rcs/update_references.lua @ 1230:02772bc49467

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

Impressum / About Us