Skip to content

Commit

Permalink
Fix Repo URLs (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsturgeon committed Oct 6, 2023
1 parent d42cf93 commit 1d1164b
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions moon/cfc_err_forwarder/formatter/get_source_url.moon
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,60 @@ publicGamemodes = {

-- source:
-- addons/acf-3/lua/entities/acf_armor/shared.lua
-- addons/cfc_pvp/lua/cfc_pvp/plugins/server/acf_caliber_limits.lua
-- gamemodes/sandbox/entities/weapons/gmod_tool/stools/duplicator/transport.lua
--
-- line: Just a number, nothing crazy
-- line: Just a line number
(source, line) ->
-- { "addons", "acf-3", "lua", "entities", "acf_armor", "shared.lua" }
-- { "gamemodes", "sandbox", "entities", "weapons", "gmod_tool", "stools", "duplicator", "transport.lua" }
sourceSpl = string.Split source, "/"

if sourceSpl[1] == "gamemodes"
root = sourceSpl[1]
mainDir = sourceSpl[2]

if root == "gamemodes"
return "https://github.com/Facepunch/garrysmod/blob/master/garrysmod/#{source}#L#{line}"

if sourceSpl[1] == "addons"
fetchPath = "addons/#{sourceSpl[2]}/.git/FETCH_HEAD", "GAME"
assert root == "addons"

fetchPath = "addons/#{mainDir}/.git/FETCH_HEAD", "GAME"
return unless file.Exists fetchPath, "GAME"

content = file.Read fetchPath, "GAME"

-- 6679969ce1b0f6baa80dc4460beb7004f3197408 branch 'master' of github.com:Stooberton/ACF-3
-- 6679969ce1b0f6baa80dc4460beb7004f3197408 branch 'master' of https://github.com/Stooberton/ACF-3
-- 6679969ce1b0f6baa80dc4460beb7004f3197408 branch 'master' of https://github.com/stooberton/acf-3.git
firstLine = string.Split(content, "\n")[1]

-- "master", "github.com:Stooberton/ACF-3"
-- "master", "https://github.com/Stooberton/ACF-3"
-- "master", "https://github.com/Stooberton/acf-3.git"
_, _, branch, repo = string.find firstLine, "branch '(.+)' of (.+)$"

return unless file.Exists fetchPath, "GAME"
-- "github.com/Stooberton/ACF-3"
repo = string.Replace repo, "https://", ""
repo = string.Replace repo, "http://", ""
repo = string.Replace repo, ":", "/"
repo = string.Replace repo, ".git", ""

content = file.Read fetchPath, "GAME"
firstLine = string.Split(content, "\n")[1]
-- { "github.com", "Stooberton", "ACF-3" }
repoSpl = string.Split repo, "/"

_, _, branch, repo = string.find firstLine, "branch '(.+)' of (.+)$"
-- "github.com"
host = repoSpl[1]

repo = string.Replace repo, "https://", ""
repo = string.Replace repo, "http://", ""
repo = string.Replace repo, ":", "/"
-- "Stooberton"
owner = repoSpl[2]

repoSpl = string.Split repo, "/"
host = repoSpl[1]
owner = repoSpl[2]
project = repoSpl[3]
-- "ACF-3"
project = repoSpl[3]

finalPath = table.concat sourceSpl, "/", 3, #sourceSpl
finalPath ..= "#L#{line}"
-- "lua/entities/acf_armor/shared.lua"
-- "sandbox/entities/waepons/gmod_stool/stools/duplicator/transport.lua"
finalPath = table.concat sourceSpl, "/", 3, #sourceSpl
finalPath ..= "#L#{line}"

finalURL = string.format "https://%s/%s/%s/blob/%s/%s", host, owner, project, branch, finalPath
finalURL = string.format "https://%s/%s/%s/blob/%s/%s", host, owner, project, branch, finalPath

return finalURL
return finalURL

0 comments on commit 1d1164b

Please sign in to comment.