blob: 8c5405308038daa86c320de248955706cc3b3c9d [file] [log] [blame]
natalie84417e82024-10-11 16:57:50 +08001
2function mysplit(inputstr, sep)
3 if sep == nil then
4 sep = "%s"
5 end
6 local t = {}
7 for str in inputstr:gmatch("([^"..sep.."]+)") do
8 table.insert(t, str)
9 end
10 return t
11end
12
13core.register_action("set_repo_name", { "http-req" }, function(txn)
14 local requestPath = txn.sf:path()
15 local pp = mysplit(requestPath, "/")
natalie48da1682024-11-12 10:21:51 +080016 local queryString = txn.sf:query()
natalie84417e82024-10-11 16:57:50 +080017 local has_srv = string.find(queryString, "service=git-")
18 local git = has_srv ~= nil
19 local e = has_srv ~= nil and #pp-2 or #pp-1
20 if pp[#pp] == "git-upload-pack" or pp[#pp] == "git-recieve-pack" then
natalie48da1682024-11-12 10:21:51 +080021 git = true
natalie84417e82024-10-11 16:57:50 +080022 end
23 local s = 1
24 if pp[1] == 'a' or pp[1] == 'p' then
natalie48da1682024-11-12 10:21:51 +080025 s = 2
natalie84417e82024-10-11 16:57:50 +080026 end
27 local repo = ""
28 if git then
29 for k = s, e, 1 do
30 repo = repo.."/"..pp[k]
31 end
32 else
33 if pp[s] == "changes" or pp[s] == "projects" then
nataliee4ad4e52024-11-01 15:29:31 +080034 repo = "/"
35 if pp[s+1] ~= nil then
36 repo = "/"..pp[s+1]
37 end
natalie84417e82024-10-11 16:57:50 +080038 core.Info(repo)
39 local sep = string.find(repo, "~")
40 if sep ~= nil then
41 repo = string.sub(repo, 1, sep - 1)
42 end
43 repo = repo:gsub("%%2F", "/")
44 repo = repo:gsub("%%2f", "/")
45 end
46 end
47 if repo == "" then
48 repo = requestPath
49 end
50 txn.http:req_set_header("Gerrit-Project", repo)
51 end)
52