blob: 6791c14363267bfb017f46db284a3f5dc834ebb5 [file] [log] [blame]
function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in inputstr:gmatch("([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
core.register_action("set_repo_name", { "http-req" }, function(txn)
local requestPath = txn.sf:path()
local pp = mysplit(requestPath, "/")
local queryString = txn.sf:query()
local has_srv = string.find(queryString, "service=git-")
local git = has_srv ~= nil
local e = has_srv ~= nil and #pp-2 or #pp-1
if pp[#pp] == "git-upload-pack" or pp[#pp] == "git-recieve-pack" then
git = true
end
local s = 1
if pp[1] == 'a' or pp[1] == 'p' then
s = 2
end
local repo = ""
if git then
for k = s, e, 1 do
repo = repo.."/"..pp[k]
end
else
if pp[s] == "changes" or pp[s] == "projects" then
repo = "/"
if pp[s+1] ~= nil then
repo = "/"..pp[s+1]
end
local sep = string.find(repo, "~")
if sep ~= nil then
repo = string.sub(repo, 1, sep - 1)
end
repo = repo:gsub("%%2F", "/")
repo = repo:gsub("%%2f", "/")
end
end
if repo == "" then
repo = requestPath
end
txn.http:req_set_header("Gerrit-Project", repo)
end)